/* LedgerWatch app stylesheet. Plain CSS, light mode only, no build step. */

:root {
  /* Spacing scale - everything below is a multiple of 4px. */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Type scale - four sizes only. */
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.25rem;
  --text-xl: 1.75rem;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;

  /* Neutral surface/text scale. */
  --color-bg: #f7f7f5;
  --color-surface: #ffffff;
  --color-border: #e3e5e1;
  --color-border-strong: #cdd1cb;
  --color-text: #16181a;
  --color-text-secondary: #5b6169;
  --color-text-muted: #8b9096;

  /* Accent - used sparingly: primary actions, active states, the brand mark. */
  --color-accent: #0f5132;
  --color-accent-hover: #0c4028;

  /* Red - reserved exclusively for genuine risk: supplier badges, risk
     signals, destructive actions. Never used decoratively. */
  --color-danger: #b3261e;
  --color-danger-soft: #fbe9e7;

  /* Amber - operational/billing warnings (e.g. "monitoring stopped"), kept
     visually distinct from red so red still means "bank fraud risk". */
  --color-warning-soft: #fdf3e2;
  --color-warning-border: #f0d38a;
  --color-warning-text: #7a5300;

  --color-info-soft: #e8eef7;
  --color-info-text: #2c4a75;

  --radius: 6px;
  --radius-lg: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}

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

h1,
h2,
h3 {
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 var(--space-4);
}
h1 {
  font-size: var(--text-xl);
}
h2 {
  font-size: var(--text-lg);
}
h3 {
  font-size: var(--text-base);
}

p {
  margin: 0 0 var(--space-3);
}

ul {
  margin: 0 0 var(--space-3);
  padding-left: var(--space-5);
}

input:focus,
select:focus,
button:focus,
a:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

/* ---- Layout ---- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

.brand {
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--color-accent);
  letter-spacing: -0.01em;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  font-size: var(--text-base);
}
.topbar nav a {
  color: var(--color-text-secondary);
}
.topbar nav a:hover {
  color: var(--color-text);
  text-decoration: none;
}
.topbar nav a.active {
  color: var(--color-accent);
  font-weight: 600;
}
.topbar form {
  margin: 0;
}

.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-7);
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.page-header h1 {
  margin-bottom: 0;
}

.page-actions {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}

/* ---- Buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 500;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  line-height: 1.2;
  white-space: nowrap;
}
.btn-sm {
  font-size: var(--text-sm);
  padding: var(--space-1) var(--space-3);
}
.btn-primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}
.btn-primary:hover {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
  text-decoration: none;
}
.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border-strong);
}
.btn-secondary:hover {
  background: var(--color-bg);
  text-decoration: none;
}
.btn-destructive {
  background: #fff;
  color: var(--color-danger);
  border-color: var(--color-danger);
}
.btn-destructive:hover {
  background: var(--color-danger-soft);
  text-decoration: none;
}
.btn:disabled {
  opacity: 0.6;
  cursor: default;
}
.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--color-accent);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
}

/* ---- Forms ---- */

form.inline {
  display: inline;
}

label {
  display: block;
  font-size: var(--text-base);
  margin-bottom: var(--space-4);
}
label > span {
  display: block;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-1);
}
.checkbox-label {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
}
.checkbox-label input[type="checkbox"] {
  margin-top: 3px;
  flex-shrink: 0;
}
.checkbox-label span {
  font-size: var(--text-base);
  color: var(--color-text);
}

input[type="email"],
input[type="password"],
input[type="text"],
select {
  width: 100%;
  font-family: inherit;
  font-size: var(--text-base);
  padding: var(--space-2) var(--space-3);
  margin-top: var(--space-1);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
}

.recipient-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: var(--space-2);
  font-size: var(--text-base);
}
.recipient-add {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-2);
}
.recipient-add input {
  flex: 1;
}

/* ---- Cards ---- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.auth-shell {
  max-width: 380px;
  margin: var(--space-7) auto 0;
}
.auth-shell .card form label:last-of-type {
  margin-bottom: var(--space-5);
}
.auth-footer {
  text-align: center;
  margin-top: var(--space-4);
  color: var(--color-text-secondary);
  font-size: var(--text-base);
}

.form-card {
  max-width: 480px;
}

.btn-block {
  width: 100%;
}

/* ---- Stat cards ---- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--space-3);
  margin: var(--space-5) 0;
}
.stat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.stat .n {
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.1;
  margin-bottom: var(--space-1);
}
.stat .label {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

/* ---- Tables ---- */

.table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base);
}
th,
td {
  text-align: left;
  vertical-align: top;
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
th {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  background: var(--color-bg);
}
tbody tr:last-child td {
  border-bottom: none;
}
td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
th a {
  color: inherit;
  text-decoration: underline;
  text-decoration-style: dotted;
}
th a:hover {
  text-decoration-style: solid;
}
th a.active {
  color: var(--color-text);
  font-weight: 700;
  text-decoration-style: solid;
}

/* ---- Badges ---- */

.badge {
  display: inline-block;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 1px var(--space-2);
  border-radius: 999px;
  line-height: 1.6;
}
.badge-supplier {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}
.badge-reverted,
.badge-dismissed {
  background: var(--color-bg);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border-strong);
}
.badge-cross-org {
  background: var(--color-info-soft);
  color: var(--color-info-text);
}

