:root {
  --purple-950: #21062e;
  --purple-900: #321044;
  --purple-800: #4a126b;
  --purple-700: #66218b;
  --purple-600: #7b2cbf;
  --purple-500: #8f45c5;
  --purple-200: #dfcbea;
  --purple-100: #f1e8f7;
  --purple-50: #faf6fc;
  --green-700: #3f9130;
  --green-600: #55b83e;
  --green-500: #68c653;
  --green-100: #eaf8e6;
  --yellow-600: #b47700;
  --yellow-100: #fff4cf;
  --red-600: #c23939;
  --red-100: #fdeaea;
  --gray-950: #1e1b22;
  --gray-700: #5f5866;
  --gray-600: #746d7a;
  --gray-500: #8b8491;
  --gray-400: #aca6b0;
  --gray-300: #d9d4dc;
  --gray-200: #e8e4eb;
  --gray-100: #f4f1f6;
  --white: #fff;
  --shadow: 0 14px 42px rgba(40, 16, 52, .10);
  --shadow-soft: 0 8px 24px rgba(40, 16, 52, .07);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--gray-950);
  background: #faf8fb;
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; }
img { max-width: 100%; }

.app-layout { min-height: 100vh; display: grid; grid-template-columns: 238px 1fr; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 238px;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  background: linear-gradient(180deg, var(--purple-950), #3c0a52);
  color: white;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px 20px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand img { width: 48px; height: 48px; border-radius: 13px; }
.brand div { display: grid; gap: 2px; }
.brand small { opacity: .65; }
.main-nav { display: grid; gap: 8px; margin-top: 18px; }
.main-nav a {
  display: flex;
  gap: 11px;
  align-items: center;
  padding: 13px 14px;
  border-radius: 13px;
  font-weight: 700;
  color: rgba(255,255,255,.82);
}
.main-nav a:hover, .main-nav a:focus { background: rgba(255,255,255,.09); color: white; }
.sidebar-footer { margin-top: auto; display: grid; gap: 4px; padding: 14px 8px 0; font-size: 13px; }
.sidebar-footer small { opacity: .65; text-transform: capitalize; }
.sidebar-footer span { margin-top: 16px; font-size: 10px; opacity: .55; line-height: 1.4; }
.text-button { border: 0; background: none; color: #b9ff9f; padding: 4px 0; text-align: left; }
.main-content { grid-column: 2; min-width: 0; }
#page { padding: 34px 28px 60px; max-width: 1560px; margin: 0 auto; }
.mobile-header { display: none; }

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 24px;
}
.page-heading h1 { margin: 0 0 6px; font-size: clamp(26px, 3vw, 36px); letter-spacing: -.04em; }
.page-heading p { margin: 0; color: var(--gray-700); }
.heading-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.back-link { display: inline-block; color: var(--purple-700); font-weight: 700; margin-bottom: 10px; }

.button, .mini-button, .filter-button {
  border: 0;
  border-radius: 11px;
  font-weight: 750;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.button:hover, .mini-button:hover { transform: translateY(-1px); }
.button { padding: 11px 16px; display: inline-flex; justify-content: center; align-items: center; gap: 8px; }
.button-primary { background: linear-gradient(135deg, var(--purple-700), var(--purple-600)); color: white; box-shadow: 0 8px 18px rgba(102,33,139,.22); }
.button-secondary { background: white; color: var(--purple-800); border: 1px solid var(--gray-300); }
.button-ghost { background: var(--gray-100); color: var(--gray-700); }
.button-full { width: 100%; }
.icon-button { border: 0; background: var(--gray-100); width: 40px; height: 40px; border-radius: 12px; font-size: 20px; }
.mini-button { display: inline-flex; align-items: center; justify-content: center; padding: 7px 10px; background: var(--purple-100); color: var(--purple-800); font-size: 12px; }
.mini-button.danger { color: var(--red-600); background: var(--red-100); }
.icon-only { width: 34px; padding-inline: 0; }
.row-actions, .file-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric-card {
  display: grid;
  gap: 4px;
  padding: 18px;
  border-radius: var(--radius);
  background: white;
  border: 1px solid var(--gray-200);
  box-shadow: 0 7px 20px rgba(40,16,52,.05);
}
.metric-card strong { font-size: 28px; color: var(--purple-800); }
.metric-card span { color: var(--gray-700); font-size: 13px; }

.control-card, .detail-card {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.control-card { overflow: hidden; }
.detail-card { padding: 22px; margin-bottom: 18px; }
.toolbar { display: grid; gap: 14px; padding: 18px; border-bottom: 1px solid var(--gray-200); }
.search-box { display: flex; align-items: center; gap: 8px; padding: 0 14px; background: var(--gray-100); border-radius: 12px; }
.search-box input { flex: 1; height: 46px; border: 0; outline: 0; background: transparent; }
.filter-row { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 2px; }
.filter-button { flex: 0 0 auto; padding: 8px 12px; color: var(--gray-700); background: white; border: 1px solid var(--gray-300); }
.filter-button.active { background: var(--purple-800); color: white; border-color: var(--purple-800); }

.table-wrap { overflow-x: auto; }
.patient-table { width: 100%; min-width: 1180px; border-collapse: collapse; }
.patient-table th, .patient-table td { padding: 13px 14px; border-bottom: 1px solid var(--gray-200); text-align: left; vertical-align: middle; }
.patient-table th { position: sticky; top: 0; background: #fbf9fc; color: var(--gray-700); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.patient-table tbody tr:hover { background: #fcf9fd; }
.patient-link { display: grid; gap: 3px; }
.patient-link strong { color: var(--purple-900); }
.patient-link small { color: var(--gray-500); }
.phone-link { color: #247b1c; font-weight: 750; }
.observation-cell { max-width: 250px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.empty-state, .empty-panel, .loading-panel, .fatal-panel { padding: 40px 20px; text-align: center; color: var(--gray-700); }
.fatal-panel { min-height: 50vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }

.status-badge { display: inline-flex; border-radius: 999px; padding: 6px 9px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.status-overdue { background: var(--red-100); color: var(--red-600); }
.status-due_soon { background: var(--yellow-100); color: var(--yellow-600); }
.status-scheduled { background: var(--green-100); color: #277b1e; }
.status-no_return { background: var(--gray-100); color: var(--gray-700); }
.status-ok { background: #edf2ff; color: #3555a7; }
.status-finished { background: var(--purple-100); color: var(--purple-800); }
.status-inactive { background: var(--gray-100); color: var(--gray-700); }
.status-abandoned { background: var(--red-100); color: var(--red-600); }

.tabs { display: flex; gap: 6px; margin-bottom: 18px; overflow-x: auto; }
.tab { border: 0; border-radius: 11px; padding: 10px 14px; background: white; color: var(--gray-700); font-weight: 800; }
.tab.active { background: var(--purple-800); color: white; }
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.info-card { background: white; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 18px; display: grid; gap: 8px; box-shadow: 0 7px 20px rgba(40,16,52,.05); }
.info-card span { color: var(--gray-700); font-size: 13px; }
.info-card strong { font-size: 20px; }

.card-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.card-heading h2 { margin: 0 0 4px; }
.card-heading p { margin: 0; color: var(--gray-700); }
.detail-list { margin: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.detail-list div { display: grid; gap: 4px; }
.detail-list div.full { grid-column: 1 / -1; }
.detail-list dt { color: var(--gray-500); font-size: 12px; text-transform: uppercase; font-weight: 800; }
.detail-list dd { margin: 0; white-space: pre-wrap; }
.card-list { display: grid; gap: 10px; }
.list-item, .file-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 15px;
  border: 1px solid var(--gray-200);
  border-radius: 13px;
}
.list-item h3, .folder-card h3 { margin: 0 0 5px; }
.list-item p { margin: 3px 0; color: var(--gray-700); }
.list-item small, .file-row small { color: var(--gray-500); }

.timeline { display: grid; gap: 12px; }
.timeline-item { display: grid; grid-template-columns: 105px 1fr; gap: 16px; padding: 15px; border: 1px solid var(--gray-200); border-radius: 13px; }
.timeline-date { color: var(--purple-700); font-weight: 900; }
.timeline-title { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.timeline-content p { margin: 8px 0; }
.timeline-content small { color: var(--gray-500); }

.upload-panel { display: grid; grid-template-columns: minmax(190px, .6fr) minmax(260px, 1.5fr) auto; align-items: end; gap: 12px; margin-bottom: 20px; }
.drop-zone { min-height: 92px; border: 2px dashed var(--gray-300); border-radius: 13px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; color: var(--gray-700); background: var(--gray-100); cursor: pointer; text-align: center; padding: 15px; }
.drop-zone.dragging { border-color: var(--purple-600); background: var(--purple-100); }
.drop-zone span { font-size: 12px; }
.folder-list { display: grid; gap: 14px; }
.folder-card { border: 1px solid var(--gray-200); border-radius: 14px; padding: 15px; }
.folder-card h3 { color: var(--purple-800); }
.file-row { padding: 10px 0; border: 0; border-top: 1px solid var(--gray-200); border-radius: 0; }
.file-row:first-of-type { border-top: 0; }

.field { display: grid; gap: 6px; }
.field span { color: var(--gray-700); font-size: 13px; font-weight: 750; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--gray-300);
  border-radius: 11px;
  padding: 11px 12px;
  color: var(--gray-950);
  background: white;
  outline: 0;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--purple-600); box-shadow: 0 0 0 3px rgba(123,44,191,.12); }
.field textarea { resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(31,10,41,.55); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; z-index: 100; }
.modal { width: min(690px, 100%); max-height: calc(100vh - 40px); overflow: hidden; display: flex; flex-direction: column; background: white; border-radius: 20px; box-shadow: 0 30px 90px rgba(20,0,30,.35); }
.modal-wide { width: min(920px, 100%); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--gray-200); }
.modal-header h2 { margin: 0; font-size: 21px; }
.modal-body { padding: 20px; overflow-y: auto; }

#toast-root { position: fixed; top: 18px; right: 18px; z-index: 200; display: grid; gap: 8px; }
.toast { min-width: 280px; max-width: 430px; padding: 13px 15px; border-radius: 12px; background: white; box-shadow: var(--shadow); border-left: 5px solid var(--green-600); }
.toast-error { border-left-color: var(--red-600); }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at top, #744094 0, var(--purple-950) 58%); }
.login-card { width: min(420px, 100%); padding: 32px; border-radius: 24px; background: rgba(255,255,255,.98); box-shadow: 0 30px 90px rgba(0,0,0,.35); text-align: center; }
.login-icon { width: 92px; height: 92px; border-radius: 24px; }
.login-card h1 { margin: 14px 0 4px; }
.login-card p { color: var(--gray-700); margin: 0 0 24px; }
.login-card form { display: grid; gap: 14px; text-align: left; }
.login-card small { display: block; margin-top: 22px; color: var(--gray-500); }

@media (max-width: 1100px) {
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .upload-panel { grid-template-columns: 1fr; }
}

@media (max-width: 780px) {
  .app-layout { display: block; }
  .sidebar { transform: translateX(-102%); transition: transform .2s ease; box-shadow: 20px 0 50px rgba(0,0,0,.25); }
  .menu-open .sidebar { transform: translateX(0); }
  .main-content { min-height: 100vh; }
  .mobile-header { position: sticky; top: 0; z-index: 20; display: flex; gap: 12px; align-items: center; padding: 10px 14px; background: rgba(255,255,255,.94); backdrop-filter: blur(12px); border-bottom: 1px solid var(--gray-200); }
  #page { padding: 20px 14px 50px; }
  .page-heading { flex-direction: column; }
  .heading-actions { width: 100%; justify-content: stretch; }
  .heading-actions .button { flex: 1; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .detail-list { grid-template-columns: 1fr; }
  .detail-list div.full { grid-column: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .timeline-item { grid-template-columns: 1fr; gap: 7px; }
  .list-item, .file-row { align-items: flex-start; flex-direction: column; }
  .file-actions { width: 100%; }
  .modal-backdrop { padding: 0; align-items: end; }
  .modal { width: 100%; max-height: 94vh; border-radius: 22px 22px 0 0; }
  #toast-root { left: 12px; right: 12px; top: 12px; }
  .toast { min-width: 0; width: 100%; }
}

.boot-screen, .boot-failure { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 24px; background: #faf8fb; color: #321044; }
.boot-screen img { width: 86px; height: 86px; border-radius: 22px; box-shadow: 0 12px 32px rgba(50,16,68,.18); }
.boot-screen strong, .boot-failure strong { font-size: 24px; }
.boot-screen span, .boot-failure span { color: #5f5866; max-width: 560px; }
.boot-failure button { border: 0; border-radius: 11px; padding: 11px 16px; background: #66218b; color: white; font-weight: 800; }


/* v0.3.0 — Operação, estoque e administração */
.button-danger {
  background: #fdeaea;
  color: #b52d2d;
  border: 1px solid #efc5c5;
}
.split-actions {
  justify-content: space-between;
  align-items: center;
}
.split-actions > div {
  display: flex;
  gap: 10px;
}
.menu-wrapper {
  position: relative;
}
.action-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 7px);
  z-index: 50;
  min-width: 210px;
  padding: 7px;
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.action-menu button {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 10px 12px;
  border-radius: 9px;
  text-align: left;
  font-weight: 750;
  color: var(--gray-700);
}
.action-menu button:hover {
  background: var(--purple-100);
  color: var(--purple-800);
}
.import-help,
.preview-summary {
  display: grid;
  gap: 5px;
  padding: 13px;
  background: var(--purple-100);
  border-radius: 12px;
  color: var(--purple-900);
}
.preview-summary {
  grid-template-columns: repeat(3, 1fr);
  text-align: center;
}
.preview-table {
  margin-top: 10px;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
}
.preview-table > div {
  display: grid;
  grid-template-columns: 1.3fr .8fr .8fr;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--gray-200);
}
.preview-table > div.invalid {
  background: var(--red-100);
}
.two-column {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
.compact-list {
  display: grid;
  gap: 9px;
}
.compact-list > div {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-200);
}
.compact-list small {
  grid-column: 1 / -1;
  color: var(--gray-500);
}
.folder-grid {
  display: grid;
  gap: 15px;
}
.folder-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.folder-heading h3 {
  margin: 0;
}
.folder-heading h3 small {
  display: inline-flex;
  margin-left: 6px;
  min-width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--purple-100);
  color: var(--purple-800);
}
.folder-card.folder-dragging {
  outline: 3px solid var(--green-600);
  background: var(--green-100);
}
.folder-empty {
  padding: 16px 6px 3px;
  color: var(--gray-500);
  font-size: 13px;
}
.mini-select {
  max-width: 150px;
  border: 1px solid var(--gray-300);
  border-radius: 9px;
  padding: 6px;
  background: white;
  font-size: 12px;
}
.metric-grid-4 {
  grid-template-columns: repeat(4, minmax(130px, 1fr));
}
.stock-toolbar {
  grid-template-columns: minmax(260px, 1fr) minmax(180px, .35fr);
}
.stock-toolbar .filter-row {
  grid-column: 1 / -1;
}
.stock-toolbar > select {
  border: 1px solid var(--gray-300);
  border-radius: 12px;
  padding: 10px 12px;
  background: white;
}
.cell-note {
  display: block;
  margin-top: 4px;
  max-width: 280px;
  color: var(--gray-500);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stock-badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.stock-out {
  background: var(--red-100);
  color: var(--red-600);
}
.stock-low {
  background: var(--yellow-100);
  color: var(--yellow-600);
}
.stock-normal {
  background: var(--green-100);
  color: #277b1e;
}
.movement-balance {
  padding: 14px;
  border-radius: 12px;
  background: var(--purple-100);
  color: var(--purple-900);
}
.boot-screen,
.boot-failure {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  text-align: center;
  background: #faf8fb;
}
.boot-screen img {
  width: 88px;
  border-radius: 22px;
}
.boot-failure button {
  margin-top: 10px;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--purple-800);
  color: white;
}

@media (max-width: 900px) {
  .two-column {
    grid-template-columns: 1fr;
  }
  .metric-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
  .stock-toolbar {
    grid-template-columns: 1fr;
  }
  .stock-toolbar .filter-row {
    grid-column: auto;
  }
}

@media (max-width: 780px) {
  .split-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }
  .split-actions > div {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .preview-summary,
  .preview-table > div {
    grid-template-columns: 1fr;
    text-align: left;
  }
  .action-menu {
    left: 0;
    right: auto;
  }
}


/* v0.3.2 — Barra de organização da lista */
.sort-bar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(210px, .65fr) auto;
  align-items: end;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--gray-200);
  border-radius: 14px;
  background:
    linear-gradient(180deg, #ffffff 0%, #faf8fb 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.9);
}

.sort-bar-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sort-bar-title > div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.sort-bar-title strong {
  color: var(--purple-900);
}

.sort-bar-title small {
  color: var(--gray-500);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sort-bar-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--purple-100);
  color: var(--purple-800);
  font-size: 19px;
  font-weight: 900;
}

.sort-field {
  display: grid;
  gap: 5px;
}

.sort-field span {
  color: var(--gray-700);
  font-size: 12px;
  font-weight: 800;
}

.sort-field select,
.sort-direction-button {
  min-height: 42px;
  border: 1px solid var(--gray-300);
  border-radius: 11px;
  background: white;
  color: var(--gray-950);
  padding: 9px 12px;
  font-weight: 750;
}

.sort-direction-button {
  min-width: 170px;
  color: var(--purple-800);
}

.sort-direction-button:hover:not(:disabled) {
  border-color: var(--purple-600);
  background: var(--purple-100);
}

.sort-direction-button:disabled {
  cursor: default;
  color: var(--gray-500);
  background: var(--gray-100);
}

.table-sort-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  text-align: left;
}

.table-sort-button:hover,
.table-sort-button.active {
  color: var(--purple-800);
}

.sort-indicator {
  display: inline-flex;
  min-width: 12px;
  color: var(--purple-700);
  font-size: 14px;
  line-height: 1;
}

@media (max-width: 900px) {
  .sort-bar {
    grid-template-columns: 1fr 1fr;
  }

  .sort-bar-title {
    grid-column: 1 / -1;
  }

  .sort-direction-button {
    min-width: 0;
  }
}

@media (max-width: 780px) {
  .sort-bar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .sort-bar-title {
    grid-column: auto;
  }

  .sort-field select,
  .sort-direction-button {
    width: 100%;
  }
}


/* v0.3.3 — limpeza visual do painel */
.row-actions { gap: 8px; }
.action-icon { width: 34px; height: 34px; padding: 0; border-radius: 999px; font-size: 14px; line-height: 1; }
.action-icon:hover { background: var(--purple-200); }
.action-icon:focus-visible { outline: 2px solid var(--purple-500); outline-offset: 2px; }


/* v0.3.5 — Auditoria administrativa */
.audit-filter-card {
  display: grid;
  grid-template-columns:
    minmax(150px, .8fr)
    minmax(170px, 1fr)
    minmax(145px, .8fr)
    minmax(185px, 1fr)
    minmax(230px, 1.4fr)
    auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--gray-200);
  border-radius: 16px;
  background: white;
  box-shadow: var(--shadow-soft);
}

.audit-filter-card .field {
  margin: 0;
}

.audit-search {
  min-width: 220px;
}

.audit-filter-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.audit-list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 16px;
  border-bottom: 1px solid var(--gray-200);
}

.audit-list-heading > div {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.audit-list-heading strong {
  color: var(--purple-800);
  font-size: 22px;
}

.audit-list-heading span,
.audit-list-heading small {
  color: var(--gray-500);
}

.audit-table {
  min-width: 1120px;
}

.audit-table th:nth-child(1) { width: 150px; }
.audit-table th:nth-child(2) { width: 190px; }
.audit-table th:nth-child(3) { width: 110px; }
.audit-table th:nth-child(4) { width: 190px; }
.audit-table th:nth-child(5) { width: 230px; }

.audit-date {
  white-space: nowrap;
}

.audit-module {
  display: inline-flex;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--purple-100);
  color: var(--purple-800);
  font-size: 12px;
  font-weight: 800;
}

.audit-details {
  max-width: 360px;
  color: var(--gray-700);
  line-height: 1.4;
}

.audit-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 14px;
  border-top: 1px solid var(--gray-200);
}

.audit-pagination span {
  min-width: 120px;
  text-align: center;
  color: var(--gray-600);
  font-weight: 750;
}

@media (max-width: 1180px) {
  .audit-filter-card {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
  }

  .audit-filter-actions {
    justify-content: flex-end;
  }
}

@media (max-width: 780px) {
  .audit-filter-card {
    grid-template-columns: 1fr;
  }

  .audit-filter-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .audit-list-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}


/* v0.4.0 — versão, indicadores discretos e operações administrativas */
.powered-line {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 3px;
}

.version-link {
  appearance: none;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 2px;
}

.version-link:hover,
.version-link:focus-visible {
  text-decoration-color: currentColor;
}

.compact-patient-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 16px;
  min-height: 28px;
  margin: -7px 0 12px;
  padding: 0 3px;
  color: var(--gray-500);
  font-size: 11px;
}

.compact-patient-stats span {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  white-space: nowrap;
}

.compact-patient-stats strong {
  color: var(--purple-800);
  font-size: 12px;
}

.version-panel {
  display: grid;
  gap: 18px;
}

.version-heading {
  display: flex;
  align-items: center;
  gap: 14px;
}

.version-heading img {
  width: 56px;
  height: 56px;
  border-radius: 14px;
}

.version-heading div {
  display: grid;
  gap: 4px;
}

.version-heading strong {
  color: var(--purple-800);
  font-size: 18px;
}

.version-heading span {
  color: var(--gray-500);
  font-size: 13px;
}

.version-notes {
  display: grid;
  gap: 8px;
}

.version-notes p {
  display: flex;
  gap: 8px;
  margin: 0;
  color: var(--gray-700);
}

.version-notes p span {
  color: var(--green-600);
  font-weight: 900;
}

.system-health-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px 18px;
  margin-bottom: 14px;
  padding: 9px 13px;
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  background: white;
  color: var(--gray-600);
  font-size: 12px;
}

.system-health-strip strong {
  color: var(--purple-800);
}

.health-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border-radius: 999px;
}

.health-ok {
  background: var(--green-500);
  box-shadow: 0 0 0 3px rgba(85, 184, 62, .12);
}

.system-health-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.health-card {
  display: grid;
  gap: 5px;
  min-height: 126px;
  padding: 15px;
  border: 1px solid var(--gray-200);
  border-radius: 15px;
  background: white;
  box-shadow: var(--shadow-soft);
}

.health-card > span {
  color: var(--gray-500);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.health-card > strong {
  color: var(--purple-800);
  font-size: 21px;
}

.health-card small {
  color: var(--gray-600);
}

.health-card a {
  width: fit-content;
  color: var(--purple-700);
  font-size: 12px;
  font-weight: 800;
}

.system-migration-list {
  display: grid;
}

.system-migration-list > div {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 16px;
  border-top: 1px solid var(--gray-200);
}

.system-migration-list > div:first-child {
  border-top: 0;
}

.system-migration-list span {
  color: var(--gray-500);
  font-size: 12px;
}

.inventory-center {
  display: grid;
  gap: 18px;
}

.inventory-open-card,
.inventory-start-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px 18px;
  align-items: center;
  padding: 15px;
  border: 1px solid var(--purple-200);
  border-radius: 15px;
  background: var(--purple-50, #faf6fc);
}

.inventory-open-card > div,
.inventory-start-card > div {
  display: grid;
  gap: 4px;
}

.inventory-open-card strong,
.inventory-start-card strong {
  color: var(--purple-800);
}

.inventory-open-card span,
.inventory-start-card span {
  color: var(--gray-600);
  font-size: 12px;
}

.inventory-start-card .field {
  grid-column: 1 / 2;
  margin: 0;
}

.inventory-start-card > button {
  grid-column: 2;
  grid-row: 1 / 3;
}

.compact-heading {
  padding-inline: 0;
}

.inventory-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px 14px;
  margin-bottom: 10px;
  color: var(--gray-600);
  font-size: 12px;
}

.inventory-meta span:first-child {
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--purple-100);
  color: var(--purple-800);
  font-weight: 800;
}

