@layer tokens, base, layout, components, responsive;

@layer tokens {
  @font-face { font-family: "Manrope Variable"; src: url("/assets/fonts/manrope-latin.woff2") format("woff2"); font-style: normal; font-weight: 200 800; font-display: swap; }
  @font-face { font-family: "DM Sans Variable"; src: url("/assets/fonts/dm-sans-latin.woff2") format("woff2"); font-style: normal; font-weight: 100 1000; font-display: swap; }
  @font-face { font-family: "IBM Plex Mono"; src: url("/assets/fonts/ibm-plex-mono-400.woff2") format("woff2"); font-style: normal; font-weight: 400; font-display: swap; }
  @font-face { font-family: "IBM Plex Mono"; src: url("/assets/fonts/ibm-plex-mono-500.woff2") format("woff2"); font-style: normal; font-weight: 500; font-display: swap; }
  :root {
    color-scheme: light;
    --paper: oklch(96.5% 0.012 91);
    --surface: oklch(99.2% 0.006 91);
    --surface-muted: oklch(93.5% 0.012 88);
    --line: oklch(86% 0.015 83);
    --ink: oklch(24% 0.025 155);
    --muted: oklch(45% 0.018 155);
    --faint: oklch(52% 0.018 155);
    --accent: oklch(39% 0.075 155);
    --accent-hover: oklch(32% 0.075 155);
    --accent-wash: oklch(89% 0.18 118);
    --success: oklch(39% 0.075 155);
    --warning: oklch(55% 0.13 69);
    --danger: oklch(49% 0.17 27);
    --mono: "IBM Plex Mono", monospace;
    --sans: "DM Sans Variable", sans-serif;
    --serif: "Manrope Variable", sans-serif;
    --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
    --space-6: 24px; --space-8: 32px; --space-12: 48px;
  }
}

@layer base {
  *, *::before, *::after { box-sizing: border-box; }
  html { min-width: 320px; background: var(--paper); }
  body { margin: 0; color: var(--ink); font: 15px/1.5 var(--sans); }
  button, input, select, textarea { font: inherit; }
  button { cursor: pointer; }
  a { color: inherit; }
  :focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
  h1, h2, h3, p { margin-top: 0; }
  h1, h2, h3 { line-height: 1.15; }
  h1 { font-size: clamp(1.7rem, 3vw, 2.3rem); letter-spacing: -.035em; }
  h2 { font-size: 1.18rem; letter-spacing: -.02em; }
  h3 { font-size: 1rem; }
  small, .eyebrow, .mono { font-family: var(--mono); }
  .mono, .amount, time { font-variant-numeric: tabular-nums; }
}

