:root {
  --ink: #19222d;
  --muted: #657280;
  --bg: #f4f7fa;
  --card: #ffffff;
  --sidebar: #101d2b;
  --sidebar-soft: #142a37;
  --active: #1f4a57;
  --teal: #0d9488;
  --teal-dark: #0f766e;
  --teal-soft: #dff7f3;
  --blue: #2563eb;
  --amber: #d97706;
  --red: #dc2626;
  --green: #16a34a;
  --border: #e2e8f0;
  --shadow: 0 16px 42px rgba(15, 23, 42, .08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

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

button {
  border: 0;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 18px 11px 16px 17px;
  color: #fff;
  background: var(--sidebar);
  z-index: 4;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 78px;
  margin-bottom: 22px;
}

.brand-logo {
  width: 56px;
  height: 56px;
  object-fit: contain;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, .22));
}

.brand-name {
  color: #fff;
  font-size: 19px;
  font-weight: 800;
  line-height: 1.04;
  letter-spacing: .01em;
  text-transform: uppercase;
}

.brand-surname {
  color: #7ed3ca;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.12;
  text-transform: uppercase;
}

.brand-sub {
  margin-top: 4px;
  color: #c7d8df;
  font-size: 12px;
  font-weight: 700;
}

.nav {
  display: grid;
  gap: 5px;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  color: #bfd3dc;
  background: transparent;
  border-radius: 0;
  cursor: pointer;
  text-align: left;
}

.nav button:hover {
  background: #193945;
}

.nav button.active {
  color: #fff;
  background: var(--active);
  font-weight: 800;
}

.nav .icon {
  width: 24px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding: 17px;
  background: var(--sidebar-soft);
}

.sidebar-footer strong,
.sidebar-footer span,
.sidebar-footer small {
  display: block;
}

.sidebar-footer strong {
  font-size: 14px;
}

.sidebar-footer span {
  margin-top: 10px;
  color: #b7ced8;
  font-size: 12px;
}

.sidebar-footer small {
  margin-top: 18px;
  color: #5eead4;
  font-size: 12px;
  font-weight: 800;
}

.main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  min-height: 82px;
  padding: 14px 30px;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid rgba(226, 232, 240, .7);
  backdrop-filter: blur(14px);
  z-index: 3;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 31px);
  line-height: 1.05;
}

.topbar p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

.date-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.content {
  padding: 24px 24px 28px;
}

.grid {
  display: grid;
  gap: 16px;
}

