:root {
  --bg: #ffffff; --fg: #1d2330; --muted: #667085; --line: #e4e7ec; --soft: #f5f7fa;
  --accent: #2f5bd3; --accent-soft: #e2e9fb; --row-alt: #fafbfe; --sel: #e8eefc;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; color: var(--fg); background: var(--bg); display: flex; flex-direction: column; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.linklike { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; color: var(--fg); text-decoration: none; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--soft); color: var(--muted); border: 1px solid var(--line); }
.badge.pro { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.btn { font: inherit; border: 1px solid var(--accent); background: var(--accent); color: #fff; padding: 5px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent); border-color: var(--line); }
.btn.ghost:hover { background: var(--soft); }
.btn.icon { min-width: 32px; padding: 5px 8px; font-weight: 700; }

.landing { max-width: 760px; margin: 0 auto; padding: 48px 16px 24px; overflow: auto; flex: 1 1 auto; width: 100%; }
.landing h1 { font-size: 28px; line-height: 1.25; margin: 0 0 8px; }
.sub { color: var(--muted); font-size: 16px; margin: 0 0 24px; }
.drop { display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; text-align: center; border: 2px dashed #b2c6ee; background: #f7faff; border-radius: 12px; padding: 48px 16px; cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop strong { font-size: 17px; }
.drop span { color: var(--muted); font-size: 13px; }
.sample { margin: 10px 0 0; text-align: center; font-size: 13px; }
.note { margin-top: 16px; padding: 12px; border-radius: 8px; background: var(--accent-soft); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.points { margin: 28px 0 0; padding-left: 18px; color: #344054; }
.points li { margin: 6px 0; }
.foot { margin-top: 40px; color: var(--muted); font-size: 13px; }

.viewer { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.title { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title .muted { font-size: 12px; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.side-toggle { display: none; }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: 110%; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(16,24,40,.12); z-index: 30; display: flex; flex-direction: column; min-width: 250px; padding: 4px; }
.menu-list button { font: inherit; text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.menu-list button:hover { background: var(--soft); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.limit-banner { padding: 7px 12px; background: #fff7e0; border-bottom: 1px solid #f1e2b3; font-size: 13px; }

.work { flex: 1 1 auto; display: flex; min-height: 0; position: relative; }
.side { flex: 0 0 240px; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--soft); }
#side-filter { margin: 8px; font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; }
.side-list { overflow: auto; flex: 1 1 auto; padding: 0 6px 12px; }
.side-h { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 12px 6px 4px; }
.item { display: flex; align-items: baseline; gap: 6px; width: 100%; font: inherit; font-size: 13px; text-align: left; background: none; border: 0; padding: 4px 8px; border-radius: 6px; cursor: pointer; color: var(--fg); }
.item:hover { background: #eef2f8; }
.item.on { background: var(--accent-soft); color: #1c3d94; font-weight: 600; }
.item .nm { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .ct { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.item.linked { color: var(--muted); cursor: default; }
.item .ic { width: 14px; flex: 0 0 14px; text-align: center; color: var(--muted); font-size: 11px; }

.pane { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs { display: flex; gap: 2px; padding: 0 8px; border-bottom: 1px solid var(--line); flex: 0 0 auto; overflow-x: auto; }
.tab { font: inherit; font-size: 13px; border: 0; background: none; padding: 7px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.on { color: var(--fg); border-bottom-color: var(--accent); }
.tabpane { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.tabpane.scroll { overflow: auto; padding: 12px 16px 24px; display: block; }
.gridbar { display: flex; gap: 8px; align-items: center; padding: 6px 8px; flex-wrap: wrap; }
#search { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; width: min(320px, 60vw); }
#search-col { font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; max-width: 180px; background: #fff; }
#rowcount { font-size: 12px; margin-left: auto; font-variant-numeric: tabular-nums; }

/* virtual grid */
.grid { position: relative; flex: 1 1 auto; overflow: auto; min-height: 0; border-top: 1px solid var(--line); outline: none; font-size: 13px; }
.g-sizer { position: relative; }
.g-head { position: sticky; top: 0; z-index: 3; display: flex; background: #eef2f8; border-bottom: 1px solid #d0d5dd; height: 30px; }
.g-body { position: absolute; left: 0; top: 30px; will-change: transform; }
.g-row { display: flex; height: 28px; border-bottom: 1px solid #eaecf0; cursor: pointer; }
.g-row:nth-child(even) { background: var(--row-alt); }
.g-row:hover { background: #f2f6fd; }
.g-row.sel { background: var(--sel); }
.g-c { flex: 0 0 auto; padding: 0 8px; line-height: 27px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid #eaecf0; }
.g-c.num { text-align: right; font-variant-numeric: tabular-nums; }
.g-c.null { color: #98a2b3; }
.g-c.rn { position: sticky; left: 0; background: inherit; color: var(--muted); text-align: right; font-size: 11px; z-index: 1; background: #f7f8fa; }
.g-row:nth-child(even) .g-c.rn { background: #f2f4f7; }
.g-h { position: relative; flex: 0 0 auto; padding: 0 18px 0 8px; line-height: 29px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-right: 1px solid #d0d5dd; cursor: pointer; user-select: none; }
.g-h.rn { position: sticky; left: 0; z-index: 4; background: #eaecf0; cursor: default; }
.g-h .arrow { position: absolute; right: 6px; color: var(--accent); }
.g-h .rz { position: absolute; right: -3px; top: 0; bottom: 0; width: 7px; cursor: col-resize; z-index: 2; }
.g-empty { padding: 24px; color: var(--muted); }

.record { flex: 0 0 360px; border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: #fff; }
.record-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.record-head strong { flex: 1 1 auto; }
.x { border: 0; background: none; font-size: 20px; cursor: pointer; color: var(--muted); }
.record-body { overflow: auto; padding: 8px 12px 24px; }
.fld { padding: 6px 0; border-bottom: 1px solid #f2f4f7; }
.fld .k { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.fld .v { white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.fld .v.null { color: #98a2b3; }
.att { display: flex; gap: 8px; align-items: center; margin-top: 4px; font-size: 13px; }

table.t { border-collapse: collapse; width: 100%; font-size: 13px; margin: 6px 0 18px; }
table.t th, table.t td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t th { background: var(--soft); font-weight: 600; }
.design h3, .rels h3 { margin: 4px 0 6px; font-size: 15px; }
.pill { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 99px; background: var(--soft); border: 1px solid var(--line); color: var(--muted); margin-right: 4px; }
.pill.key { background: #fff3c4; border-color: #f0dc8a; color: #6b5300; }
pre.sql { background: #f7f8fa; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; font-size: 13px; margin: 6px 0 12px; }
.relmap { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0 16px; }
.relcard { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; background: #fff; min-width: 220px; }
.relcard .arrow { color: var(--accent); font-weight: 700; padding: 0 4px; }

.sqlbox { padding: 8px; display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; }
#sql-text { font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; min-height: 110px; resize: vertical; padding: 8px; border: 1px solid var(--line); border-radius: 6px; }
.sqlbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#sql-msg { font-size: 12px; }

.overlay { position: fixed; inset: 0; background: rgba(255,255,255,.78); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 50; gap: 4px; text-align: center; padding: 16px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--accent-soft); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
.bar { width: min(280px, 70vw); height: 4px; background: var(--accent-soft); border-radius: 2px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; background: #1d2330; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; max-width: calc(100vw - 32px); }

dialog { border: 0; border-radius: 12px; padding: 0; box-shadow: 0 24px 48px rgba(16,24,40,.24); width: min(460px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(16,24,40,.4); }
.dlg { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { margin: 0; font-size: 19px; }
.dlg p { margin: 0; }
.dlg dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.dlg dt { color: var(--muted); }
.dlg dd { margin: 0; word-break: break-word; }
.plans { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.plan { display: flex; flex-direction: column; align-items: center; padding: 14px; border: 1px solid var(--line); border-radius: 10px; text-decoration: none; color: var(--fg); }
.plan b { font-size: 22px; }
.plan span { color: var(--muted); font-size: 12px; }
.plan.best { border-color: var(--accent); background: #f7faff; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #344054; }
.field input { font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; }
.row { display: flex; gap: 8px; justify-content: flex-end; }

.rate { position: fixed; left: 16px; bottom: 16px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(16,24,40,.12); padding: 10px 36px 10px 14px; font-size: 13px; z-index: 14; max-width: calc(100vw - 32px); }
.rate .x { position: absolute; right: 6px; top: 4px; font-size: 18px; }

@media (max-width: 860px) {
  .record { position: absolute; right: 0; top: 0; bottom: 0; width: min(360px, 92vw); z-index: 12; box-shadow: -8px 0 24px rgba(0,0,0,.18); }
}
@media (max-width: 720px) {
  .landing h1 { font-size: 22px; }
  .side-toggle { display: inline-block; }
  .side { position: absolute; left: 0; top: 0; bottom: 0; width: min(280px, 85vw); z-index: 11; box-shadow: 8px 0 24px rgba(0,0,0,.18); }
  .side.closed { display: none; }
  #btn-info { display: none; }
  .tools .btn { padding: 5px 9px; }
}

/* ---------- mail view ---------- */
.mailwrap { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; overflow: auto; }
.mailhead { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.mailhead h1 { font-size: 20px; line-height: 1.3; margin: 0 0 8px; word-break: break-word; }
.mailhead dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; margin: 0; font-size: 13px; }
.mailhead dt { color: var(--muted); }
.mailhead dd { margin: 0; word-break: break-word; }
.crumbs { font-size: 12px; margin-bottom: 6px; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--soft); }
.atts:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; font: inherit; font-size: 13px; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 4px 8px; cursor: pointer; color: var(--fg); }
.chip:hover { border-color: var(--accent); }
.chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.chip .sz { color: var(--muted); font-size: 12px; }
.remote { display: flex; gap: 8px; align-items: center; padding: 6px 16px; font-size: 13px; background: #fff8e1; border-bottom: 1px solid #f1e2b3; }
.bodyframe { flex: 1 1 auto; width: 100%; border: 0; min-height: 300px; background: #fff; }
.headers { white-space: pre-wrap; font-size: 12px; max-height: 60vh; overflow: auto; background: var(--soft); padding: 8px; border-radius: 6px; }
.error-box { max-width: 560px; margin: 48px auto; padding: 20px; border: 1px solid #f0c7c7; background: #fff5f5; border-radius: 8px; }
.error-box h2 { margin: 0 0 8px; font-size: 18px; }
@media print { .top, .toolbar, .atts .chip button, .remote, .foot { display: none !important; } .bodyframe { height: auto; } }
