:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef2f7;
  --surface-tint: #dff6ef;
  --text: #172033;
  --muted: #4b5a6d;
  --line: #c3cedb;
  --line-strong: #9eacbd;
  --primary: #0c8a76;
  --primary-dark: #087360;
  --accent: #2563eb;
  --success: #087553;
  --warning: #a15c07;
  --danger: #b42318;
  --nav: #111827;
  --nav-muted: #9aa7bb;
  --shadow: 0 10px 30px rgba(30, 41, 59, 0.07);
  --shadow-lg: 0 18px 45px rgba(30, 41, 59, 0.11);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 276px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px 18px;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #111827 0%, #172338 100%);
  color: #ffffff;
}

.brand,
.login-brand {
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #ffffff, #dffbf3);
  color: var(--primary);
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 2px;
  color: var(--nav-muted);
  font-size: 0.8rem;
}

.nav {
  margin-top: 34px;
  display: grid;
  gap: 6px;
}

.nav a {
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  color: #d6dde8;
  font-weight: 750;
  transition: background .18s ease, transform .18s ease, color .18s ease;
}

.nav a:hover,
.nav a.is-active {
  background: linear-gradient(90deg, rgba(45, 212, 191, .22), rgba(255, 255, 255, .07));
  color: #ffffff;
  transform: translateX(2px);
}

.logout-form {
  margin-top: auto;
  padding-top: 18px;
  display: grid;
  gap: 10px;
  color: var(--nav-muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.workspace {
  min-width: 0;
  padding: 34px clamp(18px, 4vw, 54px);
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

.topbar {
  margin-bottom: 28px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.18;
}

h1 {
  font-size: clamp(1.55rem, 2.4vw, 2.05rem);
  letter-spacing: -.035em;
}

h2 {
  font-size: 1.08rem;
}

h3 {
  margin-top: 18px;
  font-size: 0.96rem;
}

.page-grid,
.stack {
  display: grid;
  gap: 18px;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(300px, 410px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.invoices-layout {
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
}

.panel {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: box-shadow .2s ease, transform .2s ease;
}

.panel:hover {
  box-shadow: var(--shadow-lg);
}

.panel-header {
  margin-bottom: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.metrics-grid.compact {
  margin-bottom: 16px;
}

.metric-card {
  min-height: 98px;
  padding: 19px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(145deg, #ffffff 0%, #eef2f7 100%);
  box-shadow: 0 5px 16px rgba(30, 41, 59, .035);
}

.metric-card.highlight-warning {
  border-color: #d7a84b;
  background: #fff1c7;
}

.metric-card.highlight-success {
  border-color: #65b99a;
  background: #d9f2e7;
}

.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  margin-top: 9px;
  font-size: 1.6rem;
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.form {
  display: grid;
  gap: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 0.83rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid #9eacbd;
  border-radius: 11px;
  padding: 10px 13px;
  background: #eef2f7;
  color: var(--text);
  font: inherit;
}

input:focus,
select:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(15, 118, 110, 0.16);
  background: #fff;
}

.actions,
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 9px 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button.primary {
  background: linear-gradient(135deg, var(--primary), #0b7668);
  color: #ffffff;
  box-shadow: 0 7px 16px rgba(12, 138, 118, .2);
}

.button.primary:hover {
  background: var(--primary-dark);
}

.button.secondary {
  border-color: var(--line-strong);
}

.button.secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.button.ghost {
  border-color: rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.button.danger {
  border-color: #ffc9c9;
  background: #fff0f0;
  color: var(--danger);
}

.button.small {
  min-height: 32px;
  padding: 6px 9px;
  font-size: 0.82rem;
}

.flash-stack {
  margin-bottom: 18px;
  display: grid;
  gap: 10px;
}

.flash,
.alert {
  border-radius: 13px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 800;
}

.flash.success {
  background: #e9f7f1;
  color: var(--success);
  border-color: #b7e3d1;
}

.flash.error {
  background: #fff0f0;
  color: var(--danger);
  border-color: #ffc9c9;
}

.strong-warning {
  color: var(--warning);
  font-weight: 900;
}

.alert.warning {
  margin-bottom: 16px;
  background: #fff7e6;
  color: var(--warning);
  border-color: #f2d199;
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: #eef2f7;
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}

.list-item.linked:hover,
.list-item.selected {
  border-color: var(--primary);
  background: var(--surface-tint);
  transform: translateX(2px);
}

.list-item strong,
.list-item small {
  display: block;
}

.list-item small,
td small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.76rem;
  font-weight: 900;
  background: #dce4ee;
  color: #253449;
}

.badge.primary {
  background: #dbe7ff;
  color: var(--accent);
}

.badge.success {
  background: #d9f2e7;
  color: var(--success);
}

.badge.warning {
  background: #ffe5a6;
  color: var(--warning);
}

.table-link {
  color: var(--primary);
  font-weight: 900;
}

.person-heading {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.person-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.person-title small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-weight: 800;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #ffffff;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

table.dense {
  min-width: 920px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 0.88rem;
}

th {
  background: #e5ebf2;
  color: #26364b;
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #edf3f7;
}

.money,
.number {
  text-align: right;
  white-space: nowrap;
}

.empty {
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: 13px;
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 750;
}

.row-actions form {
  margin: 0;
}

.login-page {
  background: radial-gradient(circle at top left, rgba(15, 118, 110, 0.12), transparent 30%), var(--bg);
}

.login-shell {
  min-height: 100vh;
  width: min(440px, calc(100% - 28px));
  margin: 0 auto;
  display: grid;
  align-content: center;
  gap: 14px;
  padding: 28px 0;
}

.login-card {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #ffffff;
  box-shadow: var(--shadow-lg);
}

.login-card .brand-mark {
  background: var(--primary);
  color: #ffffff;
}

.login-brand {
  align-items: flex-start;
  margin-bottom: 22px;
}

.login-form .button {
  width: 100%;
}

.login-flashes {
  margin-bottom: 0;
}

@media (max-width: 1060px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }

  .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-top: 16px;
  }

  .logout-form {
    grid-template-columns: 1fr auto;
    align-items: center;
    padding-top: 12px;
  }

  .two-column,
  .invoices-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .workspace {
    padding: 16px;
  }

  .sidebar {
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  }

  .brand {
    align-items: flex-start;
  }

  .nav {
    grid-template-columns: 1fr 1fr;
  }

  .nav a {
    min-height: 40px;
    padding: 9px 10px;
    font-size: 0.9rem;
  }

  .topbar,
  .panel-header,
  .list-item,
  .person-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .metrics-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .metric-card {
    min-height: 86px;
  }

  .panel {
    padding: 15px;
    border-radius: 15px;
  }

  h1 {
    font-size: 1.38rem;
  }

  .actions,
  .row-actions {
    width: 100%;
  }

  .actions .button,
  .row-actions .button,
  .row-actions form {
    width: 100%;
  }
}
