/* ==========================
   NormControl Theme v2
   - Unified buttons
   - Accessible contrast
   - Responsive cards and tables
   - Dark theme default + Light theme via [data-theme="light"] or system preference
   ========================== */
:root {
  --bg: #0b1020;
  --elev-1: rgba(255, 255, 255, .05);
  --elev-2: rgba(255, 255, 255, .08);
  --border: rgba(255, 255, 255, .16);
  --text: #e9eef9;
  --text-muted: #b8c5dc;
  --brand: #ffffff;
  --brand-2: #3bd7b3;
  --ok: #51d08a;
  --warn: #ffd166;
  --err: #ff6b6b;
  --radius: 16px;
  --maxw: 1120px;
}

html[data-theme="light"] {
  --bg: #f6f8fc;
  --elev-1: #ffffff;
  --elev-2: #f0f3fa;
  --border: rgba(0, 0, 0, .12);
  --text: #0e1628;
  --text-muted: #3a4a67;
  --brand: #0f2133;
  --brand-2: #0fb49b;
  --ok: #178e57;
  --warn: #c58b00;
  --err: #c84747;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f6f8fc;
    --elev-1: #ffffff;
    --elev-2: #f0f3fa;
    --border: rgba(0, 0, 0, .12);
    --text: #0e1628;
    --text-muted: #3a4a67;
    --brand: #0f2133;
    --brand-2: #0fb49b;
    --ok: #178e57;
    --warn: #c58b00;
    --err: #c84747;
  }
}

html {
  margin: 0;
}

body {
  margin: 0;
  background:
    radial-gradient(2200px 600px at 0% -10%, rgba(118, 166, 255, .18), transparent 40%),
    radial-gradient(900px 500px at 110% 0%, rgba(59, 215, 179, .15), transparent 35%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  line-height: 1.55;
  background-repeat: no-repeat;
}

body> :where(header, h1, h2, p, section, footer, #results, ul, ol, nav) {
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: 20px;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
  background: linear-gradient(to bottom, color-mix(in oklab, var(--bg), #ffffff 12%), color-mix(in oklab, var(--bg), #ffffff 6%));
  border-bottom: 1px solid var(--border);
  padding-block: 8px;
}

header nav {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap
}

header nav a {
  color: color-mix(in oklab, var(--text), var(--bg) 35%);
  text-decoration: none;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 10px
}

header nav a:hover {
  color: var(--text);
  background: var(--elev-2)
}

/* Serious-looking theme toggle */
#themeToggle {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 8px 12px;
  border-radius: 10px;
}

#themeToggle .icon {
  width: 18px;
  height: 18px;
  display: inline-block;
}

#themeToggle .label {
  font-weight: 700
}

#themeToggle:hover {
  filter: brightness(1.06)
}

/* Unify vertical centering/height for links and buttons in the nav */
header nav a,
header nav button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  line-height: 1;
  padding: 8px 10px;
  border-radius: 10px
}

/* Push user info + auth controls to the right for logical order */


header nav #userBox {
  margin-left: auto;
  display: flex;
  flex-direction: column; /* два рядки: ім'я+тариф і під ними ліміти */
  line-height: 1.15;
}

header nav #userBox #userInfo {
  font-weight: 700;             /* Ім'я + (тариф) */
}

header nav #userBox .sub-limits {
  font-size: 0.85em;            /* Другий рядок дрібніший */
  color: var(--text-muted);     /* Спокійний колір */
  margin-top: 2px;
  white-space: nowrap;          /* Щоб не ламався в дивних місцях */
}

header nav .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1em;
  font-weight: 800;
  color: var(--brand);
  text-decoration: none;
  margin-right: 18px;
  padding: 0;
  background: none;
  cursor: pointer;        /* додали */
  pointer-events: auto;   /* додали */
}

header nav .brand-logo {
  height: 32px;
  width: auto;
  max-width: 40px;
  display: block;
}

header nav .brand-title {
  color: var(--brand);
  font-weight: 800;
  font-size: 1.08em;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

header nav .brand:hover,
header nav .brand:focus {
  background: none;
  color: var(--brand);
  text-decoration: none;
  filter: none;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.1;
  margin: 22px auto 12px
}

h2 {
  font-size: clamp(20px, 3vw, 26px);
  margin: 0 0 10px
}

p {
  color: var(--text);
  opacity: .92
}

.muted,
.text-muted {
  color: var(--text-muted)
}

section {
  margin: 20px auto;
  padding: 18px;
  background: linear-gradient(180deg, var(--elev-1), rgba(0, 0, 0, 0));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 40px rgba(0, 0, 0, .22);
}

a {
  color: var(--brand)
}

a:hover {
  text-decoration: underline
}

button,
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg), #ffffff 4%);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  /* Ensure consistent vertical centering on all screens */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  padding: 10px 14px;
  border-radius: 12px;
  transition: .15s transform ease, .15s filter ease, .15s background-color ease;
}

