:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #eef2f5;
  --line: #d8e0e6;
  --text: #17212b;
  --muted: #647386;
  --primary: #176b87;
  --primary-dark: #10566d;
  --danger: #b42318;
  --ok: #167348;
  --warn: #8a6115;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 1120px;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

button, input, select, textarea { font: inherit; }
button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  padding: 0 10px;
  cursor: pointer;
}
button:hover { border-color: #9dafbc; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.danger { color: var(--danger); border-color: #e3ada7; }
button:disabled { opacity: .55; cursor: not-allowed; }

input, select, textarea {
  width: 100%;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 6px 8px;
  outline: none;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 135, .12);
}
label { display: grid; gap: 5px; color: var(--muted); }
h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; min-width: 220px; }
.brand strong { font-size: 20px; }
.brand span, .session { color: var(--muted); }
.session { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.shell { display: grid; grid-template-columns: 184px 1fr; min-height: calc(100vh - 58px); }
body.login-mode .shell { display: block; }
body.login-mode .sidebar { display: none; }
body.login-mode .content { padding: 0; }
body.login-mode #appView { display: none !important; }
body.app-mode #loginView { display: none !important; }
.sidebar {
  padding: 12px;
  background: #e9eef2;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.nav { text-align: left; background: transparent; border-color: transparent; }
.nav.active { background: var(--surface); border-color: var(--line); color: var(--primary); }
.content { padding: 16px; overflow: auto; }

.login-view {
  position: fixed;
  inset: 58px 0 0;
  z-index: 4;
  min-height: calc(100vh - 58px);
  display: grid;
  place-items: center;
  background: var(--bg);
}
.login-box {
  width: 360px;
  display: grid;
  gap: 14px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.page { display: grid; gap: 12px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toolbar, .filters, .row-actions, .pagination, .tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.filters { padding: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.filters label { width: 170px; }
.filters .wide { width: 260px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.table-scroll {
  max-width: 100%;
  max-height: min(64vh, 720px);
  overflow-x: auto;
  overflow-y: auto;
}
.panel-head {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.panel-body { padding: 12px; }
.stats { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: 10px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.stat span { display: block; color: var(--muted); }
.stat strong { display: block; margin-top: 4px; font-size: 22px; }

table { width: 100%; border-collapse: collapse; table-layout: fixed; }
table.has-actions { min-width: 1280px; }
#deviceTable { min-width: 1880px; }
#phoneTable { min-width: 1680px; }
#batchTable, #linkTable { min-width: 1560px; }
#supplierTable { min-width: 1380px; }
#configTable { min-width: 1320px; }
#parserConfigTable { min-width: 1680px; }
.dashboard-address-list { max-height: 360px; }
.dashboard-address-table { min-width: 920px; }
.dashboard-address-table th:last-child,
.dashboard-address-table td:last-child { width: 76px; }
.dashboard-address-table .address-cell { max-width: 0; }
th, td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sms-content-cell {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  vertical-align: top;
}
.sms-content-text {
  max-height: 96px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.45;
}
th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: #3d4a58;
  font-weight: 650;
}
.table-sort {
  width: 100%;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
}
.table-sort:hover, .table-sort.active { color: var(--accent); background: transparent; }
.table-sort span:last-child { color: var(--muted); font-size: 11px; }
.table-sort.active span:last-child { color: var(--accent); }
tr:hover td { background: #f8fafb; }
.check-cell { width: 38px; }
.op-cell {
  width: 320px;
  min-width: 320px;
  max-width: 320px;
  overflow: visible;
  white-space: nowrap;
}
.op-cell button { margin-right: 4px; }
table.has-actions th:last-child,
table.has-actions td.op-cell {
  position: sticky;
  right: 0;
  z-index: 2;
  box-shadow: -1px 0 0 var(--line);
}
table.has-actions th:last-child {
  z-index: 3;
  width: 320px;
  min-width: 320px;
  max-width: 320px;
}
table.has-actions td.op-cell { background: var(--surface); }
table.has-actions tr:hover td.op-cell { background: #f8fafb; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; }
.muted { color: var(--muted); }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.danger-text { color: var(--danger); }
.badge { display: inline-block; padding: 2px 7px; border-radius: 999px; background: var(--surface-soft); }
.badge.expired { color: var(--danger); }
.grid { display: grid; gap: 10px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }
.span4 { grid-column: span 4; }
.hidden { display: none !important; }

.section-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 6px;
}
.section-title span { color: var(--muted); }
.help-box {
  padding: 10px 12px;
  border: 1px solid #bfd7e2;
  border-radius: 8px;
  background: #f4fbfd;
  color: #284556;
}
.help-box strong { color: var(--primary); }
.parser-advanced {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.parser-advanced summary {
  width: fit-content;
  cursor: pointer;
  color: var(--primary);
  font-weight: 600;
}
.parser-advanced label { margin-top: 10px; }
label small {
  color: var(--muted);
  line-height: 1.35;
}
.check-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}
.check-line {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
}
.check-line input {
  width: auto;
  min-height: 0;
}
.result-box {
  min-height: 160px;
  max-height: 320px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
  white-space: pre-wrap;
}

.pagination { justify-content: space-between; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.pagination span { color: var(--muted); }
.pagination-selection, .pagination-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pagination label { display: flex; align-items: center; gap: 5px; }
.pagination select { width: 72px; min-height: 32px; }
.pagination input[type="number"] { width: 72px; min-height: 32px; }
.page-check, .check-cell input[type="checkbox"] { width: 18px; min-height: 18px; }

dialog {
  width: min(980px, calc(100vw - 80px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}
dialog::backdrop { background: rgba(20, 31, 42, .35); }
.dialog-box { margin: 0; }
.dialog-head, .dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
.dialog-actions { border-top: 1px solid var(--line); border-bottom: 0; justify-content: flex-end; }
#dialogBody { padding: 12px; display: grid; gap: 10px; max-height: 70vh; overflow: auto; }
dialog:has(.parser-main-grid) { width: min(1420px, calc(100vw - 40px)); }
.parser-main-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.parser-main-grid .span3 { grid-column: span 3; }
.parser-edit-table { min-width: 1120px; table-layout: auto; }
.parser-edit-table th, .parser-edit-table td { overflow: visible; white-space: normal; }
.parser-edit-table input, .parser-edit-table select { min-width: 140px; }
.parser-edit-table td:last-child { width: 72px; }
.section-title button { margin-left: auto; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 10;
  max-width: 440px;
  padding: 10px 12px;
  background: #14212c;
  color: #fff;
  border-radius: 8px;
}
.toast.ok { background: var(--ok); }
.toast.error { background: var(--danger); }

@media (max-width: 800px) {
  body { min-width: 0; }
  .topbar {
    height: auto;
    min-height: 58px;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 8px;
  }
  .brand { min-width: 0; }
  .brand span { display: none; }
  .shell {
    display: block;
    min-height: calc(100vh - 98px);
  }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 4;
    flex-direction: row;
    overflow-x: auto;
    padding: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav { flex: 0 0 auto; }
  .content {
    min-width: 0;
    padding: 8px;
    overflow: visible;
  }
  .login-view {
    position: static;
    min-height: calc(100vh - 112px);
  }
  .login-box { width: min(360px, calc(100vw - 24px)); }
  .page, .panel, .filters, .pagination { min-width: 0; max-width: 100%; }
  .page-head { align-items: flex-start; flex-wrap: wrap; }
  .page-head .toolbar { width: 100%; }
  .filters label, .filters .wide { width: auto; flex: 1 1 145px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-scroll { max-width: calc(100vw - 18px); }
  .pagination { align-items: flex-start; }
  .pagination-selection, .pagination-nav { max-width: 100%; }
  .grid.two, .grid.three, .grid.four, .grid.five,
  .parser-main-grid, .check-grid { grid-template-columns: minmax(0, 1fr); }
  .span2, .span3, .span4, .parser-main-grid .span3 { grid-column: auto; }
  dialog, dialog:has(.parser-main-grid) {
    width: calc(100vw - 16px);
    max-width: calc(100vw - 16px);
  }
  #dialogBody { max-height: 72vh; }
  .toast { right: 8px; bottom: 8px; max-width: calc(100vw - 16px); }
}
