/* Flows Admin · shared stylesheet.
 *
 * Single source of design tokens + component styles for every page.
 * Per-view stylesheets only carry genuinely view-specific overrides
 * (timeline dot palette, leg cards, etc.).
 */

/* ── Tokens ──────────────────────────────────────────────────────── */

:root {
  /* Neutral scale (slate) */
  --slate-50:  #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;

  /* Surfaces */
  --bg:           var(--slate-50);
  --surface:      #ffffff;
  --surface-2:    var(--slate-50);
  --border:       var(--slate-200);
  --border-strong:var(--slate-300);

  /* Text */
  --text:         var(--slate-900);
  --text-muted:   var(--slate-500);
  --text-subtle:  var(--slate-400);

  /* Accent (indigo) */
  --accent:       #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft:  #eef2ff;
  --accent-ring:  rgba(79, 70, 229, 0.18);

  /* Semantic */
  --success:      #16a34a;
  --success-soft: #dcfce7;
  --success-text: #166534;
  --warning:      #d97706;
  --warning-soft: #fef3c7;
  --warning-text: #92400e;
  --danger:       #dc2626;
  --danger-soft:  #fee2e2;
  --danger-text:  #991b1b;
  --info:         #2563eb;
  --info-soft:    #dbeafe;
  --info-text:    #1e40af;

  --buy:          var(--success);
  --buy-soft:     var(--success-soft);
  --buy-text:     var(--success-text);
  --sell:         var(--danger);
  --sell-soft:    var(--danger-soft);
  --sell-text:    var(--danger-text);

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable",
               "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  --font-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;

  /* Spacing (4px grid) */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;
  --s-12: 48px;

  /* Radius */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;
  --r-pill: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.18);

  /* Z layers */
  --z-modal: 50;
}

/* ── Reset ───────────────────────────────────────────────────────── */

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

html { font-family: var(--font-sans); }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11";
}

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

/* ── App shell ───────────────────────────────────────────────────── */

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 48px;
  padding: 0 var(--s-5);
  display: flex;
  align-items: center;
  gap: var(--s-5);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-brand {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}
.app-brand .dot {
  display: inline-block;
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  margin-right: var(--s-2);
  vertical-align: 1px;
}
.app-nav {
  display: flex;
  gap: 2px;
}
.app-nav a {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--r-sm);
  transition: background 0.12s, color 0.12s;
}
.app-nav a:hover {
  background: var(--slate-100);
  color: var(--text);
}
.app-nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.app-header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s-4);
  font-size: 12px;
  color: var(--text-muted);
}
.app-header-right a:hover { color: var(--text); }

/* Detail-page header variant: same chrome, taller, with subtitle */
.app-header.detail {
  height: auto;
  padding: var(--s-4) var(--s-5);
  align-items: flex-start;
  position: static;
}
.app-header.detail .title-block { display: flex; flex-direction: column; gap: 2px; }
.app-header.detail h1 { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.app-header.detail .subtitle { font-size: 12px; color: var(--text-muted); }

/* ── Filters bar ─────────────────────────────────────────────────── */

.filters {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--s-4) var(--s-5);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--s-3) var(--s-4);
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 4px; }
.field label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.filters .actions {
  display: flex;
  gap: var(--s-2);
  align-items: end;
}

/* ── Form controls ───────────────────────────────────────────────── */

.input, .select {
  height: 32px;
  width: 100%;
  padding: 0 var(--s-3);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-size: 13px;
  outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input::placeholder { color: var(--text-subtle); }
.input:hover, .select:hover { border-color: var(--slate-400); }
.input:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
.select[multiple] {
  height: auto;
  min-height: 110px;
  padding: 4px;
}
.select[multiple] option { padding: 3px 6px; border-radius: 3px; }

input[type="date"] { padding-right: 6px; }
input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px; height: 14px;
  cursor: pointer;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

/* ── Buttons ─────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s, opacity 0.12s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover:not(:disabled) { background: var(--slate-100); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }

.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-sm { height: 26px; padding: 0 10px; font-size: 12px; }
.btn-link {
  height: auto;
  padding: 4px 8px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 500;
}
.btn-link:hover { background: #e0e7ff; }

/* ── Toolbar (sub-header below filters, e.g. selection + actions) ── */

.toolbar {
  padding: 10px var(--s-5);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-muted);
}
.toolbar .count {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  color: var(--text);
}
.toolbar .spacer { flex: 1; }

/* ── Main content ────────────────────────────────────────────────── */

.content { padding: var(--s-5); }

/* ── Tables ──────────────────────────────────────────────────────── */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
.table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text-muted);
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--slate-50); }

.table td.num, .table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}
.table td.mono, .table th.mono { font-family: var(--font-mono); font-size: 12px; }
.table td.id  { font-variant-numeric: tabular-nums; color: var(--text-muted); }
.table td.actions { white-space: nowrap; }

.table-footnote {
  padding: 8px 12px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Pills (status badges) ───────────────────────────────────────── */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-radius: var(--r-pill);
  background: var(--slate-100);
  color: var(--slate-700);
  white-space: nowrap;
  line-height: 1;
}
.pill::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}
.pill.no-dot::before { display: none; }

