*, *::before, *::after { box-sizing: border-box; }

:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #12151c;
  --panel-raised: #171b24;
  --panel-soft: #1c212c;
  --border: #272d39;
  --border-strong: #353d4c;
  --text: #f4f6fa;
  --muted: #929baa;
  --muted-strong: #b7bfcb;
  --accent: #6d7cff;
  --accent-strong: #8793ff;
  --accent-soft: rgba(109, 124, 255, .14);
  --green: #45d6a0;
  --green-soft: rgba(69, 214, 160, .12);
  --red: #ff6b7a;
  --red-soft: rgba(255, 107, 122, .12);
  --yellow: #f6c85f;
  --yellow-soft: rgba(246, 200, 95, .12);
  --sidebar: 218px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 18px 60px rgba(0, 0, 0, .28);
}

html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 75% -10%, rgba(109,124,255,.08), transparent 28rem),
    var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
code, .mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.hidden { display: none !important; }

/* shell */
.layout { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 90;
  display: flex;
  width: var(--sidebar);
  flex-direction: column;
  background: rgba(14, 17, 23, .97);
  border-right: 1px solid var(--border);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 70px;
  padding: 0 18px;
  font-size: 16px;
  font-weight: 730;
  letter-spacing: -.02em;
}
.logo-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 8px 24px rgba(109,124,255,.28);
}
.logo-copy small { display: block; color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: .04em; }
.sidebar-nav { flex: 1; padding: 8px 10px; overflow-y: auto; }
.nav-label {
  padding: 15px 10px 6px;
  color: #667080;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .11em;
  text-transform: uppercase;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 40px;
  margin: 2px 0;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--muted-strong);
  font-weight: 570;
  transition: .15s ease;
}
.nav-item:hover { background: var(--panel-soft); color: var(--text); }
.nav-item.active { border-color: rgba(109,124,255,.22); background: var(--accent-soft); color: #dce0ff; }
.nav-icon {
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 7px;
  background: rgba(255,255,255,.045);
  font-size: 11px;
  font-weight: 800;
  color: currentColor;
}
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 14px; border-top: 1px solid var(--border); }
.user-avatar { display: grid; width: 34px; height: 34px; flex: none; place-items: center; border-radius: 50%; background: var(--panel-soft); color: var(--accent-strong); font-weight: 750; }
.sidebar-user img { width: 34px; height: 34px; flex: none; border-radius: 50%; object-fit: cover; }
.user-info { min-width: 0; flex: 1; }
.user-name { overflow: hidden; color: var(--text); font-size: 12px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.user-badge { color: var(--green); font-size: 10px; }
.logout-form { margin: 0; }
.icon-button, .logout-btn {
  display: grid;
  width: 34px;
  height: 34px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-button:hover, .logout-btn:hover { border-color: var(--border-strong); color: var(--text); }
.sidebar-overlay { display: none; }

.main { min-height: 100vh; margin-left: var(--sidebar); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  min-height: 70px;
  align-items: center;
  gap: 10px;
  padding: 0 28px;
  border-bottom: 1px solid rgba(39,45,57,.82);
  background: rgba(11,13,18,.86);
  backdrop-filter: blur(18px);
}
.menu-toggle { display: none; }
.topbar-heading { min-width: 0; flex: 1; }
.topbar-title { font-size: 17px; font-weight: 700; letter-spacing: -.02em; }
.topbar-subtitle { color: var(--muted); font-size: 11px; }
.topbar-badge, .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted-strong);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}
.badge::before, .topbar-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-green { border-color: rgba(69,214,160,.2); background: var(--green-soft); color: var(--green); }
.badge-red { border-color: rgba(255,107,122,.2); background: var(--red-soft); color: var(--red); }
.badge-blue { border-color: rgba(109,124,255,.22); background: var(--accent-soft); color: var(--accent-strong); }
.badge-yellow { border-color: rgba(246,200,95,.2); background: var(--yellow-soft); color: var(--yellow); }
.page-content { width: 100%; max-width: 1480px; padding: 28px; }