.inventory-note {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--gray-100);
  color: var(--gray-700);
}

.inventory-table-wrap {
  max-height: min(58vh, 620px);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
}

.inventory-table {
  min-width: 900px;
}

.inventory-table thead {
  position: sticky;
  z-index: 2;
  top: 0;
}

.inventory-count-input,
.inventory-reason-input {
  width: 100%;
  min-width: 110px;
  padding: 8px 9px;
  border: 1px solid var(--gray-300);
  border-radius: 9px;
  background: white;
}

.inventory-reason-input {
  min-width: 220px;
}

.inventory-reason-input:disabled {
  background: var(--gray-100);
  color: var(--gray-400);
}

.inventory-reason-input.required-difference {
  border-color: #d28a19;
  background: #fffaf0;
}

.difference-positive {
  color: var(--green-700);
}

.difference-negative {
  color: var(--red-600);
}

@media (max-width: 900px) {
  .system-health-grid {
    grid-template-columns: repeat(2, minmax(160px, 1fr));
  }

  .inventory-open-card,
  .inventory-start-card {
    grid-template-columns: 1fr;
  }

  .inventory-start-card .field,
  .inventory-start-card > button {
    grid-column: 1;
    grid-row: auto;
  }
}

@media (max-width: 620px) {
  .compact-patient-stats {
    gap: 4px 11px;
    margin-top: -3px;
  }

  .system-health-grid {
    grid-template-columns: 1fr;
  }

  .system-migration-list > div {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
}


/* v0.4.1 — foto do paciente e sidebar recolhível */
.app-layout,
.sidebar,
.main-content {
  transition: width .2s ease, grid-template-columns .2s ease, margin .2s ease;
}

.sidebar-controls {
  display: flex;
  justify-content: flex-end;
  margin: -5px 0 8px;
}

.sidebar-toggle {
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 11px;
  background: rgba(255,255,255,.08);
  color: white;
  font-size: 18px;
}

.main-nav a.active {
  background: rgba(255,255,255,.14);
  color: white;
  box-shadow: inset 3px 0 0 #92e679;
}

.nav-icon {
  width: 24px;
  flex: 0 0 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.sidebar-user {
  display: grid;
  gap: 4px;
}

.sidebar-logout {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.logout-icon {
  display: none;
  font-size: 20px;
}

.sidebar-overlay {
  display: none;
}

body.sidebar-collapsed .app-layout {
  grid-template-columns: 78px 1fr;
}

body.sidebar-collapsed .sidebar {
  width: 78px;
  padding-inline: 10px;
}

body.sidebar-collapsed .sidebar-controls {
  justify-content: center;
}

body.sidebar-collapsed .brand {
  justify-content: center;
  padding-inline: 0;
}

body.sidebar-collapsed .brand img {
  width: 42px;
  height: 42px;
}

body.sidebar-collapsed .brand-copy,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .sidebar-user,
body.sidebar-collapsed .powered-line,
body.sidebar-collapsed .logout-label {
  display: none;
}

body.sidebar-collapsed .main-nav a {
  position: relative;
  justify-content: center;
  padding-inline: 8px;
}

body.sidebar-collapsed .main-nav a:hover::after,
body.sidebar-collapsed .main-nav a:focus-visible::after {
  content: attr(data-tooltip);
  position: absolute;
  z-index: 80;
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--purple-950);
  color: white;
  box-shadow: var(--shadow);
  white-space: nowrap;
  font-size: 12px;
}

body.sidebar-collapsed .sidebar-footer {
  align-items: center;
  justify-items: center;
  padding-inline: 0;
}

body.sidebar-collapsed .logout-icon {
  display: inline;
}

body.sidebar-collapsed .text-button {
  width: 42px;
  height: 42px;
  justify-content: center;
  padding: 0;
}

.patient-link-with-avatar {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 235px;
}

.patient-link-copy {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.patient-avatar {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--purple-100), #e4f6df);
  color: var(--purple-800);
  border: 2px solid white;
  box-shadow: 0 0 0 1px var(--gray-300);
  font-weight: 900;
  letter-spacing: -.04em;
  user-select: none;
}

.patient-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.patient-avatar-small {
  width: 38px;
  height: 38px;
  font-size: 12px;
}

.patient-avatar-large {
  width: 84px;
  height: 84px;
  font-size: 24px;
}

.patient-heading-profile {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.patient-heading-copy {
  min-width: 0;
}

.patient-photo-button {
  position: relative;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
}

.patient-photo-button:hover .patient-avatar,
.patient-photo-button:focus-visible .patient-avatar {
  box-shadow: 0 0 0 3px rgba(123,44,191,.2);
}

.patient-photo-edit-mark {
  position: absolute;
  right: -2px;
  bottom: 2px;
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border: 2px solid white;
  border-radius: 50%;
  background: var(--purple-700);
  color: white;
  font-size: 12px;
  box-shadow: var(--shadow-soft);
}

.photo-editor {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(240px, .65fr);
  gap: 28px;
  align-items: start;
}

.photo-editor-instruction {
  margin: 0 0 12px;
  color: var(--gray-700);
  text-align: center;
}

.photo-workspace {
  position: relative;
  width: min(100%, 500px);
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--gray-300);
  border-radius: 18px;
  background: var(--gray-100);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.65);
}

.photo-workspace::after {
  content: "";
  position: absolute;
  inset: 8%;
  border: 2px solid rgba(255,255,255,.9);
  border-radius: 50%;
  box-shadow: 0 0 0 999px rgba(30,27,34,.38);
  pointer-events: none;
}

.photo-workspace canvas,
.photo-workspace video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  touch-action: none;
  cursor: grab;
}

