/* =========================================================================
 * Admin UI — "Editorial Trading Terminal"
 * Ink-dark base · cream paper typography · amber-gold signal · sage/vermillion
 * Fraunces (display) · IBM Plex Sans (body) · IBM Plex Mono (numerics)
 * ========================================================================= */

/* ---------- 1. Tokens ---------- */
:root {
  /* Inks — cool-warm black spectrum */
  --ink-0:   #0A0A0F;   /* page background */
  --ink-1:   #10101A;   /* panels, sidebar, cards */
  --ink-2:   #171722;   /* inputs, table header */
  --ink-3:   #1F1F2D;   /* elevated surface, hover */
  --ink-4:   #272735;   /* deepest elevated */

  /* Paper — cream warm whites for text */
  --paper-0: #F1EADB;   /* primary text, headings */
  --paper-1: #B8B3A4;   /* secondary */
  --paper-2: #7E7A6D;   /* tertiary / meta */
  --paper-3: #4E4B43;   /* placeholder */

  /* Rules — hairline dividers */
  --rule:        #232331;
  --rule-strong: #2E2E3E;
  --rule-soft:   #1A1A25;

  /* Gold — primary accent (old coin, terminal amber) */
  --gold:        #E7B454;
  --gold-hover:  #F2C56A;
  --gold-deep:   #B8862F;
  --gold-bg:     rgba(231, 180, 84, 0.12);
  --gold-soft:   rgba(231, 180, 84, 0.06);
  --gold-line:   rgba(231, 180, 84, 0.32);

  /* Sage — success */
  --sage:        #7EB98E;
  --sage-deep:   #528666;
  --sage-bg:     rgba(126, 185, 142, 0.12);
  --sage-line:   rgba(126, 185, 142, 0.32);

  /* Vermillion — danger */
  --red:         #DF5D5D;
  --red-deep:    #B33B3B;
  --red-bg:      rgba(223, 93, 93, 0.10);
  --red-line:    rgba(223, 93, 93, 0.32);

  /* Indigo — meta / violet */
  --indigo:      #9384EC;
  --indigo-bg:   rgba(147, 132, 236, 0.12);
  --indigo-line: rgba(147, 132, 236, 0.32);

  /* Aqua — info (blue signal) */
  --aqua:        #6CC3D1;
  --aqua-bg:     rgba(108, 195, 209, 0.10);

  /* Radii — slight, editorial */
  --r-xs: 2px;
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
  --r-pill: 999px;

  /* Fonts */
  --font-sans:    "IBM Plex Sans", -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono:    "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --font-display: "Fraunces", "Iowan Old Style", "Palatino Linotype", Georgia, serif;

  /* Shadows */
  --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.02) inset,
               0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 1px 0 rgba(255, 255, 255, 0.025) inset,
               0 12px 32px rgba(0, 0, 0, 0.45);
  --shadow-dialog: 0 24px 64px rgba(0, 0, 0, 0.65),
                   0 1px 0 rgba(255, 255, 255, 0.04) inset;

  --focus-ring: 0 0 0 2px var(--ink-0), 0 0 0 4px var(--gold);

  /* Paper-grain noise overlay (tiny, subtle) */
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.95' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.94 0 0 0 0 0.91 0 0 0 0 0.85 0 0 0 0.5 0'/></filter><rect width='100%' height='100%' filter='url(%23n)' opacity='0.25'/></svg>");

  color-scheme: dark;
}

/* ---------- 2. Reset & base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--ink-0);
  color: var(--paper-0);
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.55;
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  position: relative;
  overflow-x: hidden;
}

/* Tiny grain overlay — atmosphere, not texture */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: var(--grain);
  background-size: 180px 180px;
  opacity: 0.035;
  pointer-events: none;
  z-index: 1;
  mix-blend-mode: overlay;
}

::selection {
  background: var(--gold);
  color: var(--ink-0);
}

