:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #6c7689;
  --line: #e4e8f0;
  --primary: #0f766e;
  --primary-dark: #0a5f59;
  --accent: #cee36f;
  --danger: #dc2626;
  --shadow: 0 18px 45px rgba(23, 32, 51, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  display: flex;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.sidebar {
  width: 290px;
  background: #0e1726;
  color: white;
  padding: 24px;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 34px;
}

.brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #4ade80);
  color: #0e1726;
  font-weight: 900;
}

.brand h1 { font-size: 18px; margin: 0; }
.brand p { margin: 2px 0 0; color: #aab4c5; font-size: 13px; }

nav { display: grid; gap: 8px; }

.nav-btn {
  border: 0;
  background: transparent;
  color: #d7deeb;
  text-align: left;
  padding: 13px 14px;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 700;
}

.nav-btn:hover, .nav-btn.active {
  background: rgba(206, 227, 111, 0.14);
  color: white;
}

.sidebar-footer {
  margin-top: auto;
  color: #aab4c5;
  font-size: 13px;
  border-top: 1px solid rgba(255,255,255,.08);
  padding-top: 20px;
}

.sidebar-footer p { margin: 0 0 4px; color: white; font-weight: 700; }

.main {
  margin-left: 290px;
  width: calc(100% - 290px);
  padding: 28px;
}

.mobile-header {
  display: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 24px;
}

.topbar h2 { margin: 0; font-size: 30px; }
.topbar p { margin: 6px 0 0; color: var(--muted); }

.section { display: none; }
.section.active { display: block; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 18px;
  margin-bottom: 22px;
}

.stat-card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.stat-card { padding: 22px; }
.stat-card span { color: var(--muted); font-weight: 700; font-size: 14px; }
.stat-card strong { display: block; font-size: 32px; margin-top: 8px; }

.panel { padding: 22px; }
.panel h3 { margin: 0 0 16px; }
.panel p { color: var(--muted); }

.split {
  display: grid;
  grid-template-columns: 390px 1fr;
  gap: 22px;
  align-items: start;
}

.form-panel { display: grid; gap: 14px; }

label {
  display: grid;
  gap: 7px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px 13px;
  font: inherit;
  outline: none;
  background: #fff;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, .1);
}

.primary-btn, .secondary-btn, .danger-btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 15px;
  cursor: pointer;
  font-weight: 800;
}

.primary-btn { background: var(--primary); color: white; }
.primary-btn:hover { background: var(--primary-dark); }
.secondary-btn { background: #eef2f7; color: var(--text); }
.danger-btn { background: #fee2e2; color: var(--danger); }

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
}

.panel-head h3, .panel-head p { margin: 0; }
.panel-head input, .panel-head select { max-width: 300px; }

.list { display: grid; gap: 12px; }

.item {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 15px;
  background: #fff;
}

.item-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

.item h4 { margin: 0 0 5px; }
.item p { margin: 4px 0; color: var(--muted); }

.item-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 900;
  background: #ecfeff;
  color: var(--primary);
}

