/* MTI Apps portal. Colours are tokens so dark mode is one override block. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #5d6673;
  --border: #dde1e6;
  --primary: #0f766e;
  --primary-text: #ffffff;
  --primary-soft: #e0f2ef;
  --ok: #166534; --ok-soft: #e7f5ea;
  --warn: #8a5a00; --warn-soft: #fdf3dc;
  --err: #a1261d; --err-soft: #fbe8e6;
  --info: #1e4f8a; --info-soft: #e6effa;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #232830;
    --text: #e7e9ec;
    --muted: #9aa3ae;
    --border: #2f353e;
    --primary: #2dd4bf;
    --primary-text: #062a26;
    --primary-soft: #133a36;
    --ok: #86efac; --ok-soft: #173024;
    --warn: #fcd34d; --warn-soft: #362b12;
    --err: #fca5a5; --err-soft: #3a1d1b;
    --info: #93c5fd; --info-soft: #172a42;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Thai", Helvetica, Arial, sans-serif;
}
a { color: var(--primary); }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0; }
h3 { font-size: .95rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .85rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* --- top bar ------------------------------------------------------------ */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 650; }
.brand-mark {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px;
  background: var(--primary); color: var(--primary-text); font-weight: 700;
}
.brand-mark.lg { width: 48px; height: 48px; font-size: 1.3rem; border-radius: 12px; }
.top-actions { display: flex; gap: 6px; }
.nav-link { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: .9rem; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }

.shell { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head p { margin: 0; }
.eyebrow { font-size: .75rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--primary); margin: 0 0 4px !important; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: .8rem; font-weight: 600; white-space: nowrap; }
.pill-accent { background: var(--primary-soft); color: var(--primary); padding: 1px 8px; font-size: .72rem; vertical-align: 1px; }

/* --- buttons & inputs ----------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 9px; border: 1px solid transparent;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn:disabled, .btn-disabled { opacity: .5; cursor: not-allowed; }
.btn-disabled { background: var(--surface-2); color: var(--muted); }
.btn-block { width: 100%; }
input[type="text"], input[type="email"], input[type="password"], textarea {
  width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea.mono { font-family: var(--mono); font-size: .8rem; resize: vertical; white-space: pre; }
input:focus-visible, textarea:focus-visible, .btn:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}

/* --- launcher -------------------------------------------------------------- */
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.app-card {
  display: flex; flex-direction: column; gap: 8px; padding: 20px;
  background: var(--surface); border: 1px solid var(--border); border-top: 4px solid var(--accent);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.app-card p { margin: 0; flex: 1; }
.app-card.is-disabled { opacity: .7; }
.app-card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.app-icon {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 11px;
  background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); font-weight: 700;
}
@media (prefers-color-scheme: dark) {
  .app-icon { background: color-mix(in srgb, var(--accent) 28%, transparent); color: color-mix(in srgb, var(--accent) 45%, white); }
}
.app-category { font-size: .75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.app-card-actions { margin-top: 8px; }

/* --- login ----------------------------------------------------------------- */
.login-page .shell { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-panel {
  width: min(380px, 100%); padding: 32px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); text-align: center;
}
.login-panel h1 { margin-top: 14px; }
.stack { display: flex; flex-direction: column; gap: 6px; text-align: left; margin-top: 18px; }
.stack label { font-size: .85rem; font-weight: 600; margin-top: 6px; }
.stack .btn { margin-top: 14px; }

/* --- tool page ------------------------------------------------------------- */
.tool-layout { display: grid; grid-template-columns: minmax(320px, 400px) 1fr; gap: 20px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.panel-title { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; }
.panel-title:not(:first-child) { margin-top: 24px; }
.step { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: .75rem; font-weight: 700; }

.tabs { display: flex; gap: 4px; padding: 3px; background: var(--surface-2); border-radius: 10px; margin-bottom: 12px; }
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 7px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 28px 16px; border: 2px dashed var(--border); border-radius: var(--radius); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--primary); background: var(--primary-soft); }
.dropzone-icon { font-size: 1.6rem; color: var(--primary); line-height: 1; }
.file-chip { margin-top: 6px; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); font-size: .85rem; font-family: var(--mono); word-break: break-all; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }

