:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #fff;
  --ink: #16191d;
  --muted: #68717d;
  --line: #dce1e7;
  --line-dark: #c7cdd5;
  --blue: #1268e4;
  --blue-dark: #0d52b6;
  --green: #188455;
  --red: #c83b3b;
  --sidebar: #171b21;
  --sidebar-muted: #9da6b1;
  font-family: Inter, "SF Pro Text", "Segoe UI", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: grid; grid-template-columns: 236px minmax(0, 1fr); background: var(--bg); color: var(--ink); }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }

.sidebar { min-height: 100vh; padding: 22px 14px; display: flex; flex-direction: column; background: var(--sidebar); color: #fff; }
.brand { padding: 0 10px 28px; display: flex; align-items: center; gap: 11px; }
.brand-logo { width: 42px; height: 42px; flex: none; object-fit: contain; }
.brand strong, .brand small, .connection strong, .connection small { display: block; }
.brand strong { font-size: 14px; }
.brand small, .connection small { margin-top: 2px; color: var(--sidebar-muted); font-size: 11px; }
.sidebar nav { display: grid; gap: 4px; }
.nav-item { padding: 10px 12px; border: 0; border-radius: 6px; background: transparent; color: var(--sidebar-muted); font-size: 13px; text-align: left; }
.nav-item:hover, .nav-item.active { background: #282e37; color: #fff; }
.connection { margin-top: auto; padding: 18px 10px 2px; display: flex; align-items: center; gap: 10px; border-top: 1px solid #303640; }
.connection strong { font-size: 12px; }
.dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: #707984; }
.dot.online { background: #32bb7b; box-shadow: 0 0 0 3px rgba(50, 187, 123, .15); }

main { min-width: 0; padding: 28px 34px 48px; }
.topbar { margin-bottom: 26px; display: flex; align-items: center; justify-content: space-between; }
.eyebrow { margin: 0 0 5px; color: var(--muted); font-size: 10px; letter-spacing: .14em; }
.topbar h1 { margin: 0; font-size: 24px; letter-spacing: 0; }
.top-actions, .toolbar-actions, .session-actions { display: flex; gap: 8px; }
.logout-button { height: 34px; }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--line-dark); border-radius: 6px; background: var(--surface); color: var(--ink); font-size: 17px; text-decoration: none; }
.view { display: none; }
.view.active { display: block; }

.metrics { margin-bottom: 18px; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); background: var(--surface); }
.metrics > div { padding: 17px 20px; border-top: 3px solid transparent; border-right: 1px solid var(--line); }
.metrics > div:last-child { border-right: 0; }
.metrics .metric-total { border-top-color: var(--blue); }
.metrics .metric-active { border-top-color: var(--green); }
.metrics .metric-inactive { border-top-color: var(--red); }
.metrics span, .metrics strong { display: block; }
.metrics span { margin-bottom: 5px; color: var(--muted); font-size: 11px; }
.metrics strong { font-size: 25px; }

.toolbar, .section-head { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.search { width: min(360px, 50vw); position: relative; }
.search span { position: absolute; top: 8px; left: 11px; color: var(--muted); }
.search input { padding-left: 33px; }
.primary, .secondary, .danger { padding: 8px 14px; border: 1px solid transparent; border-radius: 6px; font-size: 12px; font-weight: 600; }
.primary { background: var(--blue); color: #fff; }
.primary:hover { background: var(--blue-dark); }
.secondary { border-color: var(--line-dark); background: var(--surface); }
.danger { background: var(--red); color: #fff; }
.danger.subtle { border-color: #e4b6b6; background: transparent; color: var(--red); }
.auto-generation-button { display: inline-flex; align-items: center; gap: 7px; }
.auto-generation-button::before { width: 7px; height: 7px; content: ""; border-radius: 50%; background: #929ba5; }
.auto-generation-button.enabled::before { background: var(--green); box-shadow: 0 0 0 3px rgba(24, 132, 85, .12); }

.table-wrap { overflow: auto; border: 1px solid var(--line); background: var(--surface); }
table { width: 100%; min-width: 1210px; border-collapse: collapse; }
th, td { padding: 12px 15px; border-bottom: 1px solid var(--line); font-size: 12px; text-align: left; vertical-align: middle; }
th { background: #f9fafb; color: var(--muted); font-size: 10px; font-weight: 600; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
.right { text-align: right; }
.select-col { width: 42px; padding-right: 4px; text-align: center; }
.select-col input, td.row-select input { width: 15px; height: 15px; margin: 0; }
td.row-select { width: 42px; padding-right: 4px; text-align: center; }
.address { color: #1e2935; font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.alias-cell { min-width: 210px; display: grid; gap: 5px; }
.email-copy { width: fit-content; max-width: 100%; padding: 0; overflow: hidden; border: 0; background: transparent; cursor: copy; font-weight: 700; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.email-copy:hover { color: var(--blue); text-decoration: underline; }
.email-copy:focus-visible { border-radius: 2px; outline: 2px solid rgba(18, 104, 228, .35); outline-offset: 2px; }
.alias-cell span { color: #4f5965; font-size: 11px; }
.alias-cell small { max-width: 280px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.alias-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
.alias-meta .tag-badge { padding: 2px 5px; border: 1px solid #b8cff0; border-radius: 4px; background: #eef5ff; color: #1459a6; font-size: 9px; font-weight: 700; }
.pickup-link { min-width: 116px; display: flex; align-items: center; gap: 5px; }
.pickup-link a { color: var(--blue); font-size: 11px; font-weight: 600; text-decoration: none; white-space: nowrap; }
.copy-mini { width: 27px; height: 27px; padding: 0; display: grid; place-items: center; border: 1px solid var(--line-dark); border-radius: 5px; background: #fff; color: #47515d; font-size: 14px; }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; }
.badge::before { width: 8px; height: 8px; content: ""; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px rgba(24, 132, 85, .12); }
.badge.inactive { color: var(--muted); }
.badge.inactive::before { background: #929ba5; box-shadow: none; }
.gpt-used-control { min-width: 84px; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; font-size: 11px; white-space: nowrap; }
.gpt-used-control input { width: 15px; height: 15px; margin: 0; }
.gpt-used-control:has(input:checked) { color: var(--blue); font-weight: 700; }
.at-control { min-width: 76px; display: flex; align-items: center; gap: 6px; }
.at-copy, .at-edit { padding: 0; border: 0; background: transparent; color: var(--blue); font-size: 11px; }
.at-copy { font-family: "SFMono-Regular", Consolas, monospace; font-weight: 700; text-decoration: underline; cursor: copy; }
.at-edit { color: var(--muted); }
.at-empty { min-width: 14px; color: var(--muted); }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.row-actions button { padding: 4px 5px; border: 0; background: transparent; color: var(--blue); font-size: 11px; }
.row-actions .remove { color: var(--red); }
.empty { padding: 44px 20px; color: var(--muted); font-size: 12px; text-align: center; }
.bulk-bar { margin: -2px 0 12px; padding: 9px 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid #cbdcf6; background: #f3f7fd; }
.bulk-bar strong { font-size: 11px; }
.bulk-bar > div { display: flex; gap: 7px; }
.pagination { padding: 13px 2px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 11px; }
.pagination > div { display: flex; align-items: center; gap: 9px; }
.pagination .icon-button { width: 30px; height: 30px; }
.pagination strong { min-width: 52px; color: var(--ink); font-size: 11px; text-align: center; }

.section-head h2 { margin: 0 0 5px; font-size: 18px; }
.section-head p { margin: 0; color: var(--muted); font-size: 12px; }
.form-grid { margin-bottom: 18px; padding: 20px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; border: 1px solid var(--line); background: var(--surface); }
.form-grid label, dialog label { display: grid; gap: 6px; }
.form-grid label > span, dialog label > span { color: #39414b; font-size: 11px; font-weight: 600; }
.form-grid small { color: var(--muted); font-size: 10px; }
.full { grid-column: 1 / -1; }
.form-action { display: flex; align-items: flex-end; justify-content: flex-end; }
.check { height: 34px; display: flex !important; grid-template-columns: auto 1fr !important; align-items: center; align-self: end; }
.check input { width: auto; }
input, textarea, select { width: 100%; padding: 8px 10px; border: 1px solid var(--line-dark); border-radius: 5px; outline: none; background: #fff; color: var(--ink); font-size: 12px; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(18, 104, 228, .1); }
textarea { resize: vertical; }
.details { display: grid; grid-template-columns: 150px 1fr; border: 1px solid var(--line); background: var(--surface); font-size: 12px; }
.details:empty { display: none; }
.details dt, .details dd { margin: 0; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.details dt { background: #f9fafb; color: var(--muted); }
.code-result { padding: 18px 20px; border-left: 3px solid var(--green); background: var(--surface); }
.code-result span, .code-result strong { display: block; }
.code-result span { color: var(--muted); font-size: 11px; }
.code-result strong { margin: 5px 0; font-family: Consolas, monospace; font-size: 34px; }
.code-result p { margin: 0; color: var(--muted); font-size: 11px; }
.hidden { display: none !important; }

dialog { width: min(470px, calc(100vw - 28px)); padding: 0; border: 1px solid var(--line-dark); border-radius: 7px; box-shadow: 0 20px 60px rgba(0, 0, 0, .2); }
dialog::backdrop { background: rgba(18, 22, 27, .54); }
dialog form { padding: 22px; display: grid; gap: 15px; }
.dialog-head, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-actions { margin-top: 5px; justify-content: flex-end; }
.batch-note { padding: 10px 12px; border-left: 3px solid var(--blue); background: #f2f7ff; color: var(--muted); font-size: 11px; }
.auto-toggle { padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--line); background: #f9fafb; }
.auto-toggle input { width: 36px; height: 20px; margin: 0; position: relative; appearance: none; border: 1px solid var(--line-dark); border-radius: 10px; background: #d7dce2; transition: .16s; }
.auto-toggle input::after { width: 14px; height: 14px; position: absolute; top: 2px; left: 2px; content: ""; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: .16s; }
.auto-toggle input:checked { border-color: var(--green); background: var(--green); }
.auto-toggle input:checked::after { transform: translateX(16px); }
.auto-schedule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.auto-status { margin: 0; border: 1px solid var(--line); }
.auto-status div { padding: 8px 11px; display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 10px; border-bottom: 1px solid var(--line); }
.auto-status div:last-child { border-bottom: 0; }
.auto-status dt, .auto-status dd { margin: 0; font-size: 11px; }
.auto-status dt { color: var(--muted); }
.auto-status dd { overflow-wrap: anywhere; text-align: right; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; padding: 11px 15px; border-radius: 6px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .18s; background: #1b2027; color: #fff; font-size: 12px; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--red); }

@media (max-width: 760px) {
  body { display: block; }
  .sidebar { min-height: auto; padding: 12px; position: sticky; top: 0; z-index: 5; }
  .brand { padding: 0 4px 10px; }
  .sidebar nav { display: flex; overflow-x: auto; }
  .nav-item { white-space: nowrap; }
  .connection { display: none; }
  main { padding: 20px 14px; }
  .topbar { margin-bottom: 18px; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .metrics > div { padding: 13px 11px; }
  .metrics strong { font-size: 21px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .toolbar-actions #batchButton { grid-column: 1 / -1; }
  .auto-schedule-grid { grid-template-columns: 1fr; }
  .bulk-bar { align-items: stretch; flex-direction: column; }
  .bulk-bar > div { display: grid; grid-template-columns: repeat(2, 1fr); }
  .bulk-bar button { padding-right: 6px; padding-left: 6px; }
  .search { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .full { grid-column: auto; }
  .section-head { align-items: flex-start; }
  .logout-button { padding-right: 9px; padding-left: 9px; }
}
