:root,
[data-theme="light"] {
  --bg: #f5f6f8;
  --bg-elev: #ffffff;
  --bg-soft: #eef1f5;
  --line: #dde3eb;
  --text: #1a2330;
  --muted: #5c6b7a;
  --accent: #c9842a;
  --accent2: #0f9d8a;
  --glow1: rgba(201, 132, 42, 0.08);
  --glow2: rgba(15, 157, 138, 0.07);
  --warn: #c9842a;
  --danger: #c45c4a;
  --enquiry: #3b82f6;
  --quoted: #0f9d8a;
  --po: #c9842a;
  --dispatched: #7c6af0;
  --invoiced: #2563eb;
  --paid: #16a34a;
  --radius: 12px;
  --shadow: 0 10px 28px rgba(26, 35, 48, 0.08);
  --header-border: #e6ebf1;
  --bar-track: #e2e8f0;
  --sales: #0f9d8a;
  --purchase: #c9842a;
}

[data-theme="paper"] {
  --bg: #fafaf8;
  --bg-elev: #ffffff;
  --bg-soft: #f0f2ef;
  --line: #e2e6e0;
  --text: #1c2420;
  --muted: #66736c;
  --accent: #0d9488;
  --accent2: #0f766e;
  --glow1: rgba(13, 148, 136, 0.08);
  --glow2: rgba(15, 118, 110, 0.05);
  --warn: #b45309;
  --quoted: #0d9488;
  --po: #b45309;
  --bar-track: #e5e9e4;
  --sales: #0d9488;
  --purchase: #b45309;
}

[data-theme="amber"] {
  --bg: #0e1218;
  --bg-elev: #161c26;
  --bg-soft: #1c2430;
  --line: #2a3342;
  --text: #f2efe8;
  --muted: #9aa3b2;
  --accent: #e8a54b;
  --accent2: #3db8a0;
  --glow1: rgba(232, 165, 75, 0.14);
  --glow2: rgba(61, 184, 160, 0.11);
  --warn: #e8a54b;
  --danger: #e07a6a;
  --enquiry: #6aa9ff;
  --quoted: #3db8a0;
  --po: #e8a54b;
  --dispatched: #a78bfa;
  --invoiced: #60a5fa;
  --paid: #4ade80;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
  --header-border: #2a3342;
  --bar-track: #243041;
  --sales: #3db8a0;
  --purchase: #e8a54b;
}

[data-theme="ocean"] {
  --bg: #0b1018;
  --bg-elev: #131a26;
  --bg-soft: #1a2333;
  --line: #2a3548;
  --text: #e8eef8;
  --muted: #8b97ab;
  --accent: #5b9fd4;
  --accent2: #38bdf8;
  --glow1: rgba(56, 189, 248, 0.12);
  --glow2: rgba(91, 159, 212, 0.1);
  --warn: #e0b35c;
  --quoted: #38bdf8;
  --po: #e0b35c;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
  --header-border: #2a3548;
  --bar-track: #243041;
  --sales: #38bdf8;
  --purchase: #e0b35c;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; overscroll-behavior-y: none; }
body.no-scroll { overflow: hidden; height: 100%; }
body {
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 420px at 8% -10%, var(--glow1), transparent 55%),
    radial-gradient(800px 400px at 100% 0%, var(--glow2), transparent 50%),
    var(--bg);
  background-attachment: fixed;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

button.ghost, button.action, button.primary, button.danger, button.tiny {
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  border-radius: 9px;
  padding: 0.42rem 0.8rem;
  font-size: 0.82rem;
  font-weight: 550;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
button.ghost:hover, button.action:hover, button.action.active {
  border-color: var(--accent2);
  color: var(--accent2);
}
button.primary {
  background: color-mix(in srgb, var(--accent2) 14%, var(--bg-elev));
  border-color: color-mix(in srgb, var(--accent2) 45%, var(--line));
}
button.primary:hover { border-color: var(--accent2); color: var(--accent2); }
button.danger:hover { border-color: var(--danger); color: var(--danger); }
button.tiny { padding: 0.32rem 0.65rem; font-size: 0.78rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

@keyframes rise-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* —— Home / create company —— */
.home {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  animation: rise-in 0.45s ease both;
}
.home-card {
  width: min(480px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.75rem 1.6rem 1.5rem;
}
.home-card .company-brand {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: clamp(1.7rem, 4vw, 2.1rem);
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin: 0 0 0.35rem;
}
.powered-by {
  margin: 0 0 1.1rem;
  color: var(--muted);
  font-size: 0.78rem;
}
.powered-by strong { color: var(--text); font-weight: 600; }
.powered-by .ks-mark {
  color: var(--accent);
  font-family: "Instrument Serif", Georgia, serif;
  font-style: italic;
}

/* —— App shell —— */
.app-shell {
  display: grid;
  grid-template-columns: 15.5rem minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
  /* No animation/transform here: this element is the containing block for the
     fixed-position sidebar/drawer overlays. A transform (even a completed,
     fill-mode animation resolving to identity) would pin those overlays to
     this box instead of the viewport, making them drift/disappear on scroll. */
}
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border-right: 1px solid var(--header-border);
  padding: 1.35rem 1rem 1.1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  z-index: 40;
}
.sidebar-top {
  padding-bottom: 1.1rem;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}
.sidebar-close { display: none; }
.mobile-topbar { display: none; }
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 75;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
.brand-lockup { display: flex; flex-direction: column; gap: 0.35rem; }
.brand-mark {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 70%, #fff), var(--accent2));
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  color: #fff;
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 1.15rem;
  font-style: italic;
}
.company-brand {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.sidebar .tabs {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 0.2rem;
  margin: 1.15rem 0 0;
}
.sidebar .tabs button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 550;
  letter-spacing: -0.01em;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  transition: color 0.15s ease, background 0.15s ease;
}
.sidebar .tabs button:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--bg-soft) 80%, transparent);
}
.sidebar .tabs button.active {
  color: var(--text);
  font-weight: 650;
  background: color-mix(in srgb, var(--accent2) 14%, var(--bg-soft));
  box-shadow: inset 3px 0 0 var(--accent2);
}
.sidebar-bottom {
  margin-top: auto;
  padding-top: 0.9rem;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 0.55rem;
}
.sidebar-meta {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  color: var(--muted);
  line-height: 1.35;
  word-break: break-all;
}
.sidebar-meta strong { color: var(--text); font-weight: 500; }

