:root {
  color-scheme: light;
  --navy: #10233f;
  --navy-2: #183456;
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #14233b;
  --muted: #68758a;
  --border: #dfe6ef;
  --border-strong: #cbd5e1;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --warning: #b76a08;
  --danger: #c53d4b;
  --radius: 8px;
  --shadow: 0 10px 28px rgba(15, 35, 63, .07);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* Login */
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 32px; background: linear-gradient(135deg, var(--navy) 0 42%, #16345d 42% 58%, var(--bg) 58%); }
.login-panel { width: min(420px, 100%); padding: 40px; border: 1px solid rgba(255,255,255,.7); border-radius: 12px; background: rgba(255,255,255,.98); box-shadow: 0 24px 60px rgba(8, 28, 53, .2); }
.login-panel h1 { margin: 22px 0 8px; font-size: 28px; letter-spacing: -.03em; }
.login-panel > p { margin: 0 0 28px; color: var(--muted); line-height: 1.7; }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 20px; font-weight: 750; box-shadow: 0 8px 18px rgba(37, 99, 235, .24); }
.brand-mark.small { width: 44px; height: 32px; border-radius: 7px; font-size: 12px; box-shadow: none; }
.stack-form { display: grid; gap: 18px; }
label { display: grid; gap: 7px; color: #39475c; font-size: 12px; font-weight: 650; }
input, select, textarea { width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid var(--border-strong); border-radius: 6px; background: #fff; outline: none; font-weight: 400; transition: border-color .15s, box-shadow .15s; }
input:hover, select:hover, textarea:hover { border-color: #aebac9; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; min-height: 16px; padding: 0; margin: 0; accent-color: var(--accent); }
.form-error { min-height: 20px; margin: 0; color: var(--danger); }

/* Shell */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; z-index: 10; height: 100vh; display: flex; flex-direction: column; padding: 22px 14px 16px; background: var(--navy); color: #fff; box-shadow: 4px 0 20px rgba(10, 27, 48, .08); }
.brand { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; padding: 10px; border: 1px solid rgba(185, 198, 216, .16); border-radius: 8px; background: rgba(5, 18, 37, .18); box-shadow: inset 0 1px 4px rgba(4, 16, 34, .35), 0 1px 0 rgba(255, 255, 255, .03); font-size: 15px; letter-spacing: .01em; }
.sidebar-user { display: flex; align-items: center; gap: 7px; min-height: 28px; margin: 0 8px 14px; color: #aebed1; font-size: 12px; }
.sidebar-user::before { content: ""; flex: 0 0 auto; width: 6px; height: 6px; border-radius: 50%; background: #6ea0ff; box-shadow: 0 0 0 3px rgba(110, 160, 255, .12); }
.nav-list { display: grid; gap: 5px; }
.nav-list + .nav-list { margin-top: 5px; }
.nav-list button { position: relative; border: 0; border-radius: 7px; padding: 11px 13px; background: transparent; color: #b9c6d8; text-align: left; font-size: 14px; font-weight: 600; transition: background .15s, color .15s; }
.nav-list button:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-list button.active { background: var(--accent); color: #fff; box-shadow: 0 7px 16px rgba(13, 72, 195, .25); }
.nav-list button.active::before { content: ""; position: absolute; top: 9px; bottom: 9px; left: -14px; width: 3px; border-radius: 0 3px 3px 0; background: #85adff; }
.sidebar-footer { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 16px 8px 0; border-top: 1px solid rgba(255,255,255,.12); color: #aebed1; }
.sidebar-footer .text-button { width: max-content; padding-left: 0; color: #d7e2ef; }
#session-user { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-settings-button { flex: 0 0 auto; width: 28px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: #d7e2ef; font-size: 17px; }
.account-settings-button:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-footer .account-settings-button { margin-left: auto; }
.workspace { min-width: 0; padding: 0 30px 38px; }
.topbar { min-height: 86px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.topbar h1 { margin: 0; font-size: 23px; letter-spacing: -.025em; }
.topbar p, .section-split p { margin: 5px 0 0; color: var(--muted); line-height: 1.6; }
.topbar-actions { display: flex; gap: 10px; }

/* Controls */
.button { min-height: 40px; border: 1px solid transparent; border-radius: 6px; padding: 8px 16px; font-weight: 650; transition: background .15s, border-color .15s, box-shadow .15s; }
.button:focus-visible, .text-button:focus-visible, .nav-list button:focus-visible, .lead-category-tabs button:focus-visible { outline: 3px solid rgba(37, 99, 235, .28); outline-offset: 2px; }
.button.primary { background: var(--accent); color: #fff; box-shadow: 0 5px 12px rgba(37, 99, 235, .16); }
.button.primary:hover { background: var(--accent-hover); }
.button.secondary { border-color: var(--border-strong); background: #fff; }
.button.secondary:hover, .button.ghost:hover { border-color: #aebbc9; background: var(--surface-soft); }
.button.ghost { min-height: 34px; border-color: var(--border); background: transparent; padding: 6px 12px; }
.button.full { width: 100%; }
.text-button { border: 0; padding: 6px; background: transparent; color: var(--accent); font-weight: 650; }
.text-button:hover { color: var(--accent-hover); }
.icon-button { width: 34px; height: 34px; border: 0; background: transparent; color: var(--muted); font-size: 24px; }

/* Overview */
.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.stats-grid article { position: relative; display: grid; min-height: 116px; padding: 20px 24px; }
.stats-grid article + article::before { content: ""; position: absolute; top: 22px; bottom: 22px; left: 0; width: 1px; background: var(--border); }
.stats-grid span { color: #4c5a70; font-size: 13px; font-weight: 650; }
.stats-grid strong { align-self: center; color: #0f2b52; font-size: 31px; letter-spacing: -.04em; }
.stats-grid small { color: var(--muted); }
.surface { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.filter-bar { display: grid; grid-template-columns: repeat(6, minmax(110px, 1fr)); gap: 11px; align-items: end; padding: 18px 20px; background: var(--surface-soft); border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.filter-bar label { min-width: 0; }
.filter-bar .button, .filter-bar .text-button { min-width: 60px; }
.lead-category-tabs { display: flex; gap: 30px; overflow-x: auto; padding: 0 20px; border-bottom: 1px solid var(--border); scrollbar-width: thin; }
.lead-category-tabs button { position: relative; flex: 0 0 auto; padding: 15px 1px 14px; border: 0; background: transparent; color: #536176; font: inherit; font-weight: 600; cursor: pointer; }
.lead-category-tabs button:hover, .lead-category-tabs button.active { color: var(--accent); }
.lead-category-tabs button.active::after { content: ""; position: absolute; right: 0; bottom: -1px; left: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent); }
.selection-toolbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid #bfd2f5; background: var(--accent-soft); }
.selection-toolbar select { width: 180px; margin-left: auto; }
.selection-toolbar > label { min-width: 120px; }
.table-heading, .section-split { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 20px 22px; }
.table-heading h2, .section-split h2 { margin: 0; color: #183153; font-size: 17px; }
.table-heading p { display: inline; margin: 0 0 0 8px; color: var(--muted); }
.inline-message { color: var(--accent); font-size: 13px; }
.inline-message.error { color: var(--danger); }

/* Tables */
.table-wrap { overflow: auto; border-top: 1px solid var(--border); }
table { width: 100%; min-width: 1000px; border-collapse: collapse; }
th, td { height: 48px; padding: 10px 14px; border-bottom: 1px solid #e8edf3; text-align: left; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; background: #f5f7fa; color: #526176; font-size: 12px; font-weight: 700; letter-spacing: .01em; }
td { color: #2e3d52; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: #f7faff; }
td input, td select { min-height: 32px; padding: 5px 8px; font-size: 13px; }
.status-select { width: 96px; }
.remark-input { width: 150px; }
.select-column { width: 128px; }
.check-label { display: flex; align-items: center; gap: 8px; width: max-content; min-height: 40px; }
.check-label input { width: 16px; min-height: 16px; margin: 0; accent-color: var(--accent); }
.status-chip { display: inline-flex; align-items: center; border-radius: 5px; padding: 4px 8px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 650; }
.pagination { display: flex; justify-content: flex-end; align-items: center; gap: 12px; padding: 14px 18px; }
.pagination span { color: var(--muted); }

/* Employee management */
.employee-create { display: grid; grid-template-columns: repeat(4, minmax(108px, 1fr)) minmax(130px, 1fr) auto auto; gap: 8px; align-items: end; width: min(1080px, 82%); }
.employee-create input { min-width: 0; }
#employee-section .section-split { display: grid; }
#employee-section .employee-create { width: 100%; }
.group-tools { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; padding: 0 22px 20px; }
.group-tools .group-tools { padding: 0; }
.group-row td { background: #f3f6fa; color: #213853; font-weight: 700; }
.group-row input { width: 140px; margin-left: 6px; }
.employee-stat-name { padding-left: 28px; }
.history-membership-note { margin-left: 10px; color: var(--muted); font-size: 12px; font-weight: 400; }
.masked-phone { letter-spacing: .04em; }
.switch-button { min-width: 58px; border: 1px solid var(--border-strong); border-radius: 999px; padding: 5px 9px; background: #f5f7fa; color: var(--muted); font-size: 12px; }
.switch-button.on { border-color: #9ebcf9; background: var(--accent-soft); color: var(--accent); }

/* Settings and collector */
.settings-form { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 16px; align-items: end; padding: 2px 22px 24px; border-bottom: 1px solid var(--border); }
.settings-form .setting-enabled { align-self: center; }
.mode-field { display: flex; gap: 18px; min-height: 72px; margin: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; }
.mode-field legend { padding: 0 4px; color: #39475c; font-size: 12px; font-weight: 650; }
.mode-field .check-label { min-height: 28px; }
.run-table { min-width: 680px; }
.status-details { display: grid; grid-template-columns: repeat(6, 1fr); margin: 0; padding: 0 22px 24px; gap: 12px; }
.status-details div { grid-column: span 2; }
.status-details div:nth-child(-n+2) { grid-column: span 3; }
.status-details div { min-height: 104px; padding: 16px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-soft); }
.status-details dt { color: var(--muted); font-size: 12px; font-weight: 650; }
.status-details dd { margin: 14px 0 0; color: #17365e; font-size: 18px; font-weight: 700; }
.status-dot { color: var(--muted); }
.status-dot.ok { color: var(--accent); }
#collector-summary { display: block; margin: 0; padding: 0 22px 24px; }

/* Pending allocation */
.quantity-allocation { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); background: #fbfcfe; }
.quantity-allocation > strong, .quantity-remaining { align-self: center; white-space: nowrap; }
.quantity-allocation > strong { color: #17365e; }
.quantity-allocation label:not(.check-label) { min-width: 130px; }
.quantity-allocation .inline-message { align-self: center; }

.password-dialog { width: min(430px, calc(100% - 32px)); padding: 0; border: 0; border-radius: 10px; color: var(--text); box-shadow: 0 24px 70px rgba(8, 28, 53, .3); }
.password-dialog::backdrop { background: rgba(8, 28, 53, .55); }
.password-dialog form { padding: 24px; }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog-heading h2 { margin: 0; color: #183153; font-size: 20px; }
.dialog-heading p { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

@media (max-width: 1440px) {
  .filter-bar { grid-template-columns: repeat(4, minmax(112px, 1fr)); }
  .employee-create { width: 100%; grid-template-columns: repeat(4, minmax(110px, 1fr)) auto auto; }
  .employee-create select { grid-column: span 1; }
}

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 196px minmax(0, 1fr); }
  .workspace { padding-inline: 20px; }
  .filter-bar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-grid article:nth-child(3)::before { display: none; }
  .stats-grid article:nth-child(n+3) { border-top: 1px solid var(--border); }
  .section-split { display: grid; }
  .employee-create { grid-template-columns: repeat(3, 1fr); }
  .settings-form, .status-details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .status-details div, .status-details div:nth-child(-n+2) { grid-column: span 1; }
}

@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 12px; }
  .brand { margin-bottom: 8px; padding: 10px; }
  .nav-list { display: flex; overflow-x: auto; padding-bottom: 2px; }
  .nav-list button { flex: 0 0 auto; white-space: nowrap; }
  .nav-list button.active::before { display: none; }
  .sidebar-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; padding: 11px 4px 0; }
  .workspace { padding: 0 12px 24px; }
  .topbar { min-height: 82px; align-items: flex-start; padding: 16px 0; }
  .topbar p { font-size: 12px; }
  .topbar-actions { flex: 0 0 auto; }
  .button { padding-inline: 11px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stats-grid article { min-height: 106px; padding: 14px; }
  .stats-grid strong { font-size: 26px; }
  .filter-bar { grid-template-columns: 1fr 1fr; padding: 14px; }
  .lead-category-tabs { gap: 22px; padding-inline: 14px; }
  .table-heading, .section-split { padding: 17px 14px; }
  .employee-create { grid-template-columns: 1fr 1fr; }
  .settings-form, .status-details { grid-template-columns: 1fr; padding-inline: 14px; }
  .selection-toolbar { flex-wrap: wrap; padding-inline: 14px; }
  .selection-toolbar select { width: 100%; margin-left: 0; }
  .selection-toolbar > label { width: calc(50% - 6px); }
  .quantity-allocation { display: grid; grid-template-columns: 1fr; align-items: stretch; padding-inline: 14px; }
  .group-tools { padding-inline: 14px; }
  .login-shell { padding: 18px; background: var(--navy); }
  .login-panel { padding: 30px 24px; }
}

@media (max-width: 460px) {
  .filter-bar, .employee-create, .stats-grid { grid-template-columns: 1fr; }
  .stats-grid article + article::before { display: none; }
  .stats-grid article + article { border-top: 1px solid var(--border); }
  .topbar { display: grid; }
}