.badge.warning { background: #fff7ed; color: #c2410c; }
.badge.danger { background: #fef2f2; color: var(--danger); }

.legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 18px 0;
}

.legend-btn {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 10px 13px;
  cursor: pointer;
  font-weight: 800;
}

.legend-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.teeth-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.tooth {
  border: 2px solid var(--line);
  min-height: 70px;
  border-radius: 18px;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-weight: 900;
  background: white;
  transition: transform .15s ease, box-shadow .15s ease;
}

.tooth:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.tooth.healthy { background: #ffffff; }
.tooth.caries { background: #fee2e2; border-color: var(--danger); }
.tooth.restoration { background: #dbeafe; border-color: #2563eb; }
.tooth.missing { background: #e5e7eb; border-color: #6b7280; color: #6b7280; }
.tooth.ortho { background: #ede9fe; border-color: #7c3aed; }
.tooth.pending { background: #fef3c7; border-color: #f59e0b; }

.overlay {
  display: none;
}

/* Responsive tablets */
@media (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .split {
    grid-template-columns: 1fr;
  }

  .teeth-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* Responsive móvil */
@media (max-width: 760px) {
  body {
    display: block;
  }

  .mobile-header {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 15;
    align-items: center;
    gap: 12px;
    background: #0e1726;
    color: white;
    padding: 14px 16px;
    margin: -16px -16px 18px;
  }

  .menu-btn {
    border: 0;
    background: rgba(255,255,255,.12);
    color: white;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    font-size: 22px;
    cursor: pointer;
  }

  .sidebar {
    transform: translateX(-105%);
    transition: transform .25s ease;
    width: 82%;
    max-width: 330px;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .overlay.show {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(3, 7, 18, .48);
    z-index: 18;
  }

  .main {
    margin-left: 0;
    width: 100%;
    padding: 16px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar h2 {
    font-size: 25px;
  }

  .topbar .primary-btn {
    width: 100%;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stat-card, .panel {
    border-radius: 18px;
  }

  .panel {
    padding: 16px;
  }

  .panel-head {
    flex-direction: column;
  }

  .panel-head input, .panel-head select {
    max-width: none;
  }

  .item-head {
    flex-direction: column;
  }

  .item-actions button {
    flex: 1;
  }

  .teeth-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 9px;
  }

  .tooth {
    min-height: 58px;
    border-radius: 14px;
  }

  .legend-btn {
    flex: 1 1 calc(50% - 10px);
  }
}

/* Móvil pequeño */
@media (max-width: 420px) {
  .teeth-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .brand h1 {
    font-size: 16px;
  }

  .stat-card strong {
    font-size: 28px;
  }
}


input[readonly] {
  background: #f8fafc;
  color: var(--muted);
  cursor: not-allowed;
}

.specialist-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  background: #f1f5f9;
  color: #334155;
  font-size: 12px;
  font-weight: 800;
}


.hidden {
  display: none !important;
}

.patient-profile {
  margin-top: 22px;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 16px;
}

.profile-grid article {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  background: #fff;
}

.profile-grid h4 {
  margin: 0 0 10px;
}

.mini-list {
  display: grid;
  gap: 8px;
}

.mini-item {
  border-radius: 14px;
  background: #f8fafc;
  padding: 11px;
  border: 1px solid #eef2f7;
}

.mini-item p {
  margin: 3px 0;
}

.balance-box {
  border: 1px dashed var(--primary);
  border-radius: 14px;
  padding: 12px;
  background: #f0fdfa;
  color: #134e4a;
  font-weight: 800;
}

.appointment-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.appointment-actions button {
  flex: 1 1 120px;
}

@media (max-width: 760px) {
  .profile-grid {
    grid-template-columns: 1fr;
  }

  .appointment-actions {
    flex-direction: column;
  }

  .appointment-actions button {
    width: 100%;
  }
}


.quick-help {
  border-radius: 14px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.quick-help strong {
  color: var(--text);
}


.session-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-pill {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 10px 13px;
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
}

.logout-btn {
  text-decoration: none;
  border-radius: 14px;
  padding: 12px 15px;
  background: #fee2e2;
  color: #b91c1c;
  font-weight: 900;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at top left, rgba(206, 227, 111, .35), transparent 35%),
    linear-gradient(135deg, #0e1726, #0f766e);
}

.login-card {
  width: min(440px, 100%);
  background: white;
  border-radius: 28px;
  padding: 30px;
  box-shadow: 0 28px 80px rgba(3, 7, 18, .32);
}

.login-logo {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #4ade80);
  color: #0e1726;
  font-weight: 1000;
  margin-bottom: 16px;
}

.login-card h1 {
  margin: 0;
  font-size: 28px;
}

.login-card p {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.login-error {
  border-radius: 14px;
  background: #fef2f2;
  color: #b91c1c;
  padding: 12px;
  font-weight: 800;
}

.login-note {
  margin-top: 14px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid var(--line);
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 760px) {
  .session-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .session-actions > * {
    width: 100%;
    text-align: center;
  }
}


/* Mejoras visuales para login e instalación */
body.login-body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    radial-gradient(circle at 15% 10%, rgba(206, 227, 111, .35), transparent 30%),
    radial-gradient(circle at 85% 20%, rgba(15, 118, 110, .24), transparent 26%),
    linear-gradient(135deg, #f8fafc 0%, #eef7f4 48%, #e9f0ff 100%);
}

.login-card {
  width: min(460px, calc(100vw - 34px));
  background: rgba(255, 255, 255, .96);
  border: 1px solid rgba(226, 232, 240, .95);
  border-radius: 30px;
  padding: 34px;
  box-shadow: 0 28px 90px rgba(15, 23, 42, .16);
  margin: auto;
}

.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #58d68d);
  color: #0e1726;
  font-weight: 1000;
  margin: 0 auto 18px;
  letter-spacing: -.5px;
}

.login-card h1 {
  margin: 0;
  text-align: center;
  font-size: clamp(28px, 5vw, 36px);
  letter-spacing: -.8px;
}

.login-card > p {
  text-align: center;
  margin: 10px 0 0;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 15px;
  margin-top: 26px;
}

.login-form label {
  font-size: 13px;
}

.login-form input {
  min-height: 48px;
  border-radius: 16px;
  background: #fff;
}

.login-form .primary-btn,
.login-card .primary-btn {
  min-height: 48px;
  border-radius: 16px;
  width: 100%;
  display: inline-grid;
  place-items: center;
  text-decoration: none;
}

.login-error {
  margin-top: 18px;
  border-radius: 16px;
  background: #fff1f2;
  border: 1px solid #fecdd3;
  color: #9f1239;
  padding: 13px 14px;
  font-weight: 800;
  line-height: 1.4;
}

.login-note {
  margin-top: 16px;
  border-radius: 16px;
  background: #f8fafc;
  border: 1px solid var(--line);
  padding: 13px 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.db-help {
  margin-top: 14px;
  border-radius: 16px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  padding: 13px 14px;
  font-size: 13px;
  line-height: 1.45;
}

.db-help code {
  background: rgba(154, 52, 18, .08);
  border-radius: 8px;
  padding: 2px 6px;
}

@media (max-width: 520px) {
  body.login-body {
    padding: 14px;
  }

  .login-card {
    padding: 24px;
    border-radius: 24px;
  }
}


.success-box {
  margin-top: 18px;
  border-radius: 16px;
  background: #ecfdf5;
  border: 1px solid #bbf7d0;
  color: #166534;
  padding: 13px 14px;
  font-weight: 900;
  line-height: 1.4;
}

.login-note code,
.db-help code {
  background: rgba(15, 23, 42, .07);
  border-radius: 8px;
  padding: 2px 6px;
  color: #0f172a;
  font-weight: 800;
}


.installer-card {
  width: min(760px, calc(100vw - 34px));
}

.installer-form h3 {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 17px;
}

.installer-actions {
  display: flex;
  gap: 10px;
}

.installer-actions .secondary-btn {
  width: 100%;
}

@media (max-width: 640px) {
  .installer-card {
    width: min(100%, calc(100vw - 22px));
  }
}


.installer-card {
  width: min(760px, calc(100vw - 34px));
}

.installer-form h3 {
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 17px;
}

body.login-body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    radial-gradient(circle at 15% 10%, rgba(206, 227, 111, .35), transparent 30%),
    radial-gradient(circle at 85% 20%, rgba(15, 118, 110, .24), transparent 26%),
    linear-gradient(135deg, #f8fafc 0%, #eef7f4 48%, #e9f0ff 100%);
}

.login-card {
  width: min(460px, calc(100vw - 34px));
  background: rgba(255, 255, 255, .97);
  border: 1px solid rgba(226, 232, 240, .95);
  border-radius: 30px;
  padding: 34px;
  box-shadow: 0 28px 90px rgba(15, 23, 42, .16);
  margin: auto;
}

.login-logo {
  margin: 0 auto 18px;
}

.login-card h1,
.login-card > p {
  text-align: center;
}

.success-box {
  margin-top: 18px;
  border-radius: 16px;
  background: #ecfdf5;
  border: 1px solid #bbf7d0;
  color: #166534;
  padding: 13px 14px;
  font-weight: 900;
  line-height: 1.4;
}
