:root {
  color-scheme: light;
  --bg: #eef2f3;
  --panel: #ffffff;
  --panel-soft: #f3f6f7;
  --line: #d5dee1;
  --text: #162124;
  --muted: #68777c;
  --teal: #147d7e;
  --green: #2f8f5b;
  --red: #b94040;
  --amber: #b27815;
  --blue: #315f9f;
  --focus: #1f9ca0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}
button, input, select, textarea {
  font: inherit;
}
button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
}
button.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
button.danger { color: var(--red); }
button:disabled { opacity: .55; cursor: not-allowed; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 82px; resize: vertical; }
label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login form {
  width: min(410px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  display: grid;
  gap: 14px;
  box-shadow: 0 20px 50px rgba(20, 40, 45, .08);
}
.login h1 { margin: 0 0 6px; font-size: 28px; }
.login p, .empty { color: var(--muted); margin: 0; }
.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
}
.sidebar {
  background: #142527;
  color: #edf7f7;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand strong { display: block; font-size: 19px; }
.brand span { color: #a9c0c2; font-size: 13px; }
.nav {
  display: grid;
  gap: 8px;
}
.nav button {
  text-align: left;
  color: #dce9ea;
  background: transparent;
  border-color: transparent;
}
.nav button.active {
  background: #234043;
  border-color: #31595c;
}
.main {
  padding: 20px;
  display: grid;
  gap: 18px;
  align-content: start;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}
.topbar h1 { margin: 0; font-size: 24px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 2px rgba(19, 37, 40, .04);
}
.metric {
  display: grid;
  gap: 6px;
}
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { font-size: 27px; }
.section-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}
.section-title h2 { margin: 0; font-size: 17px; }
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th, .table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}
.row-action { white-space: nowrap; text-align: right; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-grid .full { grid-column: 1 / -1; }
.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  background: var(--panel-soft);
}
.status.pendente, .status.configurar { color: var(--amber); background: #fff2d9; }
.status.enviado, .status.pago, .status.concluido, .status.ativo { color: var(--green); background: #e3f5eb; }
.status.erro, .status.cancelado, .status.inativo { color: var(--red); background: #fae5e5; }
.status.agendado { color: var(--blue); background: #e6eefb; }
.status.confirmado { color: var(--green); background: #e3f5eb; }
.status.chegou, .status.em { color: var(--amber); background: #fff2d9; }

.workspace-head, .record-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 16px;
}
.workspace-head h2, .record-header h2 { margin: 0; font-size: 20px; }
.workspace-head p, .record-header p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.list-card { padding: 0; overflow: hidden; }
.list-toolbar {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
}
.list-card .table th, .list-card .table td { padding: 12px 14px; }
.list-card .table tr:hover td { background: #f7fafb; }
.padded { padding: 16px; }
.record-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}
.record-tabs button { padding: 8px 12px; }
.record-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
}
.record-main { grid-column: span 8; }
.record-side { grid-column: span 4; }
.info-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.info-grid div, .mini-metrics div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: #fbfcfc;
}
.info-grid span, .mini-metrics span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}
.info-grid strong, .mini-metrics strong {
  font-size: 14px;
  overflow-wrap: anywhere;
}
.mini-metrics {
  display: grid;
  gap: 10px;
}
.mini-metrics strong { font-size: 22px; }
.clinical-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.clinical-summary div {
  min-height: 64px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}
.table small { color: var(--muted); }

.sort-head, .link-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font-weight: inherit;
  text-align: left;
}
.sort-head { color: var(--muted); text-transform: uppercase; font-size: 12px; }
.link-button { color: var(--teal); }
.new-patient-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 12px;
  border: 1px dashed #9fb5ba;
  border-radius: 8px;
  background: #f7fbfb;
}

.patient-list {
  display: grid;
  gap: 8px;
  max-height: 570px;
  overflow: auto;
}
.patient-button {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 4px;
}
.patient-button.active {
  border-color: var(--teal);
  box-shadow: inset 3px 0 0 var(--teal);
}
.patient-button small { color: var(--muted); }

