/* GRI ShipPlan - Nebula theme (same tokens as SalesSphere), light first for the sheet */
:root {
  --bg: #eef2f8; --bg-2: #e6ebf3; --surface: #ffffff; --surface-2: #f4f6fb; --surface-3: #e9edf5;
  --border: #dbe2ee; --border-2: #c6d0e1; --text: #0f172a; --muted: #55657f; --faint: #8a98b3;
  --accent: #0284c7; --accent-2: #4f46e5; --ok: #16a34a; --bad: #dc2626; --warn: #d97706;
  --ok-bg: #dcfce7; --bad-bg: #fee2e2; --warn-bg: #fef3c7; --info-bg: #e0f2fe; --unc-bg: #ede9fe;
  --row-loaded: #ecf8f0; --row-unc: #f4f0fe; --cell-ro: #f5f7fa; --row-hover: #f1f5fb;
  --grid-line: #e3e8f0; --head: #1e293b; --head-text: #f8fafc; --sel: rgba(2, 132, 199, .14); --sel-solid: #dceefa;
  --font: "Inter", "Segoe UI Variable", "Segoe UI", Roboto, Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, monospace; color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b1120; --bg-2: #0f172a; --surface: #131c31; --surface-2: #1a2540; --surface-3: #22304f;
  --border: #26324d; --border-2: #34446a; --text: #e6ecf8; --muted: #8b9bbd; --faint: #5b6b8f;
  --accent: #38bdf8; --accent-2: #6366f1; --ok: #22c55e; --bad: #f87171; --warn: #fbbf24;
  --ok-bg: rgba(34, 197, 94, .16); --bad-bg: rgba(239, 68, 68, .18); --warn-bg: rgba(245, 158, 11, .18); --info-bg: rgba(56, 189, 248, .14); --unc-bg: rgba(139, 92, 246, .2);
  --row-loaded: #142b2a; --row-unc: #201f44; --cell-ro: #172138; --row-hover: #1b2642;
  --grid-line: #22304f; --head: #0f172a; --head-text: #e6ecf8; --sel: rgba(56, 189, 248, .18); --sel-solid: #1c3656; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body.sp { font-family: var(--font); font-size: 13.5px; color: var(--text); background: var(--bg); display: flex; flex-direction: column; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
.grow { flex: 1; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .bad { color: var(--bad); } .r { text-align: right; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 14px; padding: 6px 14px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; color: var(--text); white-space: nowrap; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }
.logo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff; font-size: 12px; font-weight: 900; }
.tabs { display: flex; gap: 2px; }
.tabs a { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabs a:hover { background: var(--surface-2); color: var(--text); }
.tabs a.on { background: linear-gradient(135deg, rgba(79, 70, 229, .14), rgba(2, 132, 199, .12)); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.me { text-align: right; line-height: 1.2; white-space: nowrap; } .me small { display: block; color: var(--muted); font-size: 11px; }
.icon-btn { border: 0; background: transparent; color: var(--muted); font-size: 16px; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* buttons, inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; background: var(--accent); color: #fff; font: inherit; font-weight: 600; padding: 7px 13px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(1.07); } .btn:disabled { opacity: .5; cursor: default; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn.ghost { background: var(--surface); color: var(--text); border-color: var(--border-2); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--bad); }
.btn-group { display: flex; gap: 6px; }
input[type=text], input[type=search], input[type=email], input[type=password], input[type=month], input[type=number], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-2); border-radius: 8px; padding: 6px 9px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(2, 132, 199, .35); border-color: var(--accent); }

/* sheet page */
main.sheet { flex: 1; display: flex; flex-direction: column; min-height: 0; height: calc(100vh - 47px); padding: 8px 12px 0; gap: 6px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; position: relative; }
.month-pick { display: flex; align-items: center; gap: 4px; } .month-pick input { padding: 4px 6px; }
.search input { width: 300px; padding: 5px 10px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chips button { border: 1px solid var(--border-2); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
.chips button.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.menu { position: absolute; right: 0; top: 36px; z-index: 30; background: var(--surface); border: 1px solid var(--border-2); border-radius: 10px; box-shadow: 0 12px 30px rgba(15, 23, 42, .18); padding: 6px; min-width: 300px; display: flex; flex-direction: column; }
.menu[hidden] { display: none; }
.menu button { text-align: left; border: 0; background: none; font: inherit; color: var(--text); padding: 7px 10px; border-radius: 7px; cursor: pointer; }
.menu button:hover { background: var(--surface-2); }

.summary { display: flex; gap: 6px; align-items: stretch; flex-wrap: wrap; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 4px 10px; display: flex; flex-direction: column; min-width: 78px; }
.kpi[data-f] { cursor: pointer; } .kpi[data-f]:hover { border-color: var(--accent); }
.kpi span { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; font-weight: 600; }
.kpi b { font-size: 15px; }
.kpi.k-ok b { color: var(--ok); } .kpi.k-risk b { color: var(--warn); } .kpi.k-unc b { color: #7c3aed; } .kpi.k-bad b { color: var(--bad); } .kpi.k-load b { color: var(--accent); }
.weeks { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.wk { position: relative; overflow: hidden; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 3px 9px; font: inherit; color: var(--text); cursor: pointer; display: flex; flex-direction: column; align-items: flex-start; min-width: 62px; }
.wk span { font-size: 10.5px; color: var(--muted); font-weight: 700; } .wk b { font-size: 13px; }
.wk i { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--ok); }
.wk:hover { border-color: var(--accent); }

#grid { flex: 1; min-height: 200px; border: 1px solid var(--border-2); border-radius: 8px 8px 0 0; background: var(--surface); }
.statusbar { display: flex; gap: 16px; font-size: 12px; color: var(--muted); padding: 4px 4px 6px; }
.statusbar .ok { color: var(--ok); } .statusbar .bad { color: var(--bad); font-weight: 700; } .statusbar .busy { color: var(--accent); }
.live { color: var(--ok); } .live.off { color: var(--bad); } .live.pulse { animation: pulse 1.4s; }
@keyframes pulse { 0% { text-shadow: 0 0 0 var(--ok); } 50% { text-shadow: 0 0 10px var(--ok); } }
.empty { padding: 40px; text-align: center; color: var(--muted); line-height: 1.8; }

/* ---------- Tabulator: Excel feel ---------- */
.tabulator { font-size: 12.5px; border: 0; background: var(--surface); color: var(--text); }
.tabulator .tabulator-header { background: var(--head); color: var(--head-text); border-bottom: 1px solid var(--border-2); font-weight: 600; }
.tabulator .tabulator-header .tabulator-col { background: var(--head); color: var(--head-text); border-right: 1px solid rgba(255, 255, 255, .12); border-top: 3px solid transparent; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 4px 6px; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-title { white-space: normal; font-size: 11.5px; line-height: 1.2; }
.tabulator .tabulator-header .tabulator-col.tabulator-sortable.tabulator-col-sorter-element:hover { background: #334155; }
.tabulator .tabulator-header .tabulator-col.ro .tabulator-col-title { opacity: .72; font-style: italic; }
.tabulator .tabulator-header-filter input, .tabulator .tabulator-header-filter select { padding: 2px 4px !important; font-size: 11.5px; border-radius: 4px; border: 0; background: rgba(255, 255, 255, .92); color: #0f172a; height: 22px; }
body.nofilters .tabulator .tabulator-header-filter { display: none; }
.tabulator-col.g-order { border-top-color: #3b82f6 !important; } .tabulator-col.g-production { border-top-color: #f59e0b !important; }
.tabulator-col.g-st3 { border-top-color: #14b8a6 !important; } .tabulator-col.g-loading { border-top-color: #22c55e !important; }
.tabulator-col.g-cs { border-top-color: #a855f7 !important; } .tabulator-col.g-logistics { border-top-color: #0ea5e9 !important; }
.tabulator-col.g-comment { border-top-color: #94a3b8 !important; } .tabulator-col.g-system { border-top-color: #64748b !important; }
.tabulator .tabulator-tableholder { will-change: scroll-position; }
.tabulator .tabulator-tableholder .tabulator-table { color: var(--text); background-color: var(--surface); }
.tabulator-row, .tabulator-row.tabulator-row-even { background-color: var(--surface); min-height: 25px; border-bottom: 1px solid var(--grid-line); contain: layout style; }
.tabulator-row .tabulator-cell { padding: 3px 6px; border-right: 1px solid var(--grid-line); height: 25px; line-height: 18px; overflow: hidden; text-overflow: ellipsis; position: relative; background-color: var(--surface); color: var(--text); }
.tabulator-row .tabulator-cell.ro, .tabulator-row .tabulator-cell.t-calc { background-color: var(--cell-ro); }
.tabulator-row.st-loaded .tabulator-cell { background-color: var(--row-loaded); }
.tabulator-row.st-unconfirmed .tabulator-cell { background-color: var(--row-unc); font-style: italic; }
.tabulator-row .tabulator-cell.rh { background-color: var(--surface-3) !important; color: var(--muted); font-size: 11px; text-align: center; }
.tabulator .tabulator-header .tabulator-col.rh { background: var(--head); }
.tabulator-row.st-risk .tabulator-cell.rh { border-left: 3px solid var(--bad); }
.tabulator-row.st-pending .tabulator-cell.rh { border-left: 3px solid var(--warn); }
.tabulator-row.st-unconfirmed .tabulator-cell.rh { border-left: 3px solid #8b5cf6; }
.tabulator-row.st-cancelled .tabulator-cell { text-decoration: line-through; color: var(--faint); }
.tabulator-row.flash .tabulator-cell { animation: flash 2.2s ease-out; }
@keyframes flash { 0% { background-color: #fde68a; color: #0f172a; } 100% { } }
.tabulator .tabulator-cell.tabulator-range-only-cell-selected, .tabulator .tabulator-cell.tabulator-range-highlight { }
.tabulator-row .tabulator-cell.tabulator-editing { border: 2px solid var(--accent); padding: 0; background: var(--surface) !important; overflow: visible; }
.tabulator-cell .ed { display: flex; height: 100%; align-items: center; }
.tabulator-cell .ed input[type=text] { width: 100%; height: 100%; border: 0; border-radius: 0; padding: 2px 5px; outline: none; background: var(--surface); font: inherit; }
.tabulator-cell .ed .ed-cal { border: 0; background: transparent; cursor: pointer; padding: 0 3px; font-size: 12px; }
.tabulator-cell .ed .ed-pick { position: absolute; width: 1px; height: 1px; opacity: 0; right: 0; bottom: 0; }
.tabulator-cell.auto { color: var(--faint) !important; font-style: italic; }
.tabulator-cell.bad { color: var(--bad) !important; font-weight: 600; }
.tabulator-cell.warn { color: var(--warn) !important; font-weight: 600; }
.tabulator-cell.od { color: var(--bad) !important; font-weight: 700; }
.tabulator-cell.okc { color: var(--ok); font-weight: 600; }
.tabulator-cell.mk::after { content: ""; position: absolute; top: 0; right: 0; border-style: solid; border-width: 0 7px 7px 0; border-color: transparent #f97316 transparent transparent; }
.tabulator .tabulator-footer { background: var(--surface-2); border-top: 1px solid var(--border-2); color: var(--text); }
.tabulator .tabulator-footer .tabulator-calcs-holder { background: var(--surface-2); border: 0; }
.tabulator .tabulator-footer .tabulator-calcs-holder .tabulator-row { background: var(--surface-2); font-weight: 700; }
.tabulator .tabulator-row.tabulator-group { background: var(--surface-3); border-top: 1px solid var(--border-2); font-weight: 700; padding: 4px 8px; color: var(--text); }
.tabulator .tabulator-row.tabulator-group .gh { font-weight: 500; color: var(--muted); margin-left: 8px; }
.tabulator .tabulator-tableholder .tabulator-placeholder span { color: var(--muted); font-weight: 400; }
.tabulator-menu { background: var(--surface); color: var(--text); border: 1px solid var(--border-2); border-radius: 8px; box-shadow: 0 10px 28px rgba(15, 23, 42, .18); }
.tabulator-menu .tabulator-menu-item { padding: 6px 12px; } .tabulator-menu .tabulator-menu-item:not(.tabulator-menu-item-disabled):hover { background: var(--surface-2); }
.tabulator-edit-list { background: var(--surface); color: var(--text); border: 1px solid var(--border-2); font-size: 12.5px; }
.tabulator-edit-list .tabulator-edit-list-item { color: var(--text); padding: 4px 8px; }
.tabulator-edit-list .tabulator-edit-list-item.active, .tabulator-edit-list .tabulator-edit-list-item:hover { background: var(--accent); color: #fff; }
sup.rev { color: var(--warn); font-weight: 700; font-size: 9px; } sup.ifsd { color: var(--bad); font-size: 9px; font-weight: 700; }

/* chips in cells */
.chip { display: inline-block; padding: 0 7px; border-radius: 999px; font-size: 11px; font-weight: 700; line-height: 17px; background: var(--surface-3); color: var(--muted); }
.chip.auto { background: transparent; border: 1px dashed currentColor; }
.y-yes, .c-loaded, .r-loaded, .c-closed, .p-sent { background: var(--ok-bg); color: var(--ok); }
.y-pending, .c-pending, .c-loading, .p-pending, .p-dryrun { background: var(--warn-bg); color: var(--warn); }
.y-na { background: var(--surface-3); color: var(--faint); }
.c-risk, .r-risk, .p-failed { background: var(--bad-bg); color: var(--bad); }
.c-confirmed, .r-norisk { background: var(--info-bg); color: var(--accent); }
.c-unconfirmed, .s-funnel { background: var(--unc-bg); color: #7c3aed; }
.c-cancelled { background: var(--surface-3); color: var(--faint); text-decoration: line-through; }
.s-import, .s-manual, .s-copy, .s-carried { background: var(--surface-3); color: var(--muted); }

/* toasts, dialogs, side panel */
#toasts { position: fixed; right: 16px; bottom: 34px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: 460px; }
.toast { background: var(--surface); border: 1px solid var(--border-2); border-left: 4px solid var(--accent); border-radius: 9px; padding: 10px 14px; box-shadow: 0 10px 24px rgba(15, 23, 42, .18); transition: opacity .4s, transform .4s; cursor: pointer; }
.toast.ok { border-left-color: var(--ok); } .toast.bad { border-left-color: var(--bad); } .toast.warn { border-left-color: var(--warn); }
.toast.out { opacity: 0; transform: translateY(8px); }
dialog { border: 0; padding: 0; border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: 0 24px 60px rgba(15, 23, 42, .35); max-width: min(1100px, 95vw); width: fit-content; min-width: 420px; }
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.dlg-h { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 15px; }
.dlg-b { padding: 14px 16px; max-height: 70vh; overflow: auto; }
.dlg-f { display: flex; gap: 8px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--border); }
.dlg-f:empty { display: none; }
table.mini { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.mini th { text-align: left; background: var(--surface-2); color: var(--muted); font-weight: 700; position: sticky; top: 0; }
table.mini th, table.mini td { padding: 5px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.mini small { color: var(--muted); }
.fres { max-height: 50vh; overflow: auto; margin-top: 10px; min-width: 860px; }
.cgs { display: grid; grid-template-columns: repeat(3, minmax(220px, 1fr)); gap: 10px; }
.cg { border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px 8px; margin: 0; }
.cg legend { font-weight: 700; padding: 0 6px; border-left: 4px solid; }
.cg label { display: block; padding: 2px 0; }
.side { position: fixed; right: 0; top: 47px; bottom: 0; width: 380px; background: var(--surface); border-left: 1px solid var(--border-2); z-index: 25; display: flex; flex-direction: column; box-shadow: -10px 0 30px rgba(15, 23, 42, .12); }
.side[hidden] { display: none; }
.side-h { display: flex; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.side-b { overflow: auto; padding: 8px; }
.act { padding: 7px 8px; border-radius: 8px; cursor: pointer; border-bottom: 1px solid var(--border); }
.act:hover { background: var(--surface-2); } .act small { color: var(--muted); }

/* regular pages (admin, import, plan, login) */
.page { padding: 16px 20px 40px; max-width: 1500px; width: 100%; margin: 0 auto; }
.page h1 { font-size: 20px; margin: 4px 0 4px; } .page h2 { font-size: 16px; margin: 0 0 10px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-top: 14px; }
.subnav { display: flex; gap: 4px; flex-wrap: wrap; margin: 10px 0; }
.subnav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; border: 1px solid var(--border); background: var(--surface); }
.subnav a.on { background: var(--text); color: var(--surface); }
table.list { border-collapse: collapse; width: 100%; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); background: var(--surface-2); }
table.list th, table.list td { padding: 7px 9px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.form-grid { display: grid; grid-template-columns: 260px 1fr; gap: 10px 16px; align-items: center; max-width: 980px; }
.form-grid .hint { grid-column: 2; font-size: 12px; color: var(--muted); margin-top: -6px; }
.flash { padding: 10px 14px; border-radius: 10px; margin: 10px 0; }
.flash.ok { background: var(--ok-bg); color: var(--ok); } .flash.err { background: var(--bad-bg); color: var(--bad); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: var(--surface-3); color: var(--muted); }
.login { max-width: 400px; margin: 9vh auto; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: 0 20px 50px rgba(15, 23, 42, .12); }
.login label { display: block; margin: 12px 0 4px; font-weight: 600; } .login input { width: 100%; }
.plan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.plan-sum table.list td.r, .plan-sum table.list th.r { text-align: right; }
#plan { height: 62vh; border: 1px solid var(--border-2); border-radius: 8px; }
.map-tbl select { width: 100%; }
.tabulator-frozen.tabulator-frozen-left:last-of-type, .tabulator-cell.tabulator-frozen-left + .tabulator-cell:not(.tabulator-frozen) { }
.tabulator-row .tabulator-cell.tabulator-frozen-left { border-right: 1px solid var(--grid-line); }
.tabulator .tabulator-cell.tabulator-range-selected:not(.tabulator-range-only-cell-selected):not(.rh) { background-color: var(--sel-solid) !important; }
.tabulator .tabulator-row .tabulator-cell.tabulator-range-only-cell-selected { outline: 2px solid var(--accent); outline-offset: -2px; }

.tabulator .tabulator-tableholder .tabulator-table .tabulator-row.tabulator-calcs, .tabulator .tabulator-footer .tabulator-calcs-holder .tabulator-row .tabulator-cell { background-color: var(--surface-2); color: var(--text); font-size: 12.5px; }
:root[data-theme="dark"] .tabulator .tabulator-header-filter input, :root[data-theme="dark"] .tabulator .tabulator-header-filter select { background: #1e2a45; color: var(--text); border: 1px solid var(--border-2); }
:root[data-theme="dark"] .tabulator-row .tabulator-cell.rh { color: #94a3b8; }
