/* ==========================================================
   Sachet Admin — brand header + data-first layout
   Fonts: Frutiger LT Pro (brand, headings) + Inter (UI, data)
   No framework: everything the admin uses is defined here.
========================================================== */

@font-face {
  font-family: "Inter";
  src: url("../fonts/inter-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Frutiger LT Pro";
  src: url("../fonts/FrutigerLTProRoman.otf") format("opentype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Frutiger LT Pro";
  src: url("../fonts/FrutigerLTProBold.otf") format("opentype");
  font-weight: 700;
  font-display: swap;
}

:root {
  --brand: #fecf15;
  --brand-strong: #e6bb10;
  --navy: #065378;
  --ink: #101828;
  --ink-2: #344054;
  --muted: #667085;
  --line: #e4e7ec;
  --line-soft: #f2f4f7;
  --surface: #ffffff;
  --app-bg: #f5f6f8;

  --ok-bg: #ecfdf3;   --ok-fg: #067647;   --ok-line: #abefc6;
  --bad-bg: #fef3f2;  --bad-fg: #b42318;  --bad-line: #fecdca;
  --mid-bg: #fffaeb;  --mid-fg: #b54708;  --mid-line: #fedf89;
  --idle-bg: #f2f4f7; --idle-fg: #475467; --idle-line: #e4e7ec;

  --radius: 10px;
  --radius-sm: 7px;
  --ring: 0 0 0 3px rgba(6, 83, 120, 0.22);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-raised: 0 4px 14px -4px rgba(16, 24, 40, 0.12), 0 1px 2px rgba(16, 24, 40, 0.05);

  --font-ui: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-brand: "Frutiger LT Pro", "Inter", ui-sans-serif, system-ui, sans-serif;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--app-bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--radius-sm); }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.num { font-variant-numeric: tabular-nums; }

.wrap { max-width: 1320px; margin: 0 auto; padding: 0 24px; }

/* ---------- Brand header ---------- */
.app-header {
  background: var(--brand);
  padding: 12px 0 44px;
  border-bottom: 1px solid rgba(16, 24, 40, 0.06);
}

.app-header .wrap { display: flex; align-items: center; gap: 28px; }

.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; flex-shrink: 0; }
.brand img { height: 30px; width: auto; }
.brand-tag {
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 13px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(16, 24, 40, 0.1);
  white-space: nowrap;
}

