:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #000000;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.12);
  --line-strong: rgba(0, 0, 0, 0.86);
  --inverse: #ffffff;
  --overlay: rgba(0, 0, 0, 0.42);
}

body[data-theme="dark"] {
  --bg: #000000;
  --surface: #000000;
  --text: #f5f5f7;
  --muted: #a1a1a6;
  --line: rgba(255, 255, 255, 0.16);
  --line-strong: rgba(255, 255, 255, 0.86);
  --inverse: #000000;
  --overlay: rgba(255, 255, 255, 0.18);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.workspace {
  width: min(100%, 1180px);
  padding: 40px clamp(20px, 5vw, 72px) 72px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: clamp(32px, 6vw, 72px);
}

.topbar h1,
.panel h2,
.auth-panel h2 {
  margin: 0;
  font-size: clamp(3.4rem, 8vw, 7.8rem);
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: 0;
}

.panel h2,
.auth-panel h2 {
  font-size: clamp(2.2rem, 5vw, 4.4rem);
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.back-link,
.secondary-button,
.primary-button,
.danger-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 18px;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
  white-space: nowrap;
}

.back-link,
.secondary-button {
  font-size: 0.86rem;
  font-weight: 650;
}

.primary-button,
.danger-button {
  background: var(--text);
  color: var(--inverse);
  font-weight: 700;
}

.back-link:hover,
.secondary-button:hover {
  border-color: var(--line-strong);
}

.primary-button:hover,
.danger-button:hover {
  transform: translateY(-1px);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(20px, 4vw, 44px);
  margin-bottom: clamp(40px, 7vw, 84px);
  border-top: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line);
}

.metric-item {
  min-height: 142px;
  padding: 22px 0;
}

.metric-item span,
label span,
.chart-panel h3 {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.metric-item strong {
  display: block;
  margin-top: 18px;
  overflow: hidden;
  font-size: clamp(1.55rem, 2.5vw, 2.45rem);
  font-weight: 760;
  line-height: 1.04;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-break: normal;
}

.panel,
.auth-panel {
  border-top: 1px solid var(--line-strong);
  padding: clamp(24px, 4vw, 42px) 0 0;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: clamp(24px, 5vw, 48px);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.form-grid {
  display: grid;
  gap: 22px;
}

.field-row,
.toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

label {
  display: grid;
  gap: 10px;
}

input,
select {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  outline: none;
  padding: 0;
}

input:focus,
select:focus {
  border-bottom-color: var(--line-strong);
}

.auth-panel {
  width: min(100%, 540px);
}

.toolbar {
  margin-bottom: 24px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 18px 18px 18px 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

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

td {
  font-weight: 620;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.text-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  padding: 7px 12px;
  font-size: 0.78rem;
  font-weight: 700;
}

.text-button:hover {
  border-color: var(--line-strong);
}

.text-button.is-danger {
  color: var(--text);
}

.empty-state {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 22px 0;
  color: var(--muted);
  font-weight: 650;
  text-align: left;
}

.chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: clamp(28px, 5vw, 52px);
}

.chart-panel {
  min-height: 340px;
  border-top: 1px solid var(--line);
  padding: 22px 0 0;
}

.chart-panel h3 {
  margin: 0 0 22px;
  color: var(--text);
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  justify-content: space-between;
  border-left: 1px solid var(--line);
  background: var(--surface);
  padding: 28px 24px;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark span {
  display: inline-flex;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--text);
  color: var(--inverse);
  font-weight: 760;
}

.brand-mark strong,
.brand-mark small {
  display: block;
}

.brand-mark small {
  margin-top: 3px;
  color: var(--muted);
  font-weight: 600;
}

.side-nav,
.sidebar-actions {
  display: grid;
  gap: 4px;
}

.side-nav button {
  min-height: 44px;
  border: 0;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  text-align: left;
  font-weight: 700;
}

.side-nav button:hover,
.side-nav button.is-active {
  border-bottom-color: var(--line-strong);
  color: var(--text);
}

.menu-button {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 70;
  display: none;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.menu-button span {
  position: absolute;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: var(--text);
}

.menu-button span:nth-child(1) {
  transform: translateY(-6px);
}

.menu-button span:nth-child(3) {
  transform: translateY(6px);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: var(--overlay);
}

.toast-stack {
  position: fixed;
  left: 22px;
  bottom: 22px;
  z-index: 90;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 44px));
}

.toast {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  padding: 12px 16px;
  color: var(--text);
  font-weight: 650;
}

.toast.is-error {
  background: var(--text);
  color: var(--inverse);
}

.loading-overlay,
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: var(--overlay);
  padding: 18px;
}

.loading-overlay {
  gap: 12px;
  color: #ffffff;
  font-weight: 700;
}

.loader {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.34);
  border-top-color: #ffffff;
  border-radius: 999px;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.modal-content {
  width: min(100%, 500px);
  background: var(--surface);
  padding: 28px 0;
}

.modal-content h2 {
  margin: 0;
  font-size: 1.7rem;
}

.modal-content p {
  color: var(--muted);
  font-weight: 600;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 980px) {
  .app-shell {
    display: block;
  }

  .workspace {
    padding-top: 76px;
  }

  .menu-button {
    display: inline-flex;
  }

  .sidebar {
    position: fixed;
    right: 0;
    top: 0;
    z-index: 60;
    width: min(86vw, 320px);
    transform: translateX(105%);
    transition: transform 180ms ease;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

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

@media (max-width: 680px) {
  .workspace {
    padding-inline: 18px;
  }

  .topbar,
  .panel-header,
  .modal-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar {
    display: grid;
  }

  .topbar h1 {
    font-size: clamp(3rem, 18vw, 5.8rem);
  }

  .summary-grid,
  .field-row,
  .toolbar,
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    gap: 0;
  }

  .metric-item {
    min-height: auto;
    border-bottom: 1px solid var(--line);
  }

  .metric-item:last-child {
    border-bottom: 0;
  }

  th,
  td {
    padding: 14px 14px 14px 0;
  }
}