@layer layout {
  .boot, .auth-shell { min-height: 100dvh; display: grid; place-content: center; padding: 24px; }
  .boot { color: var(--muted); text-align: center; }
  .mark { display: grid; width: 42px; height: 42px; place-items: center; margin: auto; background: oklch(89% 0.18 118); color: var(--ink); font: 600 22px var(--serif); }
  .app-shell { min-height: 100dvh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
  .rail { display: flex; flex-direction: column; gap: 32px; padding: 24px 16px; background: oklch(24% 0.025 155); color: oklch(96% 0.012 85); }
  .brand { display: flex; align-items: center; gap: 11px; padding: 0 8px; font-weight: 650; letter-spacing: .025em; text-decoration: none; }
  .brand .mark { width: 32px; height: 32px; margin: 0; background: oklch(89% 0.18 118); color: oklch(24% 0.025 155); font-size: 18px; }
  .brand small { color: oklch(76% 0.018 155); font-size: 10px; letter-spacing: .12em; }
  .nav { display: grid; gap: 4px; }
  .nav button { border: 0; border-radius: 2px; padding: 10px 11px; color: oklch(82% 0.016 145); background: transparent; text-align: left; }
  .nav button:hover, .nav button[aria-current="page"] { color: white; background: oklch(33% 0.025 155); }
  .rail-foot { margin-top: auto; color: oklch(76% 0.016 145); font-size: 12px; }
  .rail-foot button { margin-top: 10px; padding: 0; border: 0; color: inherit; background: transparent; text-decoration: underline; text-underline-offset: 3px; }
  .main { min-width: 0; padding: 34px clamp(20px, 4vw, 58px) 64px; }
  .topline { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 32px; color: var(--muted); font-size: 13px; }
  .content { width: min(100%, 1120px); margin-inline: auto; }
  .page-title { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
  .page-title p { margin: 0; color: var(--muted); }
  .columns { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; }
  .span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; } .span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; }
  .panel { container-type: inline-size; min-width: 0; padding: 20px; border: 1px solid var(--line); background: var(--surface); }
  .panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 17px; }
  .panel-head h2, .panel-head h3 { margin: 0; }
  .panel-note { color: var(--muted); font-size: 13px; }
  .mt-2 { margin-top: 8px; }
  .mt-4 { margin-top: 16px; }
  .stack { display: grid; gap: 13px; }
  .field { display: grid; gap: 6px; }
  .field label { color: var(--muted); font-size: 13px; }
  input, select, textarea { width: 100%; min-height: 42px; border: 1px solid var(--line); border-radius: 2px; padding: 9px 11px; color: var(--ink); background: white; }
  textarea { resize: vertical; }
  input[type="file"] { padding: 7px; }
  input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid color-mix(in oklch, var(--accent) 24%, transparent); }
  .field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .actions { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; }
  .button { min-height: 38px; border: 1px solid var(--line); border-radius: 2px; padding: 8px 12px; color: var(--ink); background: var(--surface); font-size: 13px; font-weight: 600; }
  .button:hover { background: var(--surface-muted); }
  .button.primary { border-color: var(--accent); color: white; background: var(--accent); }
  .button.primary:hover { background: var(--accent-hover); }
  .button.danger { color: var(--danger); }
  .button.small { min-height: 30px; padding: 5px 8px; font-size: 12px; }
  .metric { display: grid; gap: 5px; }
  .metric strong { font-size: clamp(1.55rem, 3vw, 2.05rem); font-weight: 560; letter-spacing: -.045em; }
  .metric span { color: var(--muted); font-size: 12px; }
  .storage-meter .row { padding: 0 0 8px; border: 0; color: var(--muted); font-size: 12px; }
  .storage-meter progress { display: block; width: 100%; height: 7px; border: 0; border-radius: 0; accent-color: var(--accent); }
  .storage-meter progress::-webkit-progress-bar { background: var(--surface-muted); }
  .storage-meter progress::-webkit-progress-value { background: var(--accent); }
  .status { display: inline-flex; align-items: center; gap: 6px; width: fit-content; border: 1px solid var(--line); padding: 3px 7px; color: var(--muted); font: 11px var(--mono); text-transform: uppercase; }
  .status::before { width: 6px; height: 6px; border-radius: 50%; background: currentColor; content: ""; }
  .status.good { color: var(--success); } .status.warn { color: var(--warning); } .status.bad { color: var(--danger); }
  .list { display: grid; }
  .row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; padding: 12px 0; border-top: 1px solid var(--line); }
  .row:first-child { border-top: 0; padding-top: 0; }
  .row-main { min-width: 0; display: grid; gap: 3px; }
  .row-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
  .row-main span, .row-meta { color: var(--muted); font-size: 12px; }
  .training-request { min-width: min(100%, 260px); padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-muted); }
  .training-request .field { gap: 5px; }
  .training-request select { max-width: 100%; }
  .validation-warning { color: var(--warning, #8a5a00) !important; font-weight: 600; }
  .row-end { display: flex; align-items: center; justify-content: end; flex-wrap: wrap; gap: 8px; text-align: right; }
  .empty { padding: 20px 0 3px; color: var(--muted); font-size: 13px; }
  .notice { margin-bottom: 18px; border-left: 3px solid var(--accent); padding: 11px 14px; background: var(--accent-wash); font-size: 13px; }
  .notice.error { border-color: var(--danger); background: oklch(96% 0.025 27); }
  .notice.success { border-color: var(--success); background: oklch(96% 0.025 151); }
  .key-value { display: grid; grid-template-columns: 105px minmax(0, 1fr); gap: 8px 14px; margin: 0; font-size: 13px; }
  .key-value dt { color: var(--muted); } .key-value dd { margin: 0; overflow-wrap: anywhere; }
  .secret { padding: 12px; border: 1px dashed var(--accent); background: var(--accent-wash); overflow-wrap: anywhere; font: 13px/1.6 var(--mono); }
  .table-wrap { overflow-x: auto; }
  .inquiry-workload { min-width: 280px; max-width: 560px; white-space: normal; overflow-wrap: anywhere; }
  .inquiry-workload details { margin-top: 8px; }
  .inquiry-workload summary { width: fit-content; cursor: pointer; color: var(--accent); }
  .inquiry-workload details p { line-height: 1.6; }
  table { width: 100%; border-collapse: collapse; font-size: 13px; }
  th, td { padding: 10px 12px; border-top: 1px solid var(--line); text-align: left; white-space: nowrap; }
  th { color: var(--muted); font: 11px var(--mono); text-transform: uppercase; letter-spacing: .04em; }
  td.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
  .auth-card { width: min(100%, 456px); border: 1px solid var(--line); padding: 30px; background: var(--surface); }
  .auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 34px; font-weight: 650; }
  .auth-card h1 { margin-bottom: 8px; font: 2rem/1.1 var(--serif); }
  .auth-card > p { color: var(--muted); font-size: 14px; }
  .switch-auth { margin-top: 19px; color: var(--muted); font-size: 13px; }
  .switch-auth button { border: 0; padding: 0; color: var(--accent); background: none; text-decoration: underline; }
}

