:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --bg-strong: #111827;
  --panel: rgba(255, 255, 255, .9);
  --panel-solid: #ffffff;
  --panel-soft: #f8fafc;
  --text: #111827;
  --muted: #667085;
  --muted-strong: #475467;
  --line: #dbe3ef;
  --line-strong: #cbd5e1;
  --primary: #8b5cf6;
  --primary-dark: #6d28d9;
  --accent: #f59e0b;
  --accent-soft: #fffbeb;
  --info: #0f766e;
  --info-soft: #ecfdf5;
  --danger: #b42318;
  --danger-soft: #fef2f2;
  --shadow: 0 18px 45px rgba(15, 23, 42, .09);
  --shadow-soft: 0 8px 24px rgba(15, 23, 42, .06);
  font-family: "Plus Jakarta Sans", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 12% 0%, rgba(245, 158, 11, .2), transparent 30%),
    radial-gradient(circle at 92% 8%, rgba(139, 92, 246, .2), transparent 34%),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 42%, #eef3f8 100%);
  color: var(--text);
}

body.auth-pending .shell {
  display: none;
}

body.auth-pending .float-nav {
  display: none;
}

body, button, input, select, textarea {
  font: inherit;
}

button, input, select, textarea {
  min-width: 0;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  font-weight: 750;
  cursor: pointer;
  transition: background .18s ease, box-shadow .18s ease, transform .18s ease;
}

button:hover {
  box-shadow: 0 12px 22px rgba(109, 40, 217, .2);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(139, 92, 246, .26);
  outline-offset: 2px;
}

button:disabled {
  cursor: wait;
  opacity: .68;
  transform: none;
}

button.secondary {
  border: 1px solid rgba(139, 92, 246, .22);
  background: #f5f3ff;
  color: var(--primary-dark);
}

button.secondary:hover {
  background: #ede9fe;
  box-shadow: var(--shadow-soft);
}

button.danger {
  border: 1px solid rgba(180, 35, 24, .18);
  background: var(--danger-soft);
  color: var(--danger);
}

button.danger:hover {
  background: #fee4e2;
  box-shadow: var(--shadow-soft);
}

h1, h2, p {
  margin-top: 0;
}

h1 {
  width: 100%;
  max-width: 780px;
  margin-bottom: 0;
  font-size: clamp(36px, 5vw, 64px);
  line-height: 1.02;
  letter-spacing: 0;
  overflow-wrap: break-word;
  word-break: break-word;
}

h2 {
  margin-bottom: 8px;
  font-size: 21px;
  line-height: 1.25;
  letter-spacing: 0;
}

h3 {
  margin: 0 0 8px;
  font-size: 17px;
  line-height: 1.3;
  letter-spacing: 0;
}

p {
  color: var(--muted);
  line-height: 1.65;
  overflow-wrap: anywhere;
}

a {
  color: inherit;
  text-decoration: none;
}

.shell {
  width: min(1320px, calc(100% - 40px));
  margin: 0 auto;
  padding: 24px 0 56px;
}

.hero {
  position: relative;
  overflow: hidden;
  margin-bottom: 22px;
  border: 1px solid rgba(255, 255, 255, .74);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, .96), rgba(255, 255, 255, .74)),
    linear-gradient(135deg, rgba(245, 158, 11, .16), rgba(139, 92, 246, .14));
  box-shadow: var(--shadow);
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(15, 23, 42, .04) 1px, transparent 1px),
    linear-gradient(180deg, rgba(15, 23, 42, .04) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, .65), transparent 78%);
}

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
  border-bottom: 1px solid rgba(219, 227, 239, .72);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: inline-grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: #111827;
  color: #f8fafc;
  font-size: 13px;
  font-weight: 850;
}

.brand-title,
.brand-subtitle {
  display: block;
  min-width: 0;
}

.brand-title {
  color: #111827;
  font-size: 15px;
  font-weight: 850;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.refresh-button {
  flex: 0 0 auto;
}

.topbar-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.nav-tabs {
  display: inline-flex;
  flex: 0 1 auto;
  gap: 4px;
  min-width: 0;
  padding: 4px;
  border: 1px solid rgba(219, 227, 239, .86);
  border-radius: 8px;
  background: rgba(255, 255, 255, .72);
}

button.nav-tab {
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted-strong);
  box-shadow: none;
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
}

