:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #dde3ea;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #dc2626;
  --warning: #f97316;
  --caution: #b45309;
  --ok: #16a34a;
  --expired: #111827;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 750;
  text-decoration: none;
}

.brand-logo {
  flex: 0 0 auto;
}

.nav {
  display: flex;
  align-items: center;
  gap: 14px;
}

.nav a,
.nav button,
.button-link,
.form-grid button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 12px;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
}

.nav button,
.form-grid button,
.button-link {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.site-footer {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 24px 24px;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: right;
}

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  margin-bottom: 22px;
}

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

h1 {
  margin-bottom: 6px;
  font-size: 1.65rem;
}

h2 {
  font-size: 1.05rem;
  margin-bottom: 12px;
}

p,
span {
  color: var(--muted);
}

.data-freshness {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.filter-bar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.filter-bar label {
  display: grid;
  min-width: 0;
  gap: 5px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.filter-bar input,
.filter-bar select {
  min-width: 0;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.filter-actions button,
.filter-actions a {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 6px;
  padding: 9px 12px;
  text-decoration: none;
  cursor: pointer;
  font: inherit;
}

.filter-actions a {
  background: var(--panel);
  color: var(--accent-dark);
}

.deadline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 0 0 16px;
  font-size: 0.84rem;
}

.deadline-legend a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  text-decoration: none;
}

.deadline-legend a:hover,
.deadline-legend a.active {
  background: var(--panel);
  border-color: var(--line);
}

.deadline-legend a.active {
  box-shadow: inset 0 0 0 1px currentColor;
  font-weight: 700;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.project-card,
.login-panel,
.form-panel,
.table-section,
.note {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.project-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 156px;
  padding: 16px;
  text-decoration: none;
}

.project-card:hover {
  border-top-color: var(--accent);
  border-right-color: var(--accent);
  border-bottom-color: var(--accent);
}

.deadline-card-danger {
  border-left: 6px solid var(--danger);
  background: #fff5f5;
}

.deadline-card-warning {
  border-left: 6px solid var(--warning);
  background: #fff7ed;
}

.deadline-card-caution {
  border-left: 5px solid var(--caution);
}

.deadline-card-ok {
  border-left: 6px solid var(--ok);
  background: #f0fdf4;
}

.deadline-card-expired {
  border-left: 6px solid var(--expired);
  background: #f3f4f6;
}

.code,
.badge {
  color: var(--accent-dark);
  font-weight: 700;
}

.code-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.badge {
  width: fit-content;
  border: 1px solid #99d3cc;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.8rem;
}

.deadline-pill {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.76rem;
  font-weight: 750;
  line-height: 1.2;
}

.deadline-danger,
.dot.deadline-danger {
  background: #fee2e2;
  color: #991b1b;
}

.dot.deadline-danger {
  background: var(--danger);
}

.deadline-warning,
.dot.deadline-warning {
  background: #ffedd5;
  color: #9a3412;
}

.dot.deadline-warning {
  background: var(--warning);
}

.deadline-caution,
.dot.deadline-caution {
  background: #fef3c7;
  color: var(--caution);
}

.dot.deadline-caution {
  background: var(--caution);
}

.deadline-ok,
.dot.deadline-ok {
  background: #dcfce7;
  color: #166534;
}

.dot.deadline-ok {
  background: var(--ok);
}

.deadline-expired,
.dot.deadline-expired {
  background: var(--expired);
  color: #ffffff;
}

.dot.deadline-expired {
  background: var(--expired);
}

.deadline-neutral {
  background: #eef2f7;
  color: var(--muted);
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.meta-grid div,
.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.meta-grid span,
.kpi span {
  display: block;
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.note {
  padding: 14px;
  margin-bottom: 18px;
}

.gauge-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.gauge-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 16px;
}

.gauge-card h2 {
  margin: 0;
  text-align: center;
}

.gauge {
  --gauge-color: var(--accent);
  width: 184px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, var(--panel) 0 57%, transparent 58%),
    conic-gradient(var(--gauge-color) var(--gauge-angle), #e5e7eb 0);
}

.gauge > div {
  display: grid;
  justify-items: center;
  gap: 3px;
  max-width: 132px;
  text-align: center;
}

.gauge strong {
  font-size: 1.55rem;
}

.gauge span {
  font-size: 0.76rem;
  line-height: 1.25;
}

.gauge-ok {
  --gauge-color: var(--ok);
}

.gauge-warning {
  --gauge-color: var(--warning);
}

.gauge-danger {
  --gauge-color: var(--danger);
}

.table-section {
  padding: 16px;
  margin-top: 16px;
}

.table-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 24px;
  height: 24px;
  padding: 0 4px;
  border-radius: 4px;
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.icon-link span {
  color: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

.icon-link:hover {
  color: var(--accent-dark);
  background: #eef3f6;
}

.table-scroll {
  overflow: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 760px;
  font-size: 0.88rem;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

thead th {
  background: #eef3f6;
  font-weight: 700;
}

.budget-table tbody tr:last-child {
  font-weight: 750;
}

.budget-table {
  width: max-content;
  min-width: 760px;
  table-layout: auto;
}

.budget-table th,
.budget-table td {
  background-clip: padding-box;
  overflow: visible;
  text-overflow: clip;
}

.budget-table tbody tr:nth-child(even) td {
  background-image: linear-gradient(rgba(15, 23, 42, 0.035), rgba(15, 23, 42, 0.035));
}

.resizable-table th {
  position: relative;
  user-select: none;
}

.column-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 8;
  touch-action: none;
}

.column-resizer::after {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 3px;
  width: 1px;
  background: rgba(15, 118, 110, 0.28);
  opacity: 0;
}

.resizable-table th:hover .column-resizer::after,
.is-resizing-columns .column-resizer::after {
  opacity: 1;
}

.is-resizing-columns {
  cursor: col-resize;
}

.budget-table .sticky-col {
  position: sticky;
  z-index: 3;
  box-shadow: 1px 0 0 var(--line);
}

.budget-table thead .sticky-col {
  z-index: 5;
}

.budget-table .sticky-col-1 {
  left: 0;
  min-width: 118px;
  width: 118px;
  max-width: 118px;
}

.budget-table .sticky-col-2 {
  left: 118px;
  min-width: 130px;
  width: 130px;
  max-width: 130px;
}

.budget-table th:not(.sticky-col),
.budget-table td:not(.sticky-col) {
  min-width: 124px;
  width: 124px;
}

.budget-table th.budget-group-total,
.budget-table td.budget-group-total {
  min-width: 118px;
  width: 118px;
}

.budget-table th.sticky-col,
.budget-table td.sticky-col {
  background: #ffffff;
}

.budget-table thead th.sticky-col {
  background: #eef3f6;
}

.budget-group-avant {
  background: #f1f5f9;
}

.budget-group-year-0 {
  background: #eef2ff;
}

.budget-group-year-1 {
  background: #ecfdf5;
}

.budget-group-year-2 {
  background: #fff7ed;
}

.budget-group-year-3 {
  background: #fdf2f8;
}

.budget-group-total {
  background: #f8fafc;
}

.budget-table thead .budget-group-avant {
  background: #e2e8f0;
}

.budget-table thead .budget-group-year-0 {
  background: #c7d2fe;
}

.budget-table thead .budget-group-year-1 {
  background: #bbf7d0;
}

.budget-table thead .budget-group-year-2 {
  background: #fed7aa;
}

.budget-table thead .budget-group-year-3 {
  background: #fbcfe8;
}

.budget-table thead .budget-group-total {
  background: #e5e7eb;
}

.budget-table td.is-negative {
  color: var(--danger);
  font-weight: 700;
}

.section-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.interactive-table thead .sortable-th {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 18px;
}

.interactive-table thead .sortable-th:hover {
  background: #e3eaf0;
}

.interactive-table thead .sortable-th::after {
  content: "";
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.65rem;
  opacity: 0.55;
  color: var(--accent-dark);
}

.interactive-table thead .sortable-th.sort-asc::after {
  content: "▲";
}

.interactive-table thead .sortable-th.sort-desc::after {
  content: "▼";
}

.interactive-table thead .filter-row th {
  background: #f4f7fa;
  border-bottom: 1px solid var(--line);
  padding: 3px 6px;
  cursor: default;
}

.interactive-table thead .filter-row th:hover {
  background: #f4f7fa;
}

.column-filter {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  padding: 3px 6px;
  font: inherit;
  font-size: 0.78rem;
  color: var(--muted);
  border-radius: 4px;
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
}

.column-filter::placeholder {
  color: transparent;
}

.column-filter:hover {
  border-color: var(--line);
  background: #ffffff;
}

.column-filter:focus {
  border-color: var(--accent);
  background: #ffffff;
  color: var(--text);
  outline: none;
}

.section-actions form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.form-grid {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.form-grid p {
  display: grid;
  min-width: 0;
  gap: 6px;
  margin: 0;
}

input,
select,
input[type="file"] {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  font: inherit;
  max-width: 100%;
}

.login-panel,
.form-panel {
  width: min(100%, 520px);
  max-width: 520px;
  padding: 20px;
}

.login-panel {
  margin: clamp(32px, 12vh, 96px) auto 0;
}

.login-panel h1 {
  text-align: center;
}

.form-panel select,
.form-panel input,
.form-panel button {
  width: 100%;
}

.form-panel input[type="file"] {
  background: white;
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.message {
  padding: 10px 12px;
  border-radius: 6px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
}

.back-link {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--accent-dark);
  text-decoration: none;
}

@media (max-width: 720px) {
  .topbar,
  .page-head,
  .section-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .shell {
    padding: 20px 14px 48px;
  }

  .filter-bar {
    grid-template-columns: 1fr;
  }

  .budget-table .sticky-col,
  .budget-table thead .sticky-col {
    position: sticky;
    z-index: 3;
    box-shadow: 1px 0 0 rgba(148, 163, 184, 0.28);
    background-color: #ffffff;
  }

  .budget-table thead .sticky-col {
    z-index: 5;
    background-color: #eef3f6;
  }

  .budget-table .sticky-col-2,
  .budget-table thead .sticky-col-2 {
    position: static;
    left: auto !important;
    z-index: auto;
    box-shadow: none;
  }
}
