/* Stats Cabinet
   Login: design-taste dark-tech · VARIANCE 5 / MOTION 3 / DENSITY 2
   Cabinet: emil-design-eng micro-interactions
*/

:root {
  --bg: #0b0d0f;
  --bg-elev: #12161a;
  --bg-soft: #181d22;
  --line: #273028;
  --line-soft: rgba(157, 255, 168, 0.12);
  --text: #e7eee8;
  --muted: #839087;
  --accent: #9dffa8;
  --accent-dim: #6bcf7a;
  --danger: #ff8f8f;
  --warn: #e6c07b;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

html {
  scrollbar-gutter: stable;
}

body {
  background-image:
    radial-gradient(1200px 600px at 10% -10%, rgba(157, 255, 168, 0.06), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(70, 110, 90, 0.12), transparent 50%),
    linear-gradient(180deg, #0b0d0f 0%, #0e1210 100%);
  background-attachment: fixed;
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ——— Login ——— */
.login-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(72px, 18vw) minmax(0, 1fr);
}

.login-rail {
  border-right: 1px solid var(--line);
  background:
    repeating-linear-gradient(
      180deg,
      transparent 0 10px,
      rgba(157, 255, 168, 0.035) 10px 11px
    ),
    linear-gradient(180deg, #101512, #0b0d0f);
  position: relative;
}

.login-rail::after {
  content: "";
  position: absolute;
  inset: auto 18% 18% 18%;
  height: 120px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  box-shadow: inset 0 0 40px rgba(157, 255, 168, 0.05);
}

.login-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
  padding: 48px 28px;
  animation: panel-in 280ms var(--ease-out) both;
}

@keyframes panel-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 28px;
}

.brand-kicker {
  margin: 0 0 4px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-dim);
}

.login-brand h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: linear-gradient(160deg, #1a221c, #101412);
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  padding: 10px 9px;
}

.brand-mark span {
  display: block;
  height: 3px;
  border-radius: 99px;
  background: var(--accent);
  opacity: 0.9;
}

.brand-mark span:nth-child(2) { width: 70%; opacity: 0.55; }
.brand-mark span:nth-child(3) { width: 42%; opacity: 0.3; }
.brand-mark.sm { width: 34px; height: 34px; padding: 8px 7px; border-radius: 9px; }

.login-lede {
  margin: 0 0 28px;
  color: var(--muted);
  max-width: 32ch;
}

.login-form { display: grid; gap: 14px; }

.field { display: grid; gap: 7px; }
.field span {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  border-radius: 10px;
  padding: 12px 14px;
  outline: none;
  transition: border-color 180ms var(--ease-out), box-shadow 180ms var(--ease-out), transform 120ms var(--ease-out);
}

