:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --panel-2: #fbfbfc;
  --text: #1f2933;
  --muted: #64717f;
  --line: #d9dee5;
  --accent: #0f766e;
  --accent-2: #b45309;
  --danger: #be123c;
  --shadow: 0 8px 24px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px clamp(16px, 3vw, 32px);
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

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

.top-actions form {
  margin: 0;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-weight: 720;
  text-decoration: none;
}

.user-label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.25rem, 2vw, 1.7rem);
  font-weight: 760;
}

h2 {
  font-size: 0.98rem;
  font-weight: 740;
}

#statusLine {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.controls {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-shell {
  width: min(420px, 100%);
}

.login-panel {
  display: grid;
  gap: 18px;
  padding: 26px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel p {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form button {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.login-error,
.admin-message {
  padding: 10px 12px;
  border-radius: 8px;
  font-weight: 700;
}

.login-error,
.admin-message.err {
  background: #fff1f2;
  color: var(--danger);
  border: 1px solid #fecdd3;
}

.admin-message.ok {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}

.admin-shell {
  display: grid;
  gap: 14px;
}

.create-user-form,
.inline-admin-form {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 15px;
}

.inline-admin-form {
  padding: 0;
}

.inline-admin-form input[type="password"] {
  width: 170px;
}

.check-label {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 6px;
  height: 36px;
  text-transform: none;
}

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

select,
input,
button {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

select,
input {
  padding: 0 10px;
}

button {
  cursor: pointer;
  padding: 0 12px;
  font-weight: 720;
}

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

.segmented {
  display: grid;
  grid-template-columns: repeat(5, minmax(58px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.segmented button {
  min-width: 0;
  border: 0;
  border-radius: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  font-size: 0.86rem;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: var(--accent);
  color: #fff;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 1.2rem;
}

.shell {
  width: min(1520px, 100%);
  margin: 0 auto;
  padding: 22px clamp(16px, 3vw, 32px) 36px;
}

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

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

.metric-card {
  display: grid;
  gap: 7px;
  min-height: 110px;
  padding: 18px;
}

.metric-card span,
.metric-card small {
  color: var(--muted);
}

.metric-card span {
  font-size: 0.82rem;
  font-weight: 740;
  text-transform: uppercase;
}

.metric-card strong {
  font-size: clamp(1.45rem, 3vw, 2.25rem);
  line-height: 1;
}

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

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 13px 15px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.panel canvas {
  display: block;
  width: 100%;
  height: 280px;
  padding: 10px;
}

.span-2 {
  grid-column: span 2;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 760;
  text-transform: uppercase;
}

td.numeric {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.name-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #edf7f5;
  color: #0f766e;
  font-size: 0.78rem;
  font-weight: 760;
}

.badge.warn {
  background: #fff7ed;
  color: var(--accent-2);
}

.badge.done {
  background: #f1f5f9;
  color: #475569;
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1060px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .controls {
    width: 100%;
    justify-content: flex-start;
  }

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

@media (max-width: 760px) {
  .metric-grid,
  .chart-grid,
  .table-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .segmented {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .custom-range {
    width: calc(50% - 6px);
  }

  .custom-range input {
    width: 100%;
  }
}