.app-nav { display: flex; gap: 4px; }
.app-nav a {
  font-family: var(--font-brand);
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  color: rgba(16, 24, 40, 0.72);
  transition: background-color 0.15s ease, color 0.15s ease;
}
.app-nav a:hover { background: rgba(16, 24, 40, 0.07); color: var(--ink); }
.app-nav a[aria-current="page"] { background: var(--ink); color: #fff; }

.app-user { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 13px; }
.app-user .hello { color: rgba(16, 24, 40, 0.75); white-space: nowrap; }
.app-user .hello strong { color: var(--ink); font-weight: 600; }

.nav-toggle { display: none; }

/* ---------- Page ---------- */
.app-main { margin-top: -30px; padding-bottom: 40px; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-raised);
  overflow: hidden;
}
.stat { padding: 14px 20px; border-left: 1px solid var(--line-soft); min-width: 0; }
.stat:first-child { border-left: 0; }
.stat-label {
  display: flex; align-items: center; gap: 7px;
  color: var(--muted); font-size: 12.5px; font-weight: 500;
}
.stat-label .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--line); flex-shrink: 0; }
.stat-value {
  margin-top: 4px;
  font-size: 26px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.stat-sub { margin-top: 2px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.stat--ok .dot { background: var(--ok-fg); }
.stat--ok .stat-value { color: var(--ok-fg); }
.stat--bad .dot { background: var(--bad-fg); }
.stat--bad .stat-value { color: var(--bad-fg); }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  margin: 24px 0 12px;
}
.page-title {
  margin: 0;
  font-family: var(--font-brand); font-weight: 700;
  font-size: 22px; letter-spacing: -0.01em; line-height: 1.2;
}
.page-meta { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.page-meta strong { color: var(--ink-2); font-weight: 600; }
.page-meta .pill {
  display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px;
  background: #e8f4fa; color: var(--navy); font-size: 12px; font-weight: 600;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px; font-weight: 600; line-height: 1;
  text-decoration: none; white-space: nowrap; cursor: pointer;
  box-shadow: var(--shadow);
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:hover { background: var(--line-soft); color: var(--ink); }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-primary:hover { background: #1d2939; border-color: #1d2939; color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }
.btn-ghost:hover { background: var(--line-soft); }
.btn-dark-outline { background: transparent; border-color: rgba(16, 24, 40, 0.35); color: var(--ink); box-shadow: none; }
.btn-dark-outline:hover { background: rgba(16, 24, 40, 0.08); color: var(--ink); }

/* ---------- Filter bar ---------- */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field > .field-label { font-size: 12px; font-weight: 500; color: var(--muted); }

.input, .select {
  height: 34px; min-width: 0;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 0 10px;
  font-size: 13px; color: var(--ink);
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus, .select:focus { outline: none; border-color: var(--navy); box-shadow: var(--ring); }
.select {
  appearance: none; -webkit-appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  min-width: 170px;
}
.input[type="date"] { width: 148px; }

.date-range { display: flex; align-items: center; gap: 6px; }
.date-range .sep { color: var(--muted); font-size: 12px; }

.quick { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  height: 34px; padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12.5px; font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.chip:hover { background: var(--line-soft); }
.chip[aria-pressed="true"] { background: #e8f4fa; border-color: #9fd3ea; color: var(--navy); font-weight: 600; }

.toggle { display: inline-flex; align-items: center; gap: 9px; height: 34px; cursor: pointer; user-select: none; font-size: 13px; color: var(--ink-2); }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle .track {
  width: 34px; height: 20px; border-radius: 999px; background: #d0d5dd; position: relative; flex-shrink: 0;
  transition: background-color 0.15s ease;
}
.toggle .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(16, 24, 40, 0.2);
  transition: transform 0.15s ease;
}
.toggle input:checked + .track { background: var(--navy); }
.toggle input:checked + .track::after { transform: translateX(14px); }
.toggle input:focus-visible + .track { box-shadow: var(--ring); }

.filter-actions { display: flex; gap: 6px; margin-left: auto; }

/* ---------- Table ---------- */
.table-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table-scroll { overflow-x: auto; }

.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.data th {
  position: sticky; top: 0; z-index: 1;
  text-align: left;
  background: #f9fafb;
  color: var(--muted);
  font-size: 12px; font-weight: 500;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
  vertical-align: middle;
}
.data tbody tr:last-child td { border-bottom: 0; }
.data tbody tr:hover td { background: #fafbfc; }
.data .col-id { color: var(--muted); width: 1%; }
.data .col-muted { color: var(--muted); }
.data .col-url { max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.data .col-url a { text-decoration: none; color: var(--ink); }
.data .col-url a:hover { color: var(--navy); text-decoration: underline; text-underline-offset: 2px; }
.data .empty td { text-align: center; color: var(--muted); padding: 44px 14px; white-space: normal; }

.uid {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12px; color: var(--ink-2);
  background: var(--line-soft); border: 1px solid transparent; border-radius: 6px;
  padding: 2px 7px; cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.uid:hover { border-color: var(--line); background: #fff; }
.uid svg { width: 12px; height: 12px; color: var(--muted); }
.uid.is-copied { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-fg); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; line-height: 1.4;
  border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--ok   { background: var(--ok-bg);   color: var(--ok-fg);   border-color: var(--ok-line); }
.badge--bad  { background: var(--bad-bg);  color: var(--bad-fg);  border-color: var(--bad-line); }
.badge--mid  { background: var(--mid-bg);  color: var(--mid-fg);  border-color: var(--mid-line); }
.badge--idle { background: var(--idle-bg); color: var(--idle-fg); border-color: var(--idle-line); }

/* ---------- Pagination ---------- */
.pager {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px 16px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: #fcfcfd;
  font-size: 13px;
}
.pager-meta { color: var(--muted); }
.pager-meta strong { color: var(--ink); font-weight: 600; }
.pager-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pages { display: flex; gap: 3px; list-style: none; margin: 0; padding: 0; }
.pages a, .pages span {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 9px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2); font-weight: 500; text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.pages a:hover { background: var(--line-soft); color: var(--ink); }
.pages [aria-current="page"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.pages .is-disabled { color: #98a2b3; background: var(--line-soft); border-color: var(--line-soft); }
.pages .gap { border: 0; background: transparent; min-width: 18px; padding: 0; color: var(--muted); }

.jump { display: flex; align-items: center; gap: 6px; color: var(--muted); padding-left: 12px; border-left: 1px solid var(--line); }
.jump .input { width: 64px; text-align: center; padding: 0 6px; height: 32px; -moz-appearance: textfield; }
.jump .input::-webkit-outer-spin-button,
.jump .input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.jump .btn { height: 32px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px);
  background: var(--ink); color: #fff; font-size: 13px; font-weight: 500;
  padding: 9px 14px; border-radius: 8px; box-shadow: var(--shadow-raised);
  opacity: 0; pointer-events: none; transition: opacity 0.18s ease, transform 0.18s ease; z-index: 50;
}
.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 32px 16px;
  background:
    radial-gradient(1100px 520px at 50% -10%, rgba(254, 207, 21, 0.55), transparent 65%),
    var(--app-bg);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-raised);
  overflow: hidden;
}
.login-card .login-brand { background: var(--brand); padding: 22px 28px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.login-card .login-brand img { height: 32px; width: auto; }
.login-body { padding: 26px 28px 28px; }
.login-title { margin: 0 0 4px; font-family: var(--font-brand); font-weight: 700; font-size: 22px; }
.login-sub { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login-body .field { margin-bottom: 14px; }
.login-body .input { height: 40px; width: 100%; font-size: 14px; }
.login-body .btn-primary { width: 100%; height: 42px; font-size: 14px; margin-top: 6px; }
.alert {
  margin-bottom: 16px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--bad-bg); color: var(--bad-fg); border: 1px solid var(--bad-line); font-size: 13px; font-weight: 500;
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .filter-actions { margin-left: 0; }
}

@media (max-width: 860px) {
  .wrap { padding: 0 16px; }
  .app-header { padding-bottom: 40px; }
  .app-header .wrap { flex-wrap: wrap; gap: 10px 16px; }
  .nav-toggle {
    display: inline-flex; margin-left: auto;
    width: 36px; height: 36px; align-items: center; justify-content: center;
    border: 1px solid rgba(16, 24, 40, 0.25); border-radius: var(--radius-sm);
    background: transparent; cursor: pointer;
  }
  .nav-toggle svg { width: 18px; height: 18px; }
  .app-nav, .app-user { display: none; width: 100%; }
  .app-header.is-open .app-nav { display: flex; }
  .app-header.is-open .app-user { display: flex; margin-left: 0; justify-content: space-between; padding-top: 8px; border-top: 1px solid rgba(16, 24, 40, 0.12); }
  .app-nav a { flex: 1; text-align: center; }

  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line-soft); }
  .stat-value { font-size: 22px; }

  .page-head { align-items: center; margin-top: 18px; }
  .page-title { font-size: 19px; }

  .filters { flex-direction: column; align-items: stretch; }
  .select, .date-range { width: 100%; }
  .date-range .input { flex: 1; width: auto; }
  .filter-actions { justify-content: stretch; }
  .filter-actions .btn { flex: 1; }

  .pager { flex-direction: column; align-items: stretch; }
  .pager-controls { justify-content: space-between; }
  .jump { border-left: 0; padding-left: 0; }
}

@media (max-width: 420px) {
  .brand-tag { display: none; }
  .stat { padding: 12px 14px; }
  .stat-value { font-size: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