h1, h2, h3, h4, h5, h6 {
  margin: 0 0 0.55rem;
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.015em;
  color: var(--paper-0);
  font-variation-settings: "opsz" 48, "SOFT" 50;
}

h1 {
  font-size: clamp(2rem, 3vw, 2.6rem);
  line-height: 1.04;
  font-weight: 500;
  letter-spacing: -0.025em;
  font-variation-settings: "opsz" 144, "SOFT" 30;
}
h2 {
  font-size: clamp(1.55rem, 2.2vw, 1.9rem);
  line-height: 1.08;
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 96, "SOFT" 40;
}
h3 {
  font-size: 1.1rem;
  line-height: 1.25;
  font-variation-settings: "opsz" 48, "SOFT" 50;
  font-weight: 600;
}
h4 { font-size: 0.95rem; font-weight: 600; }

p { margin: 0 0 0.75rem; color: var(--paper-0); }

a {
  color: var(--gold);
  text-decoration: none;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}
a:hover { color: var(--gold-hover); }

a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-md);
}

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.86em;
  font-weight: 500;
  background: var(--ink-2);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  padding: 0.08em 0.4em;
  color: var(--paper-0);
}

hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 1rem 0;
}

small { color: var(--paper-1); font-size: 0.82em; }

/* ---------- 3. Layout shell ---------- */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  grid-template-rows: 60px minmax(0, 1fr);
  grid-template-areas:
    "topbar topbar"
    "sidebar content";
  position: relative;
  z-index: 2;
}

/* Topbar — editorial masthead */
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1.25rem;
  background: rgba(10, 10, 15, 0.82);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  z-index: 20;
}

/* Decorative hairline rule under the topbar */
.topbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--gold-line) 15%, var(--gold-line) 85%, transparent 100%);
  opacity: 0.6;
  pointer-events: none;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand-mark {
  color: var(--gold);
  font-size: 0.85rem;
  line-height: 1;
  transform: translateY(-1px);
  text-shadow: 0 0 12px var(--gold-bg);
}

.topbar-brand strong {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.02rem;
  letter-spacing: -0.015em;
  color: var(--paper-0);
  font-variation-settings: "opsz" 14, "SOFT" 40;
}

.brand-dot { color: var(--paper-2); margin: 0 0.15em; font-weight: 400; }

.brand-accent {
  color: var(--gold);
  font-style: italic;
  font-variation-settings: "opsz" 14, "SOFT" 100;
}

.topbar-edition {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--paper-2);
  padding-left: 0.9rem;
  margin-left: 0.2rem;
  border-left: 1px solid var(--rule);
  display: none;
}

@media (min-width: 720px) {
  .topbar-edition { display: inline-flex; }
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.topbar-status {
  display: none;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--paper-1);
}

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--sage);
  box-shadow: 0 0 0 3px var(--sage-bg), 0 0 8px var(--sage);
  animation: pulse 2.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}

@media (min-width: 640px) { .topbar-status { display: inline-flex; } }

.topbar-user {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--paper-1);
  letter-spacing: 0.02em;
}
.topbar-user::before {
  content: "@";
  color: var(--paper-2);
  margin-right: 0.1em;
}

/* Sidebar — newsstand section index */
.sidebar {
  grid-area: sidebar;
  background: var(--ink-1);
  border-right: 1px solid var(--rule);
  padding: 1.2rem 0.7rem 2rem;
  min-height: 100%;
  position: relative;
}

.sidebar::before {
  content: "";
  position: absolute;
  top: 0;
  right: -1px;
  width: 1px;
  height: 120px;
  background: linear-gradient(180deg, var(--gold-line) 0%, transparent 100%);
  opacity: 0.7;
}

.sidebar-section {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--paper-2);
  margin: 0.85rem 0.9rem 0.45rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--rule-soft);
  position: relative;
}
.sidebar-section:first-child { margin-top: 0; }