button.nav-tab:hover {
  background: #f5f7fb;
  box-shadow: none;
  transform: none;
}

button.nav-tab.active,
button.nav-tab[aria-selected="true"] {
  background: #111827;
  color: #fff;
}

.hero-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, .8fr);
  gap: 28px;
  padding: 34px 34px 38px;
}

.hero-copy {
  width: 100%;
  min-width: 0;
  align-self: center;
  overflow: hidden;
}

.eyebrow,
.section-kicker {
  margin: 0 0 10px;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hero-text {
  width: 100%;
  max-width: 700px;
  margin: 18px 0 0;
  color: var(--muted-strong);
  font-size: 17px;
}

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  min-width: 0;
}

.metric-card {
  min-width: 0;
  min-height: 132px;
  padding: 18px;
  border: 1px solid rgba(219, 227, 239, .82);
  border-radius: 8px;
  background: rgba(255, 255, 255, .72);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(16px);
}

.metric-card.attention {
  background: linear-gradient(135deg, rgba(255, 251, 235, .9), rgba(255, 255, 255, .74));
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.metric-card strong {
  display: block;
  margin-top: 22px;
  font-size: 38px;
  line-height: 1;
  letter-spacing: 0;
}

.workspace {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

[hidden] {
  display: none !important;
}

.view[hidden] {
  display: none;
}

.panel {
  min-width: 0;
  margin-bottom: 16px;
  border: 1px solid rgba(219, 227, 239, .92);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
}

.form-panel {
  padding: 22px;
}

.data-panel {
  padding: 22px;
}

.panel-head {
  margin-bottom: 18px;
}

.panel-head.compact-head {
  margin-bottom: 12px;
}

.panel-head p {
  margin-bottom: 0;
}

.settings-page {
  padding: 24px;
}

.settings-page-head {
  max-width: 760px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.settings-block {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .72);
}

.settings-block.wide {
  grid-column: 1 / -1;
}

.settings-block-head {
  margin-bottom: 16px;
}

.settings-block-head h3,
.settings-subhead h3 {
  margin-bottom: 0;
}

.settings-subhead {
  margin-top: 6px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.settings-note {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid #c7d7fe;
  border-radius: 8px;
  background: #f8fbff;
  color: #24324a;
}

.settings-note strong {
  display: block;
  margin-bottom: 5px;
  font-size: 14px;
}

.settings-note p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.primary-switch {
  margin-top: 2px;
}

.sync-status {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.sync-status.on {
  border: 1px solid #a7f3d0;
  background: #ecfdf5;
  color: #047857;
}

.sync-status.off {
  border: 1px solid #fecaca;
  background: #fff7f7;
  color: #b42318;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  min-width: 0;
  color: #344054;
  font-size: 14px;
  font-weight: 750;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

input, select {
  height: 44px;
  padding: 0 13px;
}

textarea {
  min-height: 150px;
  padding: 12px 13px;
  line-height: 1.55;
  resize: vertical;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  padding: 0;
  accent-color: var(--primary-dark);
}

.switch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 4px 0 14px;
}

.section-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.bulk-rule-bar {
  display: grid;
  grid-template-columns: minmax(120px, .8fr) minmax(140px, .9fr) minmax(220px, 1.4fr) minmax(92px, .6fr) auto auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}

.bulk-rule-bar label {
  margin-bottom: 0;
}

.bulk-rule-bar .checkbox-label {
  min-height: 44px;
  align-content: center;
}

.bulk-rule-edit-bar {
  display: grid;
  grid-template-columns: minmax(112px, .8fr) auto minmax(180px, 1.2fr) auto minmax(84px, .55fr) auto minmax(98px, .65fr) auto minmax(112px, .7fr) auto auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  margin: 0 0 12px;
  border: 1px solid rgba(139, 92, 246, .22);
  border-radius: 8px;
  background: #f5f3ff;
}

.bulk-rule-edit-bar[hidden] {
  display: none;
}

.bulk-rule-edit-bar label,
.bulk-rule-edit-bar .summary-line {
  margin-bottom: 0;
}

.bulk-rule-quick-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.bulk-rule-edit-bar .checkbox-label {
  min-height: 44px;
  align-content: center;
  color: var(--primary-dark);
  font-weight: 850;
}

.select-col {
  width: 48px;
}

.rule-select,
#ruleSelectAllVisible {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.segmented-control {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 0;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

button.segment {
  min-height: 34px;
  width: auto;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted-strong);
  box-shadow: none;
  font-size: 13px;
  font-weight: 850;
}

button.segment:hover {
  background: #fff;
  box-shadow: none;
  transform: none;
}

button.segment.active,
button.segment[aria-selected="true"] {
  background: #111827;
  color: #fff;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.settings-form {
  display: grid;
  gap: 12px;
}

.threshold-editor {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(219, 227, 239, .9);
  border-radius: 8px;
  background: #f8fafc;
}

.threshold-editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.threshold-editor-head strong {
  display: block;
  margin-bottom: 4px;
  color: #0f172a;
}

.threshold-editor-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.threshold-rows {
  display: grid;
  gap: 8px;
}

.threshold-row {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) minmax(160px, 220px);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid rgba(226, 232, 240, .95);
  border-radius: 8px;
  background: #fff;
}

.threshold-row-title {
  min-width: 0;
}

.threshold-row-title strong {
  display: block;
  color: #111827;
  overflow-wrap: break-word;
}

.threshold-row-title span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.threshold-row input {
  width: 100%;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  width: min(430px, 100%);
  padding: 26px;
  border: 1px solid rgba(219, 227, 239, .92);
  border-radius: 8px;
  background: var(--panel-solid);
  box-shadow: var(--shadow);
}

.login-card h1 {
  max-width: none;
  margin-bottom: 12px;
  font-size: 28px;
  line-height: 1.15;
}

.login-error {
  padding: 10px 12px;
  border: 1px solid #fecdd3;
  border-radius: 8px;
  margin-bottom: 14px;
  color: #be123c;
  background: #fff1f2;
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: break-word;
}

.login-error[hidden] {
  display: none;
}

input::placeholder {
  color: #98a2b3;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--line-strong);
}

input[readonly] {
  background: #f2f4f7;
  color: var(--muted-strong);
  cursor: not-allowed;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(139, 92, 246, .13);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 6px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: -4px 0 16px;
}

.filter-label {
  flex: 0 0 auto;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 800;
}

.filters-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

button.filter {
  min-height: 36px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted-strong);
  box-shadow: none;
}

button.filter:hover,
button.filter.active {
  border-color: rgba(139, 92, 246, .3);
  background: #f5f3ff;
  color: var(--primary-dark);
  box-shadow: var(--shadow-soft);
}

.filter-field {
  align-content: start;
}

.quick-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.quick-options button.filter {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.filter-options-panel {
  display: grid;
  gap: 12px;
  margin: 10px 0 12px;
}

.email-template-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 250, 252, .78);
}

