@font-face {
  font-family: "Quicksand";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("fonts/quicksand-latin.woff2") format("woff2");
}

:root {
  --bg: #F5F7FB;
  --card: #FFFFFF;
  --border: #E6EAF2;
  --border-strong: #D5DBE7;
  --text: #0F172A;
  --muted: #5B6577;
  --primary: #3B5BFD;
  --primary-hover: #2F49D8;
  --primary-soft: #EEF2FF;
  --success: #16A34A;
  --success-soft: #DCFCE7;
  --warning: #D97706;
  --warning-soft: #FEF3C7;
  --danger: #DC2626;
  --danger-soft: #FEE2E2;
  --radius: 13.5px;
  --radius-sm: 7.5px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-up: 0 -4px 15px rgba(15, 23, 42, .06);
  --sidebar: 205px;
  --bar-h: 53px; /* sidebar brand block and topbar share one height so their borders line up */
  --content: 1254px;
  --ctl: 34px; /* height of inputs and buttons */
  --ease: 160ms ease;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Quicksand", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
svg { flex: none; }
.ic { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 5.5px; }

/* Thin, quiet scrollbars (page, log, table). */
* { scrollbar-width: thin; scrollbar-color: #C7CEDB transparent; }
::-webkit-scrollbar { width: 7.5px; height: 7.5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #C7CEDB; border-radius: 7.5px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: #A9B3C4; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 9.5px; }
.brand-mark { width: 28.5px; height: 28.5px; object-fit: contain; }
.brand-name { font-weight: 700; font-size: 13.5px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--muted); font-weight: 600; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5.5px;
  min-height: var(--ctl); padding: 0 15px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--card); font-weight: 600; cursor: pointer;
  transition: background var(--ease), border-color var(--ease), box-shadow var(--ease), color var(--ease);
}
.btn:disabled { cursor: not-allowed; opacity: .55; }
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 4px 11.5px rgba(59, 91, 253, .22); }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn.secondary { border-color: var(--border-strong); }
.btn.secondary:hover:not(:disabled) { background: var(--bg); }
.btn.danger { border-color: #FCA5A5; color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 30.5px; height: 30.5px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
  transition: background var(--ease), color var(--ease);
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

/* ---------- forms ---------- */
.field { display: grid; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; }
.input, select.input {
  width: 100%; min-height: var(--ctl); padding: 0 11.5px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--card);
  transition: border-color var(--ease), box-shadow var(--ease);
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 38px; }
.input-wrap .icon-btn { position: absolute; right: 2px; top: 2px; }
.search { position: relative; }
.search .ic { position: absolute; left: 11.5px; top: 9.5px; color: var(--muted); }
.search .input { padding-left: 34px; }
.error { display: flex; gap: 7.5px; align-items: flex-start; color: var(--danger); font-size: 12.5px; font-weight: 500; }
.hint { font-size: 11.5px; color: var(--muted); font-weight: 500; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 23px; }
.login-card { width: 100%; max-width: 342px; display: grid; gap: 13.5px; padding: 26.5px; }
.login-card h1 { font-size: 18px; font-weight: 700; margin-top: 5.5px; }

