/* KeyMail Specials — global styles.
   Page-specific styles live next to each component in *.razor.css. */

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

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

    /* Palette */
    --ink: #13202A;          /* text, footer, windshield frame */
    --slate: #4A5A67;        /* secondary text */
    --glass: #DCE7EE;        /* windshield tint, quiet panels */
    --glass-soft: #EEF3F6;
    --paper: #FFFFFF;
    --line: #CBD6DE;
    --green: #1E7F53;        /* KeyMail brand, actions */
    --green-deep: #155E3D;
    --green-tint: #E6F2EC;
    --amber: #FFB000;        /* dashboard "service due" light only */
    --danger: #B3261E;

    /* Type */
    --font-display: "Archivo", "Arial Black", system-ui, sans-serif;
    --font-body: "Overpass", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: "Overpass Mono", ui-monospace, "Cascadia Mono", monospace;

    --step--1: 0.875rem;
    --step-0: 1.0625rem;
    --step-1: 1.25rem;
    --step-2: clamp(1.55rem, 1.2rem + 1.4vw, 2.15rem);
    --step-3: clamp(1.9rem, 1.3rem + 2.6vw, 3rem);
    --step-4: clamp(2.4rem, 1.4rem + 4.2vw, 4.4rem);

    /* Space & shape */
    --gutter: clamp(1.25rem, 4vw, 3rem);
    --section: clamp(4rem, 9vw, 7.5rem);
    --radius: 14px;
    --radius-sm: 9px;
    --measure: 66ch;
    --wrap: 72rem;

    --shadow-1: 0 1px 2px rgb(19 32 42 / 0.06), 0 4px 14px rgb(19 32 42 / 0.06);
    --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  }
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; }
  html { -webkit-text-size-adjust: none; text-size-adjust: none; scroll-behavior: smooth; }
  body { min-height: 100dvh; }
  img, svg { display: block; max-width: 100%; }
  input, button, textarea, select { font: inherit; color: inherit; }
  @media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  }
}

@layer base {
  @view-transition { navigation: auto; }

  body {
    font-family: var(--font-body);
    font-size: var(--step-0);
    line-height: 1.6;
    color: var(--ink);
    background: var(--paper);
    -webkit-font-smoothing: antialiased;
  }

  h1, h2, h3 {
    font-family: var(--font-display);
    font-stretch: 125%;
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -0.015em;
    text-wrap: balance;
  }

  h1 { font-size: var(--step-4); }
  h2 { font-size: var(--step-3); }
  h3 { font-size: var(--step-1); font-stretch: 112%; font-weight: 750; letter-spacing: 0; line-height: 1.25; }

  p { text-wrap: pretty; }

  a {
    color: var(--green);
    text-underline-offset: 0.2em;
    text-decoration-thickness: 1px;
    &:hover { color: var(--green-deep); text-decoration-thickness: 2px; }
  }

  a[href^="tel:"] { white-space: nowrap; }

  :focus-visible {
    outline: 3px solid var(--green);
    outline-offset: 3px;
    border-radius: 4px;
  }

  /* Elements focused by script (tabindex="-1", e.g. a heading) aren't controls; don't ring them. */
  [tabindex="-1"]:focus { outline: none; }

  ::selection { background: var(--amber); color: var(--ink); }
}

@layer layout {
  .wrap {
    width: min(100% - 2 * var(--gutter), var(--wrap));
    margin-inline: auto;
  }

  .section { padding-block: var(--section); }
  .section--glass { background: var(--glass-soft); }

  .page-head {
    padding-block: clamp(3rem, 7vw, 5.5rem) clamp(2rem, 4vw, 3rem);
    border-bottom: 1px solid var(--line);
    & .lead { margin-top: 1.25rem; }
  }

  .skip {
    position: absolute;
    left: 1rem;
    top: -4rem;
    z-index: 10;
    padding: 0.6rem 1rem;
    background: var(--ink);
    color: var(--paper);
    border-radius: var(--radius-sm);
    &:focus { top: 1rem; color: var(--paper); }
  }
}

