/* =====================================================================
 * NZTTI web — Fluent (WinUI 3) styling.
 * Colour tokens follow the WinUI 3 light/dark resource sets; geometry
 * follows the WinUI contract: control radius 4px, overlay radius 8px,
 * button/input height 32px.
 * ===================================================================== */

* { box-sizing: border-box; }

/* Component classes set display:flex; without this the hidden attribute
 * would be overridden and "hidden" blocks would stay visible. */
[hidden] { display: none !important; }

:root {
  --font-ui: "Segoe UI Variable Text", "Segoe UI Variable", "Segoe UI",
    -apple-system, BlinkMacSystemFont, "Helvetica Neue",
    "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  --font-mono: "Cascadia Code", "Cascadia Mono", "JetBrains Mono", Consolas, monospace;

  --accent: #0f6cbd;
  --accent-hover: #115ea3;
  --accent-pressed: #0c3b5e;
  --accent-light-2: #c7e0f4;      /* secondary button fill, light */
  --accent-text: #ffffff;
  --accent-fg-link: #0f6cbd;
  --gradient-end: #8d4ad9;
}

html[data-theme='light'] {
  color-scheme: light;
  --bg-base: #f3f3f3;
  --bg-layer: #f9f9f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f9f9f9;
  --bg-control: #ffffff;
  --bg-control-hover: #f9f9f9;
  --bg-subtle-hover: #ededed;
  --bg-subtle-pressed: #e5e5e5;
  --stroke: #e5e5e5;
  --stroke-secondary: #d6d6d6;
  --stroke-control: #e1e1e1;
  --stroke-control-bottom: #b3b3b3;
  --stroke-divider: #e5e5e5;
  --text-primary: #1b1b1b;
  --text-secondary: #5d5d5d;
  --text-tertiary: #8a8a8a;
  --text-disabled: #a1a1a1;
  --info-bg: #f4f4f4;
  --info-stroke: #e0e0e0;
  --success-bg: #dff6dd;
  --success-stroke: #bde5b8;
  --success-fg: #0f7b0f;
  --warn-bg: #fff4ce;
  --warn-stroke: #f0e1a8;
  --warn-fg: #9d5d00;
  --error-bg: #fde7e9;
  --error-stroke: #f3c8cc;
  --error-fg: #c42b1c;
  --shadow-card: 0 2px 4px rgba(0, 0, 0, 0.05);
  --shadow-toast: 0 8px 24px rgba(0, 0, 0, 0.14);
  --checker: rgba(0, 0, 0, 0.08);
  --accent-btn-secondary: #ebebeb;
  --accent-btn-secondary-hover: #dfdfdf;
}

html[data-theme='dark'] {
  color-scheme: dark;
  --accent: #4ba1e3;              /* Windows lightens the accent in dark mode */
  --accent-hover: #68b1ec;
  --accent-pressed: #2b88d8;
  --accent-light-2: #08304a;
  --accent-text: #001a2e;
  --accent-fg-link: #6cb8f6;
  --gradient-end: #b490e8;
  --bg-base: #202020;
  --bg-layer: #272727;
  --bg-card: #2b2b2b;
  --bg-card-hover: #323232;
  --bg-control: #2d2d2d;
  --bg-control-hover: #323232;
  --bg-subtle-hover: #2f2f2f;
  --bg-subtle-pressed: #292929;
  --stroke: #383838;
  --stroke-secondary: #454545;
  --stroke-control: #3a3a3a;
  --stroke-control-bottom: #232323;
  --stroke-divider: #303030;
  --text-primary: #ffffff;
  --text-secondary: #c5c5c5;
  --text-tertiary: #8b8b8b;
  --text-disabled: #6e6e6e;
  --info-bg: #2b2b2b;
  --info-stroke: #3d3d3d;
  --success-bg: #09270c;
  --success-stroke: #1d5423;
  --success-fg: #6ccb5f;
  --warn-bg: #332705;
  --warn-stroke: #6a5518;
  --warn-fg: #fce47c;
  --error-bg: #3a1012;
  --error-stroke: #6e2829;
  --error-fg: #ff99a4;
  --shadow-card: 0 2px 4px rgba(0, 0, 0, 0.2);
  --shadow-toast: 0 8px 24px rgba(0, 0, 0, 0.4);
  --checker: rgba(255, 255, 255, 0.06);
  --accent-btn-secondary: #333333;
  --accent-btn-secondary-hover: #3d3d3d;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

.mono { font-family: var(--font-mono); }

/* thin scrollbars that follow the theme */
* { scrollbar-width: thin; scrollbar-color: var(--stroke-secondary) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--stroke-secondary); border-radius: 5px; }
*::-webkit-scrollbar-track { background: transparent; }