@layer components {
  .muted { color: var(--muted); }
  .eyebrow { margin-bottom: 8px; color: var(--faint); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; }
  .project-pick { display: flex; gap: 8px; overflow-x: auto; margin: -4px 0 18px; padding-bottom: 6px; }
  .project-pick button { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 2px; padding: 7px 10px; color: var(--muted); background: var(--surface); font-size: 12px; }
  .project-pick button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-wash); }
  .workspace-activity { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line); background: var(--surface); }
  .activity-item { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; padding: 14px 16px; }
  .activity-item + .activity-item { border-left: 1px solid var(--line); }
  .activity-copy { display: grid; gap: 3px; min-width: 0; }
  .activity-copy .eyebrow { margin: 0; }
  .activity-copy > div { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
  .activity-copy > div > span:not(.status) { min-width: 0; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
  .workspace-idle { color: var(--muted); font-size: 12px; }
  .workspace-tabs { display: flex; gap: 4px; overflow-x: auto; margin-top: 22px; border-bottom: 1px solid var(--line); }
  .workspace-tabs button { flex: 0 0 auto; min-height: 42px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; padding: 0 14px; color: var(--muted); background: transparent; font-size: 13px; font-weight: 600; white-space: nowrap; }
  .workspace-tabs button:hover { color: var(--ink); background: var(--surface-muted); }
  .workspace-tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--accent); }
  .workspace-panel { padding-top: 18px; }
  .overview-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); }
  .overview-stat { display: grid; align-content: start; justify-items: start; gap: 3px; min-width: 0; border: 0; padding: 16px; color: var(--ink); background: var(--surface); text-align: left; }
  .overview-stat + .overview-stat { border-left: 1px solid var(--line); }
  .overview-stat:hover { background: var(--surface-muted); }
  .overview-stat .eyebrow { margin: 0 0 4px; }
  .overview-stat strong { font-size: 26px; font-variant-numeric: tabular-nums; line-height: 1.1; }
  .overview-stat > span:not(.eyebrow) { color: var(--muted); font-size: 12px; }
  .overview-stat .stat-link { margin-top: 9px; color: var(--accent); font-weight: 600; }
  .workflow-guide { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; margin: 0; padding: 0; list-style: none; counter-reset: workflow; }
  .workflow-guide li { display: grid; align-content: start; gap: 5px; min-width: 0; border-top: 1px solid var(--line); padding: 14px 14px 4px 0; counter-increment: workflow; }
  .workflow-guide li + li { border-left: 1px solid var(--line); padding-left: 16px; }
  .workflow-guide li::before { color: var(--faint); content: "0" counter(workflow); font: 11px var(--mono); }
  .workflow-guide li strong { font-size: 13px; }
  .workflow-guide li span { color: var(--muted); font-size: 12px; }
  .inline-form { display: flex; gap: 8px; }
  .inline-form input { min-width: 0; }
  .cap-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .check-input { width: auto; min-height: 0; margin: 0 5px 0 0; vertical-align: middle; }
  .cap-editor { border-top: 1px solid var(--line); padding: 11px 0 3px; color: var(--muted); font-size: 12px; }
  .cap-editor summary { width: fit-content; cursor: pointer; color: var(--accent); }
  .key-record + .key-record { border-top: 1px solid var(--line); }
  .key-caps { color: var(--muted); font: 11px/1.7 var(--mono); }
  .checkout-state { margin-top: 14px; }
  .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
}

@layer responsive {
  @container (max-width: 420px) { .row { align-items: start; flex-direction: column; } .row-end { justify-content: start; text-align: left; } }
  @media (max-width: 850px) {
    .app-shell { grid-template-columns: 1fr; }
    .rail { position: sticky; z-index: 2; top: 0; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; }
    .rail .brand { padding: 0; }.rail .brand .mark { width: 29px; height: 29px; }
    .nav { display: flex; gap: 3px; overflow-x: auto; }.nav button { padding: 8px; white-space: nowrap; font-size: 12px; }
    .rail-foot { display: none; }
    .main { padding: 24px 16px 44px; }
    .topline { margin-bottom: 23px; }
  }
  @media (max-width: 650px) {
    .span-8, .span-7, .span-6, .span-5, .span-4 { grid-column: span 12; }
    .page-title { align-items: start; flex-direction: column; }
    .cap-grid, .field-row { grid-template-columns: 1fr; }
    .panel { padding: 16px; }
    .auth-card { padding: 23px; }
    .workspace-activity { grid-template-columns: 1fr; }
    .activity-item + .activity-item { border-top: 1px solid var(--line); border-left: 0; }
    .overview-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .overview-stat + .overview-stat { border-left: 0; }
    .overview-stat:nth-child(even) { border-left: 1px solid var(--line); }
    .overview-stat:nth-child(n + 3) { border-top: 1px solid var(--line); }
    .workflow-guide { grid-template-columns: 1fr; }
    .workflow-guide li + li { border-left: 0; padding-left: 0; }
  }
  @media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; } }
}