/* ---- Alert-specific bits ---- */

.field-change {
  display: block;
  margin-bottom: var(--space-2);
}
.field-change:last-child {
  margin-bottom: 0;
}
.field-label {
  display: block;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.3;
}
.field-value {
  line-height: 1.35;
}
.value-old {
  color: var(--color-text-muted);
  font-weight: 400;
}
.value-arrow {
  color: var(--color-text-muted);
  margin: 0 var(--space-1);
}
.value-new {
  color: var(--color-text);
  font-weight: 600;
}

/* Deliberately smaller and tighter than the type scale's smallest step -
   these are secondary annotations on a change, not content in their own
   right, and shouldn't compete with the value above them for attention. */
.risk-signals {
  margin-top: var(--space-1);
}
.risk-signal {
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--color-danger);
}
.risk-signal:not(:last-child)::after {
  content: "\00b7";
  color: var(--color-text-muted);
  margin: 0 var(--space-1);
  font-weight: 700;
}

.meta {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}
button + .meta {
  margin-left: var(--space-3);
}

.duplicate-contact {
  display: block;
  margin-bottom: var(--space-1);
}
.duplicate-contact:last-child {
  margin-bottom: 0;
}

.duplicate-note {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

/* ---- Alert outcomes ---- */

.outcome-cell {
  min-width: 220px;
}
.outcome-cell .outcome-select {
  margin-bottom: var(--space-1);
}
.outcome-cell .meta {
  display: block;
  margin-bottom: var(--space-1);
}
.outcome-note,
.outcome-history {
  font-size: var(--text-sm);
  margin-top: var(--space-1);
}
.outcome-note summary,
.outcome-history summary {
  cursor: pointer;
  color: var(--color-text-secondary);
}
.outcome-note summary:hover,
.outcome-history summary:hover {
  color: var(--color-text);
}
.outcome-note textarea {
  width: 100%;
  font-family: inherit;
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-3);
  margin-top: var(--space-1);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  resize: vertical;
}
.outcome-note button {
  margin-top: var(--space-1);
}
.outcome-history-item {
  padding: var(--space-2) 0;
  border-top: 1px solid var(--color-border);
}
.outcome-history-item:first-child {
  border-top: none;
  padding-top: var(--space-1);
}
.outcome-note-text {
  font-size: var(--text-sm);
  color: var(--color-text);
  margin-top: 2px;
  white-space: pre-wrap;
}

/* A corrected history entry stays fully visible - just struck through and
   muted, with a small non-struck label explaining why, so it still reads
   at a glance rather than looking like a second considered judgement. */
.outcome-corrected-text {
  text-decoration: line-through;
  color: var(--color-text-muted);
}
.outcome-corrected-label {
  font-style: italic;
  color: var(--color-text-muted);
}

/* ---- Filters ---- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-5);
  margin-bottom: var(--space-4);
  font-size: var(--text-base);
  border-bottom: 1px solid var(--color-border);
}
.filters a {
  color: var(--color-text-secondary);
  padding-bottom: var(--space-2);
  border-bottom: 2px solid transparent;
}
.filters a:hover {
  color: var(--color-text);
  text-decoration: none;
}
.filters a.active {
  color: var(--color-text);
  border-bottom-color: var(--color-accent);
  font-weight: 600;
}

/* ---- Banners ---- */

.banner {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  margin-bottom: var(--space-4);
  font-size: var(--text-base);
}
.banner-warning {
  background: var(--color-warning-soft);
  border: 1px solid var(--color-warning-border);
  color: var(--color-warning-text);
}

.error {
  color: var(--color-danger);
  font-size: var(--text-base);
}

.billing-status {
  font-size: var(--text-sm);
}

/* ---- Mobile: stack tables as cards instead of horizontal-scrolling ---- */

@media (max-width: 640px) {
  .container {
    padding: var(--space-4) var(--space-3) var(--space-6);
  }
  .topbar {
    padding: var(--space-3);
  }
  .topbar nav {
    gap: var(--space-3);
    font-size: var(--text-sm);
  }
  .nav-email {
    display: none;
  }
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }

  table.stack,
  table.stack tbody {
    display: block;
    width: 100%;
  }
  table.stack thead {
    display: none;
  }
  table.stack tr {
    display: block;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
  }
  table.stack tbody tr:last-child {
    border-bottom: none;
  }
  table.stack td {
    display: block;
    padding: var(--space-1) 0;
    border: none;
  }
  table.stack td.num {
    text-align: left;
  }
  table.stack td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: var(--text-sm);
    color: var(--color-text-secondary);
    margin-bottom: 2px;
  }
}
