:root {
  color-scheme: light;
  --bg: #eef2f4;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --line: #d8e0e4;
  --line-strong: #c6d1d6;
  --text: #182326;
  --muted: #67757b;
  --brand: #11685f;
  --brand-strong: #0c514a;
  --nav: #102b31;
  --nav-hover: #193c43;
  --warn-bg: #fff7e8;
  --warn-line: #e8cfaa;
  --warn-text: #8a4a10;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  min-height: 34px;
  padding: 0 12px;
  white-space: nowrap;
}

button:hover {
  background: var(--brand-strong);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  min-height: 34px;
  padding: 7px 9px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  outline: 2px solid rgba(17, 104, 95, 0.14);
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.shell {
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--nav);
  color: #fff;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: 42px 1fr;
  margin-bottom: 22px;
}

.brand-mark {
  align-items: center;
  background: #d9f0eb;
  border-radius: 8px;
  color: var(--brand-strong);
  display: grid;
  font-weight: 800;
  height: 42px;
  justify-items: center;
  width: 42px;
}

.brand strong {
  display: block;
  font-size: 17px;
  line-height: 1.2;
}

.brand span {
  color: #b7c9ce;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 5px;
}

.nav-item {
  background: transparent;
  color: #d8e4e7;
  justify-content: start;
  min-height: 38px;
  padding: 0 10px;
  text-align: left;
}

.nav-item.active,
.nav-item:hover {
  background: var(--nav-hover);
}

.main {
  min-width: 0;
  padding: 18px;
}

.topbar {
  align-items: start;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(220px, 1fr) minmax(420px, 620px);
  margin-bottom: 14px;
}

.title-block {
  padding: 5px 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.25;
}

h2 {
  font-size: 15px;
  line-height: 1.3;
}

.topbar p {
  color: var(--muted);
  margin-top: 4px;
}

.panel-flat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.connection {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(180px, 1fr) minmax(150px, 0.8fr) auto;
  padding: 10px;
}

.notice {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 6px;
  color: var(--warn-text);
  margin-bottom: 14px;
  padding: 10px 12px;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 14px;
}

.workspace {
  display: grid;
  gap: 14px;
}

.two-columns {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  min-width: 0;
  padding: 14px;
}

.panel.stack {
  align-content: start;
}

.panel-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin: -2px 0 2px;
  padding-bottom: 10px;
}

.table {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}

.row {
  align-items: center;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  min-width: 680px;
  padding: 9px 12px;
}

.row:first-child {
  border-top: 0;
}

.row.header {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row button {
  min-width: 56px;
}

.row-default {
  grid-template-columns: minmax(180px, 1.3fr) minmax(120px, 0.9fr) minmax(110px, 0.7fr) 70px;
}

.row-wide {
  grid-template-columns: minmax(220px, 1.5fr) minmax(130px, 0.8fr) minmax(100px, 0.7fr) 70px;
}

.row-resource {
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 0.9fr) minmax(80px, 0.6fr) 70px;
}

.row-schedule {
  grid-template-columns: minmax(110px, 0.8fr) minmax(150px, 1fr) minmax(80px, 0.6fr) minmax(80px, 0.6fr);
}

.row-appointment {
  grid-template-columns: minmax(170px, 1.2fr) minmax(100px, 0.8fr) minmax(100px, 0.8fr) minmax(90px, 0.6fr);
}

.row-log {
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) minmax(190px, 1fr) minmax(90px, 0.6fr);
}

.muted {
  color: var(--muted);
}

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

  .connection {
    grid-template-columns: minmax(180px, 1fr) minmax(150px, 1fr) auto;
  }

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

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

  .sidebar {
    height: auto;
    position: static;
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main {
    padding: 12px;
  }

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

  .row {
    min-width: 620px;
  }
}

/* Functional admin refresh */
.login-screen {
  align-items: center;
  display: grid;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(24, 40, 46, 0.12);
  display: grid;
  gap: 16px;
  margin: 0 auto;
  max-width: 420px;
  padding: 24px;
  width: 100%;
}

.login-brand {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: 42px 1fr;
}

.login-brand strong {
  display: block;
  font-size: 17px;
  line-height: 1.2;
}

.login-brand span,
.form-hint {
  color: var(--muted);
  font-size: 12px;
}

.topbar {
  display: flex;
  justify-content: space-between;
}

.top-actions,
.inline-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button-muted {
  background: #e8eef1;
  color: var(--text);
}

.button-muted:hover {
  background: #d7e2e6;
}

.button-danger {
  background: #b42318;
}

.button-danger:hover {
  background: #8f1d14;
}

.status-pill {
  background: #eaf4f2;
  border: 1px solid #c8ded9;
  border-radius: 999px;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 700;
  padding: 7px 10px;
}

.form-grid {
  align-content: start;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid .panel-head,
.form-grid .span-2,
.form-grid input[type="hidden"] {
  grid-column: 1 / -1;
}

.stats-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.stat-card span {
  color: var(--muted);
  display: block;
  font-size: 12px;
}

.stat-card strong {
  display: block;
  font-size: 26px;
  line-height: 1.2;
  margin-top: 5px;
}

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

.data-item,
.summary-strip {
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}

.data-item strong {
  display: block;
}

.data-item span,
.summary-strip {
  color: var(--muted);
}

.compact-select {
  max-width: 180px;
}

.modal {
  align-items: center;
  background: rgba(9, 20, 24, 0.42);
  display: grid;
  inset: 0;
  padding: 22px;
  position: fixed;
  z-index: 20;
}

.modal-card {
  background: var(--panel);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.22);
  display: grid;
  gap: 12px;
  margin: 0 auto;
  max-height: min(760px, 92vh);
  max-width: 780px;
  overflow: auto;
  padding: 16px;
  width: 100%;
}

.detail-grid {
  display: grid;
  gap: 8px 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.detail-grid div {
  border-bottom: 1px solid var(--line);
  padding: 7px 0;
}

.detail-grid span {
  color: var(--muted);
  display: block;
  font-size: 12px;
}

.row-article { grid-template-columns: minmax(220px, 1.5fr) minmax(90px, 0.6fr) minmax(80px, 0.5fr) minmax(120px, 0.7fr) 76px; }
.row-doctor { grid-template-columns: minmax(120px, 0.8fr) minmax(100px, 0.7fr) minmax(120px, 0.7fr) minmax(90px, 0.5fr) 76px; }
.row-slot { grid-template-columns: minmax(110px, 0.7fr) minmax(110px, 0.7fr) minmax(110px, 0.7fr) minmax(70px, 0.4fr) minmax(80px, 0.5fr) 76px; }
.row-payment { grid-template-columns: minmax(150px, 1fr) minmax(160px, 1fr) minmax(90px, 0.5fr) minmax(90px, 0.5fr) minmax(120px, 0.8fr) 76px; }
.row-ai-log { grid-template-columns: minmax(90px, 0.6fr) minmax(220px, 1.4fr) minmax(120px, 0.7fr) minmax(80px, 0.5fr) minmax(90px, 0.6fr) minmax(80px, 0.5fr); }
.row-ai-conv { grid-template-columns: minmax(110px, 0.7fr) minmax(180px, 1.2fr) minmax(160px, 1fr) minmax(70px, 0.4fr) minmax(160px, 1fr); }

@media (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar {
    display: grid;
  }

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