/* --- top bar -------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg-base) 88%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--stroke-divider);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  min-height: 56px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-shrink: 1;
}

.brand-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--accent);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-title { font-size: 14px; font-weight: 600; letter-spacing: -0.1px; white-space: nowrap; }
.brand-sub { font-size: 11px; color: var(--text-tertiary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-spacer { flex: 1; }

/* --- pivot tabs ------------------------------------------------------ */

.tabs {
  display: flex;
  gap: 4px;
  height: 40px;
}

.tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-weight: 600;
  padding: 6px 12px 10px;
  margin-top: 6px;
  border-bottom: 2px solid transparent;
  border-radius: 4px 4px 0 0;
  cursor: pointer;
}

.tab:hover { color: var(--text-primary); background: var(--bg-subtle-hover); }
.tab:focus-visible { outline: 2px solid var(--text-primary); outline-offset: -2px; }
.tab.is-active { color: var(--text-primary); border-bottom-color: var(--accent); }
.tab.is-active:hover { background: transparent; }

/* --- icon buttons ----------------------------------------------------- */

.icon-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}

.icon-btn:hover { background: var(--bg-subtle-hover); }
.icon-btn:active { background: var(--bg-subtle-pressed); color: var(--text-secondary); }
.icon-btn:focus-visible { outline: 2px solid var(--text-primary); outline-offset: 1px; }
.icon-btn svg { width: 18px; height: 18px; }

#langBtn { width: auto; padding: 0 10px; font-weight: 600; }

/* --- main / hero ------------------------------------------------------- */

main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px 64px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.hero { margin-bottom: 4px; }
.hero-title {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.15;
  margin: 0;
}
.hero-gradient {
  background: linear-gradient(90deg, var(--accent), var(--gradient-end));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-sub {
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: 15px;
  max-width: 760px;
  display: block;
}

.page-sub {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-secondary);
}

@keyframes fade-up {
  from { transform: translateY(6px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.fade-up { animation: fade-up 0.35s ease forwards; }
@media (prefers-reduced-motion: reduce) {
  .fade-up { animation: none; }
}

.page { display: none; flex-direction: column; gap: 20px; }
.page.is-active { display: flex; }

/* --- cards -------------------------------------------------------------- */

.card {
  background: var(--bg-card);
  border: 1px solid var(--stroke);
  border-radius: 8px;
  padding: 22px 24px;
  box-shadow: var(--shadow-card);
}

.card-title {
  display: block;
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 12px;
}

.card-sub { color: var(--text-secondary); font-size: 12.5px; margin-top: 10px; line-height: 1.5; }

/* --- buttons ------------------------------------------------------------ */

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 32px;
  padding: 0 14px;
  border-radius: 4px;
  border: 1px solid var(--stroke-control);
  border-bottom-color: var(--stroke-control-bottom);
  background: var(--bg-control);
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--bg-control-hover); }
.btn:active { background: var(--bg-control-hover); color: var(--text-secondary); }
.btn:focus-visible { outline: 2px solid var(--text-primary); outline-offset: 1px; }
.btn:disabled { color: var(--text-disabled); background: var(--bg-card); border-color: var(--stroke); cursor: default; }

.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-text);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent-pressed); color: var(--accent-text); }
.btn-primary:disabled { background: var(--bg-subtle-hover); color: var(--text-disabled); }

.btn-secondary {
  background: var(--accent-btn-secondary);
  border-color: transparent;
  color: var(--text-primary);
}
.btn-secondary:hover { background: var(--accent-btn-secondary-hover); }

.btn-subtle {
  background: transparent;
  border-color: transparent;
  color: var(--text-primary);
}
.btn-subtle:hover { background: var(--bg-subtle-hover); }
.btn-subtle:active { background: var(--bg-subtle-pressed); }

/* --- inputs --------------------------------------------------------------- */

.text-input {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border-radius: 4px;
  border: 1px solid var(--stroke-control);
  border-bottom-color: var(--stroke-control-bottom);
  background: var(--bg-control);
  color: var(--text-primary);
  font: inherit;
}
.text-input:hover { background: var(--bg-control-hover); }
.text-input:focus {
  outline: none;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 0;
  background: var(--bg-control);
}
.text-input::placeholder { color: var(--text-tertiary); }

textarea.text-input {
  height: auto;
  min-height: 110px;
  padding: 8px 10px;
  resize: vertical;
  line-height: 1.5;
}
textarea.text-input:focus { padding-bottom: 7px; border-bottom-width: 2px; }

.key-row { display: flex; gap: 8px; }
.key-row .text-input { flex: 1; }

.usage { font-size: 12.5px; color: var(--text-secondary); margin-top: 6px; min-height: 16px; }
.usage.over { color: var(--error-fg); font-weight: 600; }

/* --- drop zone / preview --------------------------------------------------- */

.dropzone {
  position: relative;
  border: 1px dashed var(--stroke-secondary);
  border-radius: 6px;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  color: var(--text-tertiary);
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
  text-align: center;
  padding: 16px;
}