button:hover,
.btn:hover {
  filter: brightness(1.06)
}

button:active,
.btn:active {
  transform: translateY(1px)
}

.btn--primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border-color: transparent;
  color: color-mix(in oklab, #000, var(--bg) 30%)
}

.btn--outline {
  background: transparent
}

.btn--ghost {
  background: transparent;
  border-color: color-mix(in oklab, var(--border), var(--bg) 40%)
}

#loginBtn {
  background: transparent
}

input[type="file"] {
  display: block;
  width: 100%;
  background: color-mix(in oklab, var(--bg), #ffffff 6%);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 12px
}

#upload input[type="file"] {
  box-sizing: border-box;
  max-width: 100%;
}

/* Branded file upload */
.file-upload {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap
}

.file-upload input[type="file"] {
  /* Visually hidden, accessible */
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.file-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 10px 22px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--brand);
  color: var(--bg);
  font-weight: 700;
  text-decoration: none;
  transition: background .15s, filter .15s;
}

.file-upload-btn:hover {
  filter: brightness(1.06)
}

.file-upload-filename {
  color: var(--text-muted);
  font-size: .95em
}

/* Small spinner for file checking */
.file-upload-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid color-mix(in oklab, var(--text), var(--bg) 40%);
  border-top-color: var(--brand-2);
  animation: nc-spin 1s linear infinite;
  display: none;
}

@keyframes nc-spin {
  to {
    transform: rotate(360deg)
  }
}

/* Drag-and-drop area */
.file-drop {
  flex: 1 1 240px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 12px;
  text-align: center;
  border: 2px dashed color-mix(in oklab, var(--text), var(--bg) 55%);
  color: var(--text-muted);
  background: color-mix(in oklab, var(--bg), #ffffff 4%);
}

.file-drop.is-dragover {
  border-color: var(--brand-2);
  color: var(--text);
  background: color-mix(in oklab, var(--bg), #ffffff 8%);
}

progress {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: color-mix(in oklab, var(--bg), #ffffff 6%);
  border: 1px solid var(--border)
}

progress::-webkit-progress-bar {
  background: color-mix(in oklab, var(--bg), #ffffff 6%)
}

progress::-webkit-progress-value {
  background: linear-gradient(90deg, var(--brand), var(--brand-2))
}

progress::-moz-progress-bar {
  background: linear-gradient(90deg, var(--brand), var(--brand-2))
}

#results {
  margin: 16px auto;
  /* Allow horizontal scroll on small screens so all columns stay visible */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#results table {
  width: 100%;
  border-collapse: collapse;
  background: color-mix(in oklab, var(--bg), #ffffff 4%);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden
}

#results thead th {
  position: sticky;
  top: 0;
  background: color-mix(in oklab, var(--bg), #ffffff 10%);
  backdrop-filter: blur(4px);
  text-transform: uppercase;
  letter-spacing: .3px;
  font-size: 12px;
  color: color-mix(in oklab, var(--text), var(--bg) 45%);
}

#results th,
#results td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top
}

#results tr:nth-child(even) td {
  background: color-mix(in oklab, var(--bg), #ffffff 5%)
}

#results td a {
  color: var(--brand)
}

/* Sorting affordances */
#results th.sortable {
  cursor: pointer;
  user-select: none;
}

#results th .sort-ind {
  opacity: .6;
  margin-left: 4px;
  font-size: 10px;
}

#normList {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  list-style: none;
  padding-left: 0;
  margin-top: 10px
}

#normList li {
  border: 1px solid var(--border);
  background: color-mix(in oklab, var(--bg), #ffffff 6%);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 13px
}

#warning {
  background: color-mix(in oklab, #6ba6ff, var(--bg) 82%);
  border: 1px solid color-mix(in oklab, #6b8eff, var(--bg) 55%);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px
}

@media (max-width: 720px) {
  section {
    padding: 14px
  }

  header nav {
    gap: 8px
  }
}

.pricing-hero {
  text-align: center;
  margin: 10px auto 6px
}

.pricing-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, 1fr)
}

@media (max-width: 980px) {
  .pricing-grid {
    grid-template-columns: 1fr
  }
}

.plan {
  background: linear-gradient(180deg, var(--elev-1), rgba(0, 0, 0, 0));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 18px 36px rgba(0, 0, 0, .22);
  position: relative
}

.plan h3 {
  margin: 6px 0 6px;
  font-size: 22px
}

.plan .price {
  font-weight: 800;
  font-size: 28px;
  margin: 8px 0 14px
}

.plan ul {
  list-style: none;
  padding-left: 0;
  margin: 0
}

.plan li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 8px 0;
  color: var(--text)
}

