:root {
  --bg: #f4f7f6;
  --card: #ffffff;
  --ink: #102033;
  --text: #344456;
  --muted: #687789;
  --line: #dfe8e6;
  --primary: #004684;
  --primary-2: #0b6fb8;
  --danger: #dc2626;
  --warn: #b7791f;
  --ok: #15803d;
  --shadow: 0 16px 42px rgba(12, 31, 42, .08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(90deg, rgba(0,70,132,.035) 1px, transparent 1px),
    linear-gradient(rgba(0,70,132,.035) 1px, transparent 1px),
    var(--bg);
  background-size: 44px 44px;
  font-family: Inter, Arial, sans-serif;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  min-height: 74px;
  padding: 0 28px;
  background: rgba(255,255,255,.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}
.brand { display: inline-flex; gap: 12px; align-items: center; font-weight: 900; color: var(--ink); }
.brand span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 44px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  box-shadow: 0 8px 22px rgba(0, 70, 132, .08);
}
.brand span img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.topbar nav { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.topbar nav > a,
.settings-menu summary,
.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 42px;
  padding: 0 15px;
  border: 0;
  border-radius: 999px;
  color: white;
  background: var(--primary);
  font-weight: 850;
  cursor: pointer;
}
.topbar nav > a,
.settings-menu summary,
.btn.primary {
  color: white;
  border: 1px solid var(--primary);
  background: var(--primary);
}
.btn.ghost { color: #163a5c; background: #eef6fc; border: 1px solid #c6dcec; }
.settings-menu {
  position: relative;
  display: inline-flex;
}
.settings-menu summary {
  appearance: none;
  -webkit-appearance: none;
  list-style: none !important;
  list-style-type: none !important;
  user-select: none;
}
.settings-menu summary::-webkit-details-marker {
  display: none;
}
.settings-menu summary::marker {
  content: "";
  display: none;
}
.settings-menu summary::after {
  content: "▾";
  margin-left: 8px;
  font-size: 12px;
  line-height: 1;
}
.settings-menu[open] summary {
  color: white;
  border-color: var(--primary);
  background: var(--primary);
}
.settings-menu[open] summary::after {
  transform: rotate(180deg);
}
.settings-menu > div {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 20;
  display: grid;
  gap: 8px;
  min-width: 190px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  box-shadow: var(--shadow);
}
.settings-menu > div a {
  display: inline-flex;
  align-items: center;
  width: 100%;
  justify-content: flex-start;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 10px;
  color: #163a5c;
  border: 1px solid #c6dcec;
  background: #eef6fc;
  font-weight: 850;
}
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.btn.danger { background: var(--danger); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 13px; }
.text-danger { border: 0; background: transparent; color: var(--danger); font-weight: 800; cursor: pointer; }

.container { width: min(1200px, calc(100% - 40px)); margin: 26px auto 60px; }
.page-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}
.eyebrow { margin: 0 0 8px; color: var(--primary); font-weight: 900; text-transform: uppercase; font-size: 12px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; color: var(--ink); font-size: clamp(30px, 4vw, 46px); line-height: 1.06; }
h2 { color: var(--ink); font-size: 22px; margin-bottom: 16px; }
.muted { color: var(--muted); line-height: 1.55; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions form { margin: 0; }
.status-update-form {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  flex-wrap: nowrap;
}
.status-update-form select {
  min-width: 160px;
  min-height: 42px;
}
.status-update-form .btn {
  min-width: 148px;
  white-space: nowrap;
  flex: 0 0 auto;
}
.page-tools { margin: 0 0 16px; }
.page-tools .btn,
.page-tools .btn.ghost {
  color: white;
  border-color: var(--primary);
  background: var(--primary);
}
.row-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.row-actions form { margin: 0; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.stat {
  min-height: 124px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.stat span { display: block; color: var(--muted); font-weight: 750; margin-bottom: 12px; }
.stat strong { color: var(--ink); font-size: 27px; line-height: 1.08; }
.stat.danger-stat {
  border-color: #fecaca;
  background: #fff5f5;
}
.stat.danger-stat span, .stat.danger-stat strong { color: #b91c1c; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-bottom: 18px; }
.card {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
}
.form-grid, .mini-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.mini-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.span-2 { grid-column: 1 / -1; }
label { display: grid; gap: 7px; color: var(--ink); font-weight: 800; }
input, select, textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(0,70,132,.12); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1180px; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 13px; }
.section-title-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}
.section-title-row h2 { margin-bottom: 0; }
.compact-tabs {
  width: min(960px, 100%);
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 0;
}
.compact-tabs a {
  min-height: 42px;
  font-size: 13px;
  padding: 6px 10px;
  white-space: nowrap;
}
.expenses-table table { min-width: 980px; }
.expenses-table th, .expenses-table td { padding: 11px 10px; }
.badge { display: inline-flex; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 900; background: #e2e8f0; color: #334155; }
.badge.paid { background: #dcfce7; color: #166534; }
.badge.planned { background: #fef3c7; color: #92400e; }
.badge.payable { background: #fef3c7; color: #92400e; }
.badge.debt { background: #fee2e2; color: #991b1b; }

.modal-open { overflow: hidden; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(16, 32, 51, .48);
}
.modal.is-open { display: flex; }
.modal-panel {
  width: min(720px, 100%);
  max-height: min(86vh, 720px);
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
  box-shadow: 0 24px 70px rgba(8, 25, 45, .24);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}
.modal-head h3 {
  margin: 0;
  color: var(--ink);
  font-size: 22px;
}
.modal-close {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  color: white;
  background: var(--primary);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.chip {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 7px 10px 7px 14px;
  border: 1px solid #c6dcec;
  border-radius: 999px;
  background: #f6fbff;
  color: var(--ink);
  font-weight: 800;
}
.chip button {
  min-height: 28px;
  border: 0;
  border-radius: 999px;
  background: #fee2e2;
  color: var(--danger);
  font-weight: 900;
  cursor: pointer;
}

.project-list { display: grid; gap: 10px; }
.project-row, .due-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fbfe;
}
.project-row:hover, .due-row:hover { border-color: rgba(0,70,132,.45); }
.project-row strong, .due-row strong { display: block; color: var(--ink); }
.project-row small, .due-row small { display: block; color: var(--muted); margin-top: 4px; }
.project-row.is-overdue, .due-row.is-overdue {
  border-color: #fecaca;
  background: #fff5f5;
}
.project-row.is-overdue strong, .project-row.is-overdue b,
.due-row.is-overdue strong, .due-row.is-overdue b { color: #b91c1c; }
.project-row.is-overdue small, .due-row.is-overdue small { color: #991b1b; }

.nav-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  padding: 6px;
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f3f8fd;
}
.nav-tabs a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 10px;
  color: #526477;
  font-weight: 900;
  cursor: pointer;
}
.nav-tabs a.active {
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 10px 22px rgba(15, 118, 110, .18);
}
.tab-panel { display: block; }

.dashboard-head {
  align-items: center;
  margin-bottom: 12px;
}
.dashboard-head h1 {
  font-size: clamp(28px, 3vw, 38px);
}
.dashboard-head .muted {
  margin-bottom: 0;
}
.dashboard-metrics {
  grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.dashboard-metrics .stat {
  min-height: 82px;
  padding: 13px 14px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(12, 31, 42, .055);
}
.dashboard-metrics .stat span {
  margin-bottom: 8px;
  font-size: 12px;
}
.dashboard-metrics .stat strong {
  font-size: 20px;
  letter-spacing: 0;
}
.dashboard-layout {
  grid-template-columns: 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.dashboard-card {
  padding: 16px;
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(12, 31, 42, .06);
}
.dashboard-card h2 {
  margin-bottom: 12px;
  font-size: 19px;
}
.distribution-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}
.distribution-item {
  display: grid;
  gap: 5px;
  min-height: 96px;
  padding: 13px 14px;
  border: 1px solid #c6dcec;
  border-radius: 12px;
  background: linear-gradient(180deg, #ffffff, #f6fbff);
}
.distribution-item:hover {
  border-color: var(--primary);
  box-shadow: 0 10px 24px rgba(0, 70, 132, .08);
}
.distribution-item strong {
  color: var(--ink);
  font-size: 15px;
}
.distribution-item span,
.distribution-item small {
  color: var(--muted);
  font-weight: 750;
}
.distribution-item b {
  color: var(--primary);
  font-size: 15px;
}
.dashboard-card .project-list {
  gap: 8px;
}
.dashboard-card .due-row {
  min-height: 58px;
  padding: 11px 12px;
  border-radius: 10px;
}
.dashboard-card .due-row small {
  margin-top: 2px;
}
.dashboard-tabs .nav-tabs {
  margin-bottom: 14px;
  padding: 4px;
  border-radius: 12px;
}
.dashboard-tabs .nav-tabs a {
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 9px;
  font-size: 13px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-wrap { width: min(460px, 100%); }
.login-card {
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: white;
  box-shadow: var(--shadow);
}
.login-logo {
  display: inline-flex;
  width: 92px;
  height: 68px;
  padding: 10px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
  box-shadow: 0 12px 32px rgba(0, 70, 132, .08);
}
.login-logo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.login-card h1 { font-size: 34px; }
.login-card form { display: grid; gap: 14px; }
.captcha-line {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}
.captcha-line b {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  border-radius: 12px;
  background: #eef2f7;
  color: var(--ink);
  letter-spacing: 1px;
}
.alert { padding: 12px 14px; border-radius: 12px; margin-bottom: 14px; font-weight: 800; }
.alert.danger { background: #fee2e2; color: #991b1b; }

@media (max-width: 980px) {
  .topbar { align-items: flex-start; flex-direction: column; padding: 16px 20px; }
  .topbar nav { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar nav a { width: 100%; }
  .settings-menu, .settings-menu summary { width: 100%; }
  .settings-menu > div { position: static; margin-top: 8px; box-shadow: none; }
  .container { width: min(100% - 28px, 1200px); margin-top: 18px; }
  .page-head, .grid-2 { grid-template-columns: 1fr; flex-direction: column; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .mini-form { grid-template-columns: 1fr; }
  .nav-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .section-title-row { align-items: stretch; flex-direction: column; }
  .compact-tabs { width: 100%; grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .topbar nav { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .card { padding: 18px; }
  .stat strong { font-size: 24px; }
  .project-row, .due-row { align-items: flex-start; flex-direction: column; }
  .btn, .actions, .actions form { width: 100%; }
  .status-update-form { flex-direction: row; align-items: center; width: 100%; }
  .status-update-form select { width: 100%; min-width: 0; flex: 1 1 auto; }
  .status-update-form .btn { width: auto; min-width: 132px; padding-inline: 14px; }
  .row-actions { width: 100%; }
  .row-actions .btn, .row-actions form { width: auto; }
  .captcha-line { grid-template-columns: 1fr; }
  .nav-tabs { grid-template-columns: 1fr; }
  .compact-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
