:root {
  color-scheme: dark;
  --bg: #080808;
  --surface: #121212;
  --surface-2: #191919;
  --line: rgba(255,255,255,.14);
  --text: #f7f7f7;
  --muted: #b9b9b9;
  --accent: #f0a202;
  --accent-2: #ffcf5a;
  --success: #25D366;
  --danger: #d92323;
  --shadow: 0 24px 70px rgba(0,0,0,.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 22% 0%, rgba(240,162,2,.16), transparent 30%),
    var(--bg);
}

a,
button,
input,
select {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  font-weight: 900;
}

.top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 18px 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand img {
  width: 118px;
  height: auto;
  filter: drop-shadow(0 0 28px rgba(255,160,0,.3));
}

.kicker {
  margin: 0 0 5px;
  color: var(--accent-2);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .15em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: .95;
}

nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

nav a,
nav button {
  display: inline-grid;
  min-height: 44px;
  place-items: center;
  padding: 10px 13px;
}

nav a:first-child {
  color: #101010;
  background: var(--accent);
  border-color: var(--accent);
}

.shell {
  max-width: 1240px;
  margin: 0 auto;
  padding: 12px 18px 36px;
}

.summary,
.ageing-board,
.tools,
.module-head,
.record,
dialog {
  border: 1px solid var(--line);
  background: rgba(18,18,18,.9);
  box-shadow: var(--shadow);
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.summary div,
.ageing-board div {
  min-height: 92px;
  padding: 15px;
  border-left: 1px solid var(--line);
}

.summary div:first-child,
.ageing-board div:first-child {
  border-left: 0;
}

.summary span,
.ageing-board span,
label span,
.metric span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
}

.summary strong {
  font-size: clamp(1.25rem, 3vw, 2.2rem);
}

.ageing-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 14px;
}

.ageing-board strong {
  display: block;
  color: var(--accent-2);
  font-size: clamp(1.15rem, 2.6vw, 1.8rem);
}

.ageing-board small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-weight: 800;
}

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

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

.danger {
  color: #ff6969;
}

.tools {
  display: grid;
  grid-template-columns: 1fr 240px;
  gap: 12px;
  margin-top: 14px;
  padding: 14px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--surface-2);
  outline: none;
}

.records {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.module-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 26px;
  padding: 16px;
}

.module-head h2 {
  margin-bottom: 6px;
}

.module-head p:last-child {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.supplier-summary,
.supplier-ageing,
.supplier-tools {
  margin-top: 14px;
}

.record {
  display: grid;
  gap: 14px;
  padding: 15px;
}

.record-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.record-head h2 {
  margin-bottom: 5px;
}

.status {
  display: inline-grid;
  min-height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 11px;
  color: var(--accent-2);
  background: rgba(240,162,2,.1);
  font-size: .78rem;
  font-weight: 900;
  white-space: nowrap;
}

.status.paid {
  color: var(--success);
  border-color: rgba(37,211,102,.4);
  background: rgba(37,211,102,.1);
}

.status.overdue {
  color: #ff8b86;
  border-color: rgba(227,52,47,.45);
  background: rgba(227,52,47,.12);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric,
.payments {
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(0,0,0,.18);
}

.metric strong {
  font-size: 1.2rem;
}

.record-actions {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.supplier-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.primary {
  color: #101010;
  background: var(--accent);
  border-color: var(--accent);
}

.whatsapp {
  color: #06140a;
  background: var(--success);
  border-color: var(--success);
}

.payments h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.two-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.payments ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.payments li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: .92rem;
}

.empty {
  padding: 26px;
  color: var(--muted);
  text-align: center;
  border: 1px solid var(--line);
  background: rgba(18,18,18,.9);
}

dialog {
  width: min(520px, calc(100vw - 28px));
  border-radius: 12px;
  color: var(--text);
  padding: 0;
}

dialog::backdrop {
  background: rgba(0,0,0,.65);
}

#paymentForm,
#supplierForm,
#supplierPaymentForm {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.confirm {
  color: #101010;
  background: var(--accent);
  border-color: var(--accent);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
  border: 1px solid rgba(240,162,2,.45);
  background: #151515;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .top,
  .summary,
  .ageing-board,
  .tools,
  .module-head,
  .metrics,
  .record-actions,
  .two-fields {
    grid-template-columns: 1fr;
  }

  .module-head {
    display: grid;
  }

  .ageing-board div,
  .summary div,
  .ageing-board div:first-child,
  .summary div:first-child {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .ageing-board div:first-child,
  .summary div:first-child {
    border-top: 0;
  }

  nav {
    justify-content: stretch;
  }

  nav a,
  nav button {
    flex: 1 1 140px;
  }

  .summary div,
  .summary div:first-child {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .summary div:first-child {
    border-top: 0;
  }

  .record-head {
    display: grid;
  }
}

@media print {
  body {
    background: #fff;
    color: #111;
  }

  nav,
  .tools,
  .record-actions,
  .toast {
    display: none;
  }

  .summary,
  .record,
  .metric,
  .payments {
    border-color: #ddd;
    box-shadow: none;
    background: #fff;
  }

  .brand img {
    width: 90px;
    filter: none;
  }
}