/* ---------- shell ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  background: var(--card); border-right: 1px solid var(--border);
}
.sidebar .brand { height: var(--bar-h); padding: 0 13.5px; border-bottom: 1px solid var(--border); }
.nav { padding: 11.5px 9.5px; display: grid; gap: 2px; }
.nav-label { font-size: 10px; font-weight: 700; letter-spacing: .06em; color: var(--muted); padding: 0 5.5px 5.5px; }
.nav-item {
  display: flex; align-items: center; gap: 9.5px; min-height: var(--ctl); padding: 0 9.5px; border-radius: var(--radius-sm);
  font-weight: 600; color: var(--text); text-decoration: none;
}
.nav-item.active { background: var(--primary-soft); color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }
.user-wrap { position: relative; margin: auto 9.5px 9.5px; }
.user-card {
  width: 100%; padding: 9.5px; display: flex; align-items: center; gap: 9.5px; text-align: left; cursor: pointer;
  border: 1px solid var(--border); border-radius: 11.5px; background: var(--card);
  transition: background var(--ease), border-color var(--ease);
}
.user-card:hover { background: #F8FAFC; }
.user-card[aria-expanded="true"] { border-color: #C7D2FE; background: var(--primary-soft); }
.user-card .chev { color: var(--muted); transition: transform var(--ease); }
.user-card[aria-expanded="false"] .chev { transform: rotate(180deg); }
.user-meta, .user-name, .user-role { display: block; }
.user-menu {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); z-index: 20; padding: 5px;
  background: var(--card); border: 1px solid var(--border); border-radius: 11.5px; box-shadow: 0 12px 32px rgba(15, 23, 42, .14);
}
.menu-item {
  display: flex; align-items: center; gap: 9.5px; width: 100%; min-height: var(--ctl); padding: 0 10px;
  border: 0; border-radius: 7.5px; background: none; font-weight: 600; cursor: pointer; text-align: left;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--bg); }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover, .menu-item.danger:focus-visible { background: var(--danger-soft); }
.avatar {
  width: 28.5px; height: 28.5px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--primary); color: #fff; font-weight: 700; font-size: 12.5px;
}
.user-meta { min-width: 0; flex: 1; }
.user-name { font-weight: 700; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--muted); font-weight: 600; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 11.5px; height: var(--bar-h); padding: 0 19px;
  background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
.icon-tile {
  position: relative; width: 30.5px; height: 30.5px; border-radius: var(--radius-sm); display: grid; place-items: center; flex: none;
  background: var(--primary-soft); color: var(--primary); border: 1px solid #DCE3FF;
}
.topbar h1 { font-size: 14px; font-weight: 700; line-height: 1.3; }
.topbar p { font-size: 11.5px; color: var(--muted); font-weight: 500; }
.date-chip {
  margin-left: auto; display: inline-flex; align-items: center; gap: 5.5px; padding: 5.5px 11.5px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.date-chip .ic { width: 13.5px; height: 13.5px; color: var(--primary); }

.content { width: 100%; max-width: var(--content); margin: 0 auto; padding: 17px 19px; display: grid; gap: 15px; }
.content > * { min-width: 0; }

/* ---------- step cards ---------- */
.step { padding: 15px 17px 13.5px; }
.step-head { display: flex; gap: 11.5px; align-items: center; padding-bottom: 11.5px; margin-bottom: 11.5px; border-bottom: 1px solid var(--border); }
.step-head .head-right { margin-left: auto; }
.step-title { font-size: 13.5px; font-weight: 700; }
.step-sub { font-size: 11.5px; color: var(--muted); font-weight: 500; }
.step-tools { display: flex; gap: 9.5px; align-items: center; flex-wrap: wrap; margin-bottom: 9.5px; }
.step-tools .search { flex: 1; min-width: 209px; max-width: 399px; }
.toggle { display: inline-flex; gap: 7.5px; align-items: center; font-size: 12px; font-weight: 600; cursor: pointer; min-height: 30.5px; white-space: nowrap; }
input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; margin: 0; }

