/* Proxy ERP portal — hand-written CSS, no build step. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fbfcfd;
  --border: #e2e6ec;
  --border-strong: #cbd2dc;
  --text: #16202e;
  --muted: #66707f;
  --accent: #2f5fe0;
  --accent-weak: #eaf0ff;
  --ok: #1a7f4b;
  --ok-weak: #e6f5ed;
  --warn: #a35a00;
  --danger: #c0392b;
  --danger-weak: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 12px rgba(16, 24, 40, .05);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1319;
    --surface: #161b23;
    --surface-2: #1b212b;
    --border: #262e3a;
    --border-strong: #36404f;
    --text: #e6eaf0;
    --muted: #939eae;
    --accent: #6690ff;
    --accent-weak: #1b2740;
    --ok: #4ec98a;
    --ok-weak: #14301f;
    --warn: #e0a458;
    --danger: #f0776a;
    --danger-weak: #34191a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -.011em; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.02rem; }
p { margin: 0; }
code { font-family: var(--mono); font-size: .86em; }
.muted { color: var(--muted); font-size: .89rem; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 520;
  padding: .5rem .9rem; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  cursor: pointer; transition: background .13s, border-color .13s, opacity .13s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; }
.btn.sm { padding: .3rem .6rem; font-size: .84rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: .4rem; }

/* ---------- login ---------- */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 1.9rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 1rem;
}
.brand { display: flex; align-items: center; gap: .8rem; }
.brand h1 { font-size: 1.25rem; }
.brand p { color: var(--muted); font-size: .85rem; }
.brand-mark {
  width: 38px; height: 38px; flex: none; border-radius: 9px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: .9rem; letter-spacing: .02em;
}
.brand.small h1 { font-size: 1.02rem; }
.brand.small .brand-mark { width: 30px; height: 30px; font-size: .78rem; border-radius: 7px; }

label { display: flex; flex-direction: column; gap: .32rem; font-size: .87rem; font-weight: 540; color: var(--text); }
label small { font-weight: 400; }
input, select {
  font: inherit; padding: .5rem .65rem; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.check-label { flex-direction: row; align-items: center; gap: .5rem; }
.check-label input { width: auto; }
.error { color: var(--danger); font-size: .87rem; background: var(--danger-weak); padding: .5rem .7rem; border-radius: 7px; }

/* ---------- shell ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.1rem;
  padding: .7rem 1.4rem; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.topbar .brand { cursor: pointer; }
.crumbs { color: var(--muted); font-size: .88rem; flex: 1; }
.crumbs a { color: var(--accent); text-decoration: none; cursor: pointer; }
.crumbs a:hover { text-decoration: underline; }
.topbar-right { display: flex; align-items: center; gap: .8rem; }
.user { color: var(--muted); font-size: .85rem; }

.page { max-width: 1180px; margin: 0 auto; padding: 1.6rem 1.4rem 4rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.3rem; flex-wrap: wrap; }

/* ---------- company cards ---------- */
.card-grid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); }
.company-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.05rem; cursor: pointer; box-shadow: var(--shadow);
  transition: border-color .13s, transform .13s;
  display: flex; flex-direction: column; gap: .55rem;
}
.company-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.company-card h3 { font-size: 1.03rem; }
.card-meta { display: flex; gap: .45rem; flex-wrap: wrap; align-items: center; }
.badge {
  font-size: .72rem; font-weight: 620; padding: .16rem .5rem; border-radius: 999px;
  background: var(--accent-weak); color: var(--accent); letter-spacing: .01em;
  border: 1px solid transparent; white-space: nowrap;
}
.badge.ok { background: var(--ok-weak); color: var(--ok); }
.badge.warn { background: var(--danger-weak); color: var(--warn); }
.badge.danger { background: var(--danger-weak); color: var(--danger); }
.badge.accent { background: var(--accent-weak); color: var(--accent); }
.badge.neutral, .badge.grey { background: var(--surface-2); color: var(--muted); border-color: var(--border); }
.card-stats { color: var(--muted); font-size: .83rem; font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 4rem 1rem; color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: .4rem; }
.empty p { margin-bottom: 1.1rem; }

