:root {
  color-scheme: dark;
  --bg: #0d1117;
  --surface: #141b24;
  --surface-2: #192331;
  --line: #2a3647;
  --text: #eef4f8;
  --muted: #9fb0c3;
  --teal: #2dd4bf;
  --teal-strong: #14b8a6;
  --amber: #f59e0b;
  --red: #ef4444;
  --purple: #8b5cf6;
  --green: #22c55e;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(135deg, rgba(45, 212, 191, 0.08), transparent 36%),
    linear-gradient(315deg, rgba(139, 92, 246, 0.08), transparent 42%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: var(--teal);
  text-decoration: none;
}

input,
select,
button {
  font: inherit;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex: 0 0 280px;
  flex-direction: column;
  gap: 28px;
  height: 100vh;
  padding: 28px;
  border-right: 1px solid var(--line);
  background: rgba(13, 17, 23, 0.92);
}

.brand,
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(45, 212, 191, 0.46);
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(45, 212, 191, 0.24), rgba(139, 92, 246, 0.22));
  color: var(--text);
  font-weight: 800;
}

.brand small,
.auth-brand small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.78rem;
}

.nav-stack {
  display: grid;
  gap: 8px;
}

.nav-stack a {
  padding: 11px 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
}

.nav-stack a:hover {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.user-box {
  display: grid;
  gap: 12px;
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.main-surface {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: clamp(18px, 3vw, 34px);
}

.page-header {
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 3vw, 2.55rem);
}

h2 {
  font-size: 1.45rem;
  line-height: 1.35;
}

.auth-page .app-shell {
  display: block;
}

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

.auth-panel {
  width: min(430px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 27, 36, 0.94);
  box-shadow: var(--shadow);
}

.auth-header {
  margin: 32px 0 24px;
}

.auth-link {
  margin: 18px 0 0;
  color: var(--muted);
}

.flash-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.flash,
.error-list,
.notice {
  border-radius: 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
}

.flash-success {
  border-color: rgba(34, 197, 94, 0.45);
  background: rgba(34, 197, 94, 0.12);
}

.flash-error,
.error-list,
.notice-error {
  border-color: rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.12);
}

.flash-info,
.notice-info,
.notice-review {
  border-color: rgba(45, 212, 191, 0.32);
  background: rgba(45, 212, 191, 0.1);
}

.notice-warn {
  border-color: rgba(245, 158, 11, 0.42);
  background: rgba(245, 158, 11, 0.12);
}

.form-stack {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-weight: 650;
  min-width: 0;
}

input,
select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1520;
  color: var(--text);
  outline: none;
  padding: 10px 12px;
}

input:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.14);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  line-height: 1;
  padding: 0 16px;
  text-align: center;
  white-space: nowrap;
}

.button-primary {
  background: var(--teal);
  color: #06120f;
}

.button-secondary {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.button-danger {
  background: rgba(239, 68, 68, 0.16);
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.42);
}

.button-full {
  width: 100%;
}

.button-large {
  min-height: 48px;
  width: 100%;
}

.button-small {
  min-height: 34px;
  padding: 0 12px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
  gap: 22px;
  align-items: start;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 27, 36, 0.92);
  box-shadow: var(--shadow);
}

.form-panel,
.result-panel,
.table-panel {
  padding: 22px;
}

fieldset {
  margin: 0 0 22px;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 14px;
  color: var(--text);
  font-size: 1rem;
  font-weight: 800;
}

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

.field-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.field-topline > span:first-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.field-topline small {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

.input-with-unit {
  position: relative;
  display: block;
}

.input-with-unit em {
  position: absolute;
  top: 50%;
  right: 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-style: normal;
  transform: translateY(-50%);
}

.input-with-unit input {
  padding-right: 54px;
}

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

.result-title {
  min-width: 0;
}

.button-download {
  flex: 0 0 auto;
}

.diagram-frame {
  display: grid;
  width: 100%;
  max-width: 100%;
  min-height: 260px;
  max-height: 520px;
  place-items: center;
  margin-bottom: 18px;
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.diagram-frame img {
  display: block;
  max-width: 100%;
  height: auto;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.metric {
  display: grid;
  gap: 6px;
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f1520;
}

.metric span {
  color: var(--muted);
  font-size: 0.78rem;
}

.metric strong {
  overflow-wrap: anywhere;
}

.notice-stack {
  display: grid;
  gap: 10px;
}

.notice {
  display: grid;
  gap: 6px;
  color: var(--text);
}

.toolbar-band {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 750;
}

.filter-chip.active {
  border-color: rgba(45, 212, 191, 0.55);
  color: var(--text);
}

.filter-chip span {
  color: var(--teal);
}

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

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

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

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

.action-row {
  display: flex;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.status-pending {
  border-color: rgba(245, 158, 11, 0.44);
  color: #fbbf24;
}

.status-approved {
  border-color: rgba(34, 197, 94, 0.44);
  color: #86efac;
}

.status-rejected {
  border-color: rgba(239, 68, 68, 0.44);
  color: #fca5a5;
}

.empty-state {
  display: grid;
  min-height: 220px;
  place-content: center;
  gap: 8px;
  text-align: center;
}

.empty-state span,
.muted {
  color: var(--muted);
}

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

  .sidebar {
    position: static;
    display: grid;
    grid-template-columns: minmax(180px, auto) minmax(0, 1fr) auto;
    width: 100%;
    height: auto;
    align-items: center;
    padding: 18px;
    gap: 18px;
  }

  .nav-stack {
    grid-auto-flow: column;
    justify-content: center;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .user-box {
    margin-left: auto;
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }

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

  .diagram-frame {
    place-items: start;
  }

  .diagram-frame img {
    width: 1120px;
    max-width: none;
  }
}

@media (max-width: 860px) {
  .sidebar {
    grid-template-columns: 1fr auto;
  }

  .nav-stack {
    grid-column: 1 / -1;
    justify-content: start;
  }
}

@media (max-width: 720px) {
  .main-surface {
    padding: 16px;
  }

  .sidebar {
    display: grid;
    gap: 14px;
    padding: 16px;
  }

  .nav-stack {
    grid-auto-flow: row;
  }

  .user-box {
    width: 100%;
    margin-left: 0;
  }

  .field-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .form-panel,
  .result-panel,
  .table-panel {
    padding: 16px;
  }

  .field-topline {
    display: grid;
    gap: 4px;
  }

  .field-topline small {
    text-align: left;
    white-space: normal;
  }

  .result-hero {
    display: grid;
  }

  .button-download {
    width: 100%;
  }

  .diagram-frame {
    min-height: 280px;
    max-height: 58vh;
  }

  .diagram-frame img {
    width: 1080px;
    max-width: none;
  }

  th,
  td {
    padding: 12px 10px;
  }
}

@media (max-width: 520px) {
  .brand,
  .auth-brand {
    min-width: 0;
  }

  .brand > span:last-child,
  .auth-brand > span:last-child {
    min-width: 0;
  }

  .brand strong,
  .auth-brand strong {
    display: block;
    overflow-wrap: anywhere;
  }

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

  .button {
    min-width: 0;
    white-space: normal;
  }

  .page-header {
    margin-bottom: 16px;
  }

  .auth-panel {
    padding: 22px;
  }
}