.camp-empty { padding: 19px; text-align: center; color: var(--muted); font-size: 12.5px; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; font-weight: 700; padding: 2px 7.5px; border-radius: 949px; white-space: nowrap; border: 1px solid transparent; }
.pill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill.success { background: #ECFDF3; border-color: #ABEFC6; color: #067647; }
.pill.neutral { background: #F2F4F7; border-color: #E4E7EC; color: #475467; }
.link-btn { border: 0; background: none; color: var(--primary); font-weight: 600; cursor: pointer; padding: 5.5px 2px; min-height: 30.5px; }

/* ---------- campaign table ---------- */
.table-meta { display: flex; align-items: center; gap: 7.5px; margin-left: auto; font-size: 11.5px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table-meta b { color: var(--text); }
.seg { display: inline-flex; padding: 2px; gap: 2px; border-radius: 7.5px; background: #F2F4F7; border: 1px solid var(--border); }
.seg label { cursor: pointer; position: relative; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.seg span {
  display: grid; place-items: center; min-width: 32.5px; height: 23px; padding: 0 7.5px; border-radius: 5.5px;
  font-size: 11.5px; font-weight: 600; color: var(--muted); transition: background var(--ease), color var(--ease), box-shadow var(--ease);
}
.seg label:hover span { color: var(--text); }
.seg input:checked + span { background: var(--card); color: var(--primary); box-shadow: 0 1px 3px rgba(15, 23, 42, .12); }
.seg input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 1px; }

.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--border); border-radius: 9.5px; }
/* Fixed layout: the campaign column takes what is left, so the table never needs a horizontal scroll on a laptop. */
.camp-table { width: 100%; border-collapse: collapse; font-size: 12.5px; table-layout: fixed; }
.camp-table th {
  text-align: left; padding: 8.5px 9.5px; background: #F8FAFC; border-bottom: 1px solid var(--border);
  font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); white-space: nowrap;
}
.camp-table td { padding: 11px 9.5px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.camp-table .center { text-align: center; }
.camp-table col.c-check { width: 38px; }
.camp-table col.c-id { width: 61px; }
.camp-table col.c-period { width: 171px; }
.camp-table col.c-status { width: 91px; }
.camp-table col.c-unit { width: 224px; }
.camp-table tbody tr:last-child td { border-bottom: 0; }
.camp-table tbody tr { transition: background var(--ease); }
.camp-table tbody tr:hover { background: #FAFBFE; }
.camp-table tbody tr.selected { background: #F6F8FF; }
.camp-table .check label { display: grid; place-items: center; width: 23px; height: 23px; cursor: pointer; }
.id-chip { display: inline-block; padding: 1px 6.5px; border-radius: 5.5px; background: var(--primary-soft); border: 1px solid #DCE3FF; color: var(--primary); font-weight: 700; font-size: 11.5px; font-variant-numeric: tabular-nums; }
.camp-name { font-weight: 700; font-size: 12px; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.camp-meta { font-size: 11px; color: var(--muted); font-weight: 600; }
.nowrap { white-space: nowrap; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 11.5px; margin-top: 5.5px; }
.pager-nav { display: flex; align-items: center; gap: 2px; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.pager-nav .icon-btn:disabled { opacity: .4; cursor: not-allowed; }

/* Loading state: spinner next to the toggle and shimmering placeholder rows. */
.spinner { width: 13px; height: 13px; border-radius: 50%; border: 2px solid #DCE3FF; border-top-color: var(--primary); animation: spin .7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.skel { display: inline-block; height: 10px; border-radius: 6px; vertical-align: middle;
  background: linear-gradient(90deg, #EDF0F5 25%, #F7F8FB 45%, #EDF0F5 65%); background-size: 300% 100%; animation: shimmer 1.2s ease-in-out infinite; }
.skel.block { display: block; }
.skel + .skel { margin-top: 6px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ---------- action bar ---------- */
.actionbar {
  position: sticky; bottom: 0; margin-top: auto; z-index: 5;
  display: flex; align-items: center; gap: 13.5px; padding: 9.5px max(19px, calc((100% - var(--content)) / 2 + 19px));
  background: rgba(255, 255, 255, .96); border-top: 1px solid var(--border); box-shadow: var(--shadow-up);
}
.actionbar .summary { font-size: 12px; color: var(--muted); font-weight: 600; }
.actionbar .actions { margin-left: auto; display: flex; gap: 9.5px; }

/* ---------- progress ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11.5px; }
.kpi { padding: 13.5px 13.5px 11.5px; display: grid; gap: 4px; }
.kpi-head { display: flex; justify-content: space-between; align-items: flex-start; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.kpi-head .icon-tile { width: 26.5px; height: 26.5px; }
.kpi-value { font-size: 21px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.bar { height: 5px; border-radius: 3px; background: var(--border); overflow: hidden; margin-top: 4px; }
.bar > span { display: block; height: 100%; width: 0; background: var(--primary); border-radius: 3px; transition: width 300ms ease; }
.bar.warn > span { background: var(--warning); }
.bar.ok > span { background: var(--success); }

.log-card { padding: 15px 17px; }
.log-card .step-head { margin-bottom: 5.5px; }
.log { list-style: none; margin: 0; padding: 0; max-height: 304px; overflow: auto; display: grid; }
.log li { display: flex; gap: 9.5px; align-items: flex-start; padding: 5.5px 0; border-bottom: 1px dashed var(--border); font-size: 12px; }
.log li:last-child { border-bottom: 0; }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11px; min-width: 55px; }
.dot { width: 6.5px; height: 6.5px; border-radius: 50%; background: var(--primary); margin-top: 5.5px; flex: none; }
.log li.warn .dot { background: var(--warning); }
.log li.error .dot { background: var(--danger); }
.log li.done .dot { background: var(--success); }
.files { display: flex; flex-wrap: wrap; gap: 9.5px; }
.result-banner { display: flex; gap: 9.5px; align-items: center; padding: 9.5px 13.5px; border-radius: 9.5px; font-weight: 600; }
.result-banner.ok { background: var(--success-soft); color: #166534; }
.result-banner.warn { background: var(--warning-soft); color: #92400E; }
.result-banner.error { background: var(--danger-soft); color: #991B1B; }

/* ---------- run dialog ---------- */
.dialog { border: 0; padding: 0; background: transparent; width: min(540px, calc(100vw - 28px)); max-width: none; }
.dialog::backdrop { background: rgba(15, 23, 42, .45); }
.dialog-card { background: var(--card); border-radius: var(--radius); padding: 17px; display: grid; gap: 13px; box-shadow: 0 20px 48px rgba(15, 23, 42, .25); }
.dialog-head { display: flex; gap: 11px; align-items: flex-start; }
.dialog-head .icon-btn { margin-left: auto; }
/* Fixed row height: the list shows at most 5 campaigns, more scroll inside it. */
.run-list { --row: 42px; list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 9.5px; max-height: calc(5 * var(--row) + 2px); overflow-y: auto; }
.run-list li { display: flex; gap: 9.5px; align-items: center; height: var(--row); padding: 0 11px; border-bottom: 1px solid var(--border); font-size: 12px; }
.run-list li:last-child { border-bottom: 0; }
.run-list .name { flex: 1; min-width: 0; font-weight: 700; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 10.5px; font-weight: 700; padding: 2px 7.5px; border-radius: 5.5px; background: var(--primary-soft); color: var(--primary); white-space: nowrap; }
.tag.muted { background: #F2F4F7; color: #475467; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9.5px; flex-wrap: wrap; }
.btn.region { background: #0E9F6E; color: #fff; box-shadow: 0 4px 12px rgba(14, 159, 110, .22); }
.btn.region:hover:not(:disabled) { background: #0B8A5F; }
.files .btn.primary { box-shadow: none; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar .brand { border-bottom: 0; }
  .nav { display: none; }
  .user-wrap { margin: 0 11.5px 0 auto; }
  .user-card { border: 0; padding: 4px; }
  .user-card .user-meta { display: none; }
  .user-menu { bottom: auto; top: calc(100% + 6px); left: auto; width: 180px; } /* bar is at the top here: open downwards */
  .topbar { position: static; padding: 7.5px 15px; height: auto; min-height: var(--bar-h); }
  .table-meta { margin-left: 0; }
  .date-chip { display: none; }
  .content { padding: 13.5px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .actionbar { padding: 9.5px 13.5px; }
  .camp-table { table-layout: auto; } /* narrow screens: let the table scroll inside its card */
}
@media (max-width: 560px) {
  .dialog-actions .btn { flex: 1; }
  .step { padding: 13.5px; }
  .step-head { flex-wrap: wrap; }
  .actionbar .summary { display: none; }
  .actionbar .actions { width: 100%; }
  .actionbar .actions .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