.metrics {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.two-col {
  grid-template-columns: minmax(0, 1.65fr) minmax(310px, .95fr);
  align-items: stretch;
}

.settings-grid {
  grid-template-columns: minmax(0, 1.55fr) minmax(310px, .95fr);
}

.card,
.metric,
.banner {
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.card {
  min-width: 0;
  padding: 20px;
  border-radius: var(--radius);
}

.card.tight {
  padding: 0;
  overflow: hidden;
}

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

.card h2 {
  margin: 0;
  font-size: 18px;
}

.card .sub {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.metric {
  position: relative;
  min-height: 112px;
  padding: 17px 17px 14px 22px;
  overflow: hidden;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 18px auto 18px 0;
  width: 5px;
  background: var(--accent, var(--teal));
}

.metric .label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.metric .value {
  margin-top: 12px;
  font-size: clamp(22px, 2vw, 28px);
  font-weight: 900;
}

.metric .detail {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 13px 16px;
  color: #92400e;
  background: #fffbeb;
  border-color: #fde68a;
}

.banner strong {
  display: block;
}

.table-wrap {
  overflow: auto;
}

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

th {
  color: var(--muted);
  background: #f8fafc;
  font-size: 12px;
  font-weight: 900;
  text-align: left;
  text-transform: uppercase;
}

th,
td {
  padding: 12px 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover {
  background: #f8fbfc;
}

.row-title {
  font-weight: 800;
}

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

.money {
  font-weight: 900;
}

.status {
  display: inline-flex;
  align-items: center;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.status.paid,
.status.active,
.status.closed {
  color: #166534;
  background: #dcfce7;
}

.status.late {
  color: #991b1b;
  background: #fee2e2;
}

.status.soon,
.status.wait {
  color: #92400e;
  background: #fffbeb;
}

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

.btn,
.ghost,
.danger,
.link-button {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 900;
}

.btn {
  color: #fff;
  background: var(--teal-dark);
}

.btn:hover {
  background: #0b5f59;
}

.ghost {
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--border);
}

.ghost:hover {
  background: #f8fafc;
}

.danger {
  color: var(--red);
  background: #fff;
  border: 1px solid #fecaca;
}

.link-button {
  min-height: auto;
  padding: 0;
  color: var(--teal-dark);
  background: transparent;
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

.summary-list {
  display: grid;
  gap: 9px;
}

.summary-line {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 14px;
}

.summary-line strong {
  color: var(--ink);
}

.summary-line .green {
  color: var(--green);
}

.summary-line .amber {
  color: var(--amber);
}

.summary-line .teal {
  color: var(--teal-dark);
}

.summary-line .red {
  color: var(--red);
}

.bar-chart {
  display: grid;
  gap: 12px;
  padding-top: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 90px;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.bar-track {
  height: 18px;
  background: #eef2f7;
  overflow: hidden;
}

.bar {
  height: 100%;
  min-width: 3px;
  background: var(--teal);
}

.donut {
  --loan: 0deg;
  --card: 0deg;
  width: min(220px, 70vw);
  aspect-ratio: 1;
  margin: 8px auto 18px;
  border-radius: 50%;
  background: conic-gradient(var(--blue) 0 var(--loan), var(--teal) var(--loan) calc(var(--loan) + var(--card)), #e5e7eb 0);
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 31%;
  border-radius: 50%;
  background: #fff;
}

.legend {
  display: grid;
  gap: 8px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.swatch {
  width: 18px;
  height: 10px;
  background: var(--teal);
}

.empty {
  display: grid;
  place-items: center;
  min-height: 190px;
  color: var(--muted);
  text-align: center;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field.wide {
  grid-column: 1 / -1;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 39px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cfd8e3;
  border-radius: 10px;
}

.checkline {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  align-items: center;
  padding-top: 22px;
}

.checkline label {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, .42);
  z-index: 10;
}

.modal {
  width: min(860px, 100%);
  max-height: min(92vh, 820px);
  overflow: auto;
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 28px 90px rgba(0, 0, 0, .28);
}

.modal header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}

.modal header h2 {
  margin: 0;
}

.modal form,
.modal .modal-body {
  padding: 22px;
}

.modal footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 18px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 13px 15px;
  color: #fff;
  background: #0f172a;
  border-radius: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(14px);
  transition: .2s ease;
  pointer-events: none;
  z-index: 20;
}

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

.logo-preview {
  display: block;
  width: min(540px, 100%);
  margin: 0 auto 18px;
}

.import-input {
  display: none;
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #fff;
  color: var(--ink);
  z-index: 99;
  font-size: 18px;
  font-weight: 800;
}

@media (max-width: 1180px) {
  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .two-col,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar {
    position: sticky;
    height: auto;
    padding: 11px;
  }

  .brand {
    min-height: 58px;
    margin-bottom: 10px;
  }

  .brand-logo {
    width: 48px;
    height: 48px;
  }

  .brand-name {
    font-size: 16px;
  }

  .brand-surname {
    font-size: 12px;
  }

  .brand-sub {
    display: none;
  }

  .nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .nav button {
    flex: 0 0 auto;
    min-height: 38px;
    width: auto;
    padding-inline: 12px;
    border-radius: 999px;
  }

  .nav .text {
    white-space: nowrap;
  }

  .sidebar-footer {
    display: none;
  }

  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    padding: 18px 18px 14px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .content {
    padding: 16px;
  }

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

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

  .bar-row {
    grid-template-columns: 92px 1fr;
  }

  .bar-row strong {
    grid-column: 2;
  }
}

@media (display-mode: standalone) {
  .topbar {
    padding-top: max(14px, env(safe-area-inset-top));
  }
}
