:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-strong: #eef3f6;
  --ink: #18212f;
  --muted: #667085;
  --border: #dce3ea;
  --sidebar: #121d2a;
  --sidebar-soft: #1b2b3d;
  --teal: #008f85;
  --teal-dark: #006f69;
  --amber: #f59e0b;
  --red: #ef4444;
  --green: #16a34a;
  --shadow: 0 14px 35px rgba(27, 39, 53, 0.08);
}

.auth-session {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid #cbd5e1;
  color: #334155;
  font-size: 0.82rem;
  text-decoration: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 26px 18px;
  color: #d8e2ee;
  background: linear-gradient(180deg, var(--sidebar), #0c1420);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
  font-size: 24px;
  font-weight: 800;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  font-size: 13px;
  letter-spacing: 0;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 13px 14px;
  color: #cbd7e5;
  background: transparent;
  text-align: left;
  font-weight: 650;
}

.nav-item.active,
.nav-item:hover {
  color: #fff;
  background: rgba(0, 143, 133, 0.72);
}

.account-card {
  display: grid;
  gap: 5px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: var(--sidebar-soft);
}

.account-card span {
  color: #aebdce;
  font-size: 13px;
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 0;
  font-size: 29px;
  line-height: 1.15;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
}

.topbar-actions,
.filters {
  display: flex;
  align-items: center;
  gap: 10px;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 15px;
  font-size: 14px;
  font-weight: 750;
}

.primary-button {
  border: 0;
  color: #fff;
  background: var(--teal);
}

.primary-button:hover {
  background: var(--teal-dark);
}

.secondary-button,
.ghost-button {
  border: 1px solid var(--border);
  color: var(--ink);
  background: var(--surface);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.kpi-card {
  display: grid;
  grid-template-columns: 52px 1fr;
  column-gap: 14px;
  min-height: 122px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi-icon {
  display: grid;
  grid-row: span 3;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: 24px;
  font-weight: 850;
}

.kpi-icon.teal { background: var(--teal); }
.kpi-icon.red { background: var(--red); }
.kpi-icon.amber { background: var(--amber); }
.kpi-icon.graphite { background: #334155; }

.kpi-card p,
.kpi-card small {
  margin: 0;
  color: var(--muted);
}

.kpi-card strong {
  display: block;
  margin: 4px 0;
  font-size: 25px;
  line-height: 1.1;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.panel-header.compact {
  align-items: center;
}

.panel h2 {
  margin: 0;
  font-size: 20px;
}

.panel p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.filters input,
.filters select {
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 11px;
  color: var(--ink);
  background: #fff;
  font-size: 14px;
}

.filters input {
  width: 230px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  color: #475467;
  background: #f8fafc;
  font-size: 12px;
  text-transform: uppercase;
}

td strong {
  display: block;
  margin-bottom: 3px;
}

td small {
  color: var(--muted);
}

.money-negative {
  color: var(--red);
  font-weight: 780;
}

.risk-pill,
.status-pill,
.live-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.risk-critical { color: #dc2626; border: 1px solid #fecaca; background: #fff1f2; }
.risk-high { color: #f97316; border: 1px solid #fed7aa; background: #fff7ed; }
.risk-medium { color: #d97706; border: 1px solid #fde68a; background: #fffbeb; }
.risk-low { color: #15803d; border: 1px solid #bbf7d0; background: #f0fdf4; }

.status-paid { color: #15803d; background: #dcfce7; }
.status-partial { color: #b45309; background: #fef3c7; }
.status-overdue { color: #dc2626; background: #fee2e2; }
.status-due_today,
.status-due_soon { color: #0369a1; background: #e0f2fe; }
.status-open { color: #475467; background: #eef2f7; }

.automation-panel {
  display: flex;
  flex-direction: column;
}

.live-dot {
  min-width: auto;
  color: var(--green);
  background: #dcfce7;
}

.automation-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.automation-stats span {
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 13px;
}

.automation-stats strong {
  display: block;
  color: var(--ink);
  font-size: 24px;
}

.queue-list {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.queue-item {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.queue-item header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.queue-item strong {
  font-size: 14px;
}

.queue-item p {
  margin: 0;
  font-size: 13px;
}

.automation-log {
  min-height: 44px;
  margin: 0 18px 16px;
  color: var(--teal-dark);
  font-size: 14px;
  font-weight: 700;
}

.automation-panel .secondary-button {
  margin: auto 18px 18px;
}

@media (max-width: 1400px) {
  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: block;
  }

  .brand,
  .nav-list {
    margin-bottom: 14px;
  }

  .nav-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .account-card {
    display: none;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .receivables-panel {
    grid-column: auto;
  }
}

@media (max-width: 760px) {
  .workspace {
    padding: 16px;
  }

  .topbar,
  .panel-header,
  .topbar-actions,
  .filters {
    align-items: stretch;
    flex-direction: column;
  }

  .nav-list,
  .kpi-grid,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .filters input,
  .filters select,
  .topbar-actions button {
    width: 100%;
  }

  .kpi-card {
    min-height: auto;
  }
}