.plan li .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
  margin-top: 7px;
  flex: 0 0 8px
}

.plan .muted {
  color: var(--text-muted)
}

.plan .ribbon {
  position: absolute;
  top: 12px;
  right: -40px;
  transform: rotate(25deg);
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: color-mix(in oklab, #000, var(--bg) 30%);
  padding: 6px 60px;
  font-weight: 800;
  border: 0;
  box-shadow: 0 10px 20px rgba(0, 0, 0, .25)
}

footer {
  margin: 40px auto 16px;
  color: var(--text-muted);
  font-size: 14px
}

/* Footer links and Telegram badge */
.footer-links {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  margin: 8px 0;
}

.tg-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font-weight: 600;
  border: 1px solid #ccc;
  /* тонка сіра рамка */
  border-radius: 999px;
  padding: 8px 12px;
  background: #f9f9f9;
  /* світлий нейтральний фон */
  color: #333;
  /* темний текст */
  transition: all 0.2s ease;
}

.tg-link:hover {
  background: #eaeaea;
  /* легкий hover-ефект */
  border-color: #bbb;
  text-decoration: none;
}

.tg-link .icon {
  width: 16px;
  height: 16px;
  display: inline-block;
}

/* Fix Start button appearance consistency across theme toggles */
#startBtn {
  background: linear-gradient(135deg, var(--brand), var(--brand-2)) !important;
  border: 1px solid transparent;
  color: color-mix(in oklab, #000, var(--bg) 30%);
}

#startBtn:hover {
  filter: brightness(1.06)
}

#startBtn {
  background: var(--brand) !important;
  /* базовий контраст */
  border: 1px solid transparent;
  color: var(--bg);
  /* текст контрастний до фону */
  border-radius: 10px;
  font-weight: 700;
  padding: 10px 22px;
  transition: background 0.15s, filter 0.15s;
}

#startBtn:hover {
  filter: brightness(1.06);
}

/* Обгортка секції тарифів — окрема від гріда */
.pricing-wrap {
  /* стилі section з вашого theme.css вже гарні, просто гарантуємо, що нічого не "підрізає" */
  overflow: visible;
  /* тіні та стрічка не обрізаються */
  padding-bottom: 18px;
  /* невеликий запас під тіні карток */
}

/* Сітка тарифів всередині секції */
.pricing-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, 1fr);
  align-items: stretch;
  /* усі колонки однаково високі */
  grid-auto-rows: 1fr;
  /* рядки однакової висоти за найбільшою карткою */
}

@media (max-width: 980px) {
  .pricing-grid {
    grid-template-columns: 1fr;
  }
}

/* Картка — флекс-колонка: контент зверху, кнопки внизу */
.plan {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  box-sizing: border-box;
}

/* Кнопки донизу */
.plan .actions {
  margin-top: auto;
  padding-top: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Стрічка — може виступати, але секція її більше не "ріже" */
.plan .ribbon {
  position: absolute;
  top: 12px;
  right: -40px;
  transform: rotate(25deg);
  background: var(--brand) !important;
  color: var(--bg) !important;
  padding: 6px 60px;
  font-weight: 800;
  border: 0;
  box-shadow: 0 10px 20px rgba(0, 0, 0, .12);
}

/* === Mobile tweaks (до ~640px) === */
@media (max-width: 640px){
  /* 1) Хедер компактніше */
  header nav{ gap:8px; }
  header nav .brand-title{ display:none; } /* ховаємо текст біля лого */

  /* 2) Завантаження файлу – колонкою, кнопка на всю ширину */
  .file-upload{ flex-direction: column; align-items: stretch; }
  .file-upload-btn{ width:100%; justify-content:center; height:48px; }
  .file-upload-filename{ order:3; }
  .file-drop{ display:none; } /* drag&drop не потрібен на мобільному */

  /* 3) Таблиця результатів – горизонтальний скролл замість «зламу» */
  #results table{
    display:block;
    overflow-x:auto;
    -webkit-overflow-scrolling: touch;
    min-width:720px;
  }

  /* 4) Кнопки/прогрес – комфортніші тап-зони */
  #startBtn{ width:100%; }
  progress{ height:18px; }
}
/* Мінімальна висота для натискних елементів */
button, .btn, .file-upload-btn{ min-height:44px; }

@media (max-width: 640px){
  .nav-links{ display:none; width:100%; }
  .nav-links.is-open{ display:flex; flex-direction:column; gap:6px; }
  #navToggle{ margin-left:auto; }
}