.sidebar nav ul {
  list-style: none;
  margin: 0 0 0.55rem;
  padding: 0;
  display: grid;
  gap: 1px;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.55rem 0.85rem;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  color: var(--paper-1);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  letter-spacing: -0.005em;
  text-decoration: none;
  transition: background 140ms ease, color 140ms ease,
              border-color 140ms ease, padding-left 140ms ease;
  position: relative;
}

.nav-marker {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  color: var(--paper-2);
  font-variant-numeric: tabular-nums;
  min-width: 1.6em;
  transition: color 140ms ease;
}

.nav-label { flex: 1; }

.sidebar nav a:hover {
  color: var(--paper-0);
  background: var(--ink-2);
}
.sidebar nav a:hover .nav-marker { color: var(--paper-1); }

.sidebar nav a.active {
  color: var(--paper-0);
  background: linear-gradient(90deg, var(--gold-bg) 0%, transparent 80%);
  border-color: var(--gold-line);
  padding-left: 1rem;
}
.sidebar nav a.active::before {
  content: "";
  position: absolute;
  left: -0.8rem;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 22px;
  background: var(--gold);
  border-radius: 0 2px 2px 0;
  box-shadow: 0 0 12px var(--gold-bg);
}
.sidebar nav a.active .nav-marker { color: var(--gold); }

/* Main content */
.main-content {
  grid-area: content;
  padding: 1.75rem 2rem 3.5rem;
  min-width: 0;
  position: relative;
}

.main-content > h2,
.main-content > h3 { margin-top: 0; }

/* Auth shell — login */
.auth-main {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(ellipse 800px 400px at 50% 0%, var(--gold-soft), transparent 70%),
    var(--ink-0);
}

.auth-main::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(231, 180, 84, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(231, 180, 84, 0.04) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(circle at center, #000 0%, transparent 65%);
  -webkit-mask-image: radial-gradient(circle at center, #000 0%, transparent 65%);
  pointer-events: none;
}

.login-wrap {
  width: min(100%, 420px);
  position: relative;
  z-index: 2;
}

.login-wrap::before {
  content: "EDITORIAL · TRADING · TERMINAL";
  display: block;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  letter-spacing: 0.4em;
  color: var(--gold);
  text-align: center;
  margin-bottom: 1.25rem;
  opacity: 0.75;
}

.login-card {
  background: var(--ink-1);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 1.75rem 1.75rem 2rem;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--gold) 50%, transparent);
  opacity: 0.7;
}

.login-card h2 {
  font-size: 1.7rem;
  font-variation-settings: "opsz" 72, "SOFT" 50;
  margin-bottom: 0.15rem;
}

.login-card > p {
  color: var(--paper-1);
  margin-bottom: 1.4rem;
  font-size: 0.92rem;
}

