:root {
  color-scheme: light;
  --background: 48 30% 96%;
  --foreground: 30 8% 10%;
  --card: 45 25% 93%;
  --secondary: 45 22% 90%;
  --muted-foreground: 40 6% 39%;
  --accent: 217 84% 46%;
  --accent-foreground: 0 0% 98%;
  --destructive: 4 70% 47%;
  --border: 45 18% 85%;
  --row-alt: 45 25% 94.5%;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-display: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --background: 30 8% 8%;
    --foreground: 45 25% 90%;
    --card: 30 7% 11%;
    --secondary: 30 6% 15%;
    --muted-foreground: 40 6% 60%;
    --accent: 217 90% 62%;
    --accent-foreground: 30 8% 8%;
    --destructive: 4 75% 60%;
    --border: 30 6% 20%;
    --row-alt: 30 7% 10%;
  }
}
*, *::before, *::after { box-sizing: border-box; border-radius: 0 !important; }
html, body { height: 100%; }
body {
  margin: 0; background: hsl(var(--background)); color: hsl(var(--foreground));
  font: 400 13.5px/1.5 var(--font-mono); -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column; overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
kbd, code { font-family: var(--font-mono); font-size: 11.5px; }
kbd { border: 1px solid hsl(var(--border)); padding: 0 5px; background: hsl(var(--secondary)); color: hsl(var(--muted-foreground)); }
code { background: hsl(var(--secondary)); padding: 0 4px; }
[hidden] { display: none !important; }
:focus-visible { outline: 1px solid hsl(var(--accent)); outline-offset: 1px; }

.cursor-blink::after { content: "▋"; color: hsl(var(--accent)); animation: blink 1s step-end infinite; margin-left: .08em; }
@keyframes blink { 50% { opacity: 0; } }
.page-transition { animation: page-enter 420ms cubic-bezier(0.22, 1, 0.36, 1) backwards; }
@keyframes page-enter { from { opacity: 0; transform: translateY(10px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }
@media (prefers-reduced-motion: reduce) { .page-transition, .cursor-blink::after { animation: none; } }
.section-heading { font: 700 18px/1.2 var(--font-display); letter-spacing: -0.01em; margin: 0 0 10px; }
.section-heading::before { content: "■ "; color: hsl(var(--accent)); font-weight: 400; }

/* bar */
.bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid hsl(var(--border)); min-height: 50px; flex: none; flex-wrap: wrap; }
.brand { font: 700 17px var(--font-display); color: inherit; text-decoration: none; letter-spacing: -0.01em; }
.glyph { color: hsl(var(--accent)); font-weight: 400; }
.dsname { color: hsl(var(--muted-foreground)); font-size: 12.5px; max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-wrap { flex: 1; min-width: 180px; max-width: 520px; position: relative; margin-left: auto; }
.search-wrap input { width: 100%; padding: 6px 34px 6px 10px; border: 1px solid hsl(var(--border)); background: hsl(var(--card)); outline: none; }
.search-wrap input:focus { border-color: hsl(var(--accent)); }
.search-wrap kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.bar-actions { display: flex; gap: 6px; }
#helpBtn { margin-left: auto; }
.search-wrap:not([hidden]) ~ #helpBtn { margin-left: 0; }
.btn { border: 1px solid hsl(var(--border)); background: hsl(var(--card)); padding: 5px 12px; cursor: pointer; transition: background-color .2s, border-color .2s; white-space: nowrap; }
.btn:hover { background: hsl(var(--secondary)); }
.btn.primary { background: hsl(var(--accent)); color: hsl(var(--accent-foreground)); border-color: hsl(var(--accent)); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: hsl(var(--secondary)); }
.menu { position: relative; }
.menu-pop { position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; background: hsl(var(--card)); border: 1px solid hsl(var(--border)); min-width: 180px; padding: 4px 0; display: flex; flex-direction: column; }
.menu-pop button { text-align: left; border: 0; background: none; padding: 6px 12px; cursor: pointer; }
.menu-pop button:hover, .menu-pop button:focus-visible { background: hsl(var(--secondary)); outline: none; }
.menu-pop button::before { content: "▸ "; color: transparent; }
.menu-pop button:hover::before, .menu-pop button:focus-visible::before { color: hsl(var(--accent)); }
.menu-pop hr { border: 0; border-top: 1px solid hsl(var(--border)); margin: 4px 0; }

/* landing */
.landing { flex: 1; overflow: auto; padding: clamp(28px, 7vh, 80px) clamp(16px, 5vw, 64px); max-width: 960px; width: 100%; margin: 0 auto; }
.hero { font: 700 clamp(2.25rem, 7vw, 4.5rem)/1.04 var(--font-display); letter-spacing: -0.02em; margin: 0 0 14px; }
.lede { font-size: 15.5px; color: hsl(var(--muted-foreground)); max-width: 60ch; margin: 0 0 28px; }
.drop { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; border: 1px dashed hsl(var(--border)); background: hsl(var(--card)); padding: 40px 28px; cursor: pointer; transition: background-color .2s, border-color .2s; }
.drop:hover, .drop.over, body.dragging .drop { border-color: hsl(var(--accent)); background: hsl(var(--secondary)); }
.drop-title { font: 700 22px var(--font-display); }
.drop-sub { color: hsl(var(--muted-foreground)); }
.landing-actions { margin: 14px 0; display: flex; gap: 8px; }
.private { color: hsl(var(--muted-foreground)); font-size: 12.5px; margin: 0 0 28px; }
.feats { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; border-top: 1px solid hsl(var(--border)); padding-top: 20px; color: hsl(var(--muted-foreground)); }
.feats b { color: hsl(var(--foreground)); font-weight: 600; display: inline-block; min-width: 9ch; }
.feats b::before { content: "■ "; color: hsl(var(--accent)); font-weight: 400; }

/* work */
.work { flex: 1; display: flex; min-height: 0; }
.grid-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.grid { flex: 1; overflow: auto; position: relative; outline: none; contain: strict; }
.thead { position: sticky; top: 0; z-index: 5; background: hsl(var(--background)); border-bottom: 1px solid hsl(var(--border)); width: max-content; min-width: 100%; }
.hrow, .frow, .tr { display: flex; }
.th, .td, .fcell { flex: none; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; border-right: 1px solid hsl(var(--border)); }
.th { padding: 6px 8px 2px; cursor: pointer; user-select: none; display: flex; align-items: baseline; gap: 6px; font-weight: 600; }
.th:hover { background: hsl(var(--secondary)); }
.th.active { box-shadow: inset 0 -2px 0 hsl(var(--accent)); }
.th .nm { overflow: hidden; text-overflow: ellipsis; }
.th .ty { font-size: 11px; font-weight: 400; color: hsl(var(--muted-foreground)); margin-left: auto; flex: none; }
.th .ar { color: hsl(var(--accent)); flex: none; font-weight: 400; }
.th { position: relative; }
.th .rz { position: absolute; top: 0; right: -1px; bottom: 0; width: 7px; cursor: col-resize; z-index: 1; }
.th .rz:hover { background: hsl(var(--accent) / .5); }
.td.rn { cursor: pointer; }
.td.rn:hover { color: hsl(var(--accent)); }
.rec { margin: 0; font-size: 12.5px; }
.rec dt { color: hsl(var(--muted-foreground)); font-size: 11.5px; margin-top: 8px; }
.rec dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.rec dd.e { color: hsl(var(--muted-foreground)); }
.th.drag-over { background: hsl(var(--accent) / .15); }
.fcell { padding: 2px 4px 5px; }
.fcell input { width: 100%; border: 1px solid transparent; background: hsl(var(--card)); padding: 2px 6px; font-size: 12px; outline: none; }
.fcell input:focus, .fcell input.set { border-color: hsl(var(--accent)); }
.rn { color: hsl(var(--muted-foreground)); text-align: right; font-size: 11.5px; position: sticky; left: 0; background: hsl(var(--background)); z-index: 2; }
.th.rn, .fcell.rn { z-index: 6; cursor: default; }
.tbody { position: relative; }
.tr { position: absolute; left: 0; height: 26px; line-height: 26px; }
.tr.alt { background: hsl(var(--row-alt)); }
.tr.alt .rn { background: hsl(var(--row-alt)); }
.tr:hover { background: hsl(var(--secondary)); }
.tr:hover .rn { background: hsl(var(--secondary)); }
.td { padding: 0 8px; cursor: default; }
.td.n { text-align: right; font-variant-numeric: tabular-nums; }
.td.e::after { content: "·"; color: hsl(var(--muted-foreground)); opacity: .5; }
.td.act { background: hsl(var(--accent) / .07); }
mark { background: hsl(var(--accent) / .25); color: inherit; }
.status { flex: none; border-top: 1px solid hsl(var(--border)); padding: 5px 12px; font-size: 12px; color: hsl(var(--muted-foreground)); display: flex; gap: 2px 16px; flex-wrap: wrap; }
.status b { color: hsl(var(--foreground)); font-weight: 500; }
.empty-view { padding: 40px; color: hsl(var(--muted-foreground)); position: sticky; left: 0; }

/* side */
.side { width: 340px; flex: none; border-left: 1px solid hsl(var(--border)); display: flex; flex-direction: column; min-height: 0; background: hsl(var(--card)); }
.tabs { display: flex; border-bottom: 1px solid hsl(var(--border)); flex: none; }
.tabs button { flex: 1; border: 0; background: none; padding: 9px 0; cursor: pointer; color: hsl(var(--muted-foreground)); border-bottom: 2px solid transparent; }
.tabs button.on { color: hsl(var(--foreground)); border-bottom-color: hsl(var(--accent)); }
.tab { flex: 1; overflow: auto; padding: 16px; }
.hint { color: hsl(var(--muted-foreground)); font-size: 12px; margin: 0 0 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; margin: 0 0 16px; font-size: 12.5px; }
.kv dt { color: hsl(var(--muted-foreground)); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { font-size: 11.5px; color: hsl(var(--muted-foreground)); margin: 14px 0 6px; }
.hist { display: flex; align-items: flex-end; gap: 1px; height: 64px; border-bottom: 1px solid hsl(var(--border)); }
.hist i { flex: 1; background: hsl(var(--accent)); min-height: 1px; opacity: .85; }
.hist i:hover { opacity: 1; }
.hist-ax { display: flex; justify-content: space-between; font-size: 11px; color: hsl(var(--muted-foreground)); margin-top: 3px; }
.tops { list-style: none; padding: 0; margin: 0; display: grid; gap: 3px; }
.tops li { position: relative; display: flex; justify-content: space-between; gap: 8px; padding: 2px 6px; font-size: 12px; cursor: pointer; }
.tops li .bg { position: absolute; inset: 0 auto 0 0; background: hsl(var(--accent) / .14); z-index: 0; }
.tops li span { position: relative; z-index: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tops li:hover { outline: 1px solid hsl(var(--border)); }
.tops li .c { color: hsl(var(--muted-foreground)); flex: none; font-variant-numeric: tabular-nums; }
.form { display: grid; gap: 8px; margin-bottom: 14px; }
.form label { display: grid; grid-template-columns: 9ch 1fr; align-items: center; gap: 8px; font-size: 12.5px; color: hsl(var(--muted-foreground)); }
select { border: 1px solid hsl(var(--border)); background: hsl(var(--background)); padding: 4px 6px; min-width: 0; }
.gt { width: 100%; border-collapse: collapse; font-size: 12px; }
.gt th, .gt td { text-align: left; padding: 3px 6px; border-bottom: 1px solid hsl(var(--border)); }
.gt td.n, .gt th.n { text-align: right; font-variant-numeric: tabular-nums; }
.gt th { color: hsl(var(--muted-foreground)); font-weight: 500; }
.gactions { display: flex; gap: 6px; margin: 0 0 10px; flex-wrap: wrap; }
.col-tools { display: flex; gap: 6px; margin-bottom: 8px; }
.col-list { list-style: none; padding: 0; margin: 0; }
.col-list li { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border: 1px solid transparent; cursor: grab; font-size: 12.5px; }
.col-list li:hover { background: hsl(var(--secondary)); }
.col-list li.drag-over { border-color: hsl(var(--accent)); }
.col-list li .ty { margin-left: auto; color: hsl(var(--muted-foreground)); font-size: 11px; }
.col-list li.off .nm { color: hsl(var(--muted-foreground)); text-decoration: line-through; }
input[type=checkbox] { accent-color: hsl(var(--accent)); margin: 0; }

.busy { position: fixed; inset: 0; background: hsl(var(--background) / .7); display: grid; place-items: center; z-index: 50; font-size: 15.5px; }
.toast { position: fixed; bottom: 46px; left: 50%; transform: translateX(-50%); background: hsl(var(--foreground)); color: hsl(var(--background)); padding: 7px 14px; z-index: 60; font-size: 12.5px; max-width: 90vw; }
.toast.err { background: hsl(var(--destructive)); color: #fff; }
.help { border: 1px solid hsl(var(--border)); background: hsl(var(--card)); color: inherit; padding: 22px 24px; max-width: 440px; width: 92vw; }
.help::backdrop { background: hsl(var(--background) / .6); }
.help dl { display: grid; grid-template-columns: 12ch 1fr; gap: 6px 12px; margin: 0 0 18px; font-size: 12.5px; }
.help dd { margin: 0; color: hsl(var(--muted-foreground)); }

@media (max-width: 820px) {
  body { overflow: auto; }
  .work { flex-direction: column; }
  .grid-wrap { height: 62vh; flex: none; }
  .side { width: auto; border-left: 0; border-top: 1px solid hsl(var(--border)); min-height: 50vh; }
  .search-wrap { order: 10; flex-basis: 100%; max-width: none; }
  .dsname { display: none; }
}