.pill.success, .pill.complete, .pill.executed, .pill.approved, .pill.aggregated, .pill.sent, .pill.delivered {
  background: var(--success-soft); color: var(--success-text);
}
.pill.info, .pill.in-process, .pill.authorized, .pill.created, .pill.submitted, .pill.pending-aggregation {
  background: var(--info-soft); color: var(--info-text);
}
.pill.warning, .pill.pending, .pill.retrying, .pill.partial {
  background: var(--warning-soft); color: var(--warning-text);
}
.pill.danger, .pill.rejected, .pill.expired, .pill.failed, .pill.cancelled, .pill.bounced, .pill.complaint, .pill.custom-error {
  background: var(--danger-soft); color: var(--danger-text);
}
.pill.neutral { background: var(--slate-100); color: var(--slate-700); }

.pill.buy  { background: var(--buy-soft);  color: var(--buy-text); }
.pill.sell { background: var(--sell-soft); color: var(--sell-text); }

.pill.tone-cash-in    { background: var(--success-soft); color: var(--success-text); }
.pill.tone-cash-out   { background: var(--danger-soft);  color: var(--danger-text); }

/* ── Panels (cards) ──────────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.panel + .panel { margin-top: var(--s-4); }
.panel-header {
  padding: 10px var(--s-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
}
.panel-header h3 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.panel-header .badge {
  background: var(--slate-100);
  color: var(--slate-700);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 2px 8px;
  border-radius: var(--r-pill);
}
.panel-body { padding: var(--s-4); }
.panel-body table { width: 100%; }
.panel-body table th, .panel-body table td {
  padding: 6px 8px;
  font-size: 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.panel-body table th {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-2);
}
.panel-body table tr:last-child td { border-bottom: 0; }
.panel-body table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Summary grid (detail page header card) ──────────────────────── */

.summary {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--s-4) var(--s-5);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--s-3) var(--s-5);
}
.summary .item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.summary .item label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.summary .item .value {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  word-break: break-word;
}
.summary .item.full { grid-column: 1 / -1; }
.summary .item .value .pill { vertical-align: 1px; }
.summary .item .value.money {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}
.summary .item .value.error {
  color: var(--danger-text);
  font-size: 12px;
}

/* ── Empty / messages ────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: var(--s-12) var(--s-4);
  color: var(--text-subtle);
  font-size: 13px;
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
}
.empty-state b { color: var(--text); font-weight: 600; }

.msg {
  padding: 10px var(--s-3);
  border-radius: var(--r-sm);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.msg.info    { background: var(--info-soft);    color: var(--info-text); }
.msg.error   { background: var(--danger-soft);  color: var(--danger-text); }
.msg.success { background: var(--success-soft); color: var(--success-text); }
.msg.loading { background: var(--slate-100);    color: var(--text-muted); }

/* ── Modals ──────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: var(--s-4);
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--surface);
  width: min(560px, 100%);
  max-height: 88vh;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
}
.modal.lg { width: min(960px, 100%); }
.modal-head, .modal-foot {
  padding: 12px var(--s-4);
  display: flex;
  align-items: center;
  gap: var(--s-2);
}
.modal-head { border-bottom: 1px solid var(--border); justify-content: space-between; }
.modal-head h2 { font-size: 14px; font-weight: 600; }
.modal-head .close-x {
  width: 28px; height: 28px;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.modal-head .close-x:hover { background: var(--slate-100); color: var(--text); }
.modal-body { padding: var(--s-4); overflow-y: auto; font-size: 13px; }
.modal-foot { border-top: 1px solid var(--border); justify-content: flex-end; }

.result-list {
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
.result-list li {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: var(--s-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.result-list li:last-child { border-bottom: 0; }
.result-list li.ok   { color: var(--success-text); }
.result-list li.fail { color: var(--danger-text); }

/* ── Timeline (detail pages) ─────────────────────────────────────── */

.timeline { position: relative; padding: var(--s-2) var(--s-5); }
.timeline::before {
  content: '';
  position: absolute;
  top: 16px;
  bottom: 16px;
  left: calc(var(--s-5) + 7px);
  width: 2px;
  background: var(--border);
}
.event {
  position: relative;
  padding: 10px 0 10px var(--s-6);
  font-size: 13px;
}
.event + .event { border-top: 1px dashed var(--border); }
.event .dot {
  position: absolute;
  left: 0;
  top: 14px;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--slate-300);
  border: 3px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border);
}
.event .ts {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
}
.event .ts .kind {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: var(--slate-100);
  color: var(--text-muted);
  border-radius: var(--r-sm);
  text-transform: uppercase;
}
.event .title { margin-top: 2px; font-weight: 500; color: var(--text); }
.event .detail { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.event details summary {
  display: inline-block;
  margin-top: 6px;
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
}
.event pre.json {
  margin-top: 4px;
  background: var(--slate-900);
  color: #e2e8f0;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  max-height: 220px;
  overflow: auto;
}

/* ── Layout helpers ──────────────────────────────────────────────── */

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: var(--s-4);
  padding: var(--s-5);
}
@media (max-width: 1100px) { .detail-grid { grid-template-columns: 1fr; } }

.muted   { color: var(--text-muted); }
.subtle  { color: var(--text-subtle); }
.mono    { font-family: var(--font-mono); font-size: 12px; }
.tnum    { font-variant-numeric: tabular-nums; }
.nowrap  { white-space: nowrap; }
.center  { text-align: center; }
.right   { text-align: right; }

a.inline-link { color: var(--accent); }
a.inline-link:hover { text-decoration: underline; }
