/* -------------------------------------------------------------------------
   The look.

   A dark top bar in both themes, a grey
   page, white (or slate) panels under a dark title strip, 4px corners and a
   faint shadow. Orange is the logo's colour and appears on one thing per
   panel at most, its main button. Nothing here is decoration: every border,
   colour and shadow marks a panel, a control or a state.
   ------------------------------------------------------------------------- */

:root,
:root[data-theme="light"] {
  --bar: #0f171f;
  --bar-text: #ffffff;
  --bar-muted: #a9b1bc;
  --bar-hover: rgba(255, 255, 255, 0.1);
  --page: #f0f2f5;
  --panel: #ffffff;
  --panel-head: #373f47;
  --panel-head-text: #ffffff;
  --text: #19181a;
  --muted: #62646f;
  --border: #d9dbde;
  --control-border: #b7bcc4;
  --control-bg: #ffffff;
  --control-hover: #f0f2f5;
  --neutral-fill: #e1e2e6;
  --accent: #ff8447;
  --accent-hover: #f2733a;
  --accent-ink: #19181a;
  --ok: #276b2b;
  --ok-bg: #e6f2e7;
  --danger: #c62828;
  --danger-bg: #fbe9e7;
  --focus: #1f6fd1;
  --shadow: 0 1px 3px rgba(15, 23, 31, 0.12), 0 1px 2px rgba(15, 23, 31, 0.06);
  --radius: 4px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --page: #131920;
  --panel: #232d3a;
  --panel-head: #373f47;
  --text: #eef0f3;
  --muted: #9aa3ae;
  --border: #3a4350;
  --control-border: #4b5563;
  --control-bg: #1b2430;
  --control-hover: #2b3644;
  --neutral-fill: #2b3644;
  --ok: #6cc566;
  --ok-bg: #2c413f;
  --danger: #f7736e;
  --danger-bg: #3a2629;
  --focus: #6aa8ff;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { background: var(--page); }

body {
  min-height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  color: var(--text);
  background: var(--page);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Noto Sans", Arial, sans-serif;
  font-size: 0.95rem;
  line-height: 1.5;
}

h1, h2, p { margin-top: 0; }

a { color: inherit; }

.hidden { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---- Top bar ------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  color: var(--bar-text);
  background: var(--bar);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.header-row {
  position: relative;
  min-height: 4rem;
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
  color: var(--bar-text);
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: auto;
  height: 2.2rem;
}

.brand-name {
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
}

.app-version {
  color: var(--bar-muted);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.header-link {
  display: inline-flex;
  align-items: center;
  min-height: 2.4rem;
  padding: 0 0.8rem;
  color: var(--bar-text);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.header-link:hover { background: var(--bar-hover); }

/* The page you are on, marked in the top bar. */
.header-link[aria-current="page"] {
  box-shadow: inset 0 -3px 0 var(--accent);
  border-radius: 0;
}

.theme-toggle {
  display: inline-grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  padding: 0;
  color: var(--bar-text);
  background: transparent;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}

.theme-toggle:hover { background: var(--bar-hover); }

.theme-icon {
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The icon shows where the button takes you: a sun in the dark theme, a moon
   in the light one. The label is only for the phone menu, where the button
   is a row of its own. */
.theme-icon-moon { display: none; }
:root[data-theme="light"] .theme-icon-sun { display: none; }
:root[data-theme="light"] .theme-icon-moon { display: block; }

.theme-toggle-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.login-theme-toggle { margin-left: auto; }

.nav-toggle { display: none; }

/* ---- Page and panels ----------------------------------------------------- */

main {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2rem;
  flex: 1 0 auto;
}

.panel {
  margin-bottom: 1rem;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-title {
  margin: 0;
  padding: 0.6rem 1.1rem;
  color: var(--panel-head-text);
  background: var(--panel-head);
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.4;
}

.panel-body { padding: 1.1rem; }
.panel-body > :last-child { margin-bottom: 0; }

p.panel-body { margin: 0; }

.status-panel p { margin: 0; }

.hint,
.section-copy {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
}

.section-copy { margin-top: 0; }

/* A warning to read before choosing a file: a warning triangle and
   plain text in a bordered box, no tint. */
.ai-notice {
  display: flex;
  gap: 0.7rem;
  align-items: flex-start;
  margin: 0 0 1.1rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.notice-icon {
  flex: 0 0 auto;
  width: 1.25rem;
  height: 1.25rem;
  margin-top: 0.1rem;
  fill: none;
  stroke: var(--danger);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- Form controls -------------------------------------------------------- */

.upload-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(10rem, 14rem) auto;
  gap: 0.9rem;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}

.field-label {
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
}

.field-optional {
  color: var(--muted);
  font-weight: 400;
}

input[type="text"],
input[type="password"],
input[type="search"],
textarea,
.file-picker {
  width: 100%;
  min-width: 0;
  min-height: 2.5rem;
  padding: 0.45rem 0.7rem;
  color: var(--text);
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  font: inherit;
}

textarea { resize: vertical; }

input::placeholder,
textarea::placeholder { color: var(--muted); }

input:focus-visible,
textarea:focus-visible { outline-offset: 0; }

/* The native file input is visually hidden; this label stands in for it, as
   a field with the neutral button at its start. */
.file-picker {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.25rem 0.7rem 0.25rem 0.25rem;
  cursor: pointer;
}

.file-picker-button {
  flex: 0 0 auto;
  padding: 0.3rem 0.7rem;
  background: var(--neutral-fill);
  border-radius: 3px;
  font-weight: 600;
  font-size: 0.875rem;
}

.file-picker-name {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-picker:hover .file-picker-button { background: var(--control-hover); }

label.file-picker:has(+ input:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: 0;
}

/* ---- Buttons --------------------------------------------------------------
   One neutral outlined button, and one primary in the logo's
   orange for the main action of a panel. */

button,
.download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.5rem;
  padding: 0.4rem 0.95rem;
  color: var(--text);
  background: var(--control-bg);
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

button:hover:not(:disabled),
.download:hover { background: var(--control-hover); }

button:disabled { opacity: 0.5; cursor: not-allowed; }

/* The bar's own controls keep the bar's hover. Without the higher
   specificity, the line above lit "Kirjaudu ulos" up in the panels' light
   grey on the dark bar. */
.topbar button:hover:not(:disabled),
.topbar .header-link:hover { background: var(--bar-hover); }

/* The developer export, where an admin sees it beside the others. */
.download-secondary { color: var(--muted); }

.primary-button {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.button-row,
.downloads,
.admin-downloads {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

/* ---- Queue, progress, results ---------------------------------------------- */

.queue-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.queue-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 1.1rem;
  border-top: 1px solid var(--border);
}

.queue-item:first-child { border-top: 0; }
.queue-item-running { font-weight: 600; }

.queue-badge {
  padding: 0.05rem 0.5rem;
  background: var(--neutral-fill);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

#status-text,
#duplicate-text,
#result-text { margin: 0; }

progress {
  display: block;
  width: 100%;
  height: 0.5rem;
  margin-top: 0.8rem;
  border: 0;
  border-radius: 999px;
  background: var(--neutral-fill);
  overflow: hidden;
  appearance: none;
}

progress::-webkit-progress-bar { background: var(--neutral-fill); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }

#result-text { font-size: 1.05rem; font-weight: 600; }

/* What the run could not do: red text under a warning triangle. */
.result-warnings {
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
  color: var(--danger);
  font-size: 0.9rem;
}

.result-warnings li {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.result-warnings li + li { margin-top: 0.35rem; }

.result-warnings .notice-icon {
  width: 1.1rem;
  height: 1.1rem;
  margin-top: 0.1rem;
}

.error { color: var(--danger); }

/* ---- Feedback ---------------------------------------------------------- */

.feedback-toggle {
  width: 100%;
  justify-content: flex-start;
  min-height: 3rem;
  padding: 0.6rem 1.1rem;
  background: transparent;
  border: 0;
  border-radius: 0;
  font-weight: 600;
  text-align: left;
}

.feedback-toggle-chevron {
  width: 1.1rem;
  height: 1.1rem;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.15s ease;
}

.feedback-toggle[aria-expanded="true"] .feedback-toggle-chevron { transform: rotate(90deg); }

.dev-feedback-form {
  display: grid;
  gap: 1rem;
  padding: 1.1rem;
  border-top: 1px solid var(--border);
}

.rating-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.rating-btn svg,
.feedback-drop svg {
  width: 1.15rem;
  height: 1.15rem;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#rating-up.selected {
  color: var(--ok);
  background: var(--ok-bg);
  border-color: var(--ok);
}

#rating-down.selected {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger);
}

.feedback-image-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.feedback-drop {
  justify-content: flex-start;
  min-height: 3.5rem;
  padding: 0.6rem 0.9rem;
  font-weight: 400;
  text-align: left;
}

.feedback-drop.dragover { border-color: var(--accent); background: var(--control-hover); }

.feedback-drop-copy {
  display: flex;
  flex-direction: column;
}

.feedback-drop-copy strong { font-weight: 600; }
.feedback-drop-copy span { color: var(--muted); font-size: 0.85rem; }

.feedback-image-preview {
  margin: 0.4rem 0 0;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.feedback-image-preview img {
  display: block;
  max-width: 100%;
  max-height: 16rem;
  border-radius: var(--radius);
}

.feedback-image-preview figcaption {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.dev-feedback-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.dev-feedback-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.9rem;
}

#feedback-status { margin: 0; }

/* ---- History and Palautteet ------------------------------------------------ */

.admin-counts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: 0.75rem;
}

.admin-count {
  display: flex;
  flex-direction: column;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.admin-count strong {
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.2;
}

.admin-count span { color: var(--muted); font-size: 0.85rem; }

.admin-tabs {
  display: flex;
  gap: 0.5rem;
  margin: 0 0 1rem;
}

.admin-tab.selected {
  color: var(--panel-head-text);
  background: var(--panel-head);
  border-color: var(--panel-head);
}

.admin-tab.selected:hover:not(:disabled) { background: var(--panel-head); }

.card-list {
  display: grid;
  gap: 1rem;
}

/* A run or a report: its status, time and sender in the title strip, the
   rest below it. */
.admin-card { padding-bottom: 1.1rem; }
.admin-card > :not(.admin-card-head) { margin-left: 1.1rem; margin-right: 1.1rem; }

.admin-card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
  padding: 0.55rem 1.1rem;
  color: var(--panel-head-text);
  background: var(--panel-head);
}

.admin-card-time { font-weight: 600; }
.admin-card-name { margin-left: auto; color: #d6dae0; }

.admin-card-message {
  margin-top: 0;
  margin-bottom: 0.8rem;
  font-weight: 600;
  white-space: pre-wrap;
}

.admin-card-meta {
  display: grid;
  gap: 0.2rem;
  font-size: 0.875rem;
}

.admin-meta-row { display: flex; gap: 0.75rem; }

.admin-meta-label {
  flex: 0 0 auto;
  width: 10rem;
  color: var(--muted);
}

.admin-meta-value { min-width: 0; overflow-wrap: anywhere; }

.admin-card .download { min-height: 2.2rem; font-size: 0.875rem; }

.admin-card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-top: 1rem;
}

.admin-note { flex: 1 1 14rem; width: auto; }

.admin-shot { margin: 0 0 0.9rem; }

.admin-shot img {
  display: block;
  max-width: 100%;
  max-height: 28rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.admin-shot-remove { margin-top: 0.5rem; }

.rating-badge {
  padding: 0.05rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

.rating-badge-up { color: #1f5f22; background: #e6f2e7; }
.rating-badge-down { color: #8e1c1c; background: #fbe3e1; }
.rating-badge-none { color: #2f3640; background: #e1e2e6; }

.busy { opacity: 0.6; pointer-events: none; }

.history-more {
  display: flex;
  justify-content: center;
  margin-top: 1rem;
}

/* ---- Login ------------------------------------------------------------- */

.login-main { max-width: 26rem; padding-top: 3rem; }
.login-copy { margin: 0 0 1rem; color: var(--muted); }

#login-form {
  display: grid;
  gap: 1rem;
}

#login-error { margin: 1rem 0 0; }

/* ---- Footer ------------------------------------------------------------ */

.footer {
  padding: 1rem 1.25rem 1.5rem;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

/* ---- Narrow screens -----------------------------------------------------
   Below 760 px the header's links, logout and theme button fold into a menu
   behind one button (#121). nav.js only flips the button's aria-expanded;
   showing and hiding the menu is all here, and the 760 must match nav.js. */

@media (max-width: 760px) {
  .header-row {
    min-height: 3.5rem;
    padding: 0 0.75rem;
    gap: 0.6rem;
  }

  .brand { gap: 0.6rem; }
  .brand-logo { height: 1.8rem; }
  .brand-name { font-size: 0.95rem; }

  .nav-toggle {
    display: inline-grid;
    place-items: center;
    width: 2.6rem;
    height: 2.6rem;
    min-height: 0;
    margin-left: auto;
    padding: 0;
    color: var(--bar-text);
    background: transparent;
    border: 0;
  }

  .nav-toggle:hover:not(:disabled),
  .nav-toggle[aria-expanded="true"] { background: var(--bar-hover); }

  .nav-toggle svg {
    width: 1.4rem;
    height: 1.4rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
  }

  .nav-icon-close { display: none; }
  .nav-toggle[aria-expanded="true"] .nav-icon-open { display: none; }
  .nav-toggle[aria-expanded="true"] .nav-icon-close { display: block; }

  .header-actions { display: none; }

  .nav-toggle[aria-expanded="true"] + .header-actions {
    position: absolute;
    top: 100%;
    right: 0.75rem;
    left: auto;
    z-index: 60;
    min-width: 13rem;
    margin: 0;
    padding: 0.35rem 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 6px 18px rgba(15, 23, 31, 0.25);
  }

  .nav-toggle[aria-expanded="true"] + .header-actions .header-link,
  .nav-toggle[aria-expanded="true"] + .header-actions .theme-toggle {
    width: 100%;
    height: auto;
    min-height: 2.75rem;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.6rem;
    color: var(--text);
    border-radius: 0;
    box-shadow: none;
  }

  .nav-toggle[aria-expanded="true"] + .header-actions .header-link:hover,
  .nav-toggle[aria-expanded="true"] + .header-actions .theme-toggle:hover { background: var(--control-hover); }

  .nav-toggle[aria-expanded="true"] + .header-actions .header-link[aria-current="page"] {
    box-shadow: inset 3px 0 0 var(--accent);
  }

  .nav-toggle[aria-expanded="true"] + .header-actions .theme-toggle {
    border-top: 1px solid var(--border);
    font: inherit;
    font-weight: 600;
  }

  .nav-toggle[aria-expanded="true"] + .header-actions .theme-toggle-label {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
  }

  main { padding: 1rem 0.75rem 1.5rem; }

  .upload-row,
  .dev-feedback-meta { grid-template-columns: minmax(0, 1fr); }

  .upload-row .primary-button { width: 100%; }

  .admin-counts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* A file name with no spaces pushed the card 3px past a 320px screen. */
  .admin-card-message { overflow-wrap: anywhere; }
  .admin-meta-row { flex-direction: column; gap: 0.1rem; }
  .admin-meta-label { width: auto; }
  .admin-card-name { margin-left: 0; }
}

@media (max-width: 480px) {
  .app-version { display: none; }
  .panel-title { font-size: 1rem; padding: 0.55rem 0.9rem; }
  .panel-body { padding: 0.9rem; }
  .admin-card > :not(.admin-card-head) { margin-left: 0.9rem; margin-right: 0.9rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