/* ---------- 4. Buttons ---------- */
.btn,
button,
input[type="submit"] {
  --btn-fg: var(--paper-0);
  --btn-bg: transparent;
  --btn-border: var(--rule-strong);
  --btn-bg-hover: var(--ink-3);
  --btn-border-hover: var(--rule-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 38px;
  padding: 0 1rem;
  font-family: var(--font-sans);
  font-size: 0.86rem;
  font-weight: 500;
  line-height: 1;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: var(--r-md);
  cursor: pointer;
  text-decoration: none;
  transition: background 150ms ease, border-color 150ms ease,
              color 150ms ease, transform 100ms ease, box-shadow 150ms ease;
  user-select: none;
  white-space: nowrap;
  letter-spacing: -0.002em;
}

.btn:hover,
button:hover,
input[type="submit"]:hover {
  background: var(--btn-bg-hover);
  border-color: var(--btn-border-hover);
  color: var(--btn-fg);
}

.btn:active,
button:active,
input[type="submit"]:active { transform: translateY(1px); }

.btn:disabled,
button:disabled,
input[type="submit"]:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

input[type="submit"]:focus-visible { border-radius: var(--r-md); }

/* Primary — gold coin */
.btn-primary,
input[type="submit"] {
  --btn-fg: var(--ink-0);
  --btn-bg: var(--gold);
  --btn-border: var(--gold);
  --btn-bg-hover: var(--gold-hover);
  --btn-border-hover: var(--gold-hover);
  font-weight: 600;
  box-shadow: 0 0 0 1px var(--gold-bg) inset, 0 4px 12px -4px var(--gold-bg);
}
.btn-primary:hover,
input[type="submit"]:hover { color: var(--ink-0); }

/* Secondary — outlined */
.btn-secondary {
  --btn-fg: var(--paper-0);
  --btn-bg: transparent;
  --btn-border: var(--rule-strong);
  --btn-bg-hover: transparent;
  --btn-border-hover: var(--gold);
}
.btn-secondary:hover { color: var(--gold); }

/* Ghost — topbar logout */
.btn-ghost {
  --btn-fg: var(--paper-1);
  --btn-bg: transparent;
  --btn-border: transparent;
  --btn-bg-hover: var(--ink-2);
  --btn-border-hover: transparent;
}
.btn-ghost:hover { color: var(--paper-0); }

/* Danger */
.btn-danger {
  --btn-fg: #fff;
  --btn-bg: var(--red);
  --btn-border: var(--red);
  --btn-bg-hover: var(--red-deep);
  --btn-border-hover: var(--red-deep);
  font-weight: 600;
  box-shadow: 0 4px 12px -4px var(--red-bg);
}
.btn-danger:hover { color: #fff; }

.btn-sm { height: 30px; padding: 0 0.7rem; font-size: 0.78rem; }
.btn-lg { height: 46px; padding: 0 1.5rem; font-size: 0.95rem; }
.btn-block { width: 100%; }

/* ---------- 5. Forms ---------- */
label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--paper-2);
  margin: 0 0 0.4rem;
}

label:has(> input[type="checkbox"]),
label:has(> input[type="radio"]) {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0;
  color: var(--paper-0);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
}

label:has(> input[type="checkbox"]) input,
label:has(> input[type="radio"]) input {
  width: 16px; height: 16px;
  margin: 0;
  flex-shrink: 0;
}

input,
select,
textarea {
  width: 100%;
  display: block;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--paper-0);
  background: var(--ink-2);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 0.58rem 0.8rem;
  height: 38px;
  transition: border-color 150ms ease, box-shadow 150ms ease,
              background 150ms ease;
  appearance: none;
  -webkit-appearance: none;
}

textarea {
  height: auto;
  min-height: 96px;
  resize: vertical;
  padding: 0.7rem 0.8rem;
  line-height: 1.55;
}

input::placeholder,
textarea::placeholder {
  color: var(--paper-3);
  font-style: italic;
}

input:hover,
select:hover,
textarea:hover { border-color: var(--rule-strong); }

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--gold);
  /* background-color only — shorthand would reset background-image/repeat/position
     on <select> and cause the chevron SVG to tile across the full width. */
  background-color: var(--ink-1);
  box-shadow: 0 0 0 3px var(--gold-bg);
}

input:disabled,
select:disabled,
textarea:disabled { opacity: 0.5; cursor: not-allowed; }

input[type="checkbox"],
input[type="radio"] {
  /* Базовое appearance: none в .form-inputs rule скрывало встроенный индикатор
     галочки/точки у checkbox/radio, из-за чего был виден только пустой бокс.
     Возвращаем нативный рендер — accent-color подкрашивает в золото. */
  appearance: auto;
  -webkit-appearance: auto;
  width: 16px; height: 16px;
  padding: 0;
  margin: 0 0.4rem 0 0;
  vertical-align: -3px;
  accent-color: var(--gold);
  background: transparent;
  border: none;
  border-radius: 0;
  cursor: pointer;
}

input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible { box-shadow: var(--focus-ring); }

input[type="file"] { padding: 0.4rem; line-height: 1; }
input[type="number"] { font-variant-numeric: tabular-nums; font-family: var(--font-mono); }

