:root {
  color-scheme: light;
  --ink: #15251e;
  --muted: #65766e;
  --paper: #ffffff;
  --canvas: #f3f7f5;
  --soft: #edf4f0;
  --line: #d6e2dc;
  --line-strong: #b9cec3;
  --green: #0a5c42;
  --green-2: #117b58;
  --green-soft: #e5f3ec;
  --amber: #ad6800;
  --shadow: 0 16px 45px rgba(24, 64, 47, .10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--canvas); }
body { min-height: 100%; margin: 0; color: var(--ink); background: var(--canvas); }
button { font: inherit; }

.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 12px 10px 18px;
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 7px 24px rgba(24, 64, 47, .07);
  backdrop-filter: blur(14px);
}

.identity, .top-actions { display: flex; align-items: center; }
.identity { min-width: 0; gap: 11px; }
.top-actions { gap: 8px; }
.brand-icon { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 12px; }
.brand-copy { min-width: 0; }
.brand-copy strong { display: block; font-size: 17px; letter-spacing: -.035em; }
.brand-copy span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }

.button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}
.button:hover { border-color: var(--line-strong); background: #f9fbfa; }
.button:focus-visible, .nav-marking:focus-visible, summary:focus-visible { outline: 3px solid rgba(17, 123, 88, .24); outline-offset: 2px; }
.button-primary { background: var(--green); border-color: var(--green); color: white; }
.button-primary:hover { background: var(--green-2); border-color: var(--green-2); }
.icon-button { width: 40px; padding: 0; font-size: 19px; }
.install-button { display: none; }
.install-button.ready { display: inline-flex; }

.sync-status { min-width: 115px; display: inline-flex; align-items: center; justify-content: flex-end; gap: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #20a36c; box-shadow: 0 0 0 4px rgba(32, 163, 108, .12); }
.sync-status.loading .status-dot { background: #71877c; box-shadow: 0 0 0 4px rgba(113, 135, 124, .12); animation: pulse 1.2s ease-in-out infinite; }
.sync-status.offline .status-dot, .sync-status.error .status-dot { background: #c07a14; box-shadow: 0 0 0 4px rgba(192, 122, 20, .12); }

.portal {
  min-height: 0;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  overflow: hidden;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.sidebar { min-width: 0; overflow: auto; padding: 18px 14px; background: #f8fbf9; border-right: 1px solid var(--line); }
.sidebar-heading { margin: 0 4px 13px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.flight { margin-bottom: 10px; border: 1px solid var(--line); border-radius: 14px; background: var(--paper); overflow: hidden; }
.flight[open] { border-color: var(--green-2); box-shadow: 0 0 0 1px var(--green-2); }
.flight summary { min-height: 54px; display: flex; align-items: center; gap: 10px; padding: 9px 11px; cursor: pointer; list-style: none; user-select: none; }
.flight summary::-webkit-details-marker { display: none; }
.flight summary::before { content: "›"; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 7px; background: var(--soft); color: var(--green); font-size: 19px; line-height: 1; transition: transform .16s ease; }
.flight[open] summary::before { transform: rotate(90deg); }
.flight-title { min-width: 0; flex: 1; }
.flight-title strong { display: block; font-size: 14px; }
.flight-title small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.flight-count { min-width: 26px; height: 24px; display: grid; place-items: center; padding: 0 7px; border-radius: 999px; background: var(--soft); color: var(--green); font-size: 11px; font-weight: 800; }
.marking-list { display: grid; gap: 5px; padding: 0 7px 8px; }
.nav-marking { width: 100%; min-height: 46px; border: 0; border-radius: 10px; padding: 8px 9px; display: flex; align-items: center; gap: 9px; background: transparent; color: var(--ink); text-align: left; cursor: pointer; }
.nav-marking:hover { background: var(--soft); }
.nav-marking.active { background: var(--green-soft); color: var(--green); box-shadow: inset 0 0 0 1px #bad8c9; }
.marking-state { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: #9aa9a1; }
.marking-state.working { background: #e29216; }
.marking-state.ready { background: #20a36c; }
.nav-marking-copy { min-width: 0; flex: 1; }
.nav-marking-copy strong { display: block; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.nav-marking-copy small { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }

.content { min-width: 0; overflow: auto; padding: 24px; background: var(--paper); }
.content-inner { width: min(1180px, 100%); margin: 0 auto; }
.order-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.eyebrow { margin: 0 0 7px; color: var(--green); font-size: 11px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(24px, 3vw, 36px); line-height: 1.1; letter-spacing: -.045em; }
.order-meta { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.share-button.copied { background: var(--green-soft); border-color: #bad8c9; color: var(--green); }

.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.summary-card { padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: #f8fbf9; }
.summary-card > span { display: block; margin-bottom: 10px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.metric-row { min-height: 37px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); }
.metric-row:first-of-type { border-top: 0; padding-top: 0; }
.metric-row small { color: var(--muted); font-size: 12px; }
.metric-row strong { font-size: 22px; line-height: 1; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.summary-card.completed .metric-row strong { color: var(--green); }
.summary-card.residue .metric-row strong { color: var(--amber); }

.positions { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--paper); }
.section-title { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: #f8fbf9; }
.section-title h2 { margin: 0; font-size: 15px; }
.section-title small { color: var(--muted); font-size: 12px; }
.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.data-table th { padding: 11px 13px; background: #f8fbf9; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .055em; text-align: right; text-transform: uppercase; }
.data-table th:first-child, .data-table td:first-child { width: 44%; text-align: left; }
.data-table td { padding: 12px 13px; border-bottom: 1px solid #e7eeea; font-size: 13px; text-align: right; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table td:first-child { font-weight: 650; }
.box-pill { display: inline-flex; min-width: 36px; min-height: 25px; align-items: center; justify-content: center; padding: 3px 8px; border-radius: 999px; background: var(--soft); color: var(--green); font-size: 11px; font-weight: 800; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 700; white-space: nowrap; }
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #9aa9a1; }
.status-pill.working::before { background: #e29216; }
.status-pill.ready::before { background: #20a36c; }
.mobile-cards { display: none; }
.completed-group { border-top: 1px solid var(--line); }
.completed-group summary { min-height: 50px; display: flex; align-items: center; gap: 9px; padding: 11px 16px; background: #fbfcfb; color: var(--green); cursor: pointer; font-size: 13px; font-weight: 800; list-style: none; }
.completed-group summary::-webkit-details-marker { display: none; }
.completed-group summary::before { content: "›"; font-size: 20px; transition: transform .16s ease; }
.completed-group[open] summary::before { transform: rotate(90deg); }

.state-panel { min-height: min(620px, calc(100dvh - 115px)); display: grid; place-content: center; justify-items: center; padding: 34px; text-align: center; }
.state-panel .state-icon { width: 52px; height: 52px; display: grid; place-items: center; margin-bottom: 14px; border-radius: 17px; background: var(--soft); color: var(--green); font-size: 24px; }
.state-panel h1 { max-width: 520px; font-size: 25px; }
.state-panel p { max-width: 520px; margin: 10px 0 18px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.spinner { width: 32px; height: 32px; margin-bottom: 18px; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
.sidebar:empty { display: none; }
.sidebar:empty + .content { grid-column: 1 / -1; }

.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 10; max-width: calc(100vw - 32px); transform: translate(-50%, 20px); padding: 11px 15px; border-radius: 11px; background: #19342a; color: white; box-shadow: 0 8px 28px rgba(0,0,0,.2); opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease; font-size: 13px; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .4; } }

@media (max-width: 900px) {
  .portal { grid-template-columns: 260px minmax(0, 1fr); }
  .content { padding: 20px; }
  .data-table th:first-child, .data-table td:first-child { width: 36%; }
}

@media (max-width: 720px) {
  .app-shell { display: block; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
  .topbar { position: sticky; top: 0; z-index: 5; min-height: 60px; border-width: 0 0 1px; border-radius: 0; box-shadow: none; padding: 9px 11px; }
  .brand-icon { width: 38px; height: 38px; }
  .brand-copy span, .sync-status { display: none; }
  .top-actions { gap: 6px; }
  .button { min-height: 40px; }
  .install-button { padding: 0 10px; }
  .portal { display: block; border: 0; border-radius: 0; box-shadow: none; overflow: visible; }
  .sidebar { padding: 12px 11px 5px; border: 0; border-bottom: 1px solid var(--line); overflow: visible; }
  .sidebar-heading { display: none; }
  .flight { margin-bottom: 8px; }
  .flight summary { min-height: 50px; }
  .marking-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content { overflow: visible; padding: 18px 11px 28px; }
  .order-header { align-items: stretch; flex-direction: column; gap: 12px; }
  .share-button { width: 100%; }
  .summary-grid { grid-template-columns: 1fr; gap: 8px; }
  .summary-card { padding: 13px 14px; }
  .summary-card > span { margin-bottom: 6px; }
  .metric-row { min-height: 32px; }
  .metric-row strong { font-size: 19px; }
  .data-table { display: none; }
  .mobile-cards { display: grid; gap: 8px; padding: 10px; }
  .position-card { padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); }
  .position-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
  .position-card h3 { margin: 0; font-size: 14px; line-height: 1.35; }
  .position-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
  .position-metric { padding: 8px; border-radius: 9px; background: var(--soft); }
  .position-metric small { display: block; margin-bottom: 3px; color: var(--muted); font-size: 9px; font-weight: 750; text-transform: uppercase; }
  .position-metric strong { font-size: 15px; font-variant-numeric: tabular-nums; }
  .card-status { margin-top: 10px; }
  .state-panel { min-height: calc(100dvh - 80px); padding: 28px 18px; }
}

@media (max-width: 410px) {
  .marking-list { grid-template-columns: 1fr; }
  .brand-copy strong { font-size: 15px; }
  .icon-button { width: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation-duration: .001ms !important; }
}
