/*
  CS-Oreas stylesheet.

  Deliberately plain: this is a tool people use all day, so legibility and a
  calm layout matter more than decoration. No external fonts or assets are
  referenced, which keeps the Content-Security-Policy strict.
*/

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #dde3ea;
  --text: #1d2733;
  --muted: #5b6b7d;
  --accent: #1f5f8b;          /* Analytichem-adjacent deep blue */
  --accent-dark: #17486a;
  --accent-soft: #e8f1f8;
  --warning-bg: #fdf3e2;
  --warning-border: #e5b96a;
  --warning-text: #7a5312;
  --error: #a32020;
  --ok: #1c6b3f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 35, 50, 0.08), 0 4px 14px rgba(20, 35, 50, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a21;
    --surface: #1c242e;
    --border: #2d3945;
    --text: #e6ecf2;
    --muted: #9aa9b9;
    --accent: #5aa7d8;
    --accent-dark: #7cbde6;
    --accent-soft: #23303d;
    --warning-bg: #3a2f18;
    --warning-border: #8a6a2a;
    --warning-text: #f0d5a0;
    --error: #f08a8a;
    --ok: #6fce9c;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

/*
  The whole interface is shown and hidden through the `hidden` attribute. The
  browser's own rule for it is only `display: none`, which any author rule that
  sets `display` beats on specificity, so screens with `display: flex` would
  stay visible. This rule makes the attribute authoritative.
*/
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15.5px;
  line-height: 1.55;
}

h1 { font-size: 1.5rem; margin: 0 0 0.4rem; }
h2 { font-size: 1.12rem; margin: 0 0 0.6rem; }
h3 { font-size: 0.98rem; margin: 1.4rem 0 0.5rem; color: var(--muted); }

.screen { min-height: 100vh; }
.centred { display: flex; align-items: center; justify-content: center; padding: 2rem 1rem; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ------------------------------------------------------------- layout -- */

.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: 0.7rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}

.brand { display: flex; align-items: center; gap: 0.7rem; }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--accent); color: #fff;
  font-weight: 700; font-size: 0.85rem; letter-spacing: 0.04em;
}
.brand strong { display: block; line-height: 1.15; }
.brand-sub { font-size: 0.78rem; color: var(--muted); }

.tabs { display: flex; gap: 0.25rem; margin-left: auto; }
.tab {
  border: 1px solid transparent; background: none; color: var(--muted);
  padding: 0.45rem 0.9rem; border-radius: var(--radius);
  font: inherit; font-size: 0.92rem; cursor: pointer;
}
.tab:hover { background: var(--accent-soft); color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }

.account { display: flex; align-items: center; gap: 0.9rem; font-size: 0.85rem; color: var(--muted); }

.view { max-width: 980px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.25rem;
}
.card.narrow { width: 100%; max-width: 400px; }

.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; gap: 0.75rem; }
.row.gap { gap: 0.6rem; }
.row.end { align-items: flex-end; }
.field { display: flex; flex-direction: column; flex: 1 1 170px; }

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

label, legend {
  display: block; font-size: 0.85rem; font-weight: 600;
  color: var(--muted); margin: 0.85rem 0 0.3rem;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="file"], select, textarea {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; min-height: 150px; line-height: 1.5; }

input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

button {
  font: inherit; cursor: pointer; border-radius: 8px;
  padding: 0.55rem 1.1rem; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
button.primary {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
button.primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
button.ghost { background: transparent; color: var(--muted); }
button.ghost:hover { background: var(--accent-soft); color: var(--text); }
button.small { padding: 0.4rem 0.8rem; font-size: 0.88rem; }
button.link {
  border: none; background: none; color: var(--accent);
  padding: 0; font-size: 0.85rem; text-decoration: underline;
}
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.primary[type="submit"], #login-form button, #password-form button { width: 100%; margin-top: 1.1rem; }

fieldset.visibility { border: none; padding: 0; margin: 0.6rem 0 0; }

/* --------------------------------------------------------- mode toggle -- */

.mode-toggle {
  display: inline-flex; padding: 3px; gap: 3px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 9px;
}
.mode {
  border: none; background: none; color: var(--muted);
  padding: 0.35rem 0.9rem; border-radius: 7px; font-size: 0.9rem;
}
.mode.active { background: var(--surface); color: var(--accent-dark); font-weight: 600; box-shadow: var(--shadow); }

/* ------------------------------------------------------------ answer --- */

.answer {
  margin-top: 0.9rem;
  padding: 1.1rem 1.2rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  white-space: normal;
}
.answer h3 { margin: 1.2rem 0 0.35rem; color: var(--accent-dark); font-size: 1rem; }
.answer h3:first-child { margin-top: 0; }
.answer p { margin: 0 0 0.75rem; }
.answer ul { margin: 0 0 0.85rem; padding-left: 1.25rem; }
.answer li { margin-bottom: 0.3rem; }
.answer strong { font-weight: 600; }

.references { margin-top: 1rem; }
.references ul { list-style: none; padding: 0; margin: 0; }
.references li {
  padding: 0.45rem 0; border-bottom: 1px solid var(--border); font-size: 0.9rem;
}
.references li:last-child { border-bottom: none; }
.references a { color: var(--accent); text-decoration: none; font-weight: 600; }
.references a:hover { text-decoration: underline; }
.references .sub { color: var(--muted); }

/* ------------------------------------------------------------ notices -- */

.hint { font-size: 0.85rem; color: var(--muted); margin: 0.4rem 0; }
.lead { color: var(--muted); margin: 0 0 0.6rem; font-size: 0.9rem; }
.error { color: var(--error); font-size: 0.88rem; margin-top: 0.8rem; }
.notice {
  margin-top: 0.85rem; padding: 0.6rem 0.8rem; font-size: 0.88rem;
  background: var(--accent-soft); border-radius: 8px; color: var(--accent-dark);
}
.warning {
  margin: 0.85rem 0 0; padding: 0.65rem 0.85rem; font-size: 0.88rem;
  background: var(--warning-bg); border: 1px solid var(--warning-border);
  color: var(--warning-text); border-radius: 8px;
}

.thinking { display: flex; align-items: center; gap: 0.8rem; color: var(--muted); font-size: 0.92rem; }
.spinner {
  width: 17px; height: 17px; flex: none; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 0.6rem 1.2rem; border-radius: 999px; font-size: 0.9rem; z-index: 50;
}

/* ------------------------------------------------------------- tables -- */

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; margin-top: 0.6rem; }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
td.actions { white-space: nowrap; }
.table-scroll { overflow-x: auto; }

.badge {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px;
  font-size: 0.76rem; font-weight: 600; border: 1px solid var(--border);
}
.badge.internal { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.badge.external { background: var(--accent-soft); color: var(--accent-dark); }
.badge.ok { color: var(--ok); }
.badge.bad { color: var(--error); }

.stats { display: flex; flex-wrap: wrap; gap: 1.5rem; margin-bottom: 1rem; }
.stat-value { font-size: 1.4rem; font-weight: 600; display: block; }
.stat-label { font-size: 0.8rem; color: var(--muted); }

@media (max-width: 640px) {
  .topbar { gap: 0.75rem; padding: 0.6rem 1rem; }
  .tabs { order: 3; width: 100%; margin-left: 0; }
  .account { margin-left: auto; }
  .view { padding: 1rem 0.85rem 3rem; }
}