.odontogram-shell {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(260px, 420px);
  gap: 16px;
  align-items: start;
}
.tooth small {
  display: block;
  font-size: 10px;
  color: var(--muted);
}
.odontogram-form {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}
.surfaces {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}
.surfaces label {
  display: inline-flex;
  grid-auto-flow: column;
  align-items: center;
  gap: 5px;
  text-transform: none;
  font-size: 13px;
  font-weight: 600;
}
.surfaces input { width: auto; }
.status.existente { color: #555f66; background: #edf0f1; }
.status.planejado, .tooth.planejado { color: var(--red); background: #fae5e5; }
.tooth.existente { background: #edf0f1; border-color: #a8b2b7; }

.odontogram {
  display: grid;
  grid-template-columns: repeat(16, minmax(32px, 1fr));
  gap: 6px;
}
.tooth {
  aspect-ratio: 1 / 1;
  min-width: 0;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 800;
}
.tooth.saudavel { background: #fff; }
.tooth.observar { background: #fff2d9; border-color: #e0b252; }
.tooth.tratamento { background: #e6eefb; border-color: #6c8fc7; }
.tooth.concluido { background: #e3f5eb; border-color: #70b78e; }
.tooth.ausente { background: #fae5e5; border-color: #d28080; }
.message {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  background: #172729;
  color: white;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: 0 18px 40px rgba(0,0,0,.2);
}
.hide { display: none !important; }

hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}
.compact textarea { min-height: 58px; }
.stock-usage {
  display: grid;
  gap: 8px;
  margin: 8px 0;
}
.stock-row, .movement-form {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 90px auto;
  gap: 8px;
  align-items: center;
}
.movement-form {
  grid-template-columns: 88px 80px minmax(120px, 1fr) auto;
}


.calendar-layout {
  display: grid;
  grid-template-columns: minmax(300px, 420px) 1fr;
  gap: 14px;
  align-items: start;
}
.calendar-card { overflow: auto; }
.calendar-toolbar, .calendar-filters {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.calendar-filters { justify-content: flex-start; }
.calendar-filters label { min-width: 220px; }
.calendar-grid {
  display: grid;
  grid-template-columns: 72px repeat(var(--days), minmax(130px, 1fr));
  min-width: 760px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}
.calendar-head, .time-cell, .slot-cell {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.calendar-head {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--panel-soft);
  padding: 9px;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--muted);
}
.time-cell {
  padding: 9px;
  color: var(--muted);
  font-size: 12px;
  background: #fbfcfc;
}
.slot-cell {
  min-height: 58px;
  padding: 5px;
  border-radius: 0;
  background: #fff;
  text-align: left;
  display: grid;
  align-content: start;
  gap: 4px;
}
.slot-cell:hover { background: #f1f7f7; }
.slot-cell.blocked-slot, .month-cell.blocked-slot { cursor: not-allowed; background: #f6f1f1; }
.slot-cell.blocked-slot:hover { background: #f6f1f1; }
.appointment-block, .month-event {
  display: grid;
  gap: 2px;
  padding: 6px;
  border-radius: 6px;
  border-left: 4px solid var(--blue);
  background: #e6eefb;
  color: var(--text);
  font-size: 12px;
}
.appointment-block.confirmado, .month-event.confirmado { border-color: var(--green); background: #e3f5eb; }
.appointment-block.chegou, .month-event.chegou, .appointment-block.em, .month-event.em { border-color: var(--amber); background: #fff2d9; }
.appointment-block.concluido, .month-event.concluido { border-color: var(--green); background: #e3f5eb; }
.appointment-block.cancelado, .month-event.cancelado { border-color: var(--red); background: #fae5e5; }
.appointment-block small { color: var(--muted); }

.appointment-block, .month-event { position: relative; }
.appointment-popover {
  display: none;
  position: absolute;
  left: 0;
  top: calc(100% - 1px);
  z-index: 20;
  min-width: 260px;
  max-width: 340px;
  padding: 12px;
  border: 1px solid #c7d3d6;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  box-shadow: 0 18px 44px rgba(18, 36, 40, .18);
  line-height: 1.35;
  white-space: normal;
}
.appointment-block:hover .appointment-popover,
.appointment-block:focus-within .appointment-popover,
.month-event:hover .appointment-popover,
.month-event:focus-within .appointment-popover { display: grid; gap: 6px; }
.appointment-popover em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}
.popover-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 4px;
}
.popover-actions button { padding: 7px 9px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(18, 36, 40, .38);
}
.modal-card {
  width: min(720px, 100%);
  max-height: calc(100vh - 44px);
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(18, 36, 40, .28);
}
.slot-cell, .month-cell { cursor: pointer; }
.month-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(115px, 1fr));
  min-width: 805px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}
.month-cell {
  min-height: 118px;
  padding: 8px;
  border-radius: 0;
  border-top: 0;
  border-left: 0;
  display: grid;
  align-content: start;
  gap: 5px;
  text-align: left;
}
.month-cell.muted-cell { background: #f8f9f9; color: #9aa5a8; }
.week-days {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}
.week-days label {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  text-transform: none;
  font-size: 13px;
}
.week-days input { width: auto; }

@media (max-width: 920px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 2; }
  .nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .nav button { text-align: center; }
  .span-3, .span-4, .span-5, .span-6, .span-7, .span-8, .record-main, .record-side { grid-column: span 12; }
  .odontogram { grid-template-columns: repeat(8, minmax(34px, 1fr)); }
  .odontogram-shell { grid-template-columns: 1fr; }
  .calendar-layout { grid-template-columns: 1fr; }
  .info-grid, .clinical-summary { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .main { padding: 14px; }
  .topbar, .workspace-head, .record-header { align-items: flex-start; flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  .table { font-size: 13px; }
  .table th:nth-child(3), .table td:nth-child(3) { display: none; }
  .stock-row, .movement-form, .new-patient-fields { grid-template-columns: 1fr; }
}