@layer components {
  /* Small mono label above a heading: names what the section is about. */
  .label {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--slate);
    margin-bottom: 1rem;
  }

  .lead {
    font-size: var(--step-1);
    line-height: 1.5;
    color: var(--slate);
    max-width: 38rem;
  }

  .prose {
    max-width: var(--measure);
    & > * + * { margin-top: 1.1em; }
    & h2 { font-size: var(--step-2); margin-top: 2.2em; scroll-margin-top: 1.5rem; }
    & ul { padding-left: 1.2em; }
    & li + li { margin-top: 0.35em; }
    & li::marker { color: var(--green); }
  }

  /* Buttons */
  .button {
    --bg: var(--green);
    --fg: var(--paper);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    min-height: 3rem;
    padding: 0.7rem 1.4rem;
    border: 1.5px solid var(--bg);
    border-radius: 999px;
    background: var(--bg);
    color: var(--fg);
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, transform 0.15s var(--ease-out);
    &:hover { --bg: var(--green-deep); color: var(--fg); text-decoration: none; }
    &:active { transform: translateY(1px); }
  }

  .button--ghost {
    --bg: transparent;
    --fg: var(--ink);
    border-color: var(--line);
    &:hover { --bg: var(--paper); border-color: var(--ink); }
  }

  .button--block { width: 100%; }

  /* Form fields */
  .field {
    display: grid;
    gap: 0.4rem;
    & > label, & > .field-label { font-weight: 700; font-size: 0.95rem; }
  }

  .hint { font-size: var(--step--1); color: var(--slate); }

  input:is([type="text"], [type="email"], [type="tel"], [type="password"], :not([type])),
  select,
  textarea {
    width: 100%;
    min-height: 3rem;
    padding: 0.7rem 0.9rem;
    border: 1.5px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--paper);
    transition: border-color 0.15s, box-shadow 0.15s;

    &:hover { border-color: #9FB0BD; }
    &:focus-visible {
      outline: none;
      border-color: var(--green);
      box-shadow: 0 0 0 4px rgb(30 127 83 / 0.18);
    }
    &[readonly] { background: var(--glass-soft); border-style: dashed; }
    &:disabled { background: var(--glass-soft); color: var(--slate); cursor: not-allowed; }
    &.invalid { border-color: var(--danger); }
  }

  textarea {
    min-height: 9rem;
    field-sizing: content;
    resize: vertical;
  }

  .validation-message {
    color: var(--danger);
    font-size: var(--step--1);
    font-weight: 600;
  }

  .validation-errors {
    padding: 0.9rem 1rem 0.9rem 2.2rem;
    border-left: 4px solid var(--danger);
    border-radius: var(--radius-sm);
    background: #FBEDEC;
    color: var(--danger);
    font-weight: 600;
    font-size: 0.95rem;
  }

  /* Selectable rows (radio or checkbox inside a label). Checked state comes from :has(). */
  .choice {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 0.9rem;
    align-items: start;
    padding: 1rem 1.1rem;
    border: 1.5px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    cursor: pointer;
    transition: border-color 0.15s, background-color 0.15s;

    & > input { margin-top: 0.3rem; accent-color: var(--green); width: 1.15rem; height: 1.15rem; }
    & .choice-title { font-weight: 700; }
    & .choice-text { grid-column: 2; font-size: 0.95rem; color: var(--slate); }

    &:hover { border-color: #9FB0BD; }
    &:has(> input:checked) { border-color: var(--green); background: var(--green-tint); }
    &:has(> input:focus-visible) { outline: 3px solid var(--green); outline-offset: 2px; }
  }

  /* Pill-style radio group for short options */
  .chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    border: 0;
    padding: 0;

    & label {
      position: relative;
      padding: 0.55rem 1rem;
      border: 1.5px solid var(--line);
      border-radius: 999px;
      font-size: 0.95rem;
      font-weight: 600;
      cursor: pointer;
      transition: border-color 0.15s, background-color 0.15s;
      &:hover { border-color: var(--ink); }
      &:has(input:checked) { background: var(--ink); border-color: var(--ink); color: var(--paper); }
      &:has(input:focus-visible) { outline: 3px solid var(--green); outline-offset: 2px; }
    }

    & input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
  }

  /* Centered single-task card (subscription pages, login, messages) */
  .panel {
    width: min(100%, 36rem);
    margin-inline: auto;
    padding: clamp(1.5rem, 5vw, 2.75rem);
    border: 1px solid var(--line);
    border-radius: calc(var(--radius) + 6px);
    background: var(--paper);
    box-shadow: var(--shadow-1);

    & h1 { font-size: var(--step-3); }
    & .lead { font-size: var(--step-0); margin-top: 0.75rem; }
  }

  .panel-stage {
    padding-block: clamp(2.5rem, 7vw, 5rem);
    background:
      radial-gradient(60rem 30rem at 50% -10%, var(--glass) 0%, transparent 70%),
      var(--glass-soft);
  }

  .status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    background: var(--green-tint);
    color: var(--green-deep);
    &.status--error { background: #FBEDEC; color: var(--danger); }
    &::before { content: ""; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: currentColor; }
  }

  /* Honeypot field on the contact form: hidden from people, visible to naive bots. */
  .hp-field {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
  }
}

@layer components {
  .panel .status + h1 { margin-top: 1rem; }
  .panel-actions { margin-top: 1.5rem; }
}

@layer components {
  /* Long legal pages (privacy, terms): sticky "On this page" index beside the text */
  .policy {
    display: grid;
    grid-template-columns: 16rem minmax(0, 1fr);
    gap: clamp(2rem, 6vw, 5rem);
    align-items: start;

    & .prose h2:first-child { margin-top: 0; }
    & .prose h2 { scroll-margin-top: 1.5rem; }
    & address { font-style: normal; }

    @media (max-width: 820px) {
      grid-template-columns: 1fr;
    }
  }

  .toc {
    position: sticky;
    top: 1.5rem;

    & ol {
      display: grid;
      gap: 0.15rem;
      padding: 0;
      list-style: none;
      border-left: 2px solid var(--line);
    }

    & a {
      display: block;
      padding: 0.35rem 0 0.35rem 1rem;
      margin-left: -2px;
      border-left: 2px solid transparent;
      color: var(--slate);
      font-size: 0.95rem;
      text-decoration: none;
      &:hover { color: var(--ink); border-left-color: var(--green); }
    }

    @media (max-width: 820px) {
      position: static;
    }
  }
}
