:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #1d2530;
  --muted: #687385;
  --line: #dbe1e8;
  --brand: #16a36b;
  --brand-dark: #08734a;
  --x: #222831;
  --warning: #a45a00;
  --shadow: 0 16px 48px rgba(35, 45, 60, 0.08);
}

* {
  box-sizing: border-box;
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(20px, 4vw, 56px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px clamp(16px, 3vw, 32px) 56px;
}

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

.controls-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(280px, 1.4fr) 100px 150px 150px;
  gap: 16px;
  padding: 18px;
}

.control-group {
  display: grid;
  gap: 7px;
}

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

.hint {
  color: var(--muted);
  font-size: 12px;
}

input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  background: #fbfcfd;
  color: var(--ink);
  font: 12px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.55;
}

.button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.secondary {
  background: var(--brand);
  color: #fff;
}

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

.danger {
  color: #a23b3b;
}

.logout-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.header-actions {
  display: flex;
  gap: 10px;
}

.status-panel {
  margin-top: 16px;
  padding: 14px 16px;
  color: var(--muted);
}

.status-panel.warning {
  border-color: #ecc879;
  background: #fff7e6;
  color: var(--warning);
}

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

.kpi-card {
  padding: 18px;
}

.kpi-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi-card strong {
  display: block;
  margin-top: 8px;
  font-size: 34px;
  line-height: 1;
}

.kpi-card small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.8fr);
  gap: 16px;
  margin-top: 18px;
}

.chart-panel,
.panel {
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel-heading p {
  color: var(--muted);
  font-size: 13px;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid #edf1f5;
  border-radius: 6px;
}

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

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 9px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

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

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

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: #edf7f2;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 700;
}

.tag.x {
  background: #eef0f3;
  color: var(--x);
}

.note-warning {
  color: var(--warning);
  font-weight: 700;
}

.notes {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
}

.notes li + li {
  margin-top: 8px;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
}

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

.login-panel h1 {
  margin-bottom: 8px;
}

.login-button {
  margin-top: 8px;
}

.login-error {
  padding: 10px 12px;
  border: 1px solid #efb2b2;
  border-radius: 6px;
  background: #fff0f0;
  color: #a23b3b;
  font-weight: 700;
}

.export-panel {
  margin-top: 18px;
}

.export-actions {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 10px;
  margin-bottom: 12px;
}

@media (max-width: 980px) {
  .app-header,
  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .controls-panel,
  .dashboard-grid,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .button {
    flex: 1;
  }

  .export-actions {
    grid-template-columns: 1fr;
  }
}
