/* ITPro Tools 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: #1a237e;
  --primary-text: #ffffff;
  --primary-soft: #e8eaf6;
  --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: #82b1ff;
    --primary-text: #0b1240;
    --primary-soft: #1c2550;
    --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="password"], textarea {
  width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
input[type="number"] {
  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; }
}

select {
  width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
select:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Excel to RD Prep: fields stay on one line; raw file content scrolls sideways. */
#rdprep .data td, #rdprep .data th { white-space: nowrap; min-width: 0; }
#rdprep .data td:nth-child(3) { white-space: nowrap; min-width: 0; }
#rdprep .text-preview, #po-excel .text-preview {
  margin: 0; padding: 12px 14px; background: var(--surface-2); border-radius: 10px;
  overflow: auto; max-height: 240px; white-space: pre; font-size: .8rem;
}

/* --- PO PDF to Excel ------------------------------------------------------ */
table.data tr.has-check td { background: var(--warn-soft); }
table.data td.code-missing { color: var(--warn); font-weight: 600; }

/* --- Password Generator ------------------------------------------------- */
.password-tabs { max-width: 480px; margin-bottom: 16px; }
.password-pane { padding: 20px; }
.password-options { display: grid; grid-template-columns: repeat(6, minmax(100px, 1fr)); gap: 12px; }
.password-options .field-label { margin: 0; }
.password-options input { margin-top: 5px; }
.password-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.password-actions .push-right { margin-left: auto; }
.password-results { margin-top: 16px; max-height: 560px; }
.password-results table.data td:nth-child(2) { white-space: normal; min-width: 250px; }
.password-results table.data td { vertical-align: top; }
.password-value { font-size: .95rem; letter-spacing: .02em; }
.nato-tokens { display: flex; flex-wrap: wrap; gap: 5px; }
.nato-token { display: inline-block; padding: 2px 6px; border: 1px solid; border-radius: 7px; font-size: .78rem; }
.password-row-actions { display: flex; flex-wrap: wrap; gap: 5px; min-width: 150px; }
.btn-small { padding: 5px 8px; font-size: .78rem; }
.strength-track { width: 150px; height: 7px; margin-bottom: 5px; overflow: hidden; border-radius: 99px; background: var(--surface-2); }
.strength-track span { display: block; height: 100%; border-radius: inherit; }
.password-export { display: grid; grid-template-columns: minmax(180px, 1fr) auto auto; align-items: end; gap: 8px; margin-top: 16px; }
.password-export .field-label { margin: 0; }
.clarifier-title { margin-top: 18px; }
.settings-grid { display: grid; gap: 24px; }
.password-toast { position: fixed; right: 20px; bottom: 20px; z-index: 20; max-width: min(360px, calc(100vw - 40px)); padding: 11px 16px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); }
@media (max-width: 900px) {
  .password-options { grid-template-columns: repeat(3, minmax(100px, 1fr)); }
}
@media (max-width: 560px) {
  .password-options { grid-template-columns: repeat(2, minmax(100px, 1fr)); }
  .password-export { grid-template-columns: 1fr; }
  .password-actions .push-right { margin-left: 0; }
}
