:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --ink: #102631;
  --muted: #687c86;
  --line: #dce5e9;
  --navy: #0b2635;
  --navy-2: #123848;
  --teal: #0f766e;
  --teal-2: #0d9488;
  --teal-soft: #e4f4f1;
  --amber: #b45309;
  --amber-soft: #fff3d8;
  --red: #b42318;
  --red-soft: #fff0ee;
  --blue-soft: #eaf3fb;
  --shadow: 0 10px 28px rgba(25, 51, 63, .07);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--bg); font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; font-size: 16px; line-height: 1.45; }
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
button, a.button { -webkit-tap-highlight-color: transparent; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 256px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; z-index: 30; display: flex; flex-direction: column; padding: 24px 16px; color: #d7e5eb; background: var(--navy); }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; }
.brand-mark { display: inline-grid; place-items: center; width: 42px; height: 42px; border: 1px solid rgba(255,255,255,.18); border-radius: 12px; color: #c9fff7; background: rgba(45, 212, 191, .13); font-weight: 800; letter-spacing: -.03em; }
.brand strong, .brand small { display: block; line-height: 1.05; }
.brand strong { font-size: 17px; }
.brand small { margin-top: 4px; color: #91a8b3; font-size: 13px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; }
.nav { display: grid; gap: 5px; margin-top: 34px; }
.nav a { display: flex; min-height: 44px; align-items: center; padding: 10px 13px; border-radius: 10px; color: #bdd0d8; font-size: 15px; font-weight: 600; }
.nav a:hover { color: #fff; background: rgba(255,255,255,.06); text-decoration: none; }
.nav a.active { color: #fff; background: var(--navy-2); box-shadow: inset 3px 0 0 #2dd4bf; }
.sidebar-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: auto; padding: 16px 6px 0; border-top: 1px solid rgba(255,255,255,.1); }
.user-chip { display: flex; align-items: center; gap: 9px; min-width: 0; color: #fff; font-size: 14px; }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 auto; border-radius: 50%; color: var(--navy); background: #5eead4; font-weight: 800; }
.link-button { padding: 8px; border: 0; color: #a9c1ca; background: transparent; cursor: pointer; }
.link-button:hover { color: #fff; }

.main { min-width: 0; }
.topbar { min-height: 104px; display: flex; align-items: center; gap: 14px; padding: 24px clamp(20px, 4vw, 48px); border-bottom: 1px solid var(--line); background: rgba(255,255,255,.82); backdrop-filter: blur(10px); }
.topbar h1 { margin: 0; font-size: clamp(24px, 2.6vw, 34px); line-height: 1.15; letter-spacing: -.025em; }
.topbar p { margin: 6px 0 0; color: var(--muted); }
.menu-button { display: none; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: var(--surface); font-size: 23px; cursor: pointer; }
.content { width: min(1500px, 100%); padding: 28px clamp(20px, 4vw, 48px) 64px; }

.alert { margin-bottom: 18px; padding: 13px 16px; border: 1px solid #9bd6cd; border-radius: 12px; color: #0c5d57; background: var(--teal-soft); font-weight: 600; }
.alert.error { border-color: #ffc6bf; color: var(--red); background: var(--red-soft); }
.notice { margin-bottom: 18px; padding: 14px 16px; border: 1px solid #efd29c; border-radius: 12px; color: #70410d; background: var(--amber-soft); }
.status-line { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 20px; padding: 14px 18px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); box-shadow: var(--shadow); }
.status-line > div { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.status-line span:last-child { color: var(--muted); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--amber); }
.status-dot.ok { background: #16a34a; }

.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { min-height: 150px; display: flex; flex-direction: column; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); background: var(--surface); box-shadow: var(--shadow); transition: transform .15s ease, border-color .15s ease; }
.stat-card:hover { transform: translateY(-2px); border-color: #9fc8c2; text-decoration: none; }
.stat-card > span { color: var(--muted); font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.stat-card strong { margin: 9px 0 auto; font-size: 40px; line-height: 1; letter-spacing: -.04em; }
.stat-card small { color: var(--muted); font-size: 14px; }
.stat-card.accent { color: #fff; border-color: var(--teal); background: linear-gradient(140deg, #0f766e, #075d5b); }
.stat-card.accent > span, .stat-card.accent small { color: #c9f5ef; }
.stat-card.attention { border-color: #ecd29f; background: #fffaf0; }

.panel { margin-bottom: 22px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.panel h2 { margin: 0; font-size: 20px; letter-spacing: -.015em; }
.panel-head p, .panel > div > p { margin: 5px 0 0; color: var(--muted); }
.upload-panel { display: grid; grid-template-columns: minmax(220px, .7fr) minmax(360px, 1.3fr); gap: 28px; padding: 24px; overflow: visible; }
.upload-panel h2 { margin: 4px 0 6px; }
.upload-panel p { margin: 0; color: var(--muted); }
.eyebrow { color: var(--teal); font-size: 12px; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
.upload-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
.upload-form .button { min-height: 46px; }

.button { min-height: 42px; display: inline-flex; justify-content: center; align-items: center; gap: 7px; padding: 9px 15px; border: 1px solid #bdcbd1; border-radius: 10px; color: var(--ink); background: var(--surface); cursor: pointer; font-weight: 700; line-height: 1.2; }
.button:hover { border-color: #7d999f; background: #f8fbfc; text-decoration: none; }
.button.primary { border-color: var(--teal); color: #fff; background: var(--teal); }
.button.primary:hover { background: #0b665f; }
.button.full { width: 100%; }
.button:disabled { opacity: .55; cursor: not-allowed; }
.action-bar { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-bottom: 18px; }

label { display: grid; gap: 6px; color: #334c57; font-size: 14px; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 43px; padding: 9px 11px; border: 1px solid #bdcbd1; border-radius: 9px; color: var(--ink); background: #fff; font-size: 16px; outline: none; }
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--teal-2); box-shadow: 0 0 0 3px rgba(13, 148, 136, .13); }
input[type="checkbox"] { width: 20px; min-height: 20px; accent-color: var(--teal); }
.number-input { min-width: 120px; }
.stack-form { display: grid; gap: 15px; }
.compact-form { margin-bottom: 12px; }
.form-actions { display: flex; justify-content: flex-end; padding: 16px 22px; border-top: 1px solid var(--line); }
.inline-actions { display: flex; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.full-row { grid-column: 1 / -1; }
.check-row { grid-template-columns: 22px 1fr; align-items: center; }

.table-wrap { width: 100%; overflow-x: auto; }
.wide-table table { min-width: 1450px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 16px; border-bottom: 1px solid #e7edef; text-align: left; vertical-align: top; }
th { color: #526a74; background: #f7fafb; font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .035em; white-space: nowrap; }
td { font-size: 14px; }
tbody tr:hover { background: #fbfdfd; }
tbody tr:last-child td { border-bottom: 0; }
td small, td span { display: block; margin-top: 4px; color: var(--muted); }
.item-name { min-width: 260px; max-width: 430px; }
.item-name strong { display: block; color: var(--ink); }
.row-link { color: var(--ink); font-weight: 800; }
.score { display: inline-flex; width: 48px; height: 30px; align-items: center; justify-content: center; margin: 0; border-radius: 9px; color: var(--red); background: var(--red-soft); font-weight: 800; }
.score.medium { color: var(--amber); background: var(--amber-soft); }
.score.good { color: #087a44; background: #e4f7ed; }
.badge { display: inline-flex; width: max-content; margin: 0; padding: 4px 8px; border: 1px solid #cbd6da; border-radius: 999px; color: #4c626b; background: #f5f8f9; font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge.matched, .badge.parsed, .badge.sent { color: #087a44; border-color: #9cdbb8; background: #e7f7ee; }
.badge.needs_review, .badge.draft, .badge.received { color: var(--amber); border-color: #e7ca91; background: var(--amber-soft); }
.badge.error, .badge.not_found { color: var(--red); border-color: #ffc0b9; background: var(--red-soft); }
.count-pill { display: grid; place-items: center; min-width: 34px; height: 34px; padding: 0 9px; border-radius: 999px; color: var(--teal); background: var(--teal-soft); font-weight: 800; }

.empty-inline, .empty-state { padding: 44px 24px; text-align: center; }
.empty-inline h3, .empty-state h2 { margin: 0 0 7px; }
.empty-inline p, .empty-state p { max-width: 640px; margin: 0 auto 18px; color: var(--muted); }
.draft-list { display: grid; gap: 16px; padding: 20px; }
.draft { padding: 18px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface-2); }
.draft-head { display: flex; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.draft-head > div { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.error-text { color: var(--red); }

.search-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.search-bar input { max-width: 680px; }
.pagination { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.pagination span { margin-right: auto; color: var(--muted); }
details summary { color: var(--teal); cursor: pointer; font-weight: 700; }
.mini-form { min-width: 280px; display: grid; gap: 8px; margin-top: 10px; }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.settings-card { margin: 0; }
.settings-card .form-grid { padding: 20px 22px 24px; }
.settings-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.test-form { margin: 14px 0 18px; }

.auth-body { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(circle at 15% 10%, rgba(45, 212, 191, .14), transparent 35%), var(--navy); }
.auth-wrap { width: 100%; max-width: 480px; }
.auth-wrap.wide { max-width: 720px; }
.auth-card { padding: 30px; border: 1px solid rgba(255,255,255,.08); border-radius: 22px; background: var(--surface); box-shadow: 0 24px 80px rgba(0,0,0,.28); }
.auth-card.compact { max-width: 430px; margin: auto; }
.auth-brand { width: max-content; margin-bottom: 30px; color: var(--ink); }
.auth-brand .brand-mark { color: #fff; border-color: var(--teal); background: var(--teal); }
.auth-brand strong { color: var(--ink); }
.auth-brand small { color: var(--muted); }
.auth-heading { margin-bottom: 22px; }
.auth-heading h1 { margin: 5px 0 7px; font-size: 28px; line-height: 1.15; letter-spacing: -.025em; }
.auth-heading p { margin: 0; color: var(--muted); }
.secure-note { margin: 20px 0 0; color: var(--muted); font-size: 13px; text-align: center; }
.otp { font-size: 24px; font-weight: 800; letter-spacing: .22em; text-align: center; }
.qr-layout { display: grid; grid-template-columns: 210px 1fr; align-items: center; gap: 24px; margin-bottom: 22px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); }
.qr { width: 210px; height: 210px; border-radius: 8px; }
.secret { display: block; padding: 10px; border-radius: 8px; color: var(--ink); background: #e9eef1; font-size: 14px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.backdrop { display: none; }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-grid { grid-template-columns: 1fr; }
  .settings-actions { grid-column: 1; }
}

@media (max-width: 780px) {
  .shell { display: block; }
  .sidebar { position: fixed; left: 0; transform: translateX(-105%); width: min(300px, 86vw); transition: transform .2s ease; box-shadow: 20px 0 50px rgba(0,0,0,.25); }
  .sidebar.open { transform: translateX(0); }
  .menu-button { display: inline-grid; place-items: center; flex: 0 0 auto; }
  .backdrop.show { position: fixed; inset: 0; z-index: 20; display: block; background: rgba(3, 21, 29, .54); }
  .topbar { min-height: 86px; padding: 18px 16px; align-items: flex-start; }
  .topbar h1 { font-size: 24px; }
  .topbar p { font-size: 14px; }
  .content { padding: 18px 14px 48px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { min-height: 128px; padding: 16px; }
  .stat-card strong { font-size: 34px; }
  .stat-card small { font-size: 12px; }
  .upload-panel { grid-template-columns: 1fr; gap: 18px; padding: 18px; }
  .upload-form { grid-template-columns: 1fr; }
  .panel-head { padding: 17px; }
  .panel-head .button { width: 100%; }
  .panel-head { flex-direction: column; }
  .search-bar { align-items: stretch; flex-wrap: wrap; }
  .search-bar input { flex: 1 1 100%; max-width: none; }
  .status-line { align-items: flex-start; }
  th, td { padding: 12px; }
  .action-bar { justify-content: stretch; }
  .action-bar > *, .action-bar .button { flex: 1 1 100%; width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .full-row { grid-column: 1; }
  .qr-layout { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .auth-card { padding: 24px 20px; }
}

@media (max-width: 460px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { min-height: 118px; }
  .status-line { display: grid; }
  .auth-body { padding: 12px; }
  .qr, .qr-layout img { width: 190px; height: 190px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