.photo-workspace canvas:active {
  cursor: grabbing;
}

.photo-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  color: var(--gray-500);
}

.photo-empty span {
  width: 110px;
  height: 110px;
  display: grid;
  place-items: center;
  margin: 0 auto;
  border-radius: 50%;
  background: var(--purple-100);
  color: var(--purple-800);
  font-size: 34px;
  font-weight: 900;
}

.photo-zoom {
  width: min(100%, 500px);
  margin: 12px auto 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
  color: var(--gray-700);
  font-size: 13px;
  font-weight: 800;
}

.photo-source-actions,
.photo-camera-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.photo-preview-panel {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--gray-200);
  border-radius: 18px;
  background: var(--gray-50, #faf8fb);
  text-align: center;
}

.photo-preview-panel h3 {
  margin: 0;
}

.photo-preview-panel canvas {
  width: 190px;
  height: 190px;
  border: 5px solid white;
  border-radius: 50%;
  background: var(--purple-100);
  box-shadow: 0 0 0 1px var(--gray-300), var(--shadow-soft);
}

.photo-preview-panel p {
  margin: 0;
  color: var(--gray-700);
  line-height: 1.5;
}

.photo-footer-actions > div {
  display: flex;
  gap: 10px;
}

@media (max-width: 780px) {
  body.sidebar-collapsed .app-layout {
    display: block;
  }

  body.sidebar-collapsed .sidebar {
    width: 238px;
    padding: 20px 14px;
  }

  body.sidebar-collapsed .brand-copy,
  body.sidebar-collapsed .nav-label,
  body.sidebar-collapsed .sidebar-user,
  body.sidebar-collapsed .powered-line,
  body.sidebar-collapsed .logout-label {
    display: initial;
  }

  body.sidebar-collapsed .logout-icon {
    display: none;
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 29;
    border: 0;
    background: rgba(22,6,30,.48);
  }

  body.menu-open .sidebar-overlay {
    display: block;
  }

  .patient-page-heading {
    align-items: stretch;
  }

  .patient-heading-profile {
    align-items: flex-start;
  }

  .patient-avatar-large {
    width: 68px;
    height: 68px;
    font-size: 20px;
  }

  .photo-editor {
    grid-template-columns: 1fr;
  }

  .photo-preview-panel {
    display: none;
  }

  .photo-footer-actions,
  .photo-footer-actions > div {
    width: 100%;
    flex-wrap: wrap;
  }

  .photo-footer-actions > div:last-child {
    margin-left: auto;
  }
}


/* hotfix: ações operacionais ficam indisponíveis para pacientes não ativos */
.action-icon:disabled,
.button:disabled {
  cursor: not-allowed;
  opacity: .42;
  transform: none;
}

.field-hint {
  display: block;
  margin-top: 6px;
  color: var(--gray-500);
  font-size: 11px;
  line-height: 1.35;
}
