/* =========================================================
   ЄТСНВ — Електронний довідник вантажів (ВіртЛаб)
   Дизайн: світла, "повітряна" цифрова освітня платформа.
   ========================================================= */

:root{
  --bg: #f6f8fb;
  --bg-panel: #ffffff;
  --bg-soft: #eef2f8;
  --border: #e2e8f0;
  --border-soft: #edf1f6;
  --text: #1a2233;
  --text-muted: #5b6472;
  --text-faint: #8b93a1;

  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #e8f0fe;
  --teal: #0d9488;
  --teal-soft: #e3f7f4;
  --amber: #b45309;
  --amber-soft: #fef3e0;
  --red: #dc2626;
  --red-soft: #fdecec;
  --green: #16a34a;
  --green-soft: #e9f9ee;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(20, 30, 60, .05);
  --shadow: 0 4px 16px rgba(20, 30, 60, .08);
  --shadow-lg: 0 14px 40px rgba(20, 30, 60, .14);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
h1,h2,h3,h4{ margin:0 0 .4em; font-weight:700; letter-spacing:-.01em; }
p{ margin:0 0 .6em; }
button{ font-family:inherit; }
a{ color: var(--accent); }
.hidden{ display:none !important; }
.visually-hidden{ position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); }

/* ---------- Layout shell ---------- */
.app-shell{ min-height:100%; display:flex; flex-direction:column; }