/* ---------- tabs & panels ---------- */
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border); margin-bottom: 1.3rem; }
.tab {
  font: inherit; font-weight: 550; padding: .55rem .95rem; border: 0; background: none;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.2rem; margin-bottom: 1.1rem; box-shadow: var(--shadow);
}
.panel > h3 { margin-bottom: .25rem; }
.panel > .muted { margin-bottom: .9rem; }
.form-grid { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: .9rem; }
.scenario-desc { margin: -.3rem 0 .9rem; font-style: italic; }
.status { font-size: .87rem; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.err { color: var(--danger); }

/* ---------- validation report ---------- */
.checks { list-style: none; margin: 0 0 1rem; padding: 0; display: flex; flex-direction: column; gap: .35rem; }
.checks li { display: flex; gap: .6rem; align-items: baseline; font-size: .89rem; padding: .38rem .55rem; border-radius: 7px; background: var(--surface-2); }
.checks .mark { font-weight: 700; font-size: .74rem; padding: .1rem .42rem; border-radius: 5px; }
.checks .mark.ok { background: var(--ok-weak); color: var(--ok); }
.checks .mark.fail { background: var(--danger-weak); color: var(--danger); }
.checks .detail { color: var(--muted); }
.counts { display: flex; flex-wrap: wrap; gap: .4rem; }
.count-pill { font-size: .8rem; background: var(--surface-2); border: 1px solid var(--border); padding: .22rem .55rem; border-radius: 6px; font-variant-numeric: tabular-nums; }
.count-pill b { font-weight: 620; }

/* ---------- data explorer ---------- */
.explorer-panel { padding: 0; overflow: hidden; }
.explorer { display: grid; grid-template-columns: 208px 1fr; align-items: stretch; min-height: 560px; }
@media (max-width: 860px) { .explorer { grid-template-columns: 1fr; } }

.explorer-nav {
  border-right: 1px solid var(--border); background: var(--surface-2);
  padding: .7rem .5rem; overflow-y: auto; max-height: 78vh;
}
.nav-group {
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: .75rem .55rem .3rem;
}
.nav-group:first-child { padding-top: .2rem; }
.nav-item {
  font: inherit; width: 100%; text-align: left; border: 0; background: none; color: var(--text);
  padding: .38rem .55rem; border-radius: 7px; cursor: pointer; font-size: .86rem;
  display: flex; justify-content: space-between; gap: .5rem; align-items: baseline;
}
.nav-item:hover { background: var(--surface); }
.nav-item.active { background: var(--accent); color: #fff; font-weight: 570; }
.nav-item .n { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .76rem; }
.nav-item.active .n { color: #fff; opacity: .8; }

.explorer-main { display: flex; flex-direction: column; min-width: 0; }
.explorer-bar {
  display: flex; align-items: center; gap: .8rem; padding: .7rem 1rem;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.explorer-bar input { max-width: 240px; }
.trail { display: flex; align-items: center; gap: .4rem; font-size: .9rem; min-width: 0; flex-wrap: wrap; }
.trail a { color: var(--accent); text-decoration: none; cursor: pointer; }
.trail a:hover { text-decoration: underline; }
.trail .sep { color: var(--muted); }
.trail .current { font-weight: 600; }
#explorer-body { padding: 1rem; overflow: auto; }

.table-scroll { overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.table-scroll.tall { max-height: 60vh; }
table { border-collapse: collapse; width: 100%; font-size: .84rem; }
th, td {
  text-align: left; padding: .46rem .7rem; border-bottom: 1px solid var(--border);
  white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis;
}
th, td.right, th.right { }
th.right, td.right { text-align: right; }
th {
  position: sticky; top: 0; background: var(--surface-2); font-weight: 620; font-size: .72rem;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted); z-index: 1; padding: 0;
}
th .sort-btn {
  font: inherit; color: inherit; background: none; border: 0; cursor: pointer;
  padding: .5rem .7rem; width: 100%; text-align: inherit; text-transform: inherit; letter-spacing: inherit;
}
th.right .sort-btn { text-align: right; }
th .sort-btn:hover { color: var(--text); }
th .caret { color: var(--accent); }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
tfoot td {
  background: var(--surface-2); font-weight: 650; border-top: 2px solid var(--border-strong); border-bottom: 0;
}
td.num, .num { font-variant-numeric: tabular-nums; }
td.money { font-variant-numeric: tabular-nums; }
td.money.neg, dd.money.neg { color: var(--danger); }
td.date { color: var(--text); font-variant-numeric: tabular-nums; }
.null { color: var(--muted); }
.entity-link { color: var(--accent); text-decoration: none; cursor: pointer; }
.entity-link:hover { text-decoration: underline; }
.pager { display: flex; align-items: center; gap: .6rem; padding: .7rem .2rem 0; }
.empty.small { padding: 2.4rem 1rem; }

/* ---------- detail view ---------- */
.detail-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem;
  flex-wrap: wrap; padding-bottom: 1rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border);
}
.detail-title { font-size: 1.3rem; }
.detail-badges { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.detail-actions { display: flex; gap: .45rem; flex-wrap: wrap; }
.detail-sections { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); margin-bottom: 1.3rem; }
.detail-card { border: 1px solid var(--border); border-radius: 9px; padding: .9rem 1rem; background: var(--surface-2); }
.detail-card h4 {
  margin: 0 0 .7rem; font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
}
.detail-card dl { margin: 0; display: grid; grid-template-columns: minmax(96px, 42%) 1fr; gap: .34rem .8rem; }
.detail-card dt { color: var(--muted); font-size: .83rem; }
.detail-card dd { margin: 0; font-size: .87rem; overflow-wrap: anywhere; }
.detail-card dd.num, .detail-card dd.money { text-align: left; }
.detail-table { margin-bottom: 1.3rem; }
.detail-table h4 { margin: 0 0 .55rem; font-size: .92rem; font-weight: 620; }
.pdf-frame { width: 100%; height: 620px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }

/* ---------- reports ---------- */
.report-picker { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-bottom: 1rem; }
.report-card {
  font: inherit; text-align: left; cursor: pointer; color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 9px; padding: .75rem .9rem;
  background: var(--surface); display: flex; flex-direction: column; gap: .25rem;
  transition: border-color .13s, background .13s;
}
.report-card:hover { border-color: var(--accent); }
.report-card.active { border-color: var(--accent); background: var(--accent-weak); }
.report-card strong { font-size: .94rem; }
.report-card .muted { font-size: .8rem; line-height: 1.4; }
.report-filters { margin-bottom: .8rem; }
.report-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.report-period { font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.report-table { font-size: .85rem; }
.report-table td { border-bottom: 0; padding: .3rem .7rem; }
.report-table .r-acc { width: 72px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: .8rem; }
.report-table .r-label { white-space: normal; max-width: none; }
.report-table tr.r-header td { padding-top: 1rem; font-weight: 700; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.report-table tr.r-subtotal td { font-weight: 620; border-top: 1px solid var(--border); }
.report-table tr.r-total td { font-weight: 700; border-top: 2px solid var(--border-strong); border-bottom: 1px solid var(--border-strong); background: var(--surface-2); }
.report-table tr.r-grand td { font-weight: 750; font-size: .92rem; border-top: 3px double var(--border-strong); background: var(--surface-2); }
.report-table tr.r-spacer td { height: .55rem; padding: 0; }
.report-table tr.clickable:hover { background: var(--accent-weak); cursor: pointer; }
.report-table tr.r-account:hover { background: var(--surface-2); }

.raw-dialog { width: min(760px, calc(100vw - 2rem)); }
.raw-dialog form { padding: 1.1rem; }
.raw-dialog .code-block { max-height: 62vh; overflow: auto; margin-top: .7rem; white-space: pre; }

/* ---------- settings ---------- */
.field-copy { margin-bottom: .8rem; }
.field-copy label { font-size: .82rem; color: var(--muted); margin-bottom: .28rem; display: block; font-weight: 550; }
.copy-row { display: flex; gap: .45rem; align-items: stretch; }
.copy-row code {
  flex: 1; background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px;
  padding: .48rem .65rem; overflow-x: auto; white-space: nowrap; display: block; min-width: 0;
}
.code-block {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: .8rem .9rem; overflow-x: auto; font-family: var(--mono); font-size: .8rem;
  margin: .9rem 0 0; line-height: 1.6;
}
.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip {
  display: flex; align-items: center; gap: .4rem; font-size: .82rem;
  border: 1px solid var(--border-strong); border-radius: 999px; padding: .28rem .7rem;
  cursor: pointer; user-select: none; background: var(--surface);
}
.chip input { width: auto; }
.chip.on { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); font-weight: 550; }

/* ---------- modal & toast ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 0;
  background: var(--surface); color: var(--text); box-shadow: 0 12px 40px rgba(0,0,0,.25);
  width: min(440px, calc(100vw - 2rem));
}
dialog::backdrop { background: rgba(10, 14, 20, .5); }
dialog form { padding: 1.4rem; display: flex; flex-direction: column; gap: .9rem; }
.toast {
  position: fixed; bottom: 1.4rem; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: .6rem 1.05rem; border-radius: 8px;
  font-size: .87rem; z-index: 100; box-shadow: var(--shadow);
}