.choices { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice input { margin-top: 4px; accent-color: var(--primary); }
.check { display: flex; gap: 8px; align-items: center; margin: 12px 0 4px; font-size: .9rem; cursor: pointer; }
.check input { accent-color: var(--primary); }
.field-label { display: block; font-size: .85rem; font-weight: 600; margin: 14px 0 6px; }
.actions { margin-top: 18px; }

.empty-state { text-align: center; padding: 48px 16px; }
.empty-state p { margin: 4px 0; }
.empty-icon { font-size: 2rem; color: var(--muted); }

.alert { padding: 11px 14px; border-radius: 10px; font-weight: 550; margin: 0 0 16px; }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-error { background: var(--err-soft); color: var(--err); }
.alert-info { background: var(--info-soft); color: var(--info); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; }
.kpi-value { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-label { color: var(--muted); font-size: .8rem; }

.block { margin-top: 16px; }
details.block summary { cursor: pointer; font-weight: 600; font-size: .95rem; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 10px 0 0; font-size: .9rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-family: var(--mono); font-size: .85rem; }

.issues { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; max-height: 280px; overflow: auto; }
.issue { display: flex; gap: 10px; align-items: baseline; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); font-size: .88rem; }
.issue-level { flex: none; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 1px 7px; border-radius: 99px; }
.issue-error .issue-level { background: var(--err-soft); color: var(--err); }
.issue-warning .issue-level { background: var(--warn-soft); color: var(--warn); }
.issue-info .issue-level { background: var(--info-soft); color: var(--info); }

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; max-height: 460px; }
table.data { width: 100%; border-collapse: collapse; font-size: .85rem; }
table.data th, table.data td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.data th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600; }
table.data td:nth-child(3) { white-space: normal; min-width: 200px; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:last-child td { border-bottom: 0; }

@media (max-width: 860px) {
  .tool-layout { grid-template-columns: 1fr; }
  .shell { padding: 20px 16px 48px; }
  .topbar { padding: 10px 16px; }
  .page-head { flex-direction: column; align-items: flex-start; }
}

/* Trial balance preview: keep account combinations and amounts on one line. */
#trial-balance .data td, #trial-balance .data th { white-space: nowrap; }

/* Open items: one row per currency rate input; keep the preview on one line. */
#open-items .rate-row { display: grid; grid-template-columns: 130px 1fr; align-items: center; gap: 8px; margin-bottom: 8px; }
#open-items .rate-row .field-label { margin: 0; }
#open-items .data td, #open-items .data th { white-space: nowrap; }
#open-items #adjustments { margin-top: 20px; }
#open-items .data td:first-child { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }

/* Passwordless sign-in */
.code-input { font-family: var(--mono); font-size: 1.5rem; letter-spacing: .3em; text-align: center; }
.login-links { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 14px; font-size: .88rem; color: var(--muted); }
.login-links a, .link-button { color: var(--primary); }
.link-button { border: 0; background: none; padding: 0; font: inherit; cursor: pointer; text-decoration: underline; }
.nav-user { color: var(--muted); font-size: .85rem; padding: 6px 4px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 860px) { .nav-user { display: none; } }

/* Admin usage page */
.usage-range { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.usage-range .pill { text-decoration: none; }
.usage-range .pill.is-active { background: var(--primary); color: var(--primary-text); }
.usage-section { margin-bottom: 16px; }
.usage-grid { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; }
@media (max-width: 860px) { .usage-grid { grid-template-columns: 1fr; } }
.usage-section table.data td:nth-child(3) { white-space: nowrap; min-width: 0; }

/* Admin users page */
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.btn-danger { background: var(--err-soft); color: var(--err); }
.btn-danger:hover { filter: brightness(.97); }
.user-add { display: grid; grid-template-columns: minmax(0, 1fr); max-width: 420px; }
.user-add .btn { justify-self: start; margin-top: 12px; }
.user-actions { display: flex; gap: 6px; justify-content: flex-end; }
.user-actions form { margin: 0; }
.user-table td { vertical-align: middle; }
