:root {
  --bg: #f3ede4;
  --bg-elevated: rgba(255, 248, 240, 0.88);
  --bg-panel: rgba(255, 252, 247, 0.9);
  --bg-panel-strong: #fffaf4;
  --text: #1f231f;
  --muted: #6c7069;
  --border: rgba(74, 58, 39, 0.12);
  --shadow: 0 20px 60px rgba(72, 52, 34, 0.12);
  --primary: #8a5a34;
  --primary-strong: #6d4628;
  --secondary: #31443f;
  --success: #4d8d78;
  --danger: #c86645;
  --warning: #d5a23f;
  --card-radius: 28px;
  --panel-radius: 24px;
  --pill-radius: 999px;
  --font-ui: "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
  --font-display: "Rockwell", "Georgia", serif;
}

body[data-theme="night"] {
  --bg: #161b20;
  --bg-elevated: rgba(24, 31, 38, 0.88);
  --bg-panel: rgba(28, 36, 44, 0.92);
  --bg-panel-strong: #222b33;
  --text: #eef3ee;
  --muted: #a4b3b0;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.34);
  --primary: #d4935b;
  --primary-strong: #efb27c;
  --secondary: #5c8278;
  --success: #7fcaad;
  --danger: #eb8d70;
  --warning: #efc96b;
}

body[data-theme="workshop"] {
  --bg: #e5ece6;
  --bg-elevated: rgba(248, 255, 250, 0.9);
  --bg-panel: rgba(250, 255, 251, 0.92);
  --bg-panel-strong: #fbfffc;
  --text: #1a2621;
  --muted: #557065;
  --border: rgba(44, 77, 67, 0.12);
  --shadow: 0 18px 50px rgba(35, 69, 55, 0.14);
  --primary: #406656;
  --primary-strong: #2f5244;
  --secondary: #7f5d38;
  --success: #3f8a6b;
  --danger: #bc6547;
  --warning: #c89b45;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(138, 90, 52, 0.18), transparent 34%),
    radial-gradient(circle at top right, rgba(49, 68, 63, 0.16), transparent 28%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.36), transparent 22%),
    var(--bg);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 44px 44px;
  opacity: 0.22;
}

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

button {
  cursor: pointer;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--font-display);
  letter-spacing: -0.02em;
}

p {
  margin: 0;
}

.welcome-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px 20px;
}

.welcome-card {
  width: min(1120px, 100%);
  background:
    linear-gradient(145deg, rgba(255, 250, 243, 0.92), rgba(244, 235, 224, 0.86)),
    var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 36px;
  box-shadow: var(--shadow);
  padding: clamp(28px, 4vw, 46px);
  position: relative;
  overflow: hidden;
}

.welcome-card::before,
.welcome-card::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  filter: blur(10px);
}

.welcome-card::before {
  width: 240px;
  height: 240px;
  background: rgba(138, 90, 52, 0.18);
  top: -90px;
  right: -60px;
}

.welcome-card::after {
  width: 220px;
  height: 220px;
  background: rgba(49, 68, 63, 0.15);
  bottom: -90px;
  left: -60px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.24em;
  color: var(--muted);
}

.eyebrow::before {
  content: "";
  width: 34px;
  height: 1px;
  background: currentColor;
}

.welcome-card h1 {
  font-size: clamp(2.3rem, 5vw, 4.2rem);
  line-height: 0.98;
  max-width: 820px;
}

.welcome-card > p {
  margin-top: 18px;
  max-width: 760px;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.7;
}

.welcome-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.95fr;
  gap: 20px;
  margin-top: 34px;
  position: relative;
  z-index: 1;
}

.welcome-panel,
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--panel-radius);
  box-shadow: 0 10px 26px rgba(57, 45, 31, 0.06);
}

.welcome-panel {
  padding: 24px;
}

.welcome-panel h3,
.panel-header h3 {
  font-size: 1.35rem;
}

.mini-note,
.lead,
.sidebar-note,
.empty,
.field label,
.save-status,
.legend-item span,
.line-labels span,
.vehicle-card p,
.vehicle-card-grid span,
.vehicle-card-footer,
.list-item small {
  color: var(--muted);
}

.feature-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.feature-item {
  background: rgba(255, 255, 255, 0.48);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 18px;
  padding: 14px 16px;
  line-height: 1.55;
}

.welcome-actions,
.action-row,
.hero-actions,
.toolbar-row,
.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.welcome-actions {
  margin-top: 22px;
}

.btn,
.welcome-btn,
.chip,
.status-pill,
.money-pill,
.receipt-pill,
.mini-badge {
  border-radius: var(--pill-radius);
}

.welcome-btn,
.btn {
  border: 1px solid transparent;
  padding: 12px 18px;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease, border-color 180ms ease;
}

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

.welcome-btn.primary,
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #fff;
  box-shadow: 0 12px 26px rgba(138, 90, 52, 0.22);
}

.welcome-btn.secondary,
.btn-secondary {
  background: rgba(255, 255, 255, 0.55);
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px dashed var(--border);
}