input[type="date"],
input[type="datetime-local"],
input[type="time"] {
  color-scheme: dark;
  font-family: var(--font-mono);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23B8B3A4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
  padding-right: 2.1rem;
  cursor: pointer;
}

select:focus {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23E7B454' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
}

fieldset {
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 0.9rem 1rem 0.6rem;
  margin: 0 0 1rem;
  background: var(--ink-1);
}

legend {
  padding: 0 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--gold);
  letter-spacing: 0.14em;
}

form > label { margin-top: 0.9rem; }
form > label:first-child { margin-top: 0; }

/* ---------- 6. Tables — newspaper column density ---------- */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--ink-1);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  overflow: hidden;
  font-size: 0.88rem;
}

thead th {
  text-align: left;
  padding: 0.7rem 0.9rem;
  background: var(--ink-2);
  border-bottom: 1px solid var(--rule-strong);
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--paper-2);
  white-space: nowrap;
}

tbody td {
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--rule-soft);
  color: var(--paper-0);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr { transition: background 120ms ease; }
tbody tr:hover { background: var(--ink-3); }
tbody tr:hover a[href] { color: var(--gold); }

td a {
  color: var(--paper-0);
  border-bottom: 1px dotted var(--rule-strong);
  transition: color 140ms ease, border-color 140ms ease;
}
td a:hover { color: var(--gold); border-bottom-color: var(--gold); }

/* First column — ID-ish — mono tabular */
tbody td:first-child,
thead th:first-child {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--paper-1);
  font-size: 0.82rem;
}
thead th:first-child { color: var(--paper-2); }

/* Empty-state row */
tbody tr td[colspan] {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--paper-2);
  font-style: italic;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-variation-settings: "opsz" 48, "SOFT" 60;
}

/* Inline-форма внутри ячейки (например, update category) — в одну строку. */
tbody td form {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  flex-wrap: wrap;
}

tbody td form input[type="text"],
tbody td form input[type="number"] {
  width: auto;
  height: 30px;
  padding: 0.3rem 0.6rem;
  font-size: 0.82rem;
}

tbody td form label:has(> input[type="checkbox"]) {
  font-size: 0.8rem;
}

/* ---------- 7. Cards ---------- */
.card,
article {
  background: var(--ink-1);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 1rem 1.15rem;
  margin: 0 0 1rem;
  color: var(--paper-0);
  box-shadow: var(--shadow-sm);
  position: relative;
}

article > :last-child { margin-bottom: 0; }

article header {
  margin: 0 0 0.6rem;
  padding: 0 0 0.6rem;
  border-bottom: 1px solid var(--rule);
}

article footer {
  margin: 0.6rem 0 0;
  padding: 0.6rem 0 0;
  border-top: 1px solid var(--rule);
}

/* ---------- 8. Page header — masthead ---------- */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 1.5rem;
  padding-bottom: 0.9rem;
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
  position: relative;
}

/* Double-rule — newspaper style */
.page-header::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -4px;
  height: 1px;
  background: var(--rule-soft);
}

.page-header h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.022em;
}

.page-header > div {
  display: inline-flex;
  gap: 0.55rem;
  align-items: center;
  flex-wrap: wrap;
}

/* ---------- 9. Filters & form grids ---------- */
.filters-grid,
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem 1rem;
  margin: 0 0 1.25rem;
  padding: 1rem 1.1rem 1.1rem;
  background: var(--ink-1);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  position: relative;
}

/* "FILTERS" label — только на формах method="get" (реальные фильтры).
   .filters-grid исторически используется и для POST-форм создания (categories),
   где такой лейбл был бы неуместен. */
form.filters-grid[method="get"]::before {
  content: "FILTERS";
  position: absolute;
  top: -8px;
  left: 16px;
  padding: 0 8px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.24em;
  color: var(--paper-2);
  background: var(--ink-0);
}

