/* ==========================================================================
   DSP Bulk Portal — shared styles
   One design system for every page: dark topbar, light cards, blue accent.
   Keep class names stable — templates and page JS depend on them
   (pill ok/bad/warn/queued/info, btn, card, grid, kv, qmark, btn-copy …).
   ========================================================================== */

:root {
  --bg: #f3f5f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --line-soft: #eef2f7;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --accent-strong: #1d4ed8;
  --ok: #16a34a;
  --bad: #dc2626;
  --warn: #d97706;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-md: 0 1px 2px rgba(15, 23, 42, .05), 0 8px 24px -12px rgba(15, 23, 42, .18);
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  margin: 0;
  background:
    radial-gradient(1200px 300px at 70% -180px, rgba(37, 99, 235, .07), transparent 70%),
    var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(37, 99, 235, .18); }

/* --------------------------------------------------------------------------
   Top bar
   -------------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(90deg, #0b1220 0%, #101a30 55%, #14213d 100%);
  color: #fff;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  flex-wrap: wrap;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
  box-shadow: 0 1px 3px rgba(2, 6, 23, .45);
}
.topbar .brand {
  display: inline-flex; align-items: center; gap: 9px;
  font-weight: 700; font-size: 15px; color: #fff; text-decoration: none; white-space: nowrap;
}
.topbar .brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 24px; border-radius: 7px;
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  font-size: 11px; font-weight: 800; letter-spacing: .5px; color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, .45);
}
.mainnav { display: flex; align-items: center; gap: 1px; flex: 1; flex-wrap: wrap; min-width: 0; }
.mainnav a {
  color: #b6c2d6; text-decoration: none; font-size: 12.5px; font-weight: 500;
  padding: 6px 9px; border-radius: 999px; white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}
.mainnav a:hover { background: rgba(255, 255, 255, .09); color: #fff; }
.mainnav a.active { background: rgba(96, 165, 250, .2); color: #fff; }

.topbar .ctx {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; color: #94a3b8; white-space: nowrap;
}
.topbar code {
  background: rgba(255, 255, 255, .1); padding: 1px 6px;
  border-radius: 4px; color: #e2e8f0; font-size: 11px;
}
.topbar .ctx-item a { color: #cbd5e1; text-decoration: none; }
.topbar .ctx-item a:hover { color: #fff; }
.topbar .ctx-item a.active { color: #fff; font-weight: 600; }

/* ADV quick-switcher: native select dressed for the dark topbar (names only) */
.adv-select {
  appearance: none; -webkit-appearance: none;
  background-color: rgba(255, 255, 255, .08);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  border: 1px solid rgba(255, 255, 255, .14);
  color: #e2e8f0;
  border-radius: 999px;
  padding: 3px 26px 3px 12px;
  font-size: 12px;
  font-family: inherit;
  max-width: 200px;
  cursor: pointer;
  transition: background-color .15s ease;
}
.adv-select:hover { background-color: rgba(255, 255, 255, .14); }
.adv-select:focus { outline: none; border-color: rgba(96, 165, 250, .55); }
.adv-select:disabled { opacity: .6; cursor: wait; }
.adv-select option { color: #0f172a; background: #fff; }

.userchip {
  display: inline-flex; align-items: center; gap: 7px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .1);
  padding: 4px 10px 4px 5px; border-radius: 999px;
}
.userchip .avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 999px;
  background: linear-gradient(135deg, #2563eb, #60a5fa);
  color: #fff; font-size: 11px; font-weight: 800;
}
.userchip a { color: #e2e8f0 !important; font-weight: 600; }
.userchip .logout { font-weight: 400 !important; color: #94a3b8 !important; }
.userchip .logout:hover { color: #fff !important; }

.badge { padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; letter-spacing: .4px; }
.badge-dry { background: var(--warn); color: #fff; box-shadow: 0 0 0 3px rgba(217, 119, 6, .25); }
.badge-live { background: var(--ok); color: #fff; box-shadow: 0 0 0 3px rgba(22, 163, 74, .25); }

/* --------------------------------------------------------------------------
   Layout & cards
   -------------------------------------------------------------------------- */
main { max-width: none; width: 100%; margin: 28px 0 0; padding: 0 24px 48px; animation: pageIn .18s ease; }
@keyframes pageIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}
h2 {
  margin: 0 0 10px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.01em;
  overflow: hidden; /* keep floated buttons inside */
}
h2::after {
  content: ""; display: block; width: 34px; height: 3px; margin-top: 8px;
  border-radius: 2px; background: linear-gradient(90deg, var(--accent), #93c5fd);
}
h3 { margin: 22px 0 8px; font-size: 14px; font-weight: 700; color: #334155; }
h4 { margin: 14px 0 8px; font-size: 13.5px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.warn { color: var(--bad); }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .92em;
  background: var(--line-soft);
  border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 5px;
}
h2 code, h3 code { background: transparent; border: 0; padding: 0; }

.tpl-list { list-style: none; padding: 0; }
.tpl-list li { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.tpl-list li:last-child { border-bottom: none; }
.dl {
  display: inline-block;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.dl:hover { text-decoration: underline; }

/* --------------------------------------------------------------------------
   Forms & buttons
   -------------------------------------------------------------------------- */
form label { display: block; margin: 12px 0; font-size: 13px; color: var(--muted); }
form select, form input[type=file], form input[type=text], form input[type=password],
form input[type=number], form input:not([type]) {
  display: block; margin-top: 6px; padding: 8px 11px;
  border: 1px solid #cbd5e1; border-radius: var(--radius-sm);
  font-size: 14px; width: 100%; max-width: 460px;
  background: #fff; color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
form input:focus, form select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}
form button, .btn {
  display: inline-block;
  margin-top: 12px;
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; cursor: pointer;
  text-decoration: none; line-height: 1.35;
  transition: background .15s ease, transform .06s ease, box-shadow .15s ease;
  box-shadow: 0 1px 2px rgba(37, 99, 235, .35);
}
form button:hover, .btn:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
form button:active, .btn:active { transform: translateY(1px); }
form button[disabled], .btn[disabled] { opacity: .55; cursor: wait; }
form button[disabled]:hover { filter: none; background: var(--accent); }
a.btn { margin-top: 0; }
.btn-danger {
  background: var(--bad) !important; border-color: var(--bad) !important;
  box-shadow: 0 1px 2px rgba(220, 38, 38, .35);
}
.btn-danger:hover { background: #b91c1c !important; border-color: #b91c1c !important; }
/* Secondary button for actions that shouldn't compete with the primary one */
.btn-ghost {
  background: #fff; color: var(--accent); border: 1px solid #cbd5e1;
  box-shadow: none;
}
.btn-ghost:hover { background: #f0f6ff; border-color: var(--accent); }

.btn-amazon {
  float: right; background: var(--accent); color: #fff; text-decoration: none;
  padding: 6px 13px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  box-shadow: 0 1px 2px rgba(37, 99, 235, .35);
  transition: background .15s ease;
}
.btn-amazon:hover { background: var(--accent-strong); }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; margin-right: 6px;
  background: var(--line-soft); color: #475569;
  border: 1px solid transparent;
}
.pill.ok { background: #dcfce7; color: #166534; }
.pill.bad { background: #fee2e2; color: #991b1b; }
.pill.warn { background: #fef3c7; color: #92400e; }
.pill.queued { background: #e2e8f0; color: #475569; }
.pill.info { background: #e0f2fe; color: #075985; }

.alert {
  background: #fffbeb; border: 1px solid #fde68a; border-left-width: 4px;
  border-radius: var(--radius-sm); padding: 12px 16px; margin: 12px 0;
  font-size: 13px; color: #92400e;
}
.alert code { background: rgba(146, 64, 14, .1); border: 0; padding: 1px 5px; border-radius: 4px; }

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
table.grid { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 13px; }
table.grid th, table.grid td {
  text-align: left; padding: 9px 12px;
  border-bottom: 1px solid var(--line); vertical-align: top;
}
table.grid th {
  background: #f8fafc; color: var(--muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
}
table.grid { table-layout: auto; }
table.grid tbody tr:nth-child(even) { background: #fafbfd; }
table.grid tbody tr:hover { background: #eff4fb; }
table.grid td code { white-space: nowrap; font-size: 12px; }
table.grid .nowrap { white-space: nowrap; }
table.grid .col-name { min-width: 280px; }
.grid.kv th {
  text-align: right; color: #94a3b8; font-weight: 500;
  text-transform: none; letter-spacing: 0; white-space: nowrap; width: 1%;
}
.grid.kv tbody tr:nth-child(even) { background: transparent; }
.grid.kv tbody tr:hover { background: transparent; }
.grid.kv th, .grid.kv td { padding-top: 7px; padding-bottom: 7px; vertical-align: middle; }
.grid.kv td { padding-right: 24px; }
.grid.kv tbody tr:not(:last-child) td, .grid.kv tbody tr:not(:last-child) th {
  border-bottom: 1px solid var(--line);
}
/* Right-aligned action column (me page adv table): rows with fewer buttons
   stay aligned to the column edge. */
table.grid th.actions, table.grid td.actions { text-align: right; white-space: nowrap; }

pre {
  background: #0f172a; color: #e2e8f0; padding: 10px;
  border-radius: 8px; overflow: auto; margin: 0; font-size: 12px;
}

/* --------------------------------------------------------------------------
   Full-width layout for data-table pages
   -------------------------------------------------------------------------- */
main.wide {
  max-width: 100% !important;
  width: 100% !important;
  margin-top: 28px !important;
  margin-bottom: 0 !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  padding-left: 24px !important;
  padding-right: 24px !important;
}
main.wide .card { width: auto; margin-left: 0; margin-right: 0; }

/* Inline filter form (audiences page) */
form.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
form.inline label { display: inline-flex; align-items: center; gap: 4px; margin: 0; }
form.inline input[type=text] { margin-top: 0; min-width: 260px; }

/* --------------------------------------------------------------------------
   Progress bars (.progress > div; width set by page JS)
   -------------------------------------------------------------------------- */
.progress {
  background: #e2e8f0; border-radius: 999px; height: 10px; overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, .08);
}
.progress > div {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #60a5fa);
  transition: width .4s ease;
}

/* --------------------------------------------------------------------------
   Failure-reason "?" with an instant, sticky hover tooltip
   -------------------------------------------------------------------------- */
.qmark {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin-left: 6px;
  border-radius: 999px; background: var(--bad); color: #fff;
  font-size: 11px; font-weight: 700; cursor: help; vertical-align: middle;
}
.qmark .qmark-tip {
  display: none;
  position: absolute; left: 22px; top: 50%; transform: translateY(-50%);
  z-index: 100; width: 320px;
  background: #1e293b; color: #fff;
  padding: 8px 10px; border-radius: 8px;
  font-size: 12px; font-weight: 400; line-height: 1.45;
  white-space: normal; text-align: left;
  box-shadow: 0 4px 12px rgba(15, 23, 42, .3);
}
.qmark:hover .qmark-tip { display: block; }

/* Small inline copy-to-clipboard button */
.btn-copy {
  border: 1px solid var(--line); background: #f8fafc; color: var(--ink);
  border-radius: 6px; padding: 2px 8px; font-size: 11px; font-weight: 600;
  cursor: pointer; margin-left: 6px; vertical-align: middle;
  transition: background .15s ease;
}
.btn-copy:hover { background: #eef2f7; border-color: #cbd5e1; }
/* Icon-only variant (per-row copy): fixed square so clicking never changes its width */
.btn-copy.icon {
  width: 22px; height: 20px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  overflow: hidden; color: var(--muted);
}
.btn-copy.icon:hover { color: var(--ink); }
.btn-copy.icon.done { color: var(--ok); border-color: #86efac; background: #f0fdf4; }
.btn-copy.icon svg { display: block; width: 12px; height: 12px; }

/* Order plan page */
.row { display: flex; align-items: center; flex-wrap: wrap; }
/* Horizontal button group: even heights, consistent gap, no stray margins */
.btn-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.btn-row form { display: inline; margin: 0; }
.btn-row .btn, .btn-row form button { margin-top: 0; }
.gap-x-2 > * + * { margin-left: 8px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.order-block { margin: 22px 0; padding-top: 14px; border-top: 1px solid var(--line); }
.order-block h4 { margin-top: 0; }

/* --------------------------------------------------------------------------
   Login page
   -------------------------------------------------------------------------- */
main.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: calc(100vh - 56px);
  padding-top: 0;
}
.login-card {
  width: 400px; max-width: calc(100vw - 40px);
  text-align: center;
  padding: 36px 34px 28px;
  box-shadow: var(--shadow-md);
}
.login-card .brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 38px; border-radius: 10px;
  font-size: 15px; font-weight: 800; letter-spacing: .5px;
  margin: 0 auto 14px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(37, 99, 235, .22);
}
.login-card h2 { font-size: 20px; }
.login-card h2::after { margin-left: auto; margin-right: auto; }
.login-card form { text-align: left; margin-top: 14px; }
.login-card form button { width: 100%; margin-top: 18px; padding: 10px; }
.login-card .tips { margin-top: 16px; }

/* --------------------------------------------------------------------------
   Multi-select dropdown (admin user edit: allowed ADV sites)
   -------------------------------------------------------------------------- */
.msel { position: relative; display: inline-block; }
.msel-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 40;
  min-width: 340px;
  max-width: min(480px, 90vw);
  max-height: 300px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 8px 10px;
}
.msel-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 4px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.msel-item:hover { background: var(--line-soft); }
.msel-item input[type="checkbox"] { width: auto; margin: 0; flex: none; }
.msel-name { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; }
.msel-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  border-top: 1px solid var(--line-soft);
  margin-top: 6px;
  padding-top: 6px;
  font-size: 12px;
}

/* Per-row failure list on the upload page (one failed row per line). */
.fail-list { margin-top: 6px; }
.fail-list ol { margin: 4px 0 0; padding-left: 22px; color: #dc2626; font-size: 13px; }
.fail-list li { margin: 3px 0; word-break: break-word; }
