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

@layer tokens {
  :root {
    color-scheme: light;

    --ui-bg: #f7f8f8;
    --ui-surface: #ffffff;
    --ui-surface-muted: #f0f3f4;
    --ui-border: #dde2e5;
    --ui-text: #24272b;
    --ui-muted: #68717b;
    --ui-accent: #2f6f8f;
    --ui-accent-strong: #1f5874;
    --ui-accent-soft: #e8f2f7;
    --ui-success: #2f7d4f;
    --ui-success-soft: #e8f5ed;
    --ui-warning: #9a6500;
    --ui-warning-soft: #fff4dd;
    --ui-danger: #b44235;
    --ui-danger-soft: #fcecea;

    --ui-font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --ui-leading: 1.68;
    --ui-radius: 10px;
    --ui-radius-sm: 7px;
    --ui-shadow: 0 16px 34px rgb(36 39 43 / 0.08), 0 2px 8px rgb(36 39 43 / 0.04);
    --ui-shadow-sm: 0 7px 18px rgb(36 39 43 / 0.055), 0 1px 3px rgb(36 39 43 / 0.035);

    --ui-space-1: 0.4rem;
    --ui-space-2: 0.75rem;
    --ui-space-3: 1.1rem;
    --ui-space-4: 1.65rem;
    --ui-space-5: 2.5rem;
    --ui-space-6: 4rem;

    --ui-container: 1080px;
  }
}

@layer base {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html {
    background: var(--ui-bg);
    color: var(--ui-text);
    font-family: var(--ui-font);
    font-size: 16px;
    line-height: var(--ui-leading);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
  }

  body {
    margin: 0;
    min-height: 100vh;
    background: var(--ui-bg);
  }

  :where(h1, h2, h3, p, ul, ol, dl) {
    margin-block: 0;
  }

  :where(h1, h2, h3) {
    line-height: 1.18;
    letter-spacing: 0;
  }

  h1 {
    font-size: clamp(2rem, 5vw, 3.9rem);
    font-weight: 760;
  }

  h2 {
    font-size: clamp(1.35rem, 2.4vw, 2rem);
    font-weight: 720;
  }

  h3 {
    font-size: 1.05rem;
    font-weight: 700;
  }

  a {
    color: var(--ui-accent-strong);
    text-underline-offset: 0.18em;
  }

  :where(ul, ol) {
    padding-inline-start: 1.25rem;
  }

  :where(li + li) {
    margin-block-start: 0.35rem;
  }

  :where(button, input, select, textarea) {
    font: inherit;
  }

  :where(button, [type='button'], [type='submit'], [type='reset']) {
    -webkit-tap-highlight-color: transparent;
  }

  p {
    max-width: 68ch;
  }

  :focus-visible {
    outline: 3px solid rgb(47 111 143 / 0.32);
    outline-offset: 3px;
  }
}

@layer layout {
  .container {
    width: min(100% - clamp(1.25rem, 5vw, 3rem), var(--ui-container));
    margin-inline: auto;
  }

  .stack {
    display: flex;
    flex-direction: column;
    gap: var(--stack-gap, var(--ui-space-4));
  }

  .cluster {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--cluster-gap, var(--ui-space-2));
  }

  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
    gap: var(--grid-gap, var(--ui-space-4));
  }
}