.app-content {
  min-width: 0;
  padding: 1.15rem clamp(1rem, 2vw, 2rem) 2.5rem;
  animation: rise-in 0.45s ease both;
}
.content-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem 0.75rem;
  margin: 0 0 1rem;
}
.content-meta .sync-stamp {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: var(--muted);
  margin-right: auto;
}
.content-meta .sync-stamp strong { color: var(--text); font-weight: 500; }
.content-meta .actions { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.action-bar {
  display: inline-flex;
  align-items: stretch;
  gap: 0.2rem;
  padding: 0.22rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-soft);
  max-width: 100%;
}
.action-bar .primary {
  border: 0;
  border-radius: 999px;
  padding: 0.36rem 0.85rem;
  white-space: nowrap;
}

.panel {
  background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.05rem 1.1rem 1.15rem;
  animation: rise-in 0.4s ease both;
}
.panel + .panel { margin-top: 0.9rem; }
.panel h2 {
  margin: 0 0 0.85rem;
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.panel h2 small {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 400;
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.7rem;
}
.kpi {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem 0.8rem;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  animation: rise-in 0.5s ease both;
}
.kpi:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--accent2) 40%, var(--line));
  box-shadow: var(--shadow);
}
.kpi .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.kpi .value {
  margin-top: 0.4rem;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.kpi .hint { margin-top: 0.25rem; font-size: 0.75rem; color: var(--muted); }
.kpi.alert {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line));
  background: color-mix(in srgb, var(--danger) 10%, var(--bg-soft));
}
.kpi.alert .value { color: var(--danger); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}
.tab-panel { display: grid; gap: 0.9rem; animation: rise-in 0.32s ease both; }

.pie-wrap {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 1rem;
  align-items: center;
}
.pie {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--bar-track);
}
.legend { display: grid; gap: 0.35rem; font-size: 0.85rem; }
.legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 0.4rem;
}

