/* Layout: sheet list on the left, toolbar + grid + status bar on the right, like a workbook */
/* Ultra Care Systems brand: navy #092242, logo orange #d0701a, green #a0ce4e, Open Sans */
:root {
  --bg: #f2f3f5;
  --panel: #ffffff;
  --ink: #2b2f36;
  --muted: #6b7079;
  --line: #e0dede;
  --line-soft: #eceff2;
  --head: #f6f6f6;
  --navy: #092242;
  --navy-2: #212934;
  --orange: #d0701a;
  --green: #a0ce4e;
  --green-ink: #092242;
  --accent: #092242;
  --accent-ink: #ffffff;
  --accent-soft: #e4eaf2;
  --title: #092242;
  --sel: rgba(9, 34, 66, 0.10);
  --sel-line: #092242;
  --ro: #f6f6f6;
  --warn: #9a5b00;
  --warn-soft: #fbedd5;
  --bad: #b3261e;
  --bad-soft: #f9dedb;
  --good: #3f6b12;
  --good-soft: #e5f2cf;
  --info: #1f5c8f;
  --info-soft: #dde9f5;
  --violet: #5b3b8c;
  --violet-soft: #e8e0f3;
  --r: 3px;
  --font: "Open Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d242d; --panel: #212934; --ink: #e4e8ee; --muted: #9ea0a4; --line: #333d4b; --line-soft: #2a333f;
    --head: #26303e; --accent: #8fb3e8; --accent-ink: #0b1626; --accent-soft: #233650; --title: #dbe6f6; --sel: rgba(143, 179, 232, 0.16);
    --sel-line: #8fb3e8; --ro: #252e3a; --warn: #f0b45a; --warn-soft: #3a2c12; --bad: #f2867c; --bad-soft: #3d1d1a;
    --good: #b5dc72; --good-soft: #273417; --info: #8fb4ee; --info-soft: #1b2a42; --violet: #c2a6ec; --violet-soft: #2c2240;
    --orange: #e98a35;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1d242d; --panel: #212934; --ink: #e4e8ee; --muted: #9ea0a4; --line: #333d4b; --line-soft: #2a333f;
  --head: #26303e; --accent: #8fb3e8; --accent-ink: #0b1626; --accent-soft: #233650; --title: #dbe6f6; --sel: rgba(143, 179, 232, 0.16);
  --sel-line: #8fb3e8; --ro: #252e3a; --warn: #f0b45a; --warn-soft: #3a2c12; --bad: #f2867c; --bad-soft: #3d1d1a;
  --good: #b5dc72; --good-soft: #273417; --info: #8fb4ee; --info-soft: #1b2a42; --violet: #c2a6ec; --violet-soft: #2c2240;
  --orange: #e98a35;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 13px/1.35 var(--font); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- login ---------- */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 28px; display: grid; gap: 14px; }
.login-card h1 { margin: 0; font-size: 20px; font-weight: 600; }
.login-card p { margin: 0; color: var(--muted); }
.field { display: grid; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
.field input { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 11px; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 500; }
.btn.danger { color: var(--bad); }
.btn.danger.armed { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; }
.msg { font-size: 12px; min-height: 16px; }
.msg.err { color: var(--bad); }

/* ---------- app shell ---------- */
#app { height: 100%; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
#app.nav-hidden { grid-template-columns: 0 minmax(0, 1fr); }
#nav { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.brand { padding: 14px 14px 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.brand b { white-space: nowrap; font-size: 15px; font-weight: 600; letter-spacing: .01em; }
.brand span { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#navSearch { margin: 0 12px 8px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
#sheetList { overflow: auto; padding: 0 6px 12px; flex: 1; }
.nav-group { margin-top: 10px; }
.nav-group h3 { margin: 0 8px 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.tree-node { display: grid; grid-template-columns: 14px 1fr auto; gap: 4px; width: 100%; text-align: left; background: none; border: 0; border-radius: 5px; padding: 4px 8px; align-items: center; }
.tree-node:hover { background: var(--head); }
.tree-node .car { color: var(--muted); font-size: 10px; transition: transform .12s; }
.tree-node.open .car { transform: rotate(90deg); }
.tree-node .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-node .ct, .sheet-btn .ct { font: 11px var(--mono); color: var(--muted); }
.tree-node .ct b { color: var(--warn); font-weight: 500; }
.tree-node.l0 { font-weight: 600; margin-top: 2px; }
.tree-node.l1 { padding-left: 20px; }
.tree-node.l2 { padding-left: 34px; }
.sheet-btn.l1 { padding-left: 38px; } .sheet-btn.l2 { padding-left: 48px; } .sheet-btn.l3 { padding-left: 62px; }
.np-grid { display: grid; gap: 8px; }
.popover .np-grid label { display: grid; gap: 3px; padding: 0; font-size: 12px; color: var(--muted); }
.popover .np-grid label:hover { background: none; }
.np-grid input, .np-grid select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
.sheet-btn { display: grid; grid-template-columns: 1fr auto; gap: 6px; width: 100%; text-align: left; background: none; border: 0; border-radius: 5px; padding: 5px 8px; align-items: center; }
.sheet-btn:hover { background: var(--head); }
.sheet-btn.on { background: var(--accent-soft); color: var(--ink); font-weight: 500; }
.sheet-btn .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-btn .ct { font: 11px var(--mono); color: var(--muted); }
.sheet-btn .ct b { color: var(--warn); font-weight: 500; }
.nav-foot { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; gap: 8px; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); }

#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
#sheetTitle { font-size: 15px; font-weight: 600; margin-right: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
#sheetTitle .sub { font-weight: 400; color: var(--muted); font-size: 12px; white-space: nowrap; }
#sheetTitle .ttl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-group { display: flex; gap: 6px; align-items: center; }
#search { padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; width: 190px; background: var(--bg); }
#addStore { width: 92px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
#saveState { font-size: 12px; color: var(--muted); min-width: 120px; text-align: right; }
#saveState.busy { color: var(--info); }
#saveState.err { color: var(--bad); }
#readOnlyNote { background: var(--warn-soft); color: var(--warn); font-size: 12px; padding: 6px 14px; border-bottom: 1px solid var(--line); }

/* column chooser */
.popover { position: absolute; z-index: 40; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 28px rgba(0,0,0,.16); padding: 10px; width: 270px; max-height: 70vh; overflow: auto; }
.popover h4 { margin: 2px 4px 8px; font-size: 12px; }
.popover label { display: flex; gap: 8px; align-items: center; padding: 3px 4px; border-radius: 4px; }
.popover label:hover { background: var(--head); }
.popover .row { display: flex; gap: 6px; justify-content: space-between; margin-top: 8px; }
