:root {
  /* Style Variables: change brand colors and typography from this block. */
  --bg: #f7f3e9;
  --panel: #fffdf8;
  --text: #211c1d;
  --muted: #746a61;
  --line: #e5dbc5;
  --primary: #c89d42;
  --primary-dark: #9b6d18;
  --accent: #e5c566;
  --ink: #171314;
  --danger: #a83a32;
  --shadow: 0 18px 55px rgba(45, 34, 20, 0.13);
  --font-body: "Segoe UI", Candara, Calibri, Arial, sans-serif;
  --font-display: Georgia, "Times New Roman", serif;
}

body.night {
  --bg: #100e0f;
  --panel: #1d191a;
  --text: #f8eed9;
  --muted: #b7a991;
  --line: #3d332b;
  --primary: #dfb95c;
  --primary-dark: #b8872f;
  --accent: #f0d487;
  --ink: #0c0a0a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
}

.splash-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  gap: 18px;
  align-content: center;
  background: radial-gradient(circle at 50% 42%, #332d2e 0, #231f20 48%, #090808 100%);
  color: #e8c45f;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}

.splash-screen.hidden {
  display: grid !important;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-logo {
  width: clamp(170px, 24vw, 250px);
  height: clamp(170px, 24vw, 250px);
  border-radius: 24px;
  display: grid;
  place-items: center;
  overflow: visible;
  background: #231f20;
  box-shadow: 0 0 0 1px rgba(232,196,95,0.35), 0 26px 90px rgba(0,0,0,0.55);
  animation: logoReveal 1.25s cubic-bezier(.2,.8,.2,1) both;
}

.splash-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.splash-name {
  font-family: var(--font-display);
  font-weight: 900;
  letter-spacing: 0.16em;
  animation: nameReveal 0.8s ease 0.35s both;
}

@keyframes logoReveal {
  0% { transform: scale(0.68) rotate(-8deg); opacity: 0; filter: blur(8px); }
  65% { transform: scale(1.04) rotate(1deg); opacity: 1; filter: blur(0); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes nameReveal {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* App Layout: login, shell, navigation, forms, tables, and controls. */
button, input, select, textarea {
  font: inherit;
}

h1, h2, h3, .sidebar-brand strong, .stat strong {
  font-family: var(--font-display);
}

h1, h2, h3 {
  letter-spacing: -0.025em;
}

button, .eyebrow, th, .status-pill {
  letter-spacing: 0.015em;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.is-busy {
  transform: translateY(1px);
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100svh;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: clamp(18px, 3vw, 32px);
  align-items: center;
  padding: clamp(18px, 3vw, 38px);
  background:
    radial-gradient(circle at 18% 18%, rgba(229,197,102,0.18), transparent 34%),
    linear-gradient(125deg, #2b2425 0%, #171314 58%, #090808 100%);
}

.brand-panel {
  max-width: 760px;
  color: #fff;
}

.brand-mark, .sidebar-brand span {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #231f20;
  color: var(--accent);
  font-weight: 900;
  overflow: hidden;
  box-shadow: 0 18px 35px rgba(0,0,0,0.14);
}

.brand-mark img, .sidebar-brand img, .login-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 800;
}

.brand-panel .eyebrow {
  margin-top: 28px;
  color: #e8c45f;
}

h1 {
  max-width: 720px;
  margin: 0;
  font-size: clamp(2rem, 4.6vw, 4.4rem);
  line-height: 1;
}

h2, h3 {
  margin: 0;
}

.subtext {
  max-width: 620px;
  color: rgba(255,248,232,0.78);
  font-size: 1.1rem;
  line-height: 1.7;
}

.login-card, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card {
  width: min(100%, 430px);
  margin-left: auto;
  padding: clamp(22px, 3vw, 30px);
}

.login-logo {
  width: 58px;
  height: 58px;
  margin-bottom: 16px;
  border-radius: 14px;
  background: #231f20;
  overflow: hidden;
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  background: var(--panel);
  color: var(--text);
  outline: none;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(200,157,66,0.18);
}

.password-box {
  position: relative;
  display: block;
}

.password-box input {
  padding-right: 52px;
}

.password-box .icon-btn {
  position: absolute;
  right: 6px;
  top: 6px;
}

.primary-btn, .secondary-btn, .ghost-btn, .icon-btn, .danger-btn {
  border-radius: 6px;
  border: 1px solid transparent;
  min-height: 42px;
  font-weight: 800;
}

.primary-btn {
  padding: 0 18px;
  color: #171314;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-color: var(--primary);
}

.primary-btn:hover {
  background: var(--primary-dark);
}

.secondary-btn {
  padding: 0 16px;
  color: var(--primary);
  background: rgba(200,157,66,0.10);
  border-color: rgba(155,109,24,0.28);
}

.danger-btn {
  padding: 0 16px;
  color: var(--danger);
  background: rgba(180,35,24,0.08);
  border-color: rgba(180,35,24,0.2);
}

.ghost-btn {
  padding: 0 16px;
  color: var(--text);
  background: transparent;
  border-color: var(--line);
}

.icon-btn {
  width: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  color: var(--text);
  background: var(--panel);
  border-color: var(--line);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hint {
  color: var(--muted);
  line-height: 1.5;
}

.error {
  color: var(--danger);
  min-height: 22px;
  font-weight: 800;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  background: linear-gradient(180deg, #262021 0%, #171314 56%, #0c0a0a 100%);
  color: #fff;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 30px;
}

.sidebar nav {
  display: grid;
  gap: 8px;
}

.nav-btn {
  width: 100%;
  padding: 13px 12px;
  text-align: left;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 6px;
  color: rgba(255,245,224,0.72);
  background: transparent;
  font-weight: 800;
}

.nav-btn.active, .nav-btn:hover {
  color: #fff;
  background: rgba(229,197,102,0.14);
  border-color: rgba(229,197,102,0.48);
}

.workspace {
  min-width: 0;
}

.topbar {
  min-height: 88px;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,253,248,0.88);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 5;
}

body.night .topbar {
  background: rgba(29,25,26,0.86);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

.notification-btn {
  position: relative;
}

.notification-count {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: var(--danger);
  font-size: 0.68rem;
  font-weight: 900;
}

.notification-panel {
  position: absolute;
  top: 70px;
  right: 116px;
  z-index: 10;
  width: min(360px, calc(100vw - 32px));
  max-height: 430px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.notification-item {
  width: 100%;
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  color: var(--text);
  background: transparent;
}

.notification-item:last-child {
  border-bottom: 0;
}

.notification-item.unread {
  background: rgba(200,157,66,0.10);
}

.notification-item span,
.notification-item small,
.activity-list span {
  color: var(--muted);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  gap: 18px;
}

.mini-chart {
  min-height: 210px;
  display: grid;
  grid-template-columns: repeat(7, minmax(34px, 1fr));
  gap: 10px;
  align-items: end;
  padding-top: 18px;
}

.chart-bar {
  min-height: 150px;
  display: grid;
  align-items: end;
  gap: 8px;
  text-align: center;
  color: var(--muted);
  font-size: 0.76rem;
}

.chart-bar::before {
  content: "";
  height: var(--bar-height);
  min-height: 8px;
  border-radius: 6px 6px 2px 2px;
  background: linear-gradient(180deg, var(--primary), var(--accent));
}

.chart-bar strong {
  color: var(--text);
}

.activity-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
  list-style: none;
}

.activity-list li {
  display: grid;
  gap: 3px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.archive-toolbar {
  grid-template-columns: minmax(180px, 260px) auto;
  justify-content: start;
}

.content {
  padding: 28px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.stat {
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.stat::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
}

.stat span {
  color: var(--muted);
  font-weight: 800;
}

.stat strong {
  display: block;
  margin-top: 12px;
  font-size: 2rem;
}

.panel {
  padding: 22px;
  margin-bottom: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.wide {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 12px;
  margin-bottom: 16px;
}

.table-wrap {
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

th, td {
  padding: 14px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  background: rgba(200,157,66,0.07);
}

.tool-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
}

.button-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.file-action {
  min-height: 42px;
  padding: 0 16px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid rgba(155,109,24,0.28);
  color: var(--primary);
  background: rgba(200,157,66,0.10);
  font-weight: 800;
}

.file-action input {
  display: none;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.compact-btn {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.status-pill {
  display: inline-grid;
  place-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--primary);
  background: rgba(200,157,66,0.14);
  font-size: 0.78rem;
  font-weight: 900;
}

.status-pill.deleted {
  color: var(--danger);
  background: rgba(180,35,24,0.1);
}

tr.deleted-row {
  opacity: 0.72;
}

.install-app-btn {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  min-height: 46px;
  padding: 0 20px;
  border: 1px solid rgba(184,135,47,0.45);
  border-radius: 8px;
  color: #171314;
  background: linear-gradient(135deg, #e2bf68, #b8872f);
  box-shadow: 0 16px 40px rgba(86,56,12,0.28);
  font-weight: 900;
}

.install-app-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 20px 46px rgba(86,56,12,0.36);
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.prescription-library-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.picker-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(200,157,66,0.055);
}

.picker-results {
  margin-top: 10px;
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
}

.catalog-choice {
  width: 100%;
  padding: 10px 12px;
  display: grid;
  gap: 4px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  font-weight: 800;
}

.catalog-choice:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(200,157,66,0.16);
}

.catalog-choice span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.line-item {
  display: grid;
  grid-template-columns: 1fr 110px 1fr 42px;
  gap: 10px;
  margin-bottom: 10px;
}

.line-item input[readonly] {
  background: rgba(200,157,66,0.08);
  color: var(--ink);
  font-weight: 800;
}

.mini-remove {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--danger);
  border-radius: 6px;
  font-weight: 900;
}

#printArea {
  display: none;
}

/* A4 Prescription Print Template: universal printer-friendly prescription sheet. */
.print-sheet {
  width: 210mm;
  min-height: 297mm;
  display: flex;
  flex-direction: column;
  padding: 13mm 15mm 31mm;
  border: 1.5px solid #000;
  box-sizing: border-box;
  background: #fff;
  color: #18211f;
  font-family: Candara, Calibri, "Segoe UI", Arial, sans-serif;
  position: relative;
  overflow: hidden;
}

.print-watermark {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 118mm;
  height: 118mm;
  transform: translate(-50%, -44%);
  opacity: 0.04;
  object-fit: contain;
  z-index: 0;
}

.print-sheet > *:not(.print-watermark) {
  position: relative;
  z-index: 1;
}

.print-head {
  display: grid;
  grid-template-columns: 29mm 1fr 42mm;
  gap: 8mm;
  align-items: center;
  border-bottom: 2px solid #b8872f;
  padding-bottom: 7mm;
  margin-bottom: 8mm;
}

.print-logo {
  width: 27mm;
  height: 27mm;
  object-fit: contain;
  border-radius: 3mm;
}

.print-clinic h1 {
  max-width: none;
  margin: 0;
  color: #2b2425;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22pt;
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.print-tagline {
  margin-top: 1.2mm;
  color: #554940;
  font-size: 10pt;
  line-height: 1.2;
}

.print-clinic p {
  margin: 2mm 0 0;
  color: #6f6257;
  font-size: 9.5pt;
  line-height: 1.45;
}

.print-meta {
  text-align: right;
  font-size: 9.5pt;
  line-height: 1.45;
  color: #554940;
}

.print-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3mm 8mm;
  margin-bottom: 6mm;
  padding: 4mm;
  border: 1px solid #e5dbc5;
  border-radius: 4px;
  font-size: 10pt;
}

.print-section {
  margin-top: 5mm;
  break-inside: avoid;
}

.print-section h3 {
  margin: 0 0 2.5mm;
  color: #9b6d18;
  font-size: 10.5pt;
  font-family: Georgia, "Times New Roman", serif;
  text-transform: uppercase;
  border-bottom: 1px solid #e5dbc5;
  padding-bottom: 1.5mm;
}

.print-items-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 9.5pt;
}

.print-items-table th,
.print-items-table td {
  padding: 1.8mm 2mm;
  border: 1px solid #cfc5b2;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.print-items-table th {
  color: #2b2425;
  font-weight: 700;
}

.print-items-table th:nth-child(1) {
  width: 38%;
}

.print-items-table th:nth-child(2) {
  width: 25%;
}

.print-section ul {
  margin: 0;
  padding-left: 5mm;
}

.print-section li,
.print-section p,
.print-concern {
  margin: 0 0 1.8mm;
  font-size: 10pt;
  line-height: 1.55;
}

.print-signature {
  margin-top: auto;
  margin-bottom: 14mm;
  padding-top: 10mm;
  display: flex;
  justify-content: flex-end;
}

.signature-box {
  min-width: 54mm;
  text-align: center;
  color: #2b2425;
  font-size: 10pt;
}

.signature-line {
  height: 12mm;
  border-bottom: 1.6px solid #2b2425;
  margin-bottom: 2mm;
}

.print-footer {
  position: absolute;
  left: 15mm;
  right: 15mm;
  bottom: 10mm;
  padding-top: 3mm;
  border-top: 1px solid #e5dbc5;
  color: #9b6d18;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 10.5pt;
  font-style: italic;
  text-align: center;
}

@media (max-width: 920px) {
  .login-screen, .shell {
    grid-template-columns: 1fr;
  }

  .login-screen {
    align-content: start;
  }

  .brand-panel {
    max-width: none;
  }

  .brand-panel .subtext {
    display: none;
  }

  .brand-panel .eyebrow {
    margin-top: 14px;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
  }

  .login-card {
    margin: 0;
    width: min(100%, 460px);
  }

  .sidebar {
    position: relative;
    height: auto;
  }

  .sidebar nav {
    grid-template-columns: repeat(2, 1fr);
  }

  .stats-grid, .form-grid, .toolbar, .tool-panel, .dashboard-grid, .archive-toolbar {
    grid-template-columns: 1fr;
  }

  .notification-panel {
    top: 62px;
    right: 18px;
  }

  .button-grid {
    justify-content: flex-start;
  }

  .prescription-library-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .login-screen, .content, .topbar {
    padding: 18px;
  }

  .login-screen {
    gap: 16px;
  }

  h1 {
    font-size: 2rem;
  }

  .line-item {
    grid-template-columns: 1fr;
  }

  .sidebar nav {
    grid-template-columns: 1fr;
  }

  .install-app-btn {
    left: 18px;
    right: 18px;
    width: auto;
  }
}

@media print {
  body * {
    visibility: hidden;
  }

  #printArea, #printArea * {
    visibility: visible;
  }

  #printArea {
    display: block;
    position: absolute;
    left: 0;
    top: 0;
  }

  .print-sheet {
    box-shadow: none;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  @page {
    size: A4;
    margin: 0;
  }
}