.party-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-elev);
}
.party-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.95rem;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--line);
}
.party-head.sales { box-shadow: inset 3px 0 0 var(--sales); }
.party-head.purchase { box-shadow: inset 3px 0 0 var(--purchase); }
.party-head strong { font-size: 0.95rem; }
.party-head .meta {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 0.15rem;
}
.job-list {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-elev);
}
.job {
  display: grid;
  grid-template-columns: 1.2fr 0.75fr 0.75fr 0.9fr minmax(12rem, 1.7fr) auto;
  gap: 0.5rem;
  padding: 0.7rem 0.85rem;
  border-top: 1px solid var(--line);
  align-items: start;
  background: var(--bg-elev);
}
.job.party-row {
  grid-template-columns: 1.2fr 0.8fr 0.7fr minmax(12rem, 1.6fr) auto;
  align-items: center;
}
.job.user-row {
  grid-template-columns: 1.4fr 0.8fr auto;
  align-items: center;
}
.job .actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.job-header {
  position: sticky;
  top: 0;
  z-index: 2;
  align-items: center;
  padding: 0.55rem 0.85rem;
  background: var(--bg-soft);
  border-top: 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.job-list > .job:not(.job-header):first-of-type,
.party-block .job-list > .job:not(.job-header):first-of-type { border-top: 0; }
.job select,
.action-bar select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0.32rem 1.55rem 0.32rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background-color: var(--bg-elev);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 12px) 55%,
    calc(100% - 7px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 550;
  line-height: 1.2;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.job select:hover,
.action-bar select:hover {
  border-color: color-mix(in srgb, var(--accent2) 40%, var(--line));
}
.action-bar select {
  width: auto;
  font-size: 0.8rem;
  border: 0;
  border-radius: 999px;
  background-color: transparent;
  padding: 0.36rem 1.5rem 0.36rem 0.7rem;
}
.action-bar select:hover { background-color: var(--bg-elev); }
.job select:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--accent2) 55%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent2) 14%, transparent);
}
.job.overdue {
  background: color-mix(in srgb, var(--danger) 12%, var(--bg-elev));
}
.job.overdue strong { color: var(--danger); }
.job .meta {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}
.job .tiny-updated {
  display: block;
  margin-top: 0.2rem;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.62rem;
  color: var(--muted);
}
.remarks-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem;
  align-items: start;
  min-width: 0;
}
.remarks-box {
  min-width: 0;
  margin: 0;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.remarks-box.empty { color: var(--muted); }
.icon-btn {
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  line-height: 1;
  flex-shrink: 0;
}
.icon-btn svg {
  width: 0.88rem;
  height: 0.88rem;
  display: block;
}
.job .del-slot {
  display: flex;
  justify-content: flex-end;
  padding-top: 0.1rem;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.65rem;
}
label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 550;
  letter-spacing: 0.02em;
}
input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.5rem 0.7rem;
  background: var(--bg-elev);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--accent2) 55%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent2) 16%, transparent);
}
textarea { min-height: 72px; resize: vertical; }

.company-list { margin-top: 1rem; display: grid; gap: 0.45rem; }
.company-list a {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.company-list a:hover {
  border-color: color-mix(in srgb, var(--accent2) 45%, var(--line));
  transform: translateY(-1px);
}
.company-list .slug {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: var(--muted);
}

.err {
  background: color-mix(in srgb, var(--danger) 12%, var(--bg-elev));
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line));
  color: var(--danger);
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  font-size: 0.86rem;
  margin: 0.75rem 0;
}
.empty-state {
  padding: 1.4rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 60%, transparent);
}
.empty-state strong {
  display: block;
  color: var(--text);
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
}
.muted { color: var(--muted); }
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}