@layer components {
  .card {
    padding: var(--card-padding, clamp(1.25rem, 3vw, 1.85rem));
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius);
    box-shadow: var(--ui-shadow-sm);
  }

  .panel {
    padding: var(--panel-padding, var(--ui-space-4));
    background: rgb(255 255 255 / 0.72);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
  }

  .hero {
    padding-block: clamp(3.25rem, 8vw, 6.5rem) clamp(2.5rem, 6vw, 5rem);
  }

  .hero > * {
    max-width: 760px;
  }

  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.75rem;
    padding: 0.7rem 1.1rem;
    color: #fffdfa;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
    background: var(--ui-accent);
    border: 1px solid var(--ui-accent);
    border-radius: var(--ui-radius-sm);
    box-shadow: 0 8px 16px rgb(47 111 143 / 0.14);
    cursor: pointer;
    transition:
      background-color 160ms ease,
      border-color 160ms ease,
      box-shadow 160ms ease,
      transform 160ms ease;
  }

  .btn:hover {
    background: var(--ui-accent-strong);
    border-color: var(--ui-accent-strong);
    box-shadow: 0 10px 18px rgb(31 88 116 / 0.18);
    transform: translateY(-1px);
  }

  .btn:active {
    transform: translateY(0);
  }

  .btn-secondary {
    color: var(--ui-text);
    background: var(--ui-surface);
    border-color: var(--ui-border);
    box-shadow: none;
  }

  .btn-secondary:hover {
    color: var(--ui-accent-strong);
    background: var(--ui-accent-soft);
    border-color: rgb(47 111 143 / 0.28);
    box-shadow: none;
  }

  .btn-ghost {
    color: var(--ui-accent-strong);
    background: transparent;
    border-color: transparent;
    box-shadow: none;
  }

  .btn-ghost:hover {
    background: var(--ui-accent-soft);
    border-color: transparent;
    box-shadow: none;
  }

  .badge {
    display: inline-flex;
    align-items: center;
    min-height: 1.75rem;
    padding: 0.22rem 0.62rem;
    color: var(--ui-accent-strong);
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1;
    background: var(--ui-accent-soft);
    border: 1px solid rgb(47 111 143 / 0.12);
    border-radius: var(--ui-radius-sm);
  }

  .field {
    display: grid;
    gap: var(--ui-space-2);
    color: var(--ui-muted);
    font-size: 0.92rem;
    font-weight: 700;
  }

  .input {
    width: 100%;
    min-height: 3rem;
    padding: 0.78rem 0.95rem;
    color: var(--ui-text);
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
    box-shadow: inset 0 1px 2px rgb(47 48 51 / 0.04);
    transition:
      background-color 160ms ease,
      border-color 160ms ease,
      box-shadow 160ms ease;
  }

  textarea.input {
    resize: vertical;
  }

  .input::placeholder {
    color: rgb(104 113 123 / 0.72);
  }

  .input:focus {
    background: var(--ui-surface);
    border-color: rgb(63 111 143 / 0.58);
    box-shadow:
      0 0 0 4px rgb(63 111 143 / 0.12),
      inset 0 1px 2px rgb(47 48 51 / 0.03);
    outline: 0;
  }

  .input[aria-invalid='true'],
  .input.is-invalid {
    border-color: rgb(180 66 53 / 0.58);
    box-shadow: 0 0 0 4px rgb(180 66 53 / 0.1);
  }

  .field-hint {
    color: var(--ui-muted);
    font-size: 0.86rem;
    font-weight: 500;
  }

  .alert {
    padding: var(--ui-space-3) var(--ui-space-4);
    color: var(--ui-text);
    background: var(--ui-warning-soft);
    border: 1px solid rgb(226 194 129 / 0.45);
    border-radius: var(--ui-radius-sm);
  }

  .alert-success {
    background: var(--ui-success-soft);
    border-color: rgb(47 125 79 / 0.28);
  }

  .alert-danger {
    background: var(--ui-danger-soft);
    border-color: rgb(180 66 53 / 0.28);
  }

  .empty {
    padding: clamp(2rem, 6vw, var(--ui-space-5));
    color: var(--ui-muted);
    text-align: center;
    background: var(--ui-surface-muted);
    border: 1px dashed var(--ui-border);
    border-radius: var(--ui-radius);
  }

  .divider {
    border: 0;
    border-block-start: 1px solid var(--ui-border);
    margin: 0;
  }

  .nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--ui-space-3);
    padding-block: clamp(1rem, 3vw, var(--ui-space-4));
  }

  .nav a {
    color: var(--ui-muted);
    font-weight: 700;
    text-decoration: none;
  }

  .nav a:hover {
    color: var(--ui-accent-strong);
  }

  .list {
    display: grid;
    gap: var(--ui-space-2);
    padding: 0;
    list-style: none;
  }

  .list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ui-space-3);
    padding: var(--ui-space-3);
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-sm);
  }

  .stat {
    display: grid;
    gap: 0.2rem;
  }

  .stat-value {
    font-size: clamp(1.65rem, 4vw, 2.7rem);
    font-weight: 780;
    line-height: 1;
  }

  .stat-label {
    color: var(--ui-muted);
    font-size: 0.86rem;
    font-weight: 700;
  }

  .table-wrap {
    overflow-x: auto;
    background: var(--ui-surface);
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius);
  }

  .table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.94rem;
  }

  .table th,
  .table td {
    padding: 0.85rem 1rem;
    text-align: left;
    border-block-end: 1px solid var(--ui-border);
  }

  .table th {
    color: var(--ui-muted);
    font-size: 0.82rem;
    font-weight: 750;
  }

  .table tbody tr:hover {
    background: rgb(47 111 143 / 0.035);
  }

  .table tr:last-child > * {
    border-block-end: 0;
  }
}

@layer utilities {
  .text-muted {
    color: var(--ui-muted);
  }

  .text-center {
    text-align: center;
  }

  .text-success {
    color: var(--ui-success);
  }

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

  .full-width {
    width: 100%;
  }

  .shadow-none {
    box-shadow: none;
  }

  .surface-muted {
    background: var(--ui-surface-muted);
  }

  .max-readable {
    max-width: 68ch;
  }

  .visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    white-space: nowrap;
    border: 0;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
  }
}

@media (max-width: 640px) {
  @layer tokens {
    :root {
      --ui-radius: 10px;
      --ui-radius-sm: 7px;
      --ui-space-4: 1.35rem;
      --ui-space-5: 2rem;
    }
  }

  @layer base {
    html {
      font-size: 15.5px;
    }
  }

  @layer layout {
    .grid {
      gap: var(--ui-space-3);
    }
  }

  @layer components {
    .card {
      padding: var(--card-padding, 1.2rem);
      box-shadow: 0 6px 16px rgb(36 39 43 / 0.05);
    }

    .hero {
      padding-block: 2.4rem 2rem;
    }

    .hero .cluster {
      align-items: stretch;
    }

    .btn {
      min-height: 3rem;
      padding-inline: 1rem;
    }

    .list-item {
      align-items: flex-start;
      flex-direction: column;
    }

    .hero .btn {
      width: 100%;
    }

    .nav {
      align-items: flex-start;
      justify-content: flex-start;
    }
  }
}
