:root {
  --bg: #f3f5f7;
  --bg-soft: #e9edf1;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --ink: #1d252c;
  --ink-strong: #111820;
  --muted: #64717d;
  --muted-strong: #3e4a55;
  --line: #d9e0e7;
  --line-soft: #e9eef2;
  --sidebar: #151b20;
  --sidebar-soft: #202932;
  --brand: #12726f;
  --brand-dark: #0d5f5d;
  --brand-soft: #e7f4f2;
  --accent: #a83f4b;
  --accent-soft: #fff0f2;
  --ok: #447233;
  --ok-soft: #edf6ea;
  --warning: #b87717;
  --shadow: 0 18px 45px rgba(19, 30, 40, 0.08);
  --shadow-soft: 0 8px 24px rgba(19, 30, 40, 0.06);
  --radius: 8px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Arial, Helvetica, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.7) 0, rgba(255,255,255,0) 260px),
    var(--bg);
  font-size: 14px;
  line-height: 1.45;
}

a { color: inherit; }

.app-page {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 244px;
  background: var(--sidebar);
  color: white;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-right: 1px solid rgba(255,255,255,0.08);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #1b8a82, #a83f4b);
  color: white;
  font-weight: 800;
  font-size: 20px;
  box-shadow: 0 14px 28px rgba(0,0,0,0.2);
}

.brand strong {
  display: block;
  font-size: 20px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand span {
  color: #b8c3ce;
  font-size: 12px;
}

nav {
  display: grid;
  gap: 7px;
}

nav a,
.ghost {
  color: #e9eef2;
  text-decoration: none;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  text-align: left;
  font-size: 14px;
  font-weight: 650;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

nav a:hover,
.ghost:hover {
  background: var(--sidebar-soft);
  border-color: rgba(255,255,255,0.1);
}

nav a.active {
  background: #f3f7f8;
  border-color: #f3f7f8;
  color: var(--sidebar);
}

.logout-form {
  margin-top: auto;
}

.ghost {
  cursor: pointer;
  width: 100%;
  font-family: inherit;
}

.main {
  margin-left: 244px;
  padding: 24px clamp(18px, 2.4vw, 34px) 34px;
}

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

h1,
h2 {
  color: var(--ink-strong);
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.12;
}

h2 {
  margin: 0 0 14px;
  font-size: 16px;
  line-height: 1.25;
}

p {
  margin: 5px 0 0;
  color: var(--muted);
}

.userbox {
  max-width: 260px;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--muted-strong);
  font-weight: 650;
  box-shadow: var(--shadow-soft);
  overflow-wrap: anywhere;
}

.filters,
.form-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr)) auto;
  gap: 12px;
  align-items: end;
}

.filters-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.92);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

.filters-contained {
  margin-top: 6px;
}

.filter-actions {
  display: flex;
  gap: 8px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted-strong);
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  background: white;
  color: var(--ink);
  transition: border-color 150ms ease, box-shadow 150ms ease, background-color 150ms ease;
}

select {
  appearance: auto;
}

input:focus,
select:focus,
button:focus-visible,
.button:focus-visible,
nav a:focus-visible {
  outline: 3px solid rgba(18, 114, 111, 0.18);
  outline-offset: 1px;
  border-color: var(--brand);
}

input:hover,
select:hover {
  border-color: #c5cfd8;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--brand);
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: white;
  padding: 8px 14px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  font: inherit;
  font-size: 14px;
  font-weight: 750;
  white-space: nowrap;
  transition: transform 120ms ease, background-color 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

button:hover,
.button:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
  box-shadow: 0 10px 20px rgba(18, 114, 111, 0.16);
}

button:active,
.button:active {
  transform: translateY(1px);
}

button.secondary,
.button.secondary {
  background: white;
  color: var(--brand);
  border-color: #b8d6d2;
}

button.secondary:hover,
.button.secondary:hover {
  background: var(--brand-soft);
  color: var(--brand-dark);
  box-shadow: none;
}

button.danger {
  border-color: var(--accent);
  background: var(--accent);
}

button.danger:hover {
  background: #8f3340;
  border-color: #8f3340;
  box-shadow: 0 10px 20px rgba(168, 63, 75, 0.16);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.kpi,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.kpi {
  position: relative;
  overflow: hidden;
  min-height: 116px;
  padding: 18px;
}

.kpi::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}

.kpi span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.kpi strong {
  display: block;
  margin-top: 12px;
  font-size: clamp(22px, 2.5vw, 30px);
  line-height: 1.05;
  color: var(--ink-strong);
  overflow-wrap: anywhere;
}

.panel {
  padding: 16px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.chart-panel {
  min-height: 336px;
}

canvas {
  width: 100%;
  max-height: 278px;
}

.table-panel {
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border-bottom: 1px solid var(--line-soft);
  padding: 11px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted-strong);
  font-weight: 800;
  background: var(--panel-soft);
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #fbfcfd;
}

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

.center {
  text-align: center;
  justify-content: center;
}

.actions {
  display: flex;
  gap: 7px;
  align-items: center;
  justify-content: flex-end;
}

.actions button {
  min-height: 34px;
  padding-inline: 10px;
  font-size: 13px;
}

.inline { display: inline; }

.user-grid {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr) minmax(120px, 0.8fr) 96px 72px minmax(120px, 1fr) 172px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid var(--line-soft);
}

.user-grid:not(.user-grid-head):hover {
  background: #fbfcfd;
}

.user-grid-head {
  color: var(--muted-strong);
  font-weight: 800;
  background: var(--panel-soft);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  font-size: 12px;
  text-transform: uppercase;
}

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

.check input,
.center input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  accent-color: var(--brand);
}

.alert {
  border: 1px solid rgba(68, 114, 51, 0.35);
  border-radius: var(--radius-sm);
  background: var(--ok-soft);
  color: #2f5623;
  padding: 11px 13px;
  margin-bottom: 12px;
  font-weight: 650;
}

.alert.error {
  border-color: rgba(168, 63, 75, 0.35);
  background: var(--accent-soft);
  color: #7a2d37;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    radial-gradient(circle at top left, rgba(18, 114, 111, 0.24), transparent 330px),
    linear-gradient(135deg, #111820, #202932);
}

.login-shell {
  width: min(440px, calc(100vw - 30px));
}

.login-panel {
  position: relative;
  overflow: hidden;
  background: white;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 24px 70px rgba(0,0,0,0.26);
}

.login-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 5px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}

.login-panel h1 {
  font-size: 32px;
}

.form-stack {
  display: grid;
  gap: 14px;
  margin-top: 20px;
}

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

  .filter-actions {
    grid-column: 1 / -1;
  }

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

  .user-grid {
    grid-template-columns: minmax(120px, 1fr) minmax(120px, 1fr) minmax(120px, 1fr);
  }

  .user-grid-head {
    display: none;
  }
}

@media (max-width: 900px) {
  .sidebar {
    position: static;
    width: 100%;
    padding: 14px;
    gap: 14px;
  }

  .brand {
    min-height: 40px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  nav a,
  .ghost {
    text-align: center;
    padding-inline: 8px;
  }

  .logout-form {
    margin-top: 0;
  }

  .main {
    margin-left: 0;
    padding: 18px 14px 28px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .userbox {
    max-width: none;
  }

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

  .chart-panel {
    min-height: 300px;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

@media (max-width: 640px) {
  .filters,
  .form-grid,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .filter-actions,
  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  button,
  .button {
    width: 100%;
  }

  .panel,
  .kpi {
    padding: 14px;
  }

  .user-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px 0;
  }

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