.filters-actions,
.form-actions {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  grid-column: 1 / -1;
  padding-top: 0.2rem;
  border-top: 1px dashed var(--rule-soft);
  margin-top: 0.25rem;
}

@media (min-width: 960px) {
  .filters-actions,
  .form-actions {
    grid-column: auto;
    border-top: none;
    margin-top: 0;
    padding-top: 0;
  }
}

/* Inline form compactly packed into a table cell */
.cell-form-inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
}

.cell-form-inline + .cell-form-inline {
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px dashed var(--rule-soft);
}

.cell-form-inline input[type="text"],
.cell-form-inline input[type="number"] {
  width: auto;
  flex: 1 1 120px;
  min-width: 110px;
  height: 30px;
  padding: 0.3rem 0.55rem;
  font-size: 0.82rem;
}

.cell-form-inline label {
  margin: 0;
}

/* Row of buttons (e.g. danger actions in market detail) */
.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ---------- 10. Metrics grid ---------- */
.metrics-grid,
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.85rem;
  margin: 0 0 1.4rem;
}

.metrics-grid article,
.summary-grid article {
  margin: 0;
  padding: 1.1rem 1.15rem 1rem;
}

.summary-grid article dl,
.summary-grid article ul { margin: 0; padding: 0; }

.actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.8rem;
  margin: 0 0 1rem;
}

.action-form,
.action-group {
  background: var(--ink-1);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  padding: 1rem;
  margin: 0;
  position: relative;
}

.action-group > .action-form + .action-form {
  margin-top: 0.6rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--rule-soft);
}

.action-group-danger {
  border-color: var(--red-line);
  background: var(--red-bg);
}

.action-group-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--paper-2);
  margin: 0 0 0.7rem;
}
.action-group-danger .action-group-label { color: var(--red); }

/* Metric card — big number, small label, colored tick */
.metric-card {
  position: relative;
  overflow: hidden;
  display: grid;
  gap: 0.1rem;
}

.metric-card::before {
  content: "";
  position: absolute;
  left: 0; top: 10%; bottom: 10%;
  width: 2px;
  background: var(--paper-2);
  border-radius: 0 2px 2px 0;
}

.metric-card.metric-open::before,
.metric-open::before { background: var(--sage); box-shadow: 0 0 12px var(--sage-bg); }

.metric-card.metric-closed::before,
.metric-closed::before { background: var(--gold); box-shadow: 0 0 12px var(--gold-bg); }

.metric-card.metric-draft::before,
.metric-draft::before { background: var(--indigo); box-shadow: 0 0 12px var(--indigo-bg); }

.metric-card.metric-neutral::before,
.metric-neutral::before { background: var(--paper-2); }

.metric-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 2.2rem;
  font-weight: 500;
  color: var(--paper-0);
  line-height: 1.02;
  letter-spacing: -0.035em;
  margin: 0.1rem 0 0.35rem;
}

.metric-label {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--paper-2);
  font-weight: 500;
}

.metric-sub {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--paper-1);
  margin-top: 0.35rem;
}

/* ---------- 11. Status badges — rubber-stamp ---------- */
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.22rem 0.65rem;
  border-radius: var(--r-pill);
  border: 1px solid currentColor;
  background: transparent;
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  line-height: 1.3;
  white-space: nowrap;
}

.status-draft,
.status-pending {
  color: var(--indigo);
  background: var(--indigo-bg);
  border-color: var(--indigo-line);
}

.status-open,
.status-approved,
.status-paid {
  color: var(--sage);
  background: var(--sage-bg);
  border-color: var(--sage-line);
}

.status-closed,
.status-on_hold,
.status-on-hold {
  color: var(--gold);
  background: var(--gold-bg);
  border-color: var(--gold-line);
}

.status-resolved {
  color: var(--paper-1);
  background: var(--ink-2);
  border-color: var(--rule-strong);
}