.btn-danger {
  background: rgba(200, 102, 69, 0.1);
  color: var(--danger);
  border: 1px solid rgba(200, 102, 69, 0.24);
}

.full-width {
  width: 100%;
}

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

.app-shell.active {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
}

.sidebar {
  padding: 24px 18px 18px;
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent), var(--bg-elevated);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar-header h2 {
  font-size: 2rem;
  margin-bottom: 10px;
}

.nav-group {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.nav-group-title {
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--muted);
  padding-left: 14px;
}

.nav-item {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 14px;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 14px 16px;
  border-radius: 22px;
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(138, 90, 52, 0.18), rgba(49, 68, 63, 0.12));
  border-color: rgba(138, 90, 52, 0.18);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.nav-index {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  color: var(--muted);
  font-size: 0.84rem;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
}

.main {
  padding: 28px;
}

.page-stack {
  display: grid;
}

.page {
  display: none;
  gap: 18px;
}

.page.active {
  display: grid;
}

.page-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
}

.page-header h1 {
  font-size: clamp(2rem, 4vw, 3.25rem);
  margin-bottom: 8px;
}

.page-header p {
  max-width: 760px;
  color: var(--muted);
  line-height: 1.7;
}

.hero-header,
.detail-header {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.12)),
    linear-gradient(135deg, rgba(138, 90, 52, 0.14), rgba(49, 68, 63, 0.08)),
    var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.metric-grid,
.grid-2,
.grid-3,
.dashboard-grid {
  display: grid;
  gap: 18px;
}

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

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

.vehicle-entry-panel {
  width: 100%;
}

.vehicle-detail-analytics-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

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

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

.span-2 {
  grid-column: span 2;
}

.metric-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 22px;
  box-shadow: 0 10px 24px rgba(57, 45, 31, 0.05);
  display: grid;
  gap: 10px;
}

.metric-card span {
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
}

.metric-card strong {
  font-size: 2rem;
  font-family: var(--font-display);
}

.metric-card small {
  font-size: 0.95rem;
}

.tone-amber {
  background: linear-gradient(180deg, rgba(214, 176, 121, 0.18), rgba(255, 255, 255, 0.78));
}

.tone-clay {
  background: linear-gradient(180deg, rgba(217, 106, 70, 0.12), rgba(255, 255, 255, 0.78));
}

.tone-slate {
  background: linear-gradient(180deg, rgba(49, 68, 63, 0.12), rgba(255, 255, 255, 0.78));
}

.tone-olive {
  background: linear-gradient(180deg, rgba(77, 141, 120, 0.12), rgba(255, 255, 255, 0.78));
}

.panel {
  padding: 22px;
}

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

.panel-header .lead {
  margin-top: 8px;
  line-height: 1.65;
  max-width: 680px;
}

.dual-surface {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 22px;
  align-items: center;
}

.insight-stack {
  display: grid;
  gap: 12px;
}

.insight-card {
  padding: 16px 18px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.25);
  display: grid;
  gap: 6px;
}

.insight-card span {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
}

.insight-card strong {
  font-size: 1.15rem;
}

.donut-wrap {
  position: relative;
  width: 240px;
  margin: 0 auto;
}

.donut-chart {
  width: 100%;
  display: block;
  transform: rotate(-90deg);
}

.donut-track,
.donut-ring {
  fill: none;
  stroke-width: 20;
  stroke-linecap: round;
}

.donut-track {
  stroke: rgba(0, 0, 0, 0.06);
}

.donut-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
}

.donut-center strong {
  font-family: var(--font-display);
  font-size: 2rem;
}

.donut-center span {
  color: var(--muted);
}

.chart-legend {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.chart-bars {
  display: grid;
  gap: 14px;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(0, 120px) 1fr auto;
  gap: 12px;
  align-items: center;
}

.bar-label,
.bar-value {
  font-size: 0.95rem;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--secondary), var(--primary));
}

.mini-columns {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: end;
  gap: 14px;
  min-height: 230px;
}

.mini-column {
  display: grid;
  gap: 10px;
  align-items: end;
  text-align: center;
}

.mini-column-value {
  font-size: 0.8rem;
  color: var(--muted);
}

.mini-column-bar {
  width: 100%;
  min-height: 20px;
  border-radius: 18px 18px 10px 10px;
  background: linear-gradient(180deg, var(--primary), var(--secondary));
}

.mini-column-label {
  font-size: 0.86rem;
  color: var(--muted);
}

.line-chart-wrap {
  display: grid;
  gap: 14px;
}

.line-chart {
  width: 100%;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(0, 0, 0, 0.03));
}

.line-area {
  fill: rgba(138, 90, 52, 0.16);
}

.line-path {
  fill: none;
  stroke: var(--primary);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.line-dot {
  fill: var(--secondary);
}

.line-labels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 10px;
}

.line-labels div {
  display: grid;
  gap: 4px;
}

.line-labels strong {
  font-size: 0.88rem;
}

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

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

.field label {
  font-size: 0.9rem;
}

input,
textarea,
select {
  width: 100%;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--bg-panel-strong);
  color: var(--text);
  padding: 14px 16px;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

