:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #172033;
  --muted: #667085;
  --line: #d8dee8;
  --line-soft: #edf0f5;
  --red: #9f1239;
  --red-2: #be123c;
  --red-soft: #fff1f3;
  --green: #14804a;
  --green-soft: #e9f8ef;
  --amber: #b7791f;
  --amber-soft: #fff7e6;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --shadow: 0 18px 45px rgba(23, 32, 51, 0.08);
  --radius: 8px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.login-panel {
  width: min(460px, 100%);
  display: grid;
  grid-template-columns: 1fr;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.login-form-side {
  padding: 24px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--red);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
  flex: 0 0 auto;
}

.brand-title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.brand-subtitle,
.page-note,
.muted {
  color: var(--muted);
}

.brand-subtitle {
  font-size: 12px;
  margin-top: 2px;
}

.page-title {
  margin: 0 0 8px;
  font-size: 24px;
  line-height: 1.2;
}

.page-note {
  margin: 0 0 18px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: var(--text);
  font-weight: 600;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

.textarea {
  min-height: 86px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(159, 18, 57, 0.12);
}

.button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  padding: 8px 12px;
  font-weight: 700;
}

.button.primary {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

#loginForm .button.primary {
  width: 100%;
}

.button.ghost {
  border-color: transparent;
  background: transparent;
}

.button.danger {
  border-color: #fecdd3;
  background: #fff1f3;
  color: var(--red);
}

.login-preview {
  min-height: 424px;
  background: linear-gradient(180deg, #fff5f6 0%, #f8fafc 100%);
  border-left: 1px solid var(--line);
  padding: 24px;
  display: grid;
  align-content: center;
  gap: 14px;
}

.report-asset {
  width: 100%;
  max-height: 310px;
  object-fit: cover;
  object-position: top;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.preview-caption {
  color: var(--muted);
  font-size: 13px;
}

.login-error {
  min-height: 20px;
  color: var(--red);
  font-weight: 700;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

.nav-button {
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  padding: 10px 12px;
  text-align: left;
  font-weight: 800;
}

.nav-button.active {
  background: var(--red-soft);
  color: var(--red);
}

.side-meta {
  margin-top: 20px;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface-2);
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.main {
  min-width: 0;
  padding: 22px;
}

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

.eyebrow {
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.view-title {
  margin: 2px 0 0;
  font-size: 26px;
  line-height: 1.2;
}

.context-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.compact-field {
  display: grid;
  gap: 5px;
  min-width: 180px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.compact-select {
  min-height: 36px;
  padding-block: 7px;
  color: var(--text);
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.grid {
  display: grid;
  gap: 14px;
}

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

.two-col {
  grid-template-columns: minmax(0, 1.28fr) minmax(320px, 0.72fr);
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 25px rgba(23, 32, 51, 0.04);
  padding: 14px;
}

.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card-title h2,
.card-title h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
}

.metric-card {
  display: grid;
  gap: 8px;
  min-height: 116px;
}

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

.metric-value {
  font-size: 27px;
  line-height: 1.1;
  font-weight: 850;
  color: var(--text);
  word-break: break-word;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge.good {
  background: var(--green-soft);
  color: var(--green);
}

.badge.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.bad {
  background: var(--red-soft);
  color: var(--red);
}

.badge.info {
  background: var(--blue-soft);
  color: var(--blue);
}

.chart-bars {
  height: 222px;
  display: grid;
  grid-template-columns: repeat(31, minmax(8px, 1fr));
  align-items: end;
  gap: 4px;
  padding: 16px 4px 0;
  border-top: 1px solid var(--line-soft);
}

.bar-wrap {
  height: 184px;
  display: flex;
  align-items: end;
  justify-content: center;
  position: relative;
}

.bar {
  width: 100%;
  min-height: 3px;
  border-radius: 5px 5px 0 0;
  background: var(--red);
}

.bar.good {
  background: var(--green);
}

.bar.warn {
  background: var(--amber);
}

.bar.zero {
  background: #cbd5e1;
}

.bar-label {
  position: absolute;
  bottom: -19px;
  color: var(--muted);
  font-size: 10px;
}

.progress-list {
  display: grid;
  gap: 11px;
}

.progress-row {
  display: grid;
  gap: 6px;
}

.progress-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.track {
  height: 9px;
  background: var(--line-soft);
  border-radius: 999px;
  overflow: hidden;
}

.fill {
  height: 100%;
  border-radius: 999px;
  background: var(--red);
}

.fill.green {
  background: var(--green);
}

.fill.amber {
  background: var(--amber);
}

.fill.blue {
  background: var(--blue);
}

.alert-list {
  display: grid;
  gap: 9px;
}

.alert-item {
  border: 1px solid var(--line-soft);
  border-left: 4px solid var(--green);
  border-radius: var(--radius);
  padding: 10px;
  background: #fff;
}

.alert-item.warn {
  border-left-color: var(--amber);
}

.alert-item.bad {
  border-left-color: var(--red);
}

.alert-title {
  font-weight: 850;
  margin-bottom: 3px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

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

th {
  background: #fbfcfe;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

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

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

.entry-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 14px;
}

.day-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.day-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-weight: 800;
}

.day-button.active {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

.day-button.has-data:not(.active) {
  border-color: #bbf7d0;
  background: var(--green-soft);
  color: var(--green);
}

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

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

.section-label {
  grid-column: 1 / -1;
  margin: 4px 0 -2px;
  font-size: 13px;
  font-weight: 850;
  color: var(--red);
  text-transform: uppercase;
}

.inline-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

.switch input {
  width: 18px;
  height: 18px;
}

.summary-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mini-stat {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 11px;
  background: var(--surface-2);
}

.mini-stat strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  border-radius: var(--radius);
  background: var(--text);
  color: #fff;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

.hidden {
  display: none !important;
}

@media (max-width: 1080px) {
  .kpi-grid,
  .three-col,
  .two-col,
  .settings-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 820px) {
  .login-panel,
  .app-shell,
  .entry-layout,
  .kpi-grid,
  .two-col,
  .three-col,
  .summary-list,
  .settings-grid,
  .form-section,
  .form-section.links {
    grid-template-columns: 1fr;
  }

  .login-preview {
    border-left: 0;
    border-top: 1px solid var(--line);
    min-height: unset;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .main {
    padding: 16px;
  }

  .topbar {
    display: grid;
  }

  .context-controls {
    display: grid;
    grid-template-columns: 1fr;
  }

  .compact-field {
    min-width: 0;
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    justify-content: stretch;
    width: 100%;
  }

  .top-actions .button,
  .top-actions .badge {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .chart-bars {
    gap: 2px;
  }
}