.dropzone:hover { border-color: var(--accent); color: var(--text-secondary); }
.dropzone.dragover { border-color: var(--accent); background: var(--accent-light-2); }
.dropzone svg.dz-icon { width: 28px; height: 28px; opacity: 0.8; }

.preview {
  position: relative;
  border: 1px solid var(--stroke);
  border-radius: 6px;
  padding: 0;
  cursor: default;
  background:
    repeating-conic-gradient(var(--checker) 0% 25%, transparent 0% 50%) 0 0 / 20px 20px;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.preview img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  object-fit: contain;
}

.preview-caption {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--text-secondary);
  flex-wrap: wrap;
}
.preview-caption .grow { flex: 1; }

.remove-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  background: color-mix(in srgb, var(--bg-card) 85%, transparent);
  backdrop-filter: blur(6px);
}

/* --- progress ---------------------------------------------------------------- */

.progress-row { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.progress-row .grow { flex: 1; }

.progress-label { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 6px; }

.progress-track {
  height: 4px;
  border-radius: 2px;
  background: var(--stroke);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 2px;
  background: var(--accent);
  transition: width 0.12s ease;
}

/* --- message bar / toasts ------------------------------------------------------ */

.msgbar {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 6px;
  border: 1px solid var(--info-stroke);
  background: var(--info-bg);
  font-size: 13px;
  line-height: 1.5;
}
.msgbar svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.msgbar .body { flex: 1; }
.msgbar .title { font-weight: 600; display: block; margin-bottom: 2px; }
.msgbar .dismiss {
  appearance: none; border: none; background: transparent; color: inherit;
  width: 28px; height: 28px; border-radius: 4px; cursor: pointer; padding: 4px;
}
.msgbar .dismiss:hover { background: var(--bg-subtle-hover); }
.msgbar .dismiss svg { width: 100%; height: 100%; margin: 0; }

.msgbar.success { border-color: var(--success-stroke); background: var(--success-bg); color: var(--success-fg); }
.msgbar.warning { border-color: var(--warn-stroke); background: var(--warn-bg); color: var(--warn-fg); }
.msgbar.error { border-color: var(--error-stroke); background: var(--error-bg); color: var(--error-fg); }

#toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 380px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 6px;
  border: 1px solid var(--info-stroke);
  background: var(--bg-card);
  color: var(--text-primary);
  box-shadow: var(--shadow-toast);
  font-size: 13px;
  line-height: 1.45;
  animation: fade-up 0.25s ease;
}
.toast svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.toast .title { font-weight: 600; display: block; }
.toast .body { color: var(--text-secondary); }
.toast.success svg, .toast.success .title { color: var(--success-fg); }
.toast.warning svg, .toast.warning .title { color: var(--warn-fg); }
.toast.error svg, .toast.error .title { color: var(--error-fg); }
.toast.info svg, .toast.info .title { color: var(--accent); }

/* --- radio rows -------------------------------------------------------------- */

.radio-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; cursor: pointer; font-size: 14px; }
.radio-row input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; cursor: pointer; }

.settings-block { margin-bottom: 20px; }
.settings-block:last-child { margin-bottom: 0; }
.settings-block .block-title { font-size: 14px; font-weight: 600; margin-bottom: 2px; display: block; }
.settings-block .block-hint { font-size: 12.5px; color: var(--text-tertiary); margin-bottom: 8px; display: block; }

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  cursor: pointer;
  user-select: none;
}
.switch-row input { accent-color: var(--accent); width: 16px; height: 16px; cursor: pointer; }

/* --- self test ----------------------------------------------------------------- */

.selftest-out {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--bg-layer);
  border: 1px solid var(--stroke);
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  max-height: 320px;
  overflow: auto;
  white-space: pre;
  color: var(--text-secondary);
}
.selftest-out .pass { color: var(--success-fg); }
.selftest-out .fail { color: var(--error-fg); font-weight: 600; }
.selftest-out .skip { color: var(--text-tertiary); }
.selftest-out .summary { color: var(--text-primary); font-weight: 600; }

/* --- footer ------------------------------------------------------------------ */

footer {
  border-top: 1px solid var(--stroke-divider);
  padding: 16px 24px;
}
.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--text-tertiary);
  font-size: 12px;
}

/* --- responsive ----------------------------------------------------------------- */

@media (max-width: 720px) {
  .topbar-inner { padding: 0 12px; gap: 8px; flex-wrap: wrap; padding-bottom: 4px; }
  .brand-sub { display: none; }
  main { padding: 18px 14px 48px; gap: 16px; }
  .hero-title { font-size: 25px; }
  .hero-sub { font-size: 13.5px; margin-top: 6px; }
  .card { padding: 18px 16px; }
  .footer-inner { justify-content: center; text-align: center; }
}