.field input:focus,
.field select:focus {
  border-color: rgba(157, 255, 168, 0.45);
  box-shadow: 0 0 0 3px rgba(157, 255, 168, 0.08);
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.btn-primary,
.btn-ghost,
.btn-danger,
.btn-icon {
  border: 0;
  border-radius: 10px;
  transition: transform 120ms var(--ease-out), opacity 160ms var(--ease-out), background 160ms var(--ease-out);
}

.btn-primary {
  background: var(--accent);
  color: #0b120e;
  font-weight: 600;
  padding: 12px 16px;
}

.btn-primary:hover { filter: brightness(1.05); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.55; cursor: wait; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 8px 12px;
}

.btn-ghost:hover { color: var(--text); border-color: #3a463c; }
.btn-ghost:active { transform: scale(0.97); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(255, 143, 143, 0.25);
  padding: 6px 10px;
  font-size: 12px;
}

.btn-danger:active { transform: scale(0.97); }

.btn-icon {
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  width: 36px;
  height: 36px;
}

.login-foot {
  margin-top: 28px;
  font-family: var(--mono);
  font-size: 11px;
  color: #5d675f;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ——— App shell ——— */
.app-shell {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.app-side {
  position: sticky;
  top: 0;
  align-self: start;
  width: 240px;
  height: 100dvh;
  max-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: rgba(12, 15, 13, 0.98);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  z-index: 20;
  flex-shrink: 0;
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.side-brand strong {
  font-size: 14px;
  letter-spacing: -0.02em;
}

.side-nav {
  display: grid;
  gap: 4px;
  flex: 1 1 auto;
  align-content: start;
}

.nav-item {
  display: block;
  padding: 10px 12px;
  border-radius: 9px;
  color: var(--muted);
  transition: background 160ms var(--ease-out), color 160ms var(--ease-out);
}

.nav-item:hover { color: var(--text); background: rgba(157, 255, 168, 0.04); }
.nav-item:active { transform: none; }
.nav-item.is-active {
  color: var(--accent);
  background: rgba(157, 255, 168, 0.08);
}
.nav-item.is-disabled {
  opacity: 0.35;
  pointer-events: none;
}

.side-user {
  margin-top: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.side-user-name { font-weight: 500; font-size: 14px; }
.side-user-role {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.app-main {
  padding: 28px 32px 48px;
}

.app-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-dim);
}

.app-top h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.03em;
}

.panel {
  background: rgba(18, 22, 26, 0.9);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.panel.enter {
  animation: panel-in 240ms var(--ease-out) both;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 600;
}

.muted { color: var(--muted); }

.empty-state {
  margin-top: 22px;
  border: 1px dashed #314036;
  border-radius: 12px;
  padding: 36px 20px;
  text-align: center;
  color: var(--muted);
}

.empty-glyph {
  display: inline-block;
  font-size: 22px;
  color: var(--accent-dim);
  margin-bottom: 8px;
  opacity: 0.7;
}

.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table th {
  text-align: left;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  padding: 0 10px 12px;
  border-bottom: 1px solid var(--line);
}

.data-table td {
  padding: 12px 10px;
  border-bottom: 1px solid rgba(39, 48, 40, 0.7);
  vertical-align: middle;
}

.data-table tr {
  transition: background 140ms var(--ease-out);
}

.data-table tbody tr:hover {
  background: rgba(157, 255, 168, 0.03);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  border: 1px solid var(--line);
  color: var(--muted);
}

.badge.on {
  color: var(--accent);
  border-color: rgba(157, 255, 168, 0.28);
  background: rgba(157, 255, 168, 0.08);
}

.badge.off {
  color: var(--danger);
  border-color: rgba(255, 143, 143, 0.25);
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Modal */
.modal[hidden] { display: none !important; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  animation: fade-in 180ms var(--ease-out) both;
}

.modal-card {
  position: relative;
  width: min(420px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px 18px 16px;
  animation: modal-in 220ms var(--ease-out) both;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.modal-form { display: grid; gap: 12px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.top-actions { display: flex; gap: 12px; align-items: end; }
.inline-field { display: grid; gap: 6px; min-width: 220px; }
.inline-field span {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.inline-field select {
  border: 1px solid var(--line);
  background: var(--bg-elev);
  border-radius: 10px;
  padding: 10px 12px;
}

.sync-panel { margin-bottom: 16px; }
.sync-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.sync-head h2 { margin: 0 0 4px; font-size: 16px; }

.progress-wrap { display: grid; gap: 8px; }
.progress-bar {
  height: 8px;
  border-radius: 99px;
  background: #1a211c;
  overflow: hidden;
  border: 1px solid var(--line);
}
.progress-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  border-radius: 99px;
  transition: width 200ms var(--ease-out);
}
.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}
#sync-percent { color: var(--accent); }

.kpi-row {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.kpi-row.stats-kpi-funnel {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}
.kpi {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: rgba(14, 18, 16, 0.65);
}
.kpi span {
  display: block;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.kpi strong {
  font-size: 18px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.chart-placeholder {
  border: 1px dashed #314036;
  border-radius: 12px;
  padding: 28px;
  text-align: center;
  margin-bottom: 16px;
}

#daily-tbody tr.is-clickable,
#ads-all-tbody tr.is-clickable,
#projects-tbody tr.is-clickable { cursor: pointer; }
#daily-tbody tr.is-clickable:active,
#ads-all-tbody tr.is-clickable:active,
#projects-tbody tr.is-clickable:active { transform: scale(0.995); }
#ads-all-tbody tr.is-active,
#daily-tbody tr.is-active,
#projects-tbody tr.is-active { background: rgba(157, 255, 168, 0.08); }

.stats-top {
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 18px 24px;
  margin-bottom: 18px;
}

.stats-top-left { min-width: 200px; flex: 1; }

.date-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(18, 22, 26, 0.85);
}

.date-field {
  display: grid;
  gap: 4px;
}

.date-field span {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.date-field input[type="date"],
.date-field select {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  min-width: 150px;
}

.date-field select {
  min-width: 200px;
  max-width: 280px;
}

.stats-kpi { margin-bottom: 16px; }

.cell-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.admin-sync-details {
  margin-top: 18px;
}

.admin-sync-details > summary {
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  list-style: none;
}

.admin-sync-details > summary::-webkit-details-marker { display: none; }

.admin-sync-details[open] > summary {
  color: var(--accent-dim);
  margin-bottom: 14px;
}

.sync-panel-inner .row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
}

.inline-field.compact { min-width: 160px; }

.modal-card-wide {
  max-width: 640px;
  max-height: 90vh;
  overflow: auto;
}
.acl-list { display: grid; gap: 10px; max-height: 320px; overflow: auto; }
.acl-project {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: rgba(14, 18, 16, 0.5);
}
.acl-project-head {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.acl-project-head code { color: var(--muted); font-size: 12px; }
.acl-ads {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  max-height: 160px;
  overflow: auto;
}
.acl-ad {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 12px;
  color: var(--text);
}
.cell-projects {
  max-width: 280px;
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 860px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-rail { display: none; }
  .app-shell { grid-template-columns: 1fr; }
  .app-side {
    position: sticky;
    top: 0;
    width: 100%;
    height: auto;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    z-index: 20;
  }
  .app-main { padding: 20px 16px 40px; }
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-row.stats-kpi-funnel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sync-head { flex-direction: column; }
  .date-bar { width: 100%; }
}

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