:root {
  --bg: #f4f6fb;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-strong: #ffffff;
  --ink: #19202c;
  --muted: #647086;
  --line: rgba(25, 32, 44, 0.08);
  --line-strong: rgba(25, 32, 44, 0.16);
  --accent: #446bff;
  --accent-soft: rgba(68, 107, 255, 0.12);
  --accent-2: #1ea7a1;
  --success: #3f8f57;
  --danger: #b45f55;
  --warning: #b0862b;
  --radius: 18px;
  --shadow: 0 20px 55px rgba(20, 30, 50, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(68, 107, 255, 0.08), transparent 28%),
    radial-gradient(circle at bottom right, rgba(30, 167, 161, 0.08), transparent 22%),
    var(--bg);
}

h1, h2, h3, h4 {
  font-family: "Segoe UI", Arial, sans-serif;
}

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

.welcome-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: rgba(244, 246, 251, 0.92);
  backdrop-filter: blur(12px);
}

.welcome-card {
  width: min(980px, 100%);
  padding: 44px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: 30px;
  box-shadow: var(--shadow);
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.welcome-card h1 {
  margin-top: 18px;
  font-size: clamp(42px, 6vw, 76px);
  line-height: 0.95;
}

.welcome-card p {
  margin-top: 16px;
  max-width: 720px;
  color: var(--muted);
  font-size: 17px;
}

.welcome-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 22px;
  margin-top: 28px;
}

.welcome-panel,
.panel,
.stat-card,
.hero-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.welcome-panel {
  padding: 22px;
}

.welcome-panel h3 {
  font-size: 30px;
  margin-bottom: 12px;
}

.feature-list,
.list {
  display: grid;
  gap: 10px;
}