.compact-template-head {
  margin: 0;
  padding-top: 0;
  border-top: 0;
}

.template-variable-panel {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.template-tabs {
  justify-content: flex-start;
}

.template-variable-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.template-variable-buttons button {
  width: auto;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted-strong);
  box-shadow: none;
  font-size: 12px;
}

.template-preview {
  min-height: 120px;
  padding: 14px;
  border: 1px solid #c7d7fe;
  border-radius: 8px;
  background: #fff;
  color: #1f2937;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.filter-option-group {
  display: grid;
  gap: 8px;
}

.filter-option-title {
  color: #344054;
  font-size: 13px;
  font-weight: 850;
}

.filter-option-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.filter-option-buttons button.filter {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.category-tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef2ff;
  color: #4338ca;
  font-size: 12px;
  font-weight: 850;
}

.category-tag.claud {
  background: #fff7ed;
  color: #c2410c;
}

.category-tag.other {
  background: #f2f4f7;
  color: #475467;
}

.group-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #ecfdf5;
  color: #047857;
  font-size: 12px;
  font-weight: 850;
}

.group-badge.muted-badge {
  background: #f2f4f7;
  color: #475467;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
}

.source-badge.newapi {
  background: #eef2ff;
  color: #4338ca;
}

.source-badge.sub2api {
  background: #fff7ed;
  color: #c2410c;
}

.source-badge.invalid {
  margin-left: 6px;
  background: #f2f4f7;
  color: #667085;
}

.source-badge.recharge-on {
  background: #ecfdf3;
  color: #027a48;
}

.source-badge.recharge-off {
  background: #fff1f3;
  color: #c01048;
}

.source-site {
  display: inline-flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  white-space: nowrap;
}