.status-canceled,
.status-cancelled,
.status-rejected {
  color: var(--red);
  background: var(--red-bg);
  border-color: var(--red-line);
}

/* ---------- 12. Flash + attention + breadcrumbs ---------- */
.flash-stack {
  display: grid;
  gap: 0.55rem;
  margin: 0 0 1.2rem;
}

.flash {
  display: block;
  position: relative;
  padding: 0.8rem 1rem 0.8rem 1.15rem;
  margin: 0;
  background: var(--ink-1);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--paper-2);
  border-radius: var(--r-md);
  color: var(--paper-0);
  font-size: 0.9rem;
}

.flash-success {
  border-left-color: var(--sage);
  background: var(--sage-bg);
  border-color: var(--sage-line);
}

.flash-error,
.error-message {
  display: block;
  margin: 0 0 1rem;
  padding: 0.85rem 1rem 0.85rem 1.15rem;
  background: var(--red-bg);
  border: 1px solid var(--red-line);
  border-left: 3px solid var(--red);
  border-radius: var(--r-md);
  color: var(--paper-0);
  font-size: 0.9rem;
}

.error-message ul {
  margin: 0.4rem 0 0;
  padding-left: 1.1rem;
}

@keyframes flash-fade {
  0%   { opacity: 1; max-height: 300px; margin-bottom: 0.6rem; }
  85%  { opacity: 1; }
  100% { opacity: 0; max-height: 0; margin-bottom: 0;
         padding-top: 0; padding-bottom: 0; overflow: hidden; }
}
.flash { animation: flash-fade 0.4s ease 4.8s forwards; }
.flash-error { animation: none; }

.attention-panel { margin: 0 0 1.5rem; }

.attention-panel h3 {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.55rem;
}

.attention-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.1rem;
  margin: 0 0 0.5rem;
  background: linear-gradient(90deg, var(--gold-soft) 0%, transparent 60%);
  border: 1px solid var(--gold-line);
  border-radius: var(--r-md);
  color: var(--paper-0);
  font-size: 0.92rem;
}

.attention-item strong {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.5rem;
  font-weight: 500;
  min-width: 2rem;
  color: var(--gold);
  letter-spacing: -0.02em;
}

.attention-item a {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  color: var(--gold);
}

/* Breadcrumb */
.breadcrumb-nav {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--paper-2);
  margin: 0 0 1rem;
}

.breadcrumb-nav a { color: var(--paper-1); text-decoration: none; }
.breadcrumb-nav a:hover { color: var(--gold); }
.breadcrumb-sep { color: var(--paper-3); }
.breadcrumb-current { color: var(--paper-0); }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 1.1rem 0 0;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--paper-1);
  padding: 0.5rem 0.25rem 0;
  border-top: 1px solid var(--rule-soft);
}

.pagination > :first-child,
.pagination > :last-child { min-width: 84px; }

/* ---------- 13. Pool progress — YES/NO split bar ---------- */
.pool-progress {
  width: 100%;
  height: 6px;
  border-radius: var(--r-pill);
  overflow: hidden;
  display: flex;
  background: var(--ink-3);
  border: 1px solid var(--rule);
}

.pool-progress-yes {
  background: linear-gradient(90deg, var(--sage-deep), var(--sage));
  transition: width 300ms ease;
}

.pool-progress-no {
  background: linear-gradient(90deg, var(--red), var(--red-deep));
}

/* ---------- 14. Dialog ---------- */
dialog {
  color: var(--paper-0);
  background: var(--ink-1);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-dialog);
  padding: 0;
  max-width: 460px;
  width: 92vw;
}

dialog::backdrop {
  background: rgba(5, 5, 8, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.confirm-dialog {
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-lg);
  padding: 0;
}

.confirm-dialog article {
  margin: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 1.4rem 1.4rem 1.1rem;
}

.confirm-dialog h3 { margin-top: 0; }

.confirm-footer {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.2rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--rule);
}

.confirm-footer form { display: inline; margin: 0; }