input:focus,
textarea:focus,
select:focus {
  border-color: rgba(138, 90, 52, 0.45);
  box-shadow: 0 0 0 4px rgba(138, 90, 52, 0.12);
}

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

.vehicle-roster,
.attachment-grid,
.list {
  display: grid;
  gap: 14px;
}

.vehicle-card,
.attachment-card {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.12)), var(--bg-panel-strong);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 18px;
  display: grid;
  gap: 16px;
}

.vehicle-card-top,
.vehicle-card-footer,
.list-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.vehicle-card-top h4 {
  font-size: 1.4rem;
  margin-top: 6px;
  margin-bottom: 4px;
}

.mini-badge,
.money-pill,
.receipt-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  background: rgba(255, 255, 255, 0.58);
  color: var(--muted);
}

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

.vehicle-card-grid strong {
  display: block;
  margin-top: 6px;
  font-size: 1.15rem;
}

.vehicle-next {
  color: var(--muted);
  font-size: 0.95rem;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.chip {
  background: rgba(255, 255, 255, 0.58);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
}

.chip.active {
  background: linear-gradient(135deg, var(--secondary), var(--primary));
  color: #fff;
  border-color: transparent;
}

.status-pill,
.money-pill,
.receipt-pill {
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

.status-pill {
  padding: 8px 12px;
  text-transform: uppercase;
}

.status-overdue {
  background: rgba(200, 102, 69, 0.14);
  color: var(--danger);
}

.status-dueSoon {
  background: rgba(213, 162, 63, 0.14);
  color: var(--warning);
}

.status-onTrack {
  background: rgba(77, 141, 120, 0.14);
  color: var(--success);
}

.money-pill {
  background: rgba(49, 68, 63, 0.12);
  color: var(--secondary);
}

.receipt-pill {
  background: rgba(138, 90, 52, 0.12);
  color: var(--primary);
}

.list-item {
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.46);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.attachment-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.attachment-card strong {
  font-size: 1rem;
}

.attachment-thumb {
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(49, 68, 63, 0.12), rgba(138, 90, 52, 0.16));
  display: grid;
  place-items: center;
  overflow: hidden;
}

.attachment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-thumb span {
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.16em;
}

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

.compact-grid .metric-card strong {
  font-size: 1.6rem;
}

.toolbar-row {
  justify-content: space-between;
  align-items: center;
}

.empty,
.empty-chart {
  padding: 26px 18px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.34);
  border: 1px dashed var(--border);
  text-align: center;
  line-height: 1.6;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  padding: 14px 18px;
  background: rgba(26, 38, 33, 0.94);
  color: #fff;
  border-radius: 18px;
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
  z-index: 20;
}

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

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

  .span-2 {
    grid-column: span 2;
  }
}

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

  .sidebar {
    position: relative;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .welcome-grid,
  .grid-2,
  .vehicle-detail-analytics-row,
  .metric-grid,
  .dashboard-grid,
  .grid-3,
  .dual-surface {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

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

@media (max-width: 720px) {
  .main {
    padding: 18px;
  }

  .welcome-card,
  .hero-header,
  .detail-header,
  .panel,
  .metric-card {
    border-radius: 24px;
  }

  .page-header,
  .vehicle-card-top,
  .vehicle-card-footer,
  .list-item,
  .panel-header,
  .toolbar-row {
    flex-direction: column;
    align-items: stretch;
  }

  .table-actions,
  .hero-actions,
  .action-row {
    width: 100%;
  }

  .table-actions > *,
  .hero-actions > *,
  .action-row > * {
    flex: 1 1 auto;
  }

  .bar-row {
    grid-template-columns: 1fr;
  }

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

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

  .stack-mobile {
    align-items: stretch;
  }
}


/* 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(138, 90, 52, 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%;
  }
}


@media (min-width: 981px) {
  .app-shell.active {
    grid-template-columns: 276px minmax(0, 1fr);
  }

  .sidebar {
    width: 276px;
    padding: 20px 14px 16px;
  }

  .sidebar-header h2 {
    font-size: 1.55rem;
    line-height: 1.08;
  }

  .nav-item {
    gap: 10px;
    padding: 11px 12px;
    border-radius: 16px;
  }

  .nav-index {
    width: 28px;
    height: 28px;
    font-size: 0.74rem;
  }

  .sidebar-footer .btn {
    padding: 10px 12px;
  }
}

.mobile-drawer {
  background: var(--bg-panel-strong, #fffaf4) !important;
  border-left: 1px solid var(--border, rgba(74, 58, 39, 0.16));
  box-shadow: -22px 0 54px rgba(31, 35, 31, 0.28);
}

.mobile-drawer-scrim {
  background: rgba(31, 35, 31, 0.52);
  backdrop-filter: blur(2px);
}

.mobile-drawer .nav-group-title,
.mobile-drawer .nav-item {
  color: var(--text);
}


@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: 276px;
    width: calc(100% - 276px);
    padding: 28px;
    overflow: visible !important;
  }

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

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