/* ==========================================================================
   Admin application shell and page-level composition.
   ========================================================================== */

.app { display: flex; min-height: 100vh; }

/* --- sidebar -------------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-width);
  flex: none;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar__brand {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--space-4);
  height: var(--header-height);
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 24px; height: 24px; flex: none;
  display: grid; place-items: center;
  background: var(--accent-500); color: #fff;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
}
.brand-name { font-size: var(--text-sm); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); }
.brand-env {
  font-size: var(--text-2xs); text-transform: uppercase; letter-spacing: var(--tracking-wide);
  color: var(--warn-fg); background: var(--warn-bg);
  padding: 1px 5px; border-radius: var(--radius-sm);
}

.sidebar__nav { padding: var(--space-3) var(--space-2); overflow-y: auto; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--fg-muted);
  transition: background var(--transition-fast), color var(--transition-fast);
}
.nav-item:hover { background: var(--bg-hover); color: var(--fg); text-decoration: none; }
.nav-item.is-active { background: var(--accent-50); color: var(--accent-700); font-weight: var(--weight-medium); }
@media (prefers-color-scheme: dark) {
  .nav-item.is-active { background: var(--bg-active); color: var(--fg-accent); }
}
.nav-item__icon { width: 16px; height: 16px; flex: none; opacity: 0.9; }
.nav-item__badge {
  margin-left: auto;
  min-width: 18px; padding: 0 5px; height: 18px;
  display: grid; place-items: center;
  font-size: var(--text-2xs); font-weight: var(--weight-semibold);
  background: var(--danger-bg); color: var(--danger-fg);
  border-radius: var(--radius-full);
}

.sidebar__footer { padding: var(--space-3); border-top: 1px solid var(--border); }
.user-row { display: flex; align-items: center; gap: var(--space-3); }
.avatar {
  width: 28px; height: 28px; flex: none;
  display: grid; place-items: center;
  background: var(--bg-active); color: var(--fg-muted);
  border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: var(--weight-semibold);
  text-transform: uppercase;
}

/* --- main ---------------------------------------------------------------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: none;
  align-items: center; gap: var(--space-3);
  height: var(--header-height);
  padding: 0 var(--space-4);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.content { padding: var(--space-6); max-width: var(--content-max); width: 100%; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--space-4); flex-wrap: wrap;
  margin-bottom: var(--space-5);
}
.page-head__sub { font-size: var(--text-sm); color: var(--fg-muted); margin-top: var(--space-1); }
.breadcrumb { font-size: var(--text-xs); color: var(--fg-muted); margin-bottom: var(--space-2); }

/* --- metric row ----------------------------------------------------------
   Deliberately NOT four floating cards. One bordered strip: the primary
   figure dominates, the supporting counts sit beside it. */
.metrics {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) repeat(4, minmax(110px, 1fr));
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.metric { padding: var(--space-4) var(--space-5); border-left: 1px solid var(--border); }
.metric:first-child { border-left: none; }
.metric__label { font-size: var(--text-xs); color: var(--fg-muted); margin-bottom: var(--space-2); }
.metric__value { font-size: var(--text-lg); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
.metric--primary .metric__value { font-size: var(--text-2xl); letter-spacing: var(--tracking-tight); }
.metric__note { font-size: var(--text-xs); color: var(--fg-subtle); margin-top: var(--space-1); }
.metric__value a { color: inherit; }

/* --- chart ---------------------------------------------------------------
   Hand-drawn bars. No chart library: 14 daily values does not justify
   shipping one, and this renders instantly with no layout shift. */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 128px; padding-top: var(--space-2); }
.chart__col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; min-width: 0; position: relative; }
.chart__bar { background: var(--accent-500); border-radius: 2px 2px 0 0; min-height: 2px; transition: opacity var(--transition-fast); }
.chart__bar--muted { background: var(--grey-300); }
@media (prefers-color-scheme: dark) { .chart__bar--muted { background: var(--grey-700); } }
.chart__col:hover .chart__bar { opacity: 0.75; }
.chart__axis { display: flex; justify-content: space-between; font-size: var(--text-2xs); color: var(--fg-subtle); margin-top: var(--space-2); }
.legend { display: flex; gap: var(--space-4); font-size: var(--text-xs); color: var(--fg-muted); }
.legend__key { display: inline-flex; align-items: center; gap: var(--space-2); }
.legend__swatch { width: 8px; height: 8px; border-radius: 2px; background: var(--accent-500); }
.legend__swatch--muted { background: var(--grey-300); }

