:root {
  --bg: #0a0b0e;
  --surface: #0f1115;
  --surface-2: #14171d;
  --surface-3: #1a1e25;
  --border: rgba(255, 255, 255, 0.06);
  --border-strong: rgba(255, 255, 255, 0.12);
  --divider: rgba(255, 255, 255, 0.04);

  --text: #e7ebf0;
  --text-muted: #8b93a1;
  --text-dim: #5b6371;

  --accent: #d4af52;
  --accent-soft: rgba(212, 175, 82, 0.12);
  --accent-muted: rgba(212, 175, 82, 0.6);

  --green: #3fb985;
  --green-soft: rgba(63, 185, 133, 0.12);
  --red: #eb6f6f;
  --red-soft: rgba(235, 111, 111, 0.12);
  --amber: #e8a744;
  --amber-soft: rgba(232, 167, 68, 0.14);
  --blue: #6d8bff;
  --blue-soft: rgba(109, 139, 255, 0.14);

  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-feature-settings: "ss01", "cv11";
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }
button, select, input { font-family: inherit; font-size: inherit; color: inherit; }
::selection { background: var(--accent-soft); color: var(--accent); }

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

/* =========================================================
   Gate
   ========================================================= */
.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px 20px;
  background: var(--bg);
}
.gate-card {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  padding: 36px 32px 28px;
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 380px;
  box-shadow: 0 1px 0 rgba(255,255,255,0.02) inset, 0 20px 40px -20px rgba(0,0,0,0.5);
}
.gate-logo {
  height: 56px;
  width: auto;
  display: block;
  margin: 0 auto 20px;
  object-fit: contain;
}
.gate-brand {
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.2px;
  text-align: center;
  color: var(--text);
  margin-bottom: 4px;
}
.gate-sub {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  margin-bottom: 28px;
}
.gate-card label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin: 16px 0 6px;
  font-weight: 500;
}
.gate-card input {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.gate-card input:focus {
  border-color: var(--accent-muted);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.gate-card button {
  margin-top: 20px;
  width: 100%;
  padding: 10px 14px;
  background: var(--accent);
  color: #14100a;
  border: 0;
  border-radius: var(--r-md);
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  transition: filter .12s ease;
}
.gate-card button:hover { filter: brightness(1.06); }
.gate-card button:disabled { opacity: 0.6; cursor: wait; }
.gate-err {
  color: var(--red);
  font-size: 12.5px;
  margin: 12px 0 0;
  min-height: 16px;
  text-align: center;
}
.gate-foot {
  text-align: center;
  color: var(--text-dim);
  font-size: 11px;
  margin-top: 20px;
}

/* =========================================================
   App shell
   ========================================================= */
.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 32px 60px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.2px;
}
.brand-mark {
  height: 34px;
  width: auto;
  display: block;
  object-fit: contain;
}
.brand-sub {
  display: block;
  font-weight: 400;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0;
  text-transform: none;
  margin-top: 1px;
}

.controls { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.controls select,
.controls input[type="search"] {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 7px 10px;
  font-size: 13px;
  transition: border-color .12s ease, background .12s ease;
}
.controls select:hover,
.controls input[type="search"]:hover { border-color: var(--border-strong); }
.controls select:focus,
.controls input[type="search"]:focus {
  outline: none;
  border-color: var(--accent-muted);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.controls input[type="search"] { min-width: 220px; }
.controls select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 28px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'><path fill='%238b93a1' d='M6 8 2 4h8z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .1s ease, border-color .1s ease;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-primary {
  background: var(--accent);
  color: #14100a;
  border-color: var(--accent);
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.06); background: var(--accent); border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
.small { padding: 4px 10px; font-size: 12px; }

/* =========================================================
   KPIs
   ========================================================= */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 20px;
}
@media (max-width: 1199px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 780px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px 18px;
  transition: border-color .15s ease;
}
.kpi:hover { border-color: var(--border-strong); }
.kpi-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
}
.kpi-value {
  font-size: 26px;
  font-weight: 600;
  margin-top: 4px;
  color: var(--text);
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

/* =========================================================
   Grid + cards
   ========================================================= */
.grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}
@media (max-width: 980px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px 20px;
  margin-bottom: 14px;
}
.card-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  letter-spacing: -0.1px;
  margin-bottom: 14px;
}
.card-title > span:first-child { flex: 1; }
.card-wide { min-height: 240px; }

/* =========================================================
   Mini table (properties)
   ========================================================= */
.mini-table { display: grid; gap: 2px; font-size: 13px; }
.mini-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto;
  gap: 8px;
  padding: 10px 12px;
  background: transparent;
  border-bottom: 1px solid var(--divider);
  align-items: center;
}
.mini-row:first-child { border-top: 1px solid var(--divider); }
.mini-row:hover { background: var(--surface-2); }
.mini-row .mt-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.mini-row .mt-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-3);
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.2px;
  font-variant-numeric: tabular-nums;
}
.mini-row .mt-bad { background: var(--red-soft); color: var(--red); }
.mini-row .mt-good { background: var(--green-soft); color: var(--green); }

/* =========================================================
   Insights
   ========================================================= */
.insights {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (max-width: 780px) { .insights { grid-template-columns: 1fr; } }
.insight-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px 16px;
}
.insight-block h4 {
  margin: 0 0 10px;
  font-size: 11.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
}
.insight-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--divider);
  font-size: 13px;
}
.insight-row:last-child { border-bottom: 0; }
.insight-row .ir-name { font-weight: 500; color: var(--text); }
.insight-row .ir-meta { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.insight-empty {
  color: var(--text-dim);
  font-style: normal;
  padding: 4px 0;
  font-size: 13px;
}

/* =========================================================
   Activity table
   ========================================================= */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}
.table-wrap::-webkit-scrollbar { height: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  padding: 10px 14px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--divider);
}
tbody tr:last-child td { border-bottom: 0; }
th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  background: var(--surface-2);
  position: sticky;
  top: 0;
}
th:hover { color: var(--text); }
tbody tr { transition: background .08s ease; }
tbody tr:hover td { background: var(--surface-2); }
td .snippet {
  color: var(--text-muted);
  max-width: 380px;
  display: block;
  line-height: 1.45;
}
td .pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-3);
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.2px;
  text-transform: capitalize;
}
.pill-sent { background: var(--green-soft) !important; color: var(--green) !important; }
.pill-draft { background: var(--blue-soft) !important; color: var(--blue) !important; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1px;
  white-space: nowrap;
}
.status-badge.pill-sent { background: var(--green-soft); color: var(--green); border: 1px solid rgba(63, 185, 133, 0.3); }
.status-badge.pill-draft { background: var(--blue-soft); color: var(--blue); border: 1px solid rgba(109, 139, 255, 0.3); }
td .rating {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
td .rating-low { color: var(--red); }
td .rating-mid { color: var(--amber); }

.foot {
  color: var(--text-dim);
  font-size: 11.5px;
  text-align: center;
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

/* =========================================================
   Scrollbar (global)
   ========================================================= */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); }
