:root {
  --teal: #0794a7;
  --teal-dark: #087f8e;
  --teal-soft: #d8f3f5;
  --ink: #102033;
  --muted: #6b7a8a;
  --line: #e5edf2;
  --surface: #ffffff;
  --surface-soft: #f6f9fb;
  --warning: #b55e00;
  --warning-bg: #fff5e6;
  --success: #188a60;
  --success-bg: #d8f2e7;
  --shadow: 0 18px 50px rgba(17, 38, 55, 0.10);
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #f2efe9;
}

button, input, select {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

/* Shared */
.primary-button,
.secondary-button,
.icon-button,
.date-button {
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  min-height: 48px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  transition: transform 0.14s ease, opacity 0.14s ease, background 0.14s ease;
}

.primary-button {
  background: var(--teal);
  color: white;
}

.primary-button:hover { background: var(--teal-dark); }

.secondary-button,
.icon-button,
.date-button {
  background: #f2f6f8;
  color: var(--ink);
  border: 1px solid var(--line);
}

.secondary-button:hover,
.icon-button:hover,
.date-button:hover { background: #eaf1f4; }

.primary-button:active,
.secondary-button:active,
.icon-button:active,
.date-button:active { transform: translateY(1px); }

.full-width { width: 100%; }
.compact { min-height: 40px; padding: 0 14px; border-radius: 10px; }
.text-button { background: transparent; border: 0; cursor: pointer; color: var(--muted); }
.muted { color: var(--muted); }
.small-note { font-size: 12px; }

.flash {
  border-radius: 12px;
  padding: 12px 14px;
  margin: 14px 0;
  font-size: 14px;
  background: #eef7fb;
  color: #164b60;
}
.flash.error { background: #fff1f1; color: #8a1f1f; }
.flash.success { background: #ecf8f1; color: #14653f; }

/* Staff scan pages */
.scan-body {
  min-height: 100vh;
  background: #eef3f5;
  display: grid;
  place-items: center;
  padding: 18px;
}

.scan-shell {
  width: min(100%, 390px);
}

.scan-card {
  min-height: 720px;
  background: var(--surface);
  border-radius: 0;
  border: 1px solid #dde6eb;
  box-shadow: 0 10px 28px rgba(20, 41, 56, 0.08);
  padding: 26px 28px 22px;
  display: flex;
  flex-direction: column;
  position: relative;
}

.scan-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 30px;
}

.brand-mini {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--teal);
  font-weight: 800;
  letter-spacing: -0.04em;
}

.brand-mini.large { font-size: 20px; }
.brand-mark, .brand-symbol { color: #ffa629; }

.brand-logo {
  display: block;
  width: auto;
  max-width: 100%;
  object-fit: contain;
}

.brand-mini .brand-logo {
  height: 30px;
  max-width: 132px;
}

.brand-mini.large .brand-logo {
  height: 38px;
  max-width: 152px;
}

.brand-lockup .brand-logo {
  height: 54px;
  max-width: 230px;
}

.status-pill {
  color: var(--muted);
  background: #f3f7f9;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.scan-content {
  margin-top: 42px;
}

.eyebrow,
.tiny-label {
  color: var(--teal);
  text-transform: uppercase;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.scan-card h1 {
  font-size: 36px;
  line-height: 0.96;
  letter-spacing: -0.07em;
  margin: 12px 0 38px;
}

.patient-box {
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.patient-name {
  font-size: 19px;
  font-weight: 800;
  margin-top: 6px;
}

.patient-number {
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
}

.period-confirmation {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  background: #f8fbfc;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.period-confirmation strong {
  display: block;
  margin-top: 4px;
  font-size: 16px;
}

.period-confirmation .secondary-button {
  white-space: nowrap;
  font-size: 13px;
}

.scan-instruction {
  margin-top: 18px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 15px;
}

.scan-action-form {
  margin-top: auto;
}

.scan-footer {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin-top: 14px;
}

.state-card {
  justify-content: space-between;
}

.state-center {
  text-align: center;
  margin: auto 0;
  transform: translateY(-20px);
}

.state-icon {
  width: 86px;
  height: 86px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  font-size: 42px;
  font-weight: 700;
  margin-bottom: 28px;
}

.success-icon { background: var(--success-bg); color: var(--success); }
.neutral-icon { background: #edf3f6; color: #5d7388; }
.error-icon { background: #ffecec; color: #b22; }

.state-center h1 {
  margin: 0 0 8px;
  font-size: 36px;
}

.recorded-period {
  color: var(--teal-dark);
  background: var(--teal-soft);
  display: inline-block;
  font-size: 20px;
  font-weight: 900;
  margin-bottom: 10px;
  padding: 8px 12px;
  text-transform: uppercase;
}

.state-center p {
  margin: 0 0 10px;
  color: var(--muted);
}

.state-center strong {
  display: block;
  font-size: 18px;
  margin-top: 8px;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 48px 24px;
}

.login-wrapper {
  width: min(1180px, 100%);
  min-height: 720px;
  background: white;
  border-radius: 18px;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
  box-shadow: var(--shadow);
  border: 1px solid #dde6eb;
}

.login-panel { padding: 64px; }

.brand-panel {
  background: radial-gradient(circle at 85% 5%, rgba(255,255,255,0.08) 0 22%, transparent 23%), var(--teal-dark);
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.brand-lockup {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.05em;
}

.brand-panel h1 {
  font-size: 38px;
  line-height: 1.08;
  letter-spacing: -0.06em;
  max-width: 470px;
}

.brand-panel h1 span { color: rgba(255,255,255,0.55); }
.copyright { color: rgba(255,255,255,0.65); font-size: 14px; }

.form-panel {
  display: grid;
  place-items: center;
}

.login-form-box { width: min(440px, 100%); }
.login-form-box h2 { font-size: 30px; margin: 0 0 8px; letter-spacing: -0.04em; }
.login-form-box p { color: var(--muted); margin: 0 0 32px; }

.owner-form label {
  display: block;
  margin: 18px 0 8px;
  font-size: 13px;
  color: var(--ink);
  font-weight: 700;
}

.owner-form input,
.month-form input {
  width: 100%;
  min-height: 52px;
  border: 1px solid #dbe5eb;
  border-radius: 12px;
  padding: 0 16px;
  outline: none;
  background: white;
}

.owner-form input:focus,
.month-form input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft); }
.owner-form .primary-button { margin-top: 28px; }

/* Owner dashboard */
.dashboard-page {
  min-height: 100vh;
  background: #eef3f5;
}

.app-frame {
  width: min(1220px, calc(100% - 42px));
  margin: 28px auto;
  background: white;
  border: 1px solid #dce6ec;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 180px 1fr;
  min-height: calc(100vh - 56px);
  border-radius: var(--radius);
  overflow: hidden;
}

.side-rail {
  background: #fbfdfe;
  border-right: 1px solid var(--line);
  padding: 28px 24px;
}

.nav-links {
  margin-top: 34px;
  display: grid;
  gap: 8px;
}

.nav-links a {
  padding: 12px 14px;
  border-radius: 12px;
  color: #33475b;
  font-weight: 700;
  font-size: 14px;
}

.nav-links a.active,
.nav-links a:hover { background: #f0f5f8; }

.dashboard-main {
  padding: 24px 34px 38px;
  overflow-x: auto;
}

.topbar {
  display: flex;
  justify-content: flex-end;
  gap: 16px;
  align-items: center;
  min-height: 42px;
}

.owner-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 14px;
}

.owner-chip span {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: #caeef4;
  color: var(--teal-dark);
  font-weight: 800;
}

.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin: 38px 0 26px;
}

.page-heading h1 {
  margin: 0;
  font-size: 42px;
  letter-spacing: -0.06em;
}

.page-heading p { margin: 8px 0 0; color: var(--muted); }

.date-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.icon-button { min-width: 44px; padding: 0; font-size: 25px; }

.summary-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-card {
  background: #f8fbfc;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
}

.summary-card span { display: block; color: var(--muted); font-size: 13px; font-weight: 700; }
.summary-card strong { display: block; font-size: 34px; letter-spacing: -0.05em; margin-top: 4px; }
.summary-card.warning { background: var(--warning-bg); }
.summary-card.warning strong { color: var(--warning); }

.table-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 18px;
}

.table-card h2 {
  margin: 0;
  padding: 18px 20px;
  font-size: 20px;
  letter-spacing: -0.03em;
  border-bottom: 1px solid var(--line);
}

.status-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 760px;
}

.status-table th {
  background: #f4f8fa;
  color: #466078;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.08em;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
}

.status-table th + th,
.status-table td + td { border-left: 1px solid #f0f4f6; }
.status-table tbody tr { border-bottom: 1px solid var(--line); }
.status-table tbody tr:nth-child(even) { background: #f8fbfc; }
.status-table td { padding: 18px; text-align: center; }
.status-table .patient-col, .status-table .patient-name-cell { text-align: left; }

.patient-name-cell strong { display: block; }
.patient-name-cell span { color: var(--muted); font-size: 12px; }
.time-cell { font-weight: 800; color: var(--ink); }
.time-cell.missing { color: #9badbb; font-weight: 600; }
.row-incomplete { background: #fffdf7; }

.mobile-status-list {
  display: none;
}

.patient-status-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 16px;
  display: grid;
  gap: 12px;
  padding: 16px;
}

.patient-status-card.is-incomplete {
  background: #fffdf7;
}

.patient-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.patient-card-header strong,
.patient-card-header span {
  display: block;
}

.patient-card-header strong {
  font-size: 17px;
}

.patient-card-header div span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.completion-pill {
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.completion-pill.complete {
  background: var(--success-bg);
  color: var(--success);
}

.completion-pill.incomplete {
  background: var(--warning-bg);
  color: var(--warning);
}

.dose-group {
  padding-top: 10px;
}

.dose-group + .dose-group {
  border-top: 1px solid var(--line);
}

.dose-title {
  color: #466078;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.dose-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}

.dose-row + .dose-row {
  border-top: 1px solid #edf2f5;
}

.dose-row span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.dose-row strong {
  font-size: 15px;
}

.dose-row strong.missing {
  color: #9badbb;
  font-weight: 700;
}

.dashboard-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

.month-form {
  display: flex;
  gap: 8px;
  align-items: center;
}
.month-form input { width: 90px; min-height: 40px; border-radius: 10px; }
.compact-table { min-width: 900px; font-size: 13px; }
.report-detail { max-height: 650px; overflow: auto; }

/* QR Codes */
.qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

.qr-card {
  border: 1px solid var(--line);
  background: white;
  border-radius: 16px;
  padding: 16px;
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 14px;
  align-items: center;
  break-inside: avoid;
}

.qr-card img { width: 92px; height: 92px; }
.qr-title { font-weight: 900; letter-spacing: -0.03em; }
.qr-subtitle { color: var(--muted); font-size: 13px; margin-top: 5px; line-height: 1.35; }

/* Loading button state */
button.is-loading { opacity: 0.75; pointer-events: none; }
button.is-loading::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.55);
  border-top-color: white;
  border-radius: 50%;
  margin-right: 8px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
  .login-wrapper { grid-template-columns: 1fr; min-height: auto; }
  .brand-panel { min-height: 280px; }
  .login-panel { padding: 36px 28px; }
  .brand-panel h1 { font-size: 30px; }

  .app-frame { width: 100%; margin: 0; border-radius: 0; grid-template-columns: 1fr; }
  .side-rail { border-right: 0; border-bottom: 1px solid var(--line); padding: 18px; }
  .nav-links { margin-top: 16px; display: flex; overflow-x: auto; }
  .dashboard-main { padding: 18px; }
  .page-heading { align-items: flex-start; flex-direction: column; margin-top: 24px; }
  .page-heading h1 { font-size: 36px; }
  .summary-strip { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .dashboard-main {
    overflow-x: visible;
  }

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

  .topbar > div:first-child {
    display: none;
  }

  .owner-chip {
    font-size: 13px;
  }

  .page-heading {
    gap: 14px;
  }

  .page-heading h1 {
    font-size: 34px;
  }

  .date-controls {
    width: 100%;
    display: grid;
    grid-template-columns: 48px 1fr 48px;
  }

  .date-controls .secondary-button {
    grid-column: 1 / -1;
  }

  .date-button,
  .icon-button {
    min-height: 46px;
  }

  .desktop-status-card {
    display: none;
  }

  .mobile-status-list {
    display: grid;
    gap: 12px;
  }

  .dashboard-actions {
    display: grid;
    justify-content: stretch;
  }

  .dashboard-actions form,
  .dashboard-actions button {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .scan-body { padding: 0; background: white; }
  .scan-shell { width: 100%; }
  .scan-card { min-height: 100vh; border: 0; box-shadow: none; padding: 24px; }
  .scan-card h1 { font-size: 34px; }
  .period-confirmation { align-items: stretch; flex-direction: column; }
  .summary-strip { grid-template-columns: 1fr 1fr; }
}

@media print {
  body { background: white; }
  .no-print,
  .topbar,
  .side-rail,
  .dashboard-actions { display: none !important; }
  .app-frame { width: 100%; margin: 0; box-shadow: none; border: 0; display: block; }
  .dashboard-main { padding: 0; }
  .table-card { border: 1px solid #ccc; break-inside: avoid; }
  .status-table { min-width: 0; font-size: 10px; }
  .status-table th, .status-table td { padding: 8px; }
  .qr-grid { grid-template-columns: repeat(2, 1fr); }
  .qr-card { border: 1px solid #999; }
}
