:root {
  --primary: #0e9f9a;
  --primary-dark: #0b7f7b;
  --primary-light: #e6f7f6;
  --accent: #3b82f6;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --purple: #7c3aed;
  --purple-light: #ede9fe;
  --blue-light: #dbeafe;
  --bg: #f3f6f9;
  --surface: #ffffff;
  --border: #e3e8ee;
  --text: #1e293b;
  --muted: #64748b;
  --sidebar: #0f2c3f;
  --sidebar-text: #b7c9d6;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 44, 63, .06), 0 4px 14px rgba(15, 44, 63, .05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
[data-icon] { display: inline-flex; align-items: center; }

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 250px; background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 50;
  transition: transform .25s;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 22px 20px; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-logo { width: 42px; height: 42px; border-radius: 11px; background: linear-gradient(135deg, var(--primary), #22c3bd); display: grid; place-items: center; }
.brand-logo svg { width: 24px; height: 24px; fill: #fff; stroke: none; }
.brand-name { color: #fff; font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 11px; opacity: .7; }
.nav { padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 9px; cursor: pointer; font-weight: 500; transition: .15s; user-select: none; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(14,159,154,.35); }
.sidebar-footer { padding: 16px; }
.today-box { background: rgba(255,255,255,.06); border-radius: 10px; padding: 12px 14px; }
.today-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .7; }
.today-date { color: #fff; font-weight: 600; text-transform: capitalize; }

/* Main */
.main { flex: 1; margin-left: 250px; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 18px 28px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30;
}
.topbar h1 { font-size: 21px; font-weight: 700; }
.topbar-clock {
  margin-left: auto; text-align: right; padding: 14px 22px 16px;
  background: linear-gradient(135deg, #0f2c3f 0%, #16445c 100%);
  border-radius: 12px; color: #fff; min-width: 260px;
  box-shadow: 0 4px 14px rgba(15, 44, 63, .18);
  overflow: visible; flex-shrink: 0; box-sizing: border-box;
  display: flex; flex-direction: column; justify-content: center; gap: 6px;
}
.topbar-clock-date {
  font-size: 12px; font-weight: 500; letter-spacing: .03em;
  text-transform: capitalize; opacity: .9; white-space: nowrap;
  line-height: 1.4;
}
.topbar-clock-time {
  font-family: "Segoe UI", "Roboto Mono", ui-monospace, monospace;
  font-size: 28px; font-weight: 700; letter-spacing: .06em;
  line-height: 1.3; font-variant-numeric: tabular-nums;
}
.topbar-actions { margin-left: 16px; display: flex; gap: 12px; align-items: center; }
.menu-toggle { display: none; }
.content { padding: 26px 28px 40px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Search */
.search-global { position: relative; display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 0 12px; width: 340px; color: var(--muted); }
.search-global input { border: none; background: transparent; padding: 10px 0; outline: none; width: 100%; font: inherit; color: var(--text); }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); display: none; max-height: 320px; overflow: auto; z-index: 60; }
.search-results.open { display: block; }
.search-item { padding: 10px 14px; cursor: pointer; display: flex; gap: 10px; align-items: center; color: var(--text); }
.search-item:hover { background: var(--primary-light); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; border-radius: 9px; border: 1px solid var(--border); background: #fff; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; transition: .15s; white-space: nowrap; }
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-icon { border: none; background: transparent; width: 34px; height: 34px; border-radius: 8px; display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); }
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-icon.danger:hover { background: var(--danger-light); color: var(--danger); }

/* Cards */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; margin-bottom: 22px; }
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); display: flex; gap: 16px; align-items: center; border: 1px solid var(--border); }
.stat-icon { width: 50px; height: 50px; border-radius: 12px; display: grid; place-items: center; }
.stat-icon svg { width: 24px; height: 24px; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat-hint { font-size: 12px; color: var(--muted); }
.c-teal { background: var(--primary-light); color: var(--primary); }
.c-blue { background: var(--blue-light); color: var(--accent); }
.c-green { background: var(--success-light); color: var(--success); }
.c-orange { background: var(--warning-light); color: var(--warning); }
.c-red { background: var(--danger-light); color: var(--danger); }
.c-purple { background: var(--purple-light); color: var(--purple); }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 22px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-header h3 { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card-body { padding: 18px 20px; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 22px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-equal { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }

/* Patients cards */
.patient-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 18px; }
.patient-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; cursor: pointer; transition: .18s; display: flex; flex-direction: column; gap: 12px; }
.patient-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(15,44,63,.1); border-color: var(--primary); }
.patient-top { display: flex; gap: 12px; align-items: center; }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex-shrink: 0; font-size: 15px; }
.avatar.lg { width: 76px; height: 76px; font-size: 26px; }
.patient-name { font-weight: 700; font-size: 15px; }
.patient-meta { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.patient-meta div { display: flex; gap: 8px; align-items: center; }
.patient-meta svg { width: 15px; height: 15px; }
.patient-actions { display: flex; gap: 6px; border-top: 1px solid var(--border); padding-top: 10px; justify-content: flex-end; }

.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar .input { max-width: 320px; }
.view-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: #fff; }
.view-switch button { border: none; background: transparent; padding: 8px 12px; cursor: pointer; color: var(--muted); display: grid; place-items: center; }
.view-switch button.active { background: var(--primary-light); color: var(--primary); }

.care-switch {
  display: inline-flex; gap: 6px; margin-bottom: 16px; padding: 4px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
}
.care-switch button {
  display: inline-flex; align-items: center; gap: 8px; border: none; background: transparent;
  padding: 10px 16px; border-radius: 9px; cursor: pointer; font: inherit; font-weight: 600;
  color: var(--muted); transition: .15s;
}
.care-switch button svg { width: 16px; height: 16px; }
.care-switch button:hover { color: var(--text); background: #fff; }
.care-switch button.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }
.history-banner .card-body svg { width: 22px; height: 22px; color: var(--primary); flex-shrink: 0; margin-top: 2px; }
.history-banner strong { display: block; font-size: 15px; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-green { background: var(--success-light); color: var(--success); }
.b-orange { background: var(--warning-light); color: var(--warning); }
.b-red { background: var(--danger-light); color: var(--danger); }
.b-blue { background: var(--blue-light); color: var(--accent); }
.b-gray { background: #eef2f6; color: var(--muted); }
.b-purple { background: var(--purple-light); color: var(--purple); }
.b-teal { background: var(--primary-light); color: var(--primary); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 11px 16px; background: #f8fafc; border-bottom: 1px solid var(--border); }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafcfd; }
.td-actions { text-align: right; white-space: nowrap; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px 16px; }
.col-12 { grid-column: span 12; } .col-8 { grid-column: span 8; } .col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; } .col-3 { grid-column: span 3; } .col-2 { grid-column: span 2; } .col-9 { grid-column: span 9; }
.col-5 { grid-column: span 5; } .col-7 { grid-column: span 7; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: #334155; }
.field label .req { color: var(--danger); }
.input, select.input, textarea.input { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; color: var(--text); outline: none; transition: .15s; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,159,154,.15); }
.input.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(220,38,38,.12); }
textarea.input { resize: vertical; min-height: 80px; }
.input-group { display: flex; gap: 8px; }
.form-section-title { grid-column: span 12; font-size: 13px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .05em; padding-top: 6px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.check-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; }
.check:hover { background: var(--bg); }
.check input { accent-color: var(--primary); width: 16px; height: 16px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.err { font-size: 12px; color: var(--danger); margin-top: 4px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.tab { padding: 10px 16px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; display: flex; gap: 7px; align-items: center; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,30,45,.5); display: none; align-items: flex-start; justify-content: center; z-index: 100; padding: 40px 16px; overflow-y: auto; backdrop-filter: blur(2px); }
.modal-backdrop.open { display: flex; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 860px; box-shadow: 0 20px 60px rgba(0,0,0,.25); animation: pop .2s ease; }
.modal.sm { max-width: 460px; }
.modal.md { max-width: 620px; }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 17px; }
.modal-body { padding: 20px 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; background: #fafbfc; border-radius: 0 0 14px 14px; }
.modal-footer:empty { display: none; }

/* Toasts */
.toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: #1e293b; color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow); display: flex; gap: 10px; align-items: center; animation: pop .2s; min-width: 260px; border-left: 4px solid var(--primary); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warning); }

/* Lists */
.list-item { display: flex; gap: 14px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.time-pill { background: var(--primary-light); color: var(--primary); font-weight: 700; border-radius: 8px; padding: 6px 10px; font-size: 13px; text-align: center; min-width: 62px; }
.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty svg { width: 42px; height: 42px; opacity: .4; margin-bottom: 8px; }

/* Chart */
.chart { display: flex; align-items: flex-end; gap: 14px; height: 220px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-pair { display: flex; gap: 4px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bar { width: 40%; max-width: 28px; border-radius: 6px 6px 0 0; min-height: 3px; transition: height .4s; position: relative; }
.bar.in { background: linear-gradient(180deg, #22c3bd, var(--primary)); }
.bar.out { background: linear-gradient(180deg, #fca5a5, #ef4444); }
.bar-label { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.legend .l-in::before { background: var(--primary); }
.legend .l-out::before { background: #ef4444; }

/* Patient profile */
.profile-head { display: flex; gap: 20px; align-items: center; padding: 22px; flex-wrap: wrap; }
.profile-head h2 { font-size: 22px; }
.profile-tags { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.profile-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.info-item .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.info-item .v { font-weight: 500; word-break: break-word; }
.alert-box { background: var(--danger-light); color: #991b1b; border-radius: 10px; padding: 12px 16px; display: flex; gap: 10px; align-items: flex-start; margin-bottom: 16px; }

/* Odontogram */
.odonto-wrap { overflow-x: auto; padding: 6px 0; }
.odonto { min-width: 760px; }
.odonto-row { display: flex; justify-content: center; gap: 4px; margin: 6px 0; }
.odonto-sep { width: 18px; }
.odonto-divider { border-top: 2px dashed var(--border); margin: 10px 40px; }
.tooth { width: 40px; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; }
.tooth .shape { width: 36px; height: 44px; border: 2px solid #cbd5e1; border-radius: 12px 12px 16px 16px; background: #fff; display: grid; place-items: center; font-size: 11px; font-weight: 700; transition: .15s; }
.tooth.lower .shape { border-radius: 16px 16px 12px 12px; }
.tooth:hover .shape { border-color: var(--primary); transform: scale(1.08); }
.tooth .num { font-size: 11px; color: var(--muted); font-weight: 600; }
.st-carie .shape { background: #fee2e2; border-color: #ef4444; color: #b91c1c; }
.st-restaurado .shape { background: #dbeafe; border-color: #3b82f6; color: #1d4ed8; }
.st-canal .shape { background: #ede9fe; border-color: #7c3aed; color: #6d28d9; }
.st-coroa .shape { background: #fef3c7; border-color: #d97706; color: #b45309; }
.st-implante .shape { background: #dcfce7; border-color: #16a34a; color: #15803d; }
.st-ausente .shape { background: #f1f5f9; border-color: #94a3b8; border-style: dashed; color: #64748b; }
.st-extracao .shape { background: #fff1f2; border-color: #be123c; color: #be123c; }
.odonto-legend { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.odonto-legend .badge { cursor: pointer; border: 2px solid transparent; }
.odonto-legend .badge.sel { border-color: currentColor; }

/* Agenda */
.agenda-layout { display: grid; grid-template-columns: 320px 1fr; gap: 22px; }
.calendar { user-select: none; }
.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.cal-head strong { text-transform: capitalize; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-dow { font-size: 11px; color: var(--muted); font-weight: 700; padding: 4px 0; }
.cal-day { padding: 8px 0; border-radius: 8px; cursor: pointer; position: relative; font-weight: 500; }
.cal-day:hover { background: var(--bg); }
.cal-day.other { color: #cbd5e1; }
.cal-day.today { color: var(--primary); font-weight: 800; }
.cal-day.sel { background: var(--primary); color: #fff; }
.cal-day.has::after { content: ""; position: absolute; bottom: 3px; left: 50%; transform: translateX(-50%); width: 5px; height: 5px; border-radius: 50%; background: var(--warning); }
.cal-day.sel.has::after { background: #fff; }
.slot { display: flex; gap: 14px; padding: 12px 14px; border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 10px; margin-bottom: 10px; align-items: center; background: #fff; }
.slot.s-confirmado { border-left-color: var(--accent); }
.slot.s-concluido { border-left-color: var(--success); }
.slot.s-cancelado { border-left-color: var(--danger); opacity: .7; }
.slot.s-faltou { border-left-color: var(--warning); }
.slot-time { font-weight: 800; font-size: 15px; min-width: 64px; }
.slot-info { flex: 1; min-width: 0; }

/* Print */
@media print {
  .sidebar, .topbar, .no-print, .toasts { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* Responsive */
@media (max-width: 1100px) {
  .grid-2, .grid-equal, .agenda-layout { grid-template-columns: 1fr; }
  .search-global { width: 240px; }
}
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-grid; }
  #overviewMenuBtn { display: none; }
  .search-global { display: none; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 14px 16px; }
  .topbar-clock { min-width: 0; padding: 12px 16px; order: 3; width: 100%; text-align: center; box-sizing: border-box; }
  .topbar-clock-date { white-space: normal; font-size: 12px; }
  .topbar-clock-time { font-size: 24px; line-height: 1.3; }
  .topbar-actions { margin-left: auto; }
  .content { padding: 18px 14px; }
  .form-grid > [class*="col-"] { grid-column: span 12; }
  .check-grid { grid-template-columns: 1fr 1fr; }
}