/* type and sections */
.page-intro { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.page-intro h1 { margin: 0; font-size: clamp(22px, 2.1vw, 30px); line-height: 1.15; letter-spacing: -.035em; }
.page-intro p { max-width: 650px; margin: 7px 0 0; color: var(--muted); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 15px; }
.section-title { font-size: 15px; font-weight: 700; letter-spacing: -.015em; }
.section-sub { margin-top: 3px; color: var(--muted); font-size: 12px; }
.eyebrow { margin-bottom: 6px; color: var(--accent-strong); font-size: 10px; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.text-muted { color: var(--muted); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-yellow { color: var(--yellow); }
.text-accent { color: var(--accent-strong); }
.text-sm { font-size: 12px; }
.text-bold { font-weight: 700; }

/* layout blocks */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(290px, .65fr); gap: 18px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.card {
  min-width: 0;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(255,255,255,.018), transparent), var(--panel);
  box-shadow: 0 1px 0 rgba(255,255,255,.02) inset;
}
.card-title { margin-bottom: 15px; color: var(--muted-strong); font-size: 12px; font-weight: 700; letter-spacing: .055em; text-transform: uppercase; }
.card-sub { margin-top: 4px; color: var(--muted); font-size: 12px; }
.card-accent { border-color: rgba(109,124,255,.25); background: linear-gradient(135deg, rgba(109,124,255,.12), transparent 55%), var(--panel); }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { position: relative; min-width: 0; overflow: hidden; padding: 17px 18px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.stat-card::after { content: ""; position: absolute; top: 0; right: 0; width: 54px; height: 54px; border-radius: 0 0 0 54px; background: var(--accent-soft); opacity: .55; }
.stat-card.green::after { background: var(--green-soft); }
.stat-card.red::after { background: var(--red-soft); }
.stat-card.yellow::after { background: var(--yellow-soft); }
.stat-label { color: var(--muted); font-size: 11px; font-weight: 650; }
.stat-num { margin-top: 7px; font-size: 26px; font-weight: 760; letter-spacing: -.04em; line-height: 1.1; }
.stat-desc { margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.metric-list { display: flex; flex-direction: column; }
.metric-row { display: grid; grid-template-columns: minmax(120px, .75fr) minmax(0, 1.25fr); gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.metric-row:last-child { border-bottom: 0; }
.metric-label { color: var(--muted); font-size: 12px; }
.metric-value { min-width: 0; overflow: hidden; color: var(--text); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.readiness { display: grid; gap: 9px; }
.check-item { display: flex; align-items: center; gap: 9px; color: var(--muted-strong); font-size: 12px; }
.check-mark { display: grid; width: 20px; height: 20px; flex: none; place-items: center; border-radius: 7px; background: var(--red-soft); color: var(--red); font-size: 10px; font-weight: 800; }
.check-item.ok .check-mark { background: var(--green-soft); color: var(--green); }
.empty-state { padding: 36px 18px; text-align: center; }
.empty-icon { display: grid; width: 44px; height: 44px; margin: 0 auto 12px; place-items: center; border: 1px solid var(--border); border-radius: 13px; background: var(--panel-soft); color: var(--muted-strong); font-weight: 750; }
.empty-state h3 { margin: 0 0 5px; font-size: 14px; }
.empty-state p { margin: 0; color: var(--muted); font-size: 12px; }
.notice { padding: 12px 14px; border: 1px solid rgba(246,200,95,.22); border-radius: 10px; background: var(--yellow-soft); color: #ebd28f; font-size: 12px; }
.notice.danger { border-color: rgba(255,107,122,.22); background: var(--red-soft); color: #ffacb5; }
.notice.success { border-color: rgba(69,214,160,.22); background: var(--green-soft); color: #8be8c5; }

/* controls */
.btn {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--panel-soft);
  color: var(--text);
  font-weight: 650;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .08s;
}
.btn:hover { border-color: var(--border-strong); background: #252b37; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .form-input:focus-visible, .pill:focus-visible, .icon-button:focus-visible { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
.btn:disabled { opacity: .42; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 9px 24px rgba(109,124,255,.2); }
.btn-primary:hover { border-color: transparent; background: var(--accent-strong); }
.btn-ghost { border-color: var(--border); background: transparent; color: var(--muted-strong); }
.btn-danger { border-color: rgba(255,107,122,.22); background: var(--red-soft); color: var(--red); }
.btn-sm { min-height: 32px; padding: 5px 10px; font-size: 12px; }
.btn-icon { width: 34px; padding: 0; }
.button-row { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; color: var(--muted-strong); font-size: 11px; font-weight: 650; }
.form-hint { margin-top: 6px; color: var(--muted); font-size: 11px; }
.form-input {
  display: block;
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
  background: #0f1218;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.form-input:focus { border-color: rgba(109,124,255,.7); box-shadow: 0 0 0 3px rgba(109,124,255,.12); }
.form-input::placeholder { color: #606979; }
textarea.form-input { min-height: 126px; resize: vertical; }
select.form-input { appearance: auto; }
.inline-form { display: flex; gap: 9px; }
.inline-form .form-input { flex: 1; }
.toggle { position: relative; display: inline-flex; width: 44px; height: 25px; flex: none; }
.toggle input { position: absolute; opacity: 0; }
.toggle-track { position: absolute; inset: 0; border: 1px solid var(--border-strong); border-radius: 999px; background: #262c37; cursor: pointer; transition: .15s; }
.toggle-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #aab1bd; transition: .15s; }
.toggle input:checked + .toggle-track { border-color: var(--accent); background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(19px); background: #fff; }
.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { min-width: 46px; min-height: 34px; padding: 6px 12px; border: 1px solid var(--border); border-radius: 9px; background: transparent; color: var(--muted-strong); font-weight: 650; cursor: pointer; }
.pill:hover { border-color: var(--border-strong); color: var(--text); }
.pill.active { border-color: rgba(109,124,255,.45); background: var(--accent-soft); color: #d8dcff; }

/* lists and tables */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 11px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 13px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { background: rgba(255,255,255,.018); color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .07em; text-transform: uppercase; }
td { font-size: 12px; }
tr:last-child td { border-bottom: 0; }
.truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.delivery-list { display: flex; flex-direction: column; }
.delivery-item { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 40px; border-bottom: 1px solid var(--border); }
.delivery-item:last-child { border-bottom: 0; }
.delivery-status { display: grid; width: 20px; height: 20px; place-items: center; border-radius: 50%; background: var(--green-soft); color: var(--green); font-size: 10px; font-weight: 800; }
.delivery-status.fail { background: var(--red-soft); color: var(--red); }
.delivery-target { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.delivery-time { color: var(--muted); font-size: 10px; }
.account-list { display: flex; flex-direction: column; }
.acc-item { display: flex; align-items: center; gap: 12px; min-height: 68px; padding: 11px 3px; border-bottom: 1px solid var(--border); }
.acc-item:last-child { border-bottom: 0; }
.acc-avatar { display: grid; width: 38px; height: 38px; flex: none; place-items: center; border-radius: 11px; background: var(--accent-soft); color: var(--accent-strong); font-size: 11px; font-weight: 800; }
.acc-phone { font-weight: 650; }
.acc-status { margin-top: 2px; color: var(--muted); font-size: 11px; }
.target-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.target-row:last-child { border-bottom: 0; }
.target-index { display: grid; width: 26px; height: 26px; flex: none; place-items: center; border-radius: 7px; background: var(--panel-soft); color: var(--muted); font-size: 10px; }
.target-name { min-width: 0; flex: 1; overflow: hidden; color: #d7dbff; text-overflow: ellipsis; white-space: nowrap; }
.msg-list { display: flex; flex-direction: column; gap: 8px; min-height: 100px; }
.msg-card { display: flex; width: 100%; align-items: flex-start; gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: #0f1218; color: var(--text); text-align: left; cursor: pointer; transition: .15s; }
.msg-card:hover { border-color: var(--border-strong); background: var(--panel-raised); }
.msg-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.msg-id { color: var(--accent-strong); font-size: 10px; font-weight: 750; }
.msg-date { color: var(--muted); font-size: 10px; }
.msg-text { margin-top: 5px; overflow-wrap: anywhere; color: var(--muted-strong); font-size: 12px; white-space: pre-wrap; }

/* feedback */
#toast-container { position: fixed; top: 18px; right: 18px; z-index: 999; display: flex; width: min(360px, calc(100vw - 36px)); flex-direction: column; gap: 8px; }
.toast { display: flex; align-items: flex-start; gap: 10px; padding: 11px 13px; border: 1px solid var(--border); border-radius: 10px; background: #171b23; box-shadow: var(--shadow); color: var(--text); font-size: 12px; animation: toast-in .2s ease; }
.toast-mark { display: grid; width: 20px; height: 20px; flex: none; place-items: center; border-radius: 6px; background: var(--accent-soft); color: var(--accent-strong); font-size: 10px; font-weight: 800; }
.toast-success .toast-mark { background: var(--green-soft); color: var(--green); }
.toast-error .toast-mark { background: var(--red-soft); color: var(--red); }
@keyframes toast-in { from { transform: translateY(-7px); opacity: 0; } }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.25); border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.dispatch-log { display: none; max-height: 200px; margin-top: 12px; overflow: auto; padding: 12px; border: 1px solid var(--border); border-radius: 9px; background: #0a0c10; font: 11px/1.7 "SFMono-Regular", Consolas, monospace; }
.dispatch-log.open { display: block; }
.log-ok { color: var(--green); }
.log-err { color: var(--red); }
.log-skip { color: var(--yellow); }

/* modal */
.modal-overlay { position: fixed; inset: 0; z-index: 200; display: none; padding: 18px; align-items: center; justify-content: center; background: rgba(2,3,6,.72); backdrop-filter: blur(8px); }
.modal-overlay.open { display: flex; }
.modal { width: min(460px, 100%); max-height: calc(100vh - 36px); overflow: auto; padding: 22px; border: 1px solid var(--border-strong); border-radius: 16px; background: var(--panel); box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.modal-title { font-size: 16px; font-weight: 720; }

/* login */
.login-page { display: grid; min-height: 100vh; grid-template-columns: minmax(0, 1.2fr) minmax(360px, .8fr); }
.login-brand { display: flex; flex-direction: column; justify-content: flex-end; padding: clamp(32px, 6vw, 84px); background: radial-gradient(circle at 25% 30%, rgba(109,124,255,.18), transparent 25rem); }
.login-brand .logo-icon { width: 46px; height: 46px; margin-bottom: 28px; border-radius: 13px; }
.login-brand h1 { max-width: 600px; margin: 0; font-size: clamp(38px, 5vw, 72px); line-height: .98; letter-spacing: -.055em; }
.login-brand p { max-width: 520px; margin: 20px 0 0; color: var(--muted-strong); font-size: 15px; }
.login-side { display: flex; align-items: center; justify-content: center; padding: 30px; border-left: 1px solid var(--border); background: rgba(15,18,24,.75); }
.login-box { width: min(380px, 100%); }
.login-title { margin: 0 0 7px; font-size: 24px; letter-spacing: -.03em; }
.login-sub { margin: 0 0 26px; color: var(--muted); }
.login-divider { display: flex; align-items: center; gap: 10px; margin: 22px 0; color: var(--muted); font-size: 10px; text-transform: uppercase; }
.login-divider::before, .login-divider::after { content: ""; height: 1px; flex: 1; background: var(--border); }
.security-note { display: flex; gap: 9px; margin-top: 22px; color: var(--muted); font-size: 11px; }
.access-denied { margin-top: 12px; padding: 10px 12px; border: 1px solid rgba(255,107,122,.22); border-radius: 9px; background: var(--red-soft); color: #ffabb4; font-size: 12px; }
.error-page { display: grid; min-height: 100vh; padding: 24px; place-items: center; text-align: center; }
.error-code { color: var(--red); font-size: 64px; font-weight: 800; line-height: 1; }
.error-text { margin: 12px 0 20px; color: var(--muted); }

/* helpers */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.flex-1 { flex: 1; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.w-full { width: 100%; }

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

@media (max-width: 780px) {
  :root { --sidebar: 230px; }
  .sidebar { transform: translateX(-101%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { position: fixed; inset: 0; z-index: 80; display: none; background: rgba(0,0,0,.55); }
  .sidebar-overlay.open { display: block; }
  .main { margin-left: 0; }
  .topbar { min-height: 62px; padding: 0 16px; }
  .menu-toggle { display: grid; }
  .topbar-subtitle { display: none; }
  .page-content { padding: 18px 14px 32px; }
  .grid-2 { grid-template-columns: 1fr; }
  .page-intro { flex-direction: column; }
  .login-page { grid-template-columns: 1fr; }
  .login-brand { display: none; }
  .login-side { min-height: 100vh; border-left: 0; }
}

@media (max-width: 500px) {
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 14px; }
  .stat-num { font-size: 22px; }
  .card { padding: 16px; }
  .topbar-badge { display: none; }
  .inline-form { flex-direction: column; }
  .inline-form .btn { width: 100%; }
  .button-row .btn { flex: 1; }
  .metric-row { grid-template-columns: 1fr; gap: 3px; }
  .delivery-time { display: none; }
  .acc-item { align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