.topbar{
  position:sticky; top:0; z-index:40;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner{
  max-width:1180px; margin:0 auto; padding:12px 20px;
  display:flex; align-items:center; gap:14px; flex-wrap:wrap;
}
.brand{ display:flex; align-items:center; gap:10px; font-weight:700; cursor:pointer; }
.brand-mark{
  width:34px; height:34px; border-radius:10px;
  background: linear-gradient(135deg, var(--accent), var(--teal));
  color:#fff; display:flex; align-items:center; justify-content:center;
  font-size:15px; font-weight:800;
}
.brand-text-a{ color: var(--text-muted); font-weight:600; }
.crumb-sep{ color: var(--text-faint); }
.brand-text-b{ color: var(--text); }

.topbar-spacer{ flex:1; }
.edition-badge{
  font-size:12.5px; color: var(--text-muted); background: var(--bg-soft);
  border:1px solid var(--border); padding:5px 10px; border-radius:999px;
  white-space:nowrap;
}
.topbar-nav{ display:flex; gap:4px; flex-wrap:wrap; }
.topbar-nav button{
  border:none; background:transparent; padding:8px 12px; border-radius:999px;
  font-size:14px; color: var(--text-muted); cursor:pointer; font-weight:600;
}
.topbar-nav button:hover{ background: var(--bg-soft); color: var(--text); }
.topbar-nav button.active{ background: var(--accent-soft); color: var(--accent-dark); }

/* ---------- Main / views ---------- */
main{ flex:1; }
.view{ max-width:1180px; margin:0 auto; padding:28px 20px 64px; }

.breadcrumb{
  display:flex; align-items:center; gap:6px; flex-wrap:wrap;
  font-size:13.5px; color: var(--text-muted); margin-bottom:18px;
}
.breadcrumb button{
  border:none; background:none; color: var(--accent); cursor:pointer; padding:2px 0; font-size:13.5px;
}
.breadcrumb span.sep{ color: var(--text-faint); }
.breadcrumb span.current{ color: var(--text); font-weight:600; }

/* ---------- Hero / home ---------- */
.hero{ text-align:center; padding: 34px 10px 8px; }
.hero-eyebrow{
  display:inline-block; font-size:12.5px; letter-spacing:.06em; font-weight:700;
  color: var(--accent-dark); background: var(--accent-soft); padding:5px 12px; border-radius:999px;
  margin-bottom:14px; text-transform:uppercase;
}
.hero h1{ font-size:clamp(28px,4vw,40px); margin-bottom:6px; }
.hero p.sub{ color: var(--text-muted); font-size:16.5px; max-width:640px; margin:0 auto 26px; }

.search-hero{ max-width:640px; margin:0 auto 10px; }
.search-box{
  display:flex; align-items:center; gap:10px;
  background:#fff; border:1.5px solid var(--border); border-radius:16px;
  padding:6px 8px 6px 18px; box-shadow: var(--shadow);
}
.search-box:focus-within{ border-color: var(--accent); box-shadow:0 0 0 4px var(--accent-soft); }
.search-box .icon{ font-size:18px; color: var(--text-faint); }
.search-box input{
  flex:1; border:none; outline:none; font-size:16px; padding:12px 4px; background:transparent; color:var(--text);
}
.search-box .clear-btn{
  border:none; background:var(--bg-soft); color:var(--text-muted); width:28px; height:28px; border-radius:50%;
  cursor:pointer; font-size:15px; line-height:1; display:none;
}
.search-box .clear-btn.show{ display:inline-flex; align-items:center; justify-content:center; }
.btn-primary{
  border:none; background: var(--accent); color:#fff; padding:12px 22px; border-radius:12px;
  font-weight:700; font-size:15px; cursor:pointer; white-space:nowrap;
}
.btn-primary:hover{ background: var(--accent-dark); }
.search-hint{ font-size:13px; color: var(--text-faint); margin-top:10px; }

/* mode cards */
.mode-grid{
  display:grid; grid-template-columns:repeat(4,1fr); gap:16px; margin:36px 0 30px;
}
@media (max-width:900px){ .mode-grid{ grid-template-columns:repeat(2,1fr); } }
@media (max-width:520px){ .mode-grid{ grid-template-columns:1fr; } }
.mode-card{
  background:#fff; border:1px solid var(--border); border-radius: var(--radius);
  padding:20px 18px; cursor:pointer; text-align:left; transition:.15s ease;
  box-shadow: var(--shadow-sm);
}
.mode-card:hover{ transform:translateY(-2px); box-shadow: var(--shadow); border-color:#c9d6ee; }
.mode-card .emoji{ font-size:26px; display:block; margin-bottom:10px; }
.mode-card h3{ font-size:16px; margin-bottom:4px; }
.mode-card p{ font-size:13.5px; color: var(--text-muted); margin:0; }

.stats-row{
  display:grid; grid-template-columns:repeat(3,1fr); gap:14px; margin-top:8px;
}
@media (max-width:700px){ .stats-row{ grid-template-columns:1fr; } }
.stat-card{
  background: var(--bg-panel); border:1px solid var(--border-soft); border-radius: var(--radius);
  padding:18px 20px; text-align:center;
}
.stat-num{ font-size:26px; font-weight:800; color: var(--accent-dark); font-family: var(--font-mono); }
.stat-label{ font-size:13px; color: var(--text-muted); margin-top:2px; }

/* ---------- Panels / sections ---------- */
.panel{
  background: var(--bg-panel); border:1px solid var(--border); border-radius: var(--radius-lg);
  padding:22px; box-shadow: var(--shadow-sm);
}
.section-head{ display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:16px; flex-wrap:wrap; }
.section-head h2{ font-size:20px; }
.section-sub{ color: var(--text-muted); font-size:13.5px; }

/* ---------- Result list / cards ---------- */
.result-list{ display:flex; flex-direction:column; gap:8px; }
.result-item{
  display:flex; align-items:center; justify-content:space-between; gap:14px;
  background:#fff; border:1px solid var(--border-soft); border-radius:12px;
  padding:13px 16px; cursor:pointer; transition:.12s;
}
.result-item:hover{ border-color:#c9d6ee; background: var(--accent-soft); }
.result-name{ font-weight:600; font-size:14.5px; }
.result-name mark{ background:#fde68a; color:inherit; border-radius:3px; padding:0 1px; }
.result-sub{ font-size:12.5px; color: var(--text-muted); margin-top:2px; }
.result-code{
  font-family: var(--font-mono); font-size:14px; background: var(--bg-soft);
  padding:5px 10px; border-radius:8px; color: var(--text); white-space:nowrap;
}
.result-kind-tag{
  font-size:11px; padding:2px 7px; border-radius:999px; font-weight:700; margin-left:8px;
}
.tag-cargo{ background: var(--teal-soft); color: var(--teal); }
.tag-position{ background: var(--amber-soft); color: var(--amber); }

.empty-state{ text-align:center; padding:48px 12px; color: var(--text-muted); }
.empty-state .emoji{ font-size:34px; display:block; margin-bottom:10px; }
.empty-state h3{ color: var(--text); }

.loading-inline{ display:flex; align-items:center; gap:10px; color: var(--text-muted); padding:24px; justify-content:center; }
.spinner{
  width:18px; height:18px; border-radius:50%; border:2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin{ to{ transform: rotate(360deg); } }

/* ---------- Alphabetic panel ---------- */
.alpha-letters{ display:flex; flex-wrap:wrap; gap:6px; margin-bottom:18px; }
.alpha-letters button{
  min-width:34px; height:34px; padding:0 6px; border-radius:9px; border:1px solid var(--border);
  background:#fff; color: var(--text); cursor:pointer; font-weight:700; font-size:14px;
}
.alpha-letters button:hover{ border-color: var(--accent); }
.alpha-letters button.active{ background: var(--accent); border-color: var(--accent); color:#fff; }
.alpha-letters button:disabled{ opacity:.35; cursor:not-allowed; }

.toolbar{ display:flex; gap:10px; align-items:center; flex-wrap:wrap; margin-bottom:16px; }
.toolbar input[type="search"]{
  flex:1; min-width:180px; padding:10px 12px; border-radius:10px; border:1px solid var(--border); font-size:14px;
}
.toolbar select{ padding:9px 10px; border-radius:10px; border:1px solid var(--border); font-size:13.5px; background:#fff; }
.count-pill{ font-size:12.5px; color: var(--text-muted); background: var(--bg-soft); padding:5px 10px; border-radius:999px; }

/* ---------- Analytical table ---------- */
.table-wrap{
  overflow:auto; border:1px solid var(--border-soft); border-radius:12px; max-height:64vh;
}
table.data-table{ width:100%; border-collapse:collapse; font-size:13.5px; min-width:760px; }
table.data-table thead th{
  position:sticky; top:0; background: var(--bg-soft); text-align:left; padding:10px 12px;
  font-size:12px; text-transform:uppercase; letter-spacing:.04em; color: var(--text-muted);
  border-bottom:1px solid var(--border); cursor:pointer; user-select:none; white-space:nowrap;
}
table.data-table thead th .sort-arrow{ opacity:.4; margin-left:4px; font-size:11px; }
table.data-table thead th.sorted .sort-arrow{ opacity:1; color:var(--accent); }
table.data-table tbody td{ padding:9px 12px; border-bottom:1px solid var(--border-soft); vertical-align:top; }
table.data-table tbody tr{ cursor:pointer; }
table.data-table tbody tr:hover{ background: var(--accent-soft); }
table.data-table td.code-cell{ font-family: var(--font-mono); white-space:nowrap; }

.pagination{ display:flex; align-items:center; justify-content:center; gap:8px; margin-top:16px; flex-wrap:wrap; }
.pagination button{
  border:1px solid var(--border); background:#fff; border-radius:9px; padding:7px 12px; cursor:pointer; font-size:13.5px;
}
.pagination button:disabled{ opacity:.4; cursor:not-allowed; }
.pagination button.active{ background: var(--accent); color:#fff; border-color: var(--accent); }
.pagination .page-info{ font-size:13px; color: var(--text-muted); margin:0 6px; }

/* ---------- Filters ---------- */
.filter-chips{ display:flex; gap:8px; flex-wrap:wrap; }
.chip{
  border:1px solid var(--border); background:#fff; padding:6px 12px; border-radius:999px; font-size:13px; cursor:pointer;
}
.chip.active{ background: var(--accent); color:#fff; border-color: var(--accent); }

/* ---------- Cargo card ---------- */
.card-overlay{
  position:fixed; inset:0; background:rgba(15,23,42,.45); z-index:80;
  display:flex; align-items:flex-start; justify-content:center; padding:40px 16px; overflow:auto;
}
.cargo-card{
  background:#fff; border-radius:var(--radius-lg); max-width:720px; width:100%;
  box-shadow: var(--shadow-lg); padding:28px; position:relative; animation: pop .15s ease;
}
@keyframes pop{ from{ transform:scale(.97); opacity:0; } to{ transform:scale(1); opacity:1; } }
.cargo-card .close-x{
  position:absolute; top:16px; right:16px; border:none; background: var(--bg-soft); width:32px; height:32px;
  border-radius:50%; cursor:pointer; font-size:16px; color: var(--text-muted);
}
.cargo-card h2{ font-size:22px; padding-right:36px; }
.cargo-card .code-line{
  display:inline-flex; align-items:center; gap:8px; font-family: var(--font-mono); font-size:17px;
  background: var(--bg-soft); padding:6px 14px; border-radius:10px; margin-bottom:6px;
}
.card-section{ margin-top:20px; }
.card-section h4{
  font-size:12px; text-transform:uppercase; letter-spacing:.05em; color: var(--text-faint); margin-bottom:8px;
}
.field-row{ display:flex; gap:10px; padding:7px 0; border-bottom:1px solid var(--border-soft); font-size:14px; }
.field-row:last-child{ border-bottom:none; }
.field-row .fname{ width:220px; flex-shrink:0; color: var(--text-muted); }
.field-row .fval{ flex:1; }
.related-list{ display:flex; flex-direction:column; gap:6px; }
.related-list .rl-item{
  background: var(--bg-soft); border-radius:9px; padding:8px 12px; cursor:pointer; font-size:13.5px; display:flex; justify-content:space-between; gap:8px;
}
.related-list .rl-item:hover{ background: var(--accent-soft); }
.gnv-list{ display:flex; flex-direction:column; gap:6px; }
.gnv-item{ font-size:13.5px; background: var(--teal-soft); border-radius:9px; padding:8px 12px; display:flex; gap:10px; }
.gnv-item .gnv-code{ font-family: var(--font-mono); color: var(--teal); font-weight:700; white-space:nowrap; }
.card-actions{ display:flex; gap:10px; margin-top:24px; flex-wrap:wrap; }
.btn-secondary{
  border:1px solid var(--border); background:#fff; color: var(--text); padding:10px 16px; border-radius:10px;
  font-size:14px; cursor:pointer; font-weight:600;
}
.btn-secondary:hover{ background: var(--bg-soft); }
.btn-ghost-teal{ border:1px solid var(--teal); color: var(--teal); background:#fff; }
.btn-ghost-teal:hover{ background: var(--teal-soft); }

/* ---------- Training ---------- */
.training-setup{ max-width:560px; margin:0 auto; text-align:center; }
.opt-group{ margin:20px 0; }
.opt-group .opt-label{ font-size:13px; color: var(--text-muted); margin-bottom:8px; text-transform:uppercase; letter-spacing:.04em; }
.opt-buttons{ display:flex; gap:8px; justify-content:center; flex-wrap:wrap; }
.opt-buttons button{
  border:1.5px solid var(--border); background:#fff; padding:9px 18px; border-radius:10px; cursor:pointer; font-weight:600; font-size:14px;
}
.opt-buttons button.active{ background: var(--accent); border-color: var(--accent); color:#fff; }

.quiz-progress{ display:flex; align-items:center; gap:10px; margin-bottom:22px; }
.quiz-progress .bar{ flex:1; height:8px; background: var(--bg-soft); border-radius:999px; overflow:hidden; }
.quiz-progress .bar-fill{ height:100%; background: var(--accent); border-radius:999px; transition:width .2s; }
.quiz-progress .qcount{ font-size:13px; color: var(--text-muted); white-space:nowrap; }

.quiz-card{ max-width:560px; margin:0 auto; text-align:center; }
.quiz-card .qlabel{ font-size:12.5px; color: var(--text-faint); text-transform:uppercase; letter-spacing:.05em; margin-bottom:10px; }
.quiz-card .qtext{ font-size:23px; font-weight:700; margin-bottom:24px; line-height:1.35; }
.quiz-card input[type="text"]{
  width:100%; padding:14px 16px; font-size:18px; border-radius:12px; border:1.5px solid var(--border); text-align:center;
  font-family: var(--font-mono); letter-spacing:.03em;
}
.quiz-card input[type="text"]:focus{ outline:none; border-color: var(--accent); box-shadow:0 0 0 4px var(--accent-soft); }
.quiz-feedback{ margin-top:18px; padding:14px; border-radius:12px; font-size:15px; text-align:left; }
.quiz-feedback.ok{ background: var(--green-soft); color:#166534; }
.quiz-feedback.bad{ background: var(--red-soft); color:#991b1b; }
.quiz-feedback b{ font-family: var(--font-mono); }

.quiz-result{ max-width:520px; margin:0 auto; text-align:center; }
.result-score{ font-size:52px; font-weight:800; color: var(--accent-dark); font-family: var(--font-mono); }
.result-grade{ font-size:16px; color: var(--text-muted); margin-bottom:20px; }
.result-metrics{ display:grid; grid-template-columns:repeat(2,1fr); gap:12px; margin:22px 0; }
.result-metrics .m{ background: var(--bg-soft); border-radius:12px; padding:14px; }
.result-metrics .m .v{ font-size:20px; font-weight:800; }
.result-metrics .m .l{ font-size:12px; color: var(--text-muted); }

.stats-box{ display:flex; gap:14px; flex-wrap:wrap; justify-content:center; margin-top:26px; font-size:13px; color: var(--text-muted); }
.stats-box b{ color: var(--text); }

/* ---------- Toast ---------- */
.toast{
  position:fixed; bottom:28px; left:50%; transform:translateX(-50%) translateY(20px);
  background: var(--text); color:#fff; padding:11px 20px; border-radius:12px; font-size:14px;
  box-shadow: var(--shadow-lg); opacity:0; transition:.2s; z-index:120; pointer-events:none;
}
.toast.show{ opacity:1; transform:translateX(-50%) translateY(0); }

/* ---------- AI Consultant ---------- */
.consultant-fab{
  position:fixed; bottom:22px; right:22px; z-index:70;
  background: linear-gradient(135deg, var(--accent), var(--teal)); color:#fff; border:none;
  border-radius:999px; padding:13px 20px 13px 16px; display:flex; align-items:center; gap:8px;
  box-shadow: var(--shadow-lg); cursor:pointer; font-weight:700; font-size:14px;
}
.consultant-panel{
  position:fixed; bottom:22px; right:22px; z-index:90; width:380px; max-width:calc(100vw - 24px);
  height:min(560px, calc(100vh - 44px)); background:#fff; border-radius:18px; box-shadow: var(--shadow-lg);
  display:flex; flex-direction:column; overflow:hidden; border:1px solid var(--border);
}
.consultant-head{
  background: linear-gradient(135deg, var(--accent), var(--teal)); color:#fff; padding:14px 16px;
  display:flex; align-items:center; justify-content:space-between;
}
.consultant-head h4{ margin:0; font-size:14.5px; }
.consultant-head p{ margin:2px 0 0; font-size:11.5px; opacity:.85; }
.consultant-head button{ border:none; background:rgba(255,255,255,.2); color:#fff; width:26px; height:26px; border-radius:50%; cursor:pointer; }
.consultant-body{ flex:1; overflow:auto; padding:14px; display:flex; flex-direction:column; gap:10px; background: var(--bg); }
.msg{ max-width:88%; padding:10px 13px; border-radius:13px; font-size:13.5px; line-height:1.45; }
.msg.bot{ background:#fff; border:1px solid var(--border-soft); align-self:flex-start; border-bottom-left-radius:3px; }
.msg.user{ background: var(--accent); color:#fff; align-self:flex-end; border-bottom-right-radius:3px; }
.msg .msg-code{
  display:inline-block; margin-top:6px; font-family: var(--font-mono); background: var(--bg-soft); padding:3px 8px; border-radius:6px; font-size:12.5px; cursor:pointer;
}
.msg-suggestions{ display:flex; flex-wrap:wrap; gap:6px; margin-top:8px; }
.msg-suggestions button{
  border:1px solid var(--border); background: var(--bg-soft); border-radius:999px; padding:5px 10px; font-size:12px; cursor:pointer;
}
.consultant-quick{ display:flex; gap:6px; padding:0 14px 10px; flex-wrap:wrap; }
.consultant-quick button{
  border:1px solid var(--border); background:#fff; border-radius:999px; padding:5px 10px; font-size:11.5px; cursor:pointer; color: var(--text-muted);
}
.consultant-input{ display:flex; gap:8px; padding:12px; border-top:1px solid var(--border-soft); }
.consultant-input input{ flex:1; padding:10px 12px; border-radius:10px; border:1px solid var(--border); font-size:13.5px; }
.consultant-input button{
  border:none; background: var(--accent); color:#fff; width:38px; border-radius:10px; cursor:pointer; font-size:15px;
}

/* ---------- Footer ---------- */
footer{ text-align:center; padding:22px; color: var(--text-faint); font-size:12.5px; }

/* ---------- Responsive ---------- */
@media (max-width:640px){
  .field-row{ flex-direction:column; gap:2px; }
  .field-row .fname{ width:auto; font-size:12.5px; }
  .consultant-panel{ width:calc(100vw - 20px); right:10px; bottom:10px; }
  .consultant-fab{ right:14px; bottom:14px; }
}
