:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --green: #15803d;
  --red: #dc2626;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow-x: clip;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.auth-body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 410px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
}

.auth-brand, .topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
  text-decoration: none;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--primary);
  display: inline-block;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.topbar-nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
}

.topbar-nav a.active, .topbar-nav a:hover {
  background: #eff6ff;
  color: var(--primary);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-name { font-size: 13px; color: var(--muted); }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 22px 18px 40px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.page-head h1 { margin: 0 0 4px; font-size: 24px; }
.breadcrumb { font-size: 13px; margin-bottom: 4px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
code { background: #e2e8f0; padding: 2px 6px; border-radius: 4px; font-size: 12px; overflow-wrap: anywhere; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 28px; font-weight: 800; line-height: 1.15; }
.kpi-link, .kpi-sub { font-size: 13px; margin-top: 4px; }

.two-col {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  min-width: 0;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.card-head h2 { margin: 0; font-size: 17px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }

.mini-list { display: flex; flex-direction: column; gap: 10px; }
.mini-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.mini-row:last-child { border-bottom: 0; padding-bottom: 0; }
.mini-title { font-weight: 600; }
.mini-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: #f8fafc; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f1f5f9; color: var(--text); }
.btn-danger-ghost { background: transparent; color: var(--red); }
.btn-danger-ghost:hover { background: #fef2f2; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green { background: #dcfce7; color: #166534; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #e2e8f0; color: #334155; }

.tag-warn { color: #b45309; font-weight: 600; }
.tag-ads { display: inline-block; margin-top: 3px; background: #fef3c7; color: #92400e; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 700; }

.color-chip {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  display: inline-block;
  margin-right: 6px;
  vertical-align: middle;
}

.filter-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
}
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.script-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.script-box summary { cursor: pointer; font-weight: 600; color: #1e3a8a; }
.script-body { margin-top: 8px; font-size: 14px; }
.script-body p { margin: 6px 0; }

.activate-banner {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-weight: 600; font-size: 14px; }
.alert-ok { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

.empty-state { padding: 26px 14px; text-align: center; color: var(--muted); }
.action-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline-form { display: inline-flex; gap: 8px; align-items: center; }

.stack-form, .form-section { display: flex; flex-direction: column; gap: 12px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-grid label, .stack-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.form-grid label.full { grid-column: 1 / -1; }
.pair-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid #93c5fd;
  border-color: var(--primary);
}
.color-input { height: 38px; padding: 3px; cursor: pointer; }
.auto-submit-select { width: auto; min-width: 130px; padding: 5px 8px; font-size: 13px; }
.form-foot { display: flex; justify-content: flex-end; margin-top: 8px; }

.ai-box {
  margin-top: 6px;
  padding: 6px 8px;
  background: #eff6ff;
  border-left: 3px solid var(--primary);
  border-radius: 4px;
}

dialog.modal {
  border: 0;
  padding: 0;
  border-radius: 12px;
  width: min(560px, calc(100vw - 24px));
  max-height: 90dvh;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  margin: auto;
}
dialog.modal::backdrop { background: rgba(15, 23, 42, 0.55); }
.modal-box { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.btn-close { border: 0; background: transparent; font-size: 18px; cursor: pointer; color: var(--muted); padding: 4px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-col { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar-inner { padding: 10px 14px; }
  .container { padding: 16px 12px 32px; }
}