/* --- two column page layout ---------------------------------------------- */
.split { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--space-5); align-items: start; }
.split--wide { grid-template-columns: minmax(0, 1fr) 380px; }

/* --- definition lists (detail pages) ------------------------------------- */
.dl { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: var(--space-3) var(--space-5); font-size: var(--text-sm); }
.dl dt { color: var(--fg-muted); }
.dl dd { margin: 0; word-break: break-word; }

/* --- filter bar ----------------------------------------------------------- */
.filters {
  display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.filters .input, .filters .select { height: 30px; font-size: var(--text-xs); width: auto; min-width: 130px; }
.filters .input { min-width: 200px; }

/* --- pagination ----------------------------------------------------------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); font-size: var(--text-xs); color: var(--fg-muted); }
.pagination__links { display: flex; gap: var(--space-2); }

/* --- timeline (audit) ----------------------------------------------------- */
.timeline { position: relative; padding-left: var(--space-5); }
.timeline::before {
  content: ""; position: absolute; left: 4px; top: 6px; bottom: 6px;
  width: 1px; background: var(--border);
}
.timeline__item { position: relative; padding-bottom: var(--space-4); }
.timeline__item:last-child { padding-bottom: 0; }
.timeline__item::before {
  content: ""; position: absolute; left: calc(-1 * var(--space-5) + 1px); top: 5px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--border-strong); border: 2px solid var(--bg-surface);
  box-sizing: content-box;
}
.timeline__item--ok::before { background: var(--ok-dot); }
.timeline__item--warn::before { background: var(--warn-dot); }
.timeline__item--danger::before { background: var(--danger-dot); }
.timeline__time { font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--fg-subtle); }
.timeline__title { font-size: var(--text-sm); font-weight: var(--weight-medium); }
.timeline__body { font-size: var(--text-xs); color: var(--fg-muted); }

/* --- merchant cards ------------------------------------------------------- */
.merchant-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--space-4); }
.merchant-card { display: flex; flex-direction: column; }
.merchant-card.needs-attention { border-color: var(--warn-dot); }
.merchant-card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5) var(--space-3); }
.merchant-card__body { padding: 0 var(--space-5) var(--space-4); flex: 1; }
.merchant-card__foot { display: flex; gap: var(--space-2); padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border); background: var(--bg-sunken); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.provider-tag { font-size: var(--text-xs); color: var(--fg-muted); }

/* --- key reveal ----------------------------------------------------------- */
.reveal {
  border: 1px solid var(--ok-dot); background: var(--ok-bg);
  border-radius: var(--radius-md); padding: var(--space-4);
}
.reveal__title { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--ok-fg); margin-bottom: var(--space-2); }
.reveal .copy { background: var(--bg-surface); border-color: var(--ok-dot); }

/* --- login ---------------------------------------------------------------- */
.login {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: var(--space-6);
  background: var(--bg-app);
}
.login__card { width: 100%; max-width: 360px; }
.login__brand { display: flex; align-items: center; gap: var(--space-3); justify-content: center; margin-bottom: var(--space-6); }

/* --- responsive ----------------------------------------------------------- */
@media (max-width: 1080px) {
  .split, .split--wide { grid-template-columns: minmax(0, 1fr); }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metric { border-left: none; border-top: 1px solid var(--border); }
  .metric:nth-child(-n+2) { border-top: none; }
  .metric:nth-child(even) { border-left: 1px solid var(--border); }
}

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 60;
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: translateX(0); }
  .topbar { display: flex; }
  .content { padding: var(--space-4); }
  .scrim { position: fixed; inset: 0; background: rgba(11, 13, 18, 0.45); z-index: 50; }

  /* Tables become record cards rather than a horizontally-scrolling grid:
     an operator on a phone reads one payment at a time, not 8 columns. */
  .table--stack thead { display: none; }
  .table--stack, .table--stack tbody, .table--stack tr, .table--stack td { display: block; width: 100%; }
  .table--stack tr {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
  }
  .table--stack td { border: none; padding: var(--space-1) 0; display: flex; justify-content: space-between; gap: var(--space-4); }
  .table--stack td::before {
    content: attr(data-label);
    font-size: var(--text-xs); color: var(--fg-muted); flex: none;
  }
  .table--stack td.num, .table--stack td.money { text-align: right; }
  .table--stack td[data-label=""]::before { content: none; }
}

@media (max-width: 560px) {
  .metrics { grid-template-columns: 1fr; }
  .metric { border-left: none !important; border-top: 1px solid var(--border); }
  .metric:first-child { border-top: none; }
  .merchant-grid { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; gap: var(--space-1) 0; }
  .dl dt { margin-top: var(--space-2); }
}