.source-site .site-link,
.source-site-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr) minmax(260px, 1.6fr) minmax(120px, 1fr) minmax(90px, .7fr) auto auto;
  gap: 10px;
  min-width: min(100%, 960px);
}

.inline-form input,
.inline-form select {
  height: 42px;
  min-width: 0;
}

.inline-form textarea {
  min-height: 42px;
  resize: vertical;
  min-width: 0;
}

.inline-form select[multiple] {
  height: 96px;
}

.category-main-group-picker {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.category-main-group-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  max-height: 118px;
  overflow: auto;
}

.category-main-group-choice {
  width: auto;
  min-height: 30px;
  min-width: 0;
  padding: 0 10px;
  border-color: #cbd5e1;
  background: #fff;
  color: #344054;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.category-main-group-choice.active {
  border-color: rgba(109, 40, 217, .32);
  background: #eef2ff;
  color: #4338ca;
}

.category-main-group-choice[data-platform*="anthropic"].active,
.category-main-group-choice[data-platform*="claude"].active {
  border-color: rgba(194, 65, 12, .28);
  background: #fff7ed;
  color: #c2410c;
}

.category-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.category-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-height: 40px;
  padding: 6px 8px 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.category-chip strong,
.site-link {
  min-width: 0;
  overflow-wrap: anywhere;
}

.category-actions {
  display: inline-flex;
  gap: 6px;
}

.category-main-group-tags {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 0;
}

.panel-divider {
  height: 1px;
  margin: 24px 0;
  background: var(--line);
}

.summary-line {
  margin: 14px 0 10px;
}

.summary-line.success {
  color: #166534;
}

.summary-line.warning {
  color: #92400e;
}

.compact-list {
  display: grid;
  gap: 6px;
  margin: 8px 0 0;
  padding-left: 18px;
}

.cheapest-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 12px 0 4px;
}

.cheapest-card {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.cheapest-card strong,
.cheapest-card span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.cheapest-rate {
  color: var(--info);
  font-size: 22px;
  font-weight: 900;
}

.category-actions button,
.table-actions button {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 180px;
}

.site-link {
  color: var(--primary-dark);
  font-weight: 850;
  text-decoration: underline;
  text-decoration-color: rgba(109, 40, 217, .28);
  text-underline-offset: 3px;
}

.site-link:hover {
  color: #4c1d95;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

.compact-table {
  margin-top: 14px;
}

.table-controls,
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
}

.table-controls[hidden],
.pager[hidden] {
  display: none;
}

.table-search {
  flex: 1 1 260px;
  min-width: 0;
}

.table-page-size {
  width: 150px;
}

.pager {
  justify-content: flex-end;
}

.pager-info {
  color: var(--muted);
  font-size: 13px;
}

.pager button {
  width: auto;
  min-height: 32px;
  padding: 0 10px;
}

.compact-table table {
  min-width: 760px;
}

th, td {
  padding: 14px 16px;
  border-bottom: 1px solid #edf1f7;
  text-align: left;
  vertical-align: top;
  overflow-wrap: break-word;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
  color: #667085;
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0;
}

th[data-sort] {
  cursor: pointer;
  user-select: none;
}

th[data-sort]::after {
  content: "↕";
  display: inline-block;
  margin-left: 6px;
  color: #98a2b3;
  font-size: 11px;
}

th[data-sort].sorted-asc::after {
  content: "↑";
  color: var(--primary-dark);
}

th[data-sort].sorted-desc::after {
  content: "↓";
  color: var(--primary-dark);
}

td {
  color: #344054;
  font-size: 14px;
}

tbody tr {
  transition: background .16s ease;
}

tbody tr:hover {
  background: #fbfdff;
}

tr:last-child td {
  border-bottom: 0;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(15, 118, 110, .16);
  border-radius: 999px;
  background: var(--info-soft);
  color: var(--info);
  font-size: 12px;
  font-weight: 850;
}

.status.disabled {
  border-color: rgba(102, 112, 133, .18);
  background: #f2f4f7;
  color: var(--muted);
}

.site-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.site-item {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f9fbfd);
}

.site-title {
  min-width: 0;
  color: var(--text);
  font-weight: 850;
  overflow-wrap: break-word;
}

.site-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.site-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.muted {
  color: var(--muted);
  overflow-wrap: break-word;
}

.error {
  padding: 10px 12px;
  border: 1px solid rgba(180, 35, 24, .16);
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  overflow-wrap: break-word;
}

