:root {
  --primary: #0d6efd;
  --bg: #f4f7fb;
  --card: #ffffff;
  --border: #dfe6ee;
  --text: #1f2a37;
  --muted: #6b7686;
  --danger: #dc3545;
  --success: #198754;
}
* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body { margin: 0; font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
#app { display: flex; min-height: 100vh; width: 100%; max-width: 100%; }

.login-wrap { display:flex; align-items:center; justify-content:center; width:100%; padding: 16px; }
.login-card { background: var(--card); padding: 40px; border-radius: 12px; box-shadow: 0 4px 20px rgba(0,0,0,.08); width: min(340px, 100%); }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p.sub { color: var(--muted); font-size: 13px; margin-top:0; margin-bottom: 24px; }
input, select, textarea, button { font-family: inherit; font-size: 14px; }
input, select, textarea { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 12px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea { margin-bottom: 0; }
button { cursor: pointer; border: none; border-radius: 8px; padding: 10px 16px; background: var(--primary); color: white; font-weight: 600; }
button.secondary { background: #eef2f7; color: var(--text); }
button.danger { background: var(--danger); }
.error-msg { color: var(--danger); font-size: 13px; margin-bottom: 10px; }

.sidebar { width: 220px; background: #101828; color: white; padding: 20px 0; flex-shrink: 0; }
.sidebar h2 { font-size: 15px; padding: 0 20px; margin-bottom: 20px; }
.sidebar a { display: block; padding: 10px 20px; color: #cbd5e1; text-decoration: none; font-size: 14px; }
.sidebar a.active, .sidebar a:hover { background: #1d2939; color: white; }
.sidebar .user-box { padding: 12px 20px; border-top: 1px solid #1d2939; margin-top: 20px; font-size: 12px; color: #9aa5b1; }

.main { flex: 1; padding: 28px 32px; overflow-y: auto; min-width: 0; }
.main h1 { font-size: 22px; margin-bottom: 20px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 20px; margin-bottom: 20px; overflow-x: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
table { width: 100%; border-collapse: collapse; min-width: 480px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--muted); font-weight: 600; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.badge.ok { background: #d1fae5; color: #065f46; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.danger { background: #fee2e2; color: #991b1b; }
.toolbar { display:flex; justify-content: space-between; align-items:center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.kpi { font-size: 26px; font-weight: 700; }
.kpi-label { color: var(--muted); font-size: 12px; }
.tooth-grid { display: grid; grid-template-columns: repeat(16, 1fr); gap: 4px; margin: 20px 0; }
.tooth { border: 1px solid var(--border); border-radius: 6px; text-align: center; padding: 6px 2px; font-size: 10px; cursor: pointer; background: white; }
.tooth.caries { background: #fee2e2; }
.tooth.obturado { background: #dbeafe; }
.tooth.ausente { background: #e5e7eb; color: #9ca3af; }
.tooth.corona { background: #fef3c7; }

/* ---- Modales: centrados, con limite de ancho/alto y scroll interno ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  z-index: 49; display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto; padding: 24px 12px;
}
.modal-box {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  z-index: 50;
  margin: 0 auto;
}

/* ---- Menu lateral: fijo en pantallas grandes, hamburguesa en moviles ---- */
.mobile-topbar { display: none; }
.sidebar-overlay { display: none; }

@media (max-width: 900px) {
  #app { flex-direction: column; }
  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: #101828; color: white; padding: 14px 16px; position: sticky; top: 0; z-index: 40;
  }
  .mobile-topbar h2 { font-size: 15px; margin: 0; }
  .hamburger-btn {
    background: none; border: none; color: white; font-size: 22px; padding: 4px 8px; cursor: pointer;
  }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 240px; z-index: 60;
    transform: translateX(-100%); transition: transform 0.2s ease-in-out;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 55;
  }
  .main { padding: 18px 14px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar button { width: 100%; }
  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal-box { max-width: 100%; max-height: 100vh; border-radius: 0; min-height: 100vh; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}