/* Theme picker (same as AI app) */
.theme-picker { position: relative; z-index: 30; }
.theme-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  font-size: 0.76rem;
  font-weight: 550;
  cursor: pointer;
}
.theme-trigger:hover,
.theme-trigger[aria-expanded="true"] {
  background: var(--bg-soft);
  border-color: var(--line);
}
.theme-swatches { display: flex; gap: 3px; flex-shrink: 0; }
.theme-swatches i {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--line) 70%, #fff);
  display: block;
}
.theme-trigger-label { flex: 1; text-align: left; }
.theme-trigger-label small {
  display: block;
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.theme-chevron { color: var(--muted); font-size: 0.65rem; }
.theme-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 0.4rem);
  padding: 0.4rem;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.3rem;
}
.theme-menu[hidden] { display: none !important; }
.theme-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.55rem 0.6rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 550;
  cursor: pointer;
  text-align: left;
}
.theme-option:hover { background: var(--bg-soft); border-color: var(--line); }
.theme-option[aria-selected="true"] {
  background: color-mix(in srgb, var(--accent2) 12%, var(--bg-soft));
  border-color: color-mix(in srgb, var(--accent2) 40%, var(--line));
}
.theme-option .theme-swatches i:nth-child(1) { background: var(--t1); }
.theme-option .theme-swatches i:nth-child(2) { background: var(--t2); }
.theme-option .theme-swatches i:nth-child(3) { background: var(--t3); }
.theme-option[data-theme-pick="light"] { --t1: #ffffff; --t2: #c9842a; --t3: #0f9d8a; }
.theme-option[data-theme-pick="paper"] { --t1: #fafaf8; --t2: #0d9488; --t3: #0f766e; }
.theme-option[data-theme-pick="amber"] { --t1: #0e1218; --t2: #e8a54b; --t3: #3db8a0; }
.theme-option[data-theme-pick="ocean"] { --t1: #0b1018; --t2: #5b9fd4; --t3: #38bdf8; }
.theme-check { margin-left: auto; color: var(--accent2); opacity: 0; }
.theme-option[aria-selected="true"] .theme-check { opacity: 1; }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100%);
  background: var(--bg-elev);
  border-left: 1px solid var(--line);
  z-index: 70;
  transform: translateX(104%);
  transition: transform 0.25s ease;
  padding: 1.2rem 1.15rem 1.5rem;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.drawer.open { transform: none; }
.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}
.drawer h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
}
.drawer .drawer-sub {
  margin: 0.2rem 0 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  color: var(--muted);
}
.drawer label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0.75rem 0 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 550;
}
.drawer input,
.drawer select,
.drawer textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  font: inherit;
  font-size: 0.88rem;
}
.drawer textarea { min-height: 88px; resize: vertical; }
.drawer .row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}
.drawer .drawer-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.2rem;
  justify-content: flex-end;
}
.drawer .hint {
  margin: 0.85rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

@media (max-width: 960px) {
  .app-shell { display: block; min-height: 0; }
  body { background-attachment: scroll; }
  .mobile-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--bg-elev);
    border-bottom: 1px solid var(--header-border);
    padding: 0.65rem 0.9rem;
  }
  .mobile-topbar-title {
    font-family: "Instrument Serif", Georgia, serif;
    font-size: 1.05rem;
    flex: 1;
    text-align: center;
  }
  .mobile-topbar-stamp {
    font-family: "IBM Plex Mono", monospace;
    font-size: 0.66rem;
    color: var(--muted);
    text-align: right;
    flex-shrink: 0;
  }
  .mobile-topbar-stamp strong { color: var(--text); font-weight: 500; }
  .content-meta .sync-stamp { display: none; }
  .menu-btn {
    width: 2.15rem;
    height: 2.15rem;
    padding: 0;
    display: inline-grid;
    place-items: center;
    border: 1px solid var(--line);
    background: var(--bg-elev);
    color: var(--text);
    border-radius: 9px;
    cursor: pointer;
  }
  .menu-btn svg { width: 1.05rem; height: 1.05rem; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(280px, 82vw);
    height: 100vh;
    height: 100dvh;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    z-index: 80;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .sidebar-close { display: inline-grid; }
  .grid-2 { grid-template-columns: 1fr; }
  .job {
    grid-template-columns: 1fr 1fr;
  }
  .remarks-wrap { grid-column: 1 / -1; }
  .job .del-slot { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 640px) {
  html { -webkit-text-size-adjust: 100%; }
  .app-content { padding: 0.85rem 0.7rem 2rem; }
  .sidebar { padding: 0.9rem 0.75rem 0.75rem; width: min(260px, 84vw); }
  .sidebar-top { padding-bottom: 0.75rem; }
  .sidebar-bottom { margin-top: 0.75rem; padding-top: 0.75rem; }

  .content-meta { justify-content: flex-start; margin-bottom: 0.75rem; }
  .content-meta .sync-stamp { flex-basis: 100%; margin-right: 0; order: 2; }
  .content-meta .actions { order: 1; width: 100%; justify-content: flex-end; }

  .panel { padding: 0.85rem 0.75rem 0.95rem; }
  .summary { grid-template-columns: repeat(2, 1fr); }
  .pie-wrap { grid-template-columns: 1fr; justify-items: center; text-align: center; gap: 0.75rem; }
  .legend { justify-items: start; }

  .party-head { flex-wrap: wrap; row-gap: 0.4rem; }

  /* Card layout: turn grid rows into stacked, labeled cards */
  .job-header { display: none; }
  .job,
  .job.party-row,
  .job.user-row {
    grid-template-columns: 1fr;
    gap: 0.45rem;
    padding: 0.8rem 0.85rem;
  }
  .job [data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.62rem;
    font-weight: 650;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.25rem;
  }
  .job .del-slot { justify-content: flex-end; padding-top: 0; }
  .job .actions { justify-content: flex-start; }

  .drawer { padding: 1rem 0.85rem 1.25rem; }
  .drawer .row-2 { grid-template-columns: 1fr; }
}