/* ---------- 15. Login-specific ---------- */
.login-card form {
  display: grid;
  gap: 1rem;
}

.login-card label { margin: 0 0 0.3rem; }
.login-card input { background: var(--ink-2); }
.login-card .btn-block { margin-top: 0.35rem; }

.login-card .muted-text {
  margin-top: 0.9rem;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}

.login-card .error-message { margin-bottom: 0.5rem; }

/* ---------- 16. Utilities ---------- */
.muted-text { color: var(--paper-1); font-size: 0.85rem; }
.accent-text { color: var(--gold); }
.danger-text { color: var(--red); }

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.uppercase-label {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--paper-2);
}

.stack-sm { display: grid; gap: 0.5rem; }
.stack-md { display: grid; gap: 0.85rem; }
.stack-lg { display: grid; gap: 1.25rem; }

/* Definition list — used on detail pages */
dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 0.9rem;
  margin: 0;
}
dt {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--paper-2);
  align-self: center;
}
dd {
  margin: 0;
  color: var(--paper-0);
}

/* ---------- 17. Responsive ---------- */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 54px auto minmax(0, 1fr);
    grid-template-areas:
      "topbar"
      "sidebar"
      "content";
  }

  .topbar { padding: 0 1rem; }
  .topbar-edition { display: none; }
  .brand-mark { font-size: 0.75rem; }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--rule);
    padding: 0.55rem 0.75rem;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }

  .sidebar-section {
    display: none; /* hide section headers on mobile chip-nav */
  }

  .sidebar nav {
    display: flex;
    flex-direction: row;
    gap: 0.4rem;
    width: max-content;
    padding: 0 0.25rem;
  }

  .sidebar nav ul {
    display: flex;
    flex-direction: row;
    gap: 0.3rem;
    margin: 0;
  }

  .sidebar nav a {
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--rule);
    border-radius: var(--r-pill);
    font-size: 0.82rem;
    white-space: nowrap;
  }

  .nav-marker { display: none; }

  .sidebar nav a.active {
    padding-left: 0.8rem;
    background: var(--gold-bg);
    color: var(--gold);
    border-color: var(--gold-line);
  }
  .sidebar nav a.active::before { display: none; }

  .main-content { padding: 1.2rem 1rem 2.5rem; }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.7rem;
  }
}

/* Таблицы на мобилке: оборачиваем в скролл-контейнер вместо расширения страницы.
   display:block на table ломает border-collapse/alignment, но визуально это
   стандартный responsive-pattern, и ширина body больше не «прыгает». */
@media (max-width: 900px) {
  .main-content table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    white-space: nowrap;
  }
  .main-content table thead,
  .main-content table tbody { display: table; width: 100%; min-width: max-content; }
  .main-content table tr { display: table-row; }
  .main-content table th,
  .main-content table td { display: table-cell; }

  /* Длинные заголовки ячеек «Название» могут переноситься */
  .main-content table td:nth-child(2) { white-space: normal; }
}

@media (max-width: 600px) {
  table { font-size: 0.82rem; }
  thead th,
  tbody td { padding: 0.6rem 0.65rem; }

  .metric-value { font-size: 1.85rem; }

  .filters-grid,
  .form-grid {
    grid-template-columns: 1fr;
    padding: 1rem 0.9rem;
  }

  .metrics-grid,
  .summary-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.65rem;
  }

  /* Грид-ячейкам нужно min-width: 0, иначе intrinsic width карточек
     (длинный текст в dl) распирает колонку за viewport. */
  .metrics-grid > *,
  .summary-grid > * { min-width: 0; }

  dl { grid-template-columns: 1fr; }
  dt { margin-top: 0.3rem; }
}

/* На узких экранах гарантируем одну колонку для summary-блоков */
@media (max-width: 480px) {
  .summary-grid { grid-template-columns: 1fr; }
}

/* ---------- 18. Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .status-dot { animation: none; }
}