.empty-state {
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.app-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 22px;
  padding: 16px 12px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.app-footer a {
  color: var(--primary-dark);
  font-weight: 800;
  text-decoration: underline;
  text-decoration-color: rgba(109, 40, 217, .28);
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.float-nav {
  position: fixed;
  right: 16px;
  bottom: 18px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: min(148px, calc(100vw - 24px));
  padding: 8px;
  border: 1px solid rgba(219, 227, 239, .92);
  border-radius: 8px;
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 16px 42px rgba(15, 23, 42, .16);
  backdrop-filter: blur(12px);
}

.float-nav button {
  width: 100%;
  min-height: 31px;
  padding: 0 10px;
  border-radius: 7px;
  font-size: 12px;
  white-space: nowrap;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  max-width: min(420px, calc(100vw - 40px));
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 8px;
  background: #111827;
  color: white;
  box-shadow: 0 18px 50px rgba(15, 23, 42, .28);
  overflow-wrap: break-word;
}

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

@media (max-width: 980px) {
  .hero-grid,
  .workspace,
  .settings-grid,
  .site-list,
  .bulk-rule-bar,
  .bulk-rule-edit-bar {
    grid-template-columns: 1fr;
  }

  .hero-grid {
    gap: 22px;
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 24px, 1320px);
    padding-top: 12px;
    padding-bottom: 92px;
  }

  .topbar,
  .row {
    align-items: stretch;
    flex-direction: column;
  }

  .nav-tabs {
    width: 100%;
  }

  button.nav-tab {
    flex: 1 1 0;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .settings-note {
    flex-direction: column;
    align-items: stretch;
  }

  .threshold-row {
    grid-template-columns: 1fr;
  }

  .sync-status {
    width: fit-content;
  }

  .topbar-actions button {
    flex: 1 1 130px;
  }

  .hero-grid {
    padding: 24px 18px 22px;
    min-width: 0;
  }

  h1 {
    max-width: 11em;
    font-size: 28px;
    line-height: 1.14;
    word-break: break-all;
  }

  .hero-metrics,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .hero-text {
    max-width: 22em;
    font-size: 14px;
    line-height: 1.7;
  }

  .metric-card {
    min-height: 104px;
  }

  .metric-card strong {
    margin-top: 14px;
    font-size: 32px;
  }

  .form-panel,
  .data-panel,
  .settings-page,
  .settings-block {
    padding: 16px;
  }

  .site-header {
    align-items: stretch;
    flex-direction: column;
  }

  .site-actions,
  .actions,
  .category-actions {
    justify-content: flex-start;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }

  button.nav-tab,
  button.segment {
    width: auto;
  }

  .table-controls,
  .pager {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-line,
  .table-page-size,
  .table-refresh {
    width: 100%;
  }

  .responsive-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .responsive-table {
    min-width: 0;
  }

  .responsive-table thead {
    display: none;
  }

  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }

  .responsive-table tbody {
    display: grid;
    gap: 12px;
  }

  .responsive-table tr {
    min-width: 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel-solid);
    box-shadow: var(--shadow-soft);
  }

  .responsive-table tr:hover {
    background: var(--panel-solid);
  }

  .responsive-table td {
    display: grid;
    grid-template-columns: minmax(72px, 28%) minmax(0, 1fr);
    gap: 10px;
    min-width: 0;
    padding: 8px 4px;
    border-bottom: 1px solid #edf1f7;
    font-size: 13px;
  }

  .responsive-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 850;
  }

  .responsive-table td:last-child {
    border-bottom: 0;
  }

  .responsive-table td.empty-state {
    display: block;
    padding: 18px 10px;
  }

  .responsive-table td.empty-state::before {
    content: none;
  }

  .responsive-table .source-site {
    flex-wrap: wrap;
    white-space: normal;
  }

  .responsive-table .source-site .site-link,
  .responsive-table .source-site-name {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .responsive-table .table-actions {
    min-width: 0;
  }

  .responsive-table .table-actions button {
    flex: 1 1 88px;
    width: auto;
  }

  .float-nav {
    left: 12px;
    right: 12px;
    bottom: 10px;
    flex-direction: row;
    max-width: none;
    overflow-x: auto;
    padding: 7px;
  }

  .float-nav button {
    flex: 0 0 auto;
    width: auto;
  }

  .toast {
    right: 12px;
    bottom: 66px;
    max-width: calc(100vw - 24px);
  }
}