.feature-item,
.list-item {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.welcome-actions {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.btn,
.welcome-btn {
  border: none;
  border-radius: 14px;
  padding: 14px 18px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.btn:hover,
.welcome-btn:hover {
  transform: translateY(-1px);
}

.btn-primary,
.welcome-btn.primary {
  background: linear-gradient(135deg, var(--accent), #6f90ff);
  color: #fff;
}

.btn-secondary,
.welcome-btn.secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line-strong);
}

.btn-danger {
  background: rgba(180, 95, 85, 0.12);
  color: var(--danger);
  border: 1px solid rgba(180, 95, 85, 0.2);
}

.app-shell {
  display: none;
  min-height: 100vh;
}

.app-shell.active {
  display: flex;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 296px;
  padding: 24px 18px 20px;
  overflow-y: auto;
  background: rgba(255, 255, 255, 0.9);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.sidebar-header {
  padding: 18px;
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(68, 107, 255, 0.12), rgba(30, 167, 161, 0.12));
  border: 1px solid var(--line);
  margin-bottom: 18px;
}

.sidebar-header h2 {
  margin-top: 10px;
  font-size: 28px;
}

.sidebar-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.nav-group {
  margin-bottom: 18px;
}

.nav-group-title {
  padding: 8px 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: var(--ink);
  padding: 12px 14px;
  text-align: left;
  cursor: pointer;
}

.nav-item:hover {
  background: rgba(68, 107, 255, 0.06);
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(68, 107, 255, 0.14), rgba(30, 167, 161, 0.14));
  border-color: rgba(68, 107, 255, 0.16);
  color: var(--accent);
  font-weight: 700;
}

.nav-index {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 800;
}

.sidebar-footer {
  position: sticky;
  bottom: 0;
  padding-top: 12px;
  background: linear-gradient(180deg, rgba(255,255,255,0), rgba(255,255,255,0.96) 24%);
}

.sidebar-footer .btn {
  width: 100%;
  margin-top: 10px;
}

.save-status {
  margin-top: 10px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.main {
  margin-left: 296px;
  width: calc(100% - 296px);
  padding: 32px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.page-header {
  margin-bottom: 20px;
}

.page-header h1 {
  font-size: clamp(38px, 5vw, 62px);
  line-height: 0.98;
}

.page-header p,
.mini-note,
.lead {
  margin-top: 12px;
  color: var(--muted);
  font-size: 15px;
}

.hero-card,
.panel,
.stat-card {
  padding: 22px;
}

.hero-card {
  background: linear-gradient(135deg, rgba(68, 107, 255, 0.12), rgba(30, 167, 161, 0.12)), var(--panel);
}

.hero-title {
  margin-top: 10px;
  font-size: clamp(34px, 4vw, 54px);
  line-height: 0.98;
}

.hero-meta,
.tag-row,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hero-meta {
  margin-top: 16px;
}

.pill,
.chip,
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.pill,
.chip,
.status.soft {
  background: #fff;
  border: 1px solid var(--line);
}

.status.yes {
  background: rgba(63, 143, 87, 0.12);
  border: 1px solid rgba(63, 143, 87, 0.18);
  color: var(--success);
}

.status.no {
  background: rgba(180, 95, 85, 0.12);
  border: 1px solid rgba(180, 95, 85, 0.18);
  color: var(--danger);
}

.status.pending {
  background: rgba(176, 134, 43, 0.12);
  border: 1px solid rgba(176, 134, 43, 0.18);
  color: var(--warning);
}

.cards-4,
.grid-2,
.grid-3,
.field-grid {
  display: grid;
  gap: 18px;
}

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

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

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

.field-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.stat-value {
  margin-top: 10px;
  font-size: clamp(26px, 3vw, 42px);
  font-weight: 800;
}

.stat-sub {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.field {
  display: grid;
  gap: 8px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: #fff;
  color: var(--ink);
  padding: 12px 14px;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.table-wrap {
  overflow-x: auto;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.list-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.progress-shell {
  width: 100%;
  height: 12px;
  background: rgba(25, 32, 44, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.dashboard-chart {
  width: 100%;
}

.dashboard-chart svg {
  display: block;
  width: 100%;
  height: auto;
}

.dashboard-chart-empty {
  min-height: 220px;
  display: grid;
  place-items: center;
}

.dashboard-chart-bar {
  overflow: hidden;
}

.dashboard-chart-donut {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 220px);
  align-items: center;
  gap: 18px;
}

.dashboard-donut-visual {
  display: flex;
  align-items: center;
  justify-content: center;
}

.dashboard-donut-legend {
  display: grid;
  gap: 10px;
}

.dashboard-donut-legend-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  font-size: 13px;
}

.dashboard-donut-swatch {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.empty {
  padding: 16px;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  min-width: 220px;
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.code-block {
  display: block;
  padding: 12px 14px;
  border-radius: 14px;
  background: #101621;
  color: #dce7ff;
  overflow-x: auto;
  font-family: Consolas, monospace;
  font-size: 13px;
}

@media (max-width: 1180px) {
  .cards-4,
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .app-shell.active {
    display: block;
  }

  .sidebar {
    position: relative;
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .main {
    margin-left: 0;
    width: 100%;
    padding: 22px;
  }

  .welcome-grid,
  .grid-2,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-chart-donut {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .cards-4,
  .grid-3,
  .field-grid.three {
    grid-template-columns: 1fr;
  }
}


/* Installable browser PWA additions */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body.drawer-open {
  overflow: hidden;
}

.mobile-topbar,
.mobile-drawer,
.mobile-drawer-scrim,
.mobile-tabbar {
  display: none;
}

.mobile-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 35;
  align-items: center;
  gap: 10px;
  min-height: calc(68px + var(--safe-top));
  padding: calc(10px + var(--safe-top)) 12px 10px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.mobile-title {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}

.mobile-title strong,
.mobile-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-title span {
  color: var(--muted);
  font-size: 12px;
}

.mobile-topbar .btn,
.mobile-drawer .btn {
  min-width: 0;
  padding: 10px 12px;
}

.mobile-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 35;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.mobile-tab-btn {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  padding: 9px 4px;
  font-size: 12px;
  font-weight: 800;
}

.mobile-tab-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(68, 107, 255, 0.3);
}

.mobile-drawer-scrim {
  position: fixed;
  inset: 0;
  z-index: 38;
  background: rgba(23, 37, 31, 0.38);
}

.mobile-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 39;
  width: min(390px, 92vw);
  max-height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: calc(18px + var(--safe-top)) 16px calc(18px + var(--safe-bottom));
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 50px rgba(23, 37, 31, 0.18);
}

.mobile-drawer-header,
.mobile-drawer-actions {
  display: grid;
  gap: 10px;
}

.mobile-drawer-header {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  margin-bottom: 14px;
}

.mobile-drawer-actions {
  margin-bottom: 14px;
}

.app-shell.drawer-open .mobile-drawer,
.app-shell.drawer-open .mobile-drawer-scrim {
  display: block;
}

@media (pointer: coarse), (max-width: 980px) {
  html,
  body {
    height: 100% !important;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: hidden !important;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }

  body:not(.drawer-open) {
    position: static !important;
    overflow-y: hidden !important;
  }

  .app-shell {
    width: 100%;
    max-width: 100%;
  }

  .main,
  .page-stack,
  .page.active {
    height: auto !important;
    max-height: none !important;
    overflow-y: visible !important;
  }

  .welcome-screen {
    position: fixed;
    inset: 0;
    min-height: 0;
    height: 100dvh !important;
    align-items: flex-start;
    padding: calc(18px + var(--safe-top)) 14px calc(18px + var(--safe-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .welcome-card {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 980px) {
  .app-shell.active {
    display: block;
    position: fixed !important;
    inset: 0 !important;
    width: 100%;
    max-width: 100%;
    height: 100dvh !important;
    max-height: 100dvh !important;
    min-height: 0;
    padding-top: calc(74px + var(--safe-top));
    padding-bottom: calc(78px + var(--safe-bottom));
    overflow-x: hidden;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
  }

  .mobile-topbar {
    display: flex;
  }

  .mobile-tabbar {
    display: grid;
  }

  .sidebar {
    display: none;
  }

  .main {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
    padding: 16px;
  }

  .welcome-grid,
  .today-hero,
  .today-visual-grid,
  .grid-2,
  .grid-3,
  .cards-3,
  .cards-4,
  .field-grid,
  .field-grid.three,
  .mobile-drawer-actions {
    grid-template-columns: minmax(0, 1fr);
  }

  .panel,
  .stat-card,
  .mini-card,
  .med-card,
  .welcome-panel {
    padding: 16px;
    border-radius: 16px;
  }

  .page-header h1 {
    font-size: 34px;
    line-height: 1;
  }

  .panel-header,
  .list-item,
  .med-header,
  .action-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .tag-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .table-wrap {
    overflow-x: auto;
    max-width: 100%;
  }
}


.mobile-drawer {
  background: var(--panel-strong, #ffffff) !important;
  border-left: 1px solid var(--line-strong, rgba(25, 32, 44, 0.16));
  box-shadow: -22px 0 54px rgba(25, 32, 44, 0.28);
}

.mobile-drawer-scrim {
  background: rgba(25, 32, 44, 0.48);
  backdrop-filter: blur(2px);
}


@media (display-mode: standalone) and (min-width: 981px) {
  html,
  body {
    height: auto !important;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto !important;
  }

  body:not(.drawer-open) {
    overflow-y: auto !important;
  }

  .app-shell.active {
    display: flex;
    position: static !important;
    inset: auto !important;
    width: 100%;
    min-height: 100vh;
    height: auto !important;
    max-height: none !important;
    padding-top: 0;
    padding-bottom: 0;
    overflow: visible !important;
  }

  .main {
    margin-left: 296px;
    width: calc(100% - 296px);
    padding: 32px;
    overflow: visible !important;
  }

  .sidebar {
    display: block;
    position: fixed;
    inset: 0 auto 0 0;
    width: 296px;
  }

  .mobile-topbar,
  .mobile-tabbar {
    display: none !important;
  }
}