/* --- Mobile nav layout --- */
@media (max-width: 640px){
  header nav{
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand ctrls"
      "user  user"
      "links links";
    align-items: center;
    gap: 8px;
  }
  header nav .brand{ grid-area: brand; }
  header nav .nav-ctrls{ grid-area: ctrls; display: inline-flex; gap: 8px; }

  header nav .nav-links{
    grid-area: links;
    display: none;
    width: 100%;
    padding-top: 4px;
    border-top: 1px dashed var(--border);
  }
  header nav .nav-links.is-open{
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  /* другий рядок під ім'ям — не обмежуємо в один рядок */
  header nav #userBox .sub-limits{
    white-space: normal;
    line-height: 1.3;
  }
  /* показуємо кнопку Меню лише на мобільних */
  #navToggle{ display: inline-flex; }
}

/* На десктопі: «Меню» ховаємо, лінки показуємо в ряд */
@media (min-width: 641px){
  #navToggle{ display: none; }
  .nav-links{ display: inline-flex !important; gap: 12px; }
}

/* --- Header layout fixes (desktop) --- */
header nav { justify-content: flex-start; }
header nav .nav-ctrls { margin-left: 8px; }
header nav #userBox { margin-left: auto; }

/* Лого стабільно вирівняне */
header nav .brand-logo { height: 32px; width: auto; display: block; }
header nav .brand-title { line-height: 1; }

/* Компактніший блок підписки */
#userBox { line-height: 1.2; }
#userBox #userInfo { font-weight: 700; }
#userBox .sub-limits { font-size: 0.82em; color: var(--text-muted); white-space: nowrap; }

/* Кнопка "Обрати PDF" не вилазить */
.file-upload { min-width: 0; flex-wrap: wrap; }
.file-upload-btn { max-width: 100%; box-sizing: border-box; }

/* На мобільних — ще компактніше */
@media (max-width: 640px){
  header nav .brand-title{ display:none; }
  #userBox .sub-limits{ font-size: 0.78em; white-space: normal; }
  .file-upload-btn{ width:100%; }
  .file-drop{ display:none; }
}

/* Табличні заголовки: прибрати uppercase (ламає назви) */
#results thead th { text-transform: none; letter-spacing: .2px; }

/* --- 1) Вирівнюємо кнопки в шапці на великих екранах --- */
header nav { align-items: center; }               /* вертикальне вирівнювання */
.nav-ctrls { display:flex; gap:8px; align-items:center; }
.nav-ctrls button, #navToggle { height: 32px; line-height: 32px; }

/* --- 2) Колонка КОД має бути завжди видима --- */
/* Якщо десь ховаються колонки через nth-child — примусово показуємо першу */
#results table th:first-child,
#results table td:first-child {
  display: table-cell !important;
  white-space: nowrap;
}

/* Якщо ви даєте колонці атрибут data-col="code" — зафіксуємо й його */
#results table th[data-col="code"],
#results table td[data-col="code"] {
  display: table-cell !important;
  white-space: nowrap;
  width: 1%;
}

/* --- 3) Дворядкова шапка на вузьких екранах --- */
@media (max-width: 640px){
  /* робимо навбар сіткою з двох рядків */
  header nav{
    display: grid;
    grid-template-columns: auto auto 1fr auto;   /* лого | Меню | (розпірка) | кнопки */
    grid-template-areas:
      "brand toggle . ctrls"
      "sub   sub    sub sub";
    row-gap: 6px;
  }

  /* емблема/бренд завжди ліворуч */
  header nav .brand{ grid-area: brand; display:flex; align-items:center; }
  header nav .brand-logo{ height: 28px; width:auto; display:block; margin-right:8px; }
  header nav .brand-title{ font-size: 16px; }

  /* кнопка "Меню" відразу праворуч від бренду */
  #navToggle{ grid-area: toggle; align-self:center; }

  /* праворуч — «Увійти» та «Тема» в один рядок */
  .nav-ctrls{ grid-area: ctrls; justify-self:end; }

  /* рядок підписки/лімітів — другим рядком на всю ширину */
  #userBox{ grid-area: sub; justify-self: stretch; line-height:1.2; }

  /* щоб усе вміщалося в два рядки, прибираємо зайве */
  .nav-links{ display:none; }             /* список розділів відкривається через Меню */
}

/* --- Мобільне меню (всередині екрану) --- */
@media (max-width: 640px){
  .nav-links {
    position: absolute;
    top: 100%;              /* відразу під хедером */
    left: 0;
    right: 0;
    width: 100%;
    background: var(--bg);  /* фон теми */
    border-top: 1px solid var(--border-color, #ccc);
    display: none;
    flex-direction: column;
    gap: 8px;
    padding: 8px 12px;
    box-sizing: border-box;
    z-index: 1000;
    max-height: 80vh;       /* щоб не перекривало весь екран */
    overflow-y: auto;
  }

  .nav-links.is-open {
    display: flex;
  }

  .nav-links a {
    width: 100%;
    text-align: left;
  }
}

#navToggle {
  height: 32px;
  line-height: 32px;
  align-self: center;
}
