/* ════════════════════════════════════════════════════════════════════════
 * Signaturen — Editorial Swiss Hybrid
 * Cream background • Almost-black text • Coral accent
 * Display: Fraunces (variable opsz) — characterful editorial serif
 * Body: Hanken Grotesk — Swiss-feeling neogrotesque
 * Mono: JetBrains Mono — for tabular figures
 * ════════════════════════════════════════════════════════════════════════ */

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

/* ──── Reset ──────────────────────────────────────────────────────────── */
@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  * { margin: 0; padding: 0; }
  html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
  body { line-height: 1.5; -webkit-font-smoothing: antialiased; }
  img, picture, video, canvas, svg { display: block; max-width: 100%; }
  input, button, textarea, select { font: inherit; color: inherit; }
  p, h1, h2, h3, h4, h5, h6 { overflow-wrap: break-word; }
  button { background: none; border: 0; cursor: pointer; }
  a { color: inherit; text-decoration: none; }
  table { border-collapse: collapse; width: 100%; }
}

/* ──── Design Tokens ──────────────────────────────────────────────────── */
@layer tokens {
  :root {
    /* Color — warm editorial */
    --bg:           oklch(96.5% 0.012 75);   /* warm cream */
    --bg-elevated:  oklch(98.5% 0.008 75);   /* card surface */
    --bg-sunken:    oklch(94% 0.014 75);     /* sidebar */
    --fg:           oklch(20% 0.014 60);     /* warm almost-black */
    --fg-muted:     oklch(48% 0.012 60);     /* secondary text */
    --fg-subtle:    oklch(65% 0.010 60);     /* metadata */
    --border:       oklch(88% 0.012 65);     /* hairline */
    --border-strong: oklch(78% 0.012 65);
    --accent:       oklch(58% 0.18 28);      /* warm coral red */
    --accent-soft:  oklch(92% 0.05 28);
    --accent-fg:    oklch(98% 0.005 28);

    --positive:     oklch(45% 0.12 145);     /* deep green */
    --positive-soft: oklch(92% 0.06 145);
    --warning:      oklch(60% 0.15 70);      /* amber */
    --warning-soft: oklch(94% 0.06 70);
    --danger:       oklch(50% 0.18 25);

    /* Typography */
    --font-display: "Fraunces", "Times New Roman", serif;
    --font-body:    "Hanken Grotesk", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    --font-mono:    "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

    /* Spatial */
    --space-1: 0.25rem;   /* 4px */
    --space-2: 0.5rem;    /* 8px */
    --space-3: 0.75rem;   /* 12px */
    --space-4: 1rem;      /* 16px */
    --space-5: 1.5rem;    /* 24px */
    --space-6: 2rem;      /* 32px */
    --space-7: 3rem;      /* 48px */
    --space-8: 4rem;      /* 64px */

    --radius-sm: 4px;
    --radius:    8px;
    --radius-lg: 12px;

    /* Layout */
    --sidebar-width: 264px;
    --content-max:   1200px;

    /* Motion */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --duration-fast: 150ms;
    --duration: 250ms;
  }
}

/* ──── Base / Typography ──────────────────────────────────────────────── */
@layer base {
  body {
    font-family: var(--font-body);
    font-feature-settings: "ss01", "cv11";
    background: var(--bg);
    color: var(--fg);
    font-size: 14px;
    letter-spacing: -0.005em;
  }

  h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-variation-settings: "opsz" 144, "wght" 380, "SOFT" 30;
    line-height: 1.1;
    letter-spacing: -0.025em;
    color: var(--fg);
  }

  h1 {
    font-size: clamp(2.25rem, 1.5rem + 2vw, 3.25rem);
    font-variation-settings: "opsz" 144, "wght" 360, "SOFT" 50;
  }

  h2 {
    font-size: 1.625rem;
    font-variation-settings: "opsz" 72, "wght" 420, "SOFT" 30;
  }

  h3 {
    font-size: 1.125rem;
    font-variation-settings: "opsz" 14, "wght" 600;
    letter-spacing: -0.01em;
  }

  /* Tabular numerics in stats and tables */
  .num, td.num, .stat-value, time {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum", "cv11";
  }

  /* Selection */
  ::selection { background: var(--fg); color: var(--bg); }
}

/* ──── Layout: App shell ──────────────────────────────────────────────── */
@layer layout {
  body:has(.sidebar) {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    min-height: 100vh;
  }

  .sidebar {
    background: var(--bg-sunken);
    border-right: 1px solid var(--border);
    padding: var(--space-5) 0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
  }

  .main {
    min-width: 0;
    padding: var(--space-6) var(--space-7);
    max-width: var(--content-max);
  }

  .topbar {
    margin-bottom: var(--space-6);
    padding-bottom: var(--space-5);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-4);
    min-height: 60px;
  }

  /* Page-level grid for detail pages */
  .page-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-6);
  }

  @media (min-width: 1100px) {
    .page-grid--with-side {
      grid-template-columns: minmax(0, 1fr) 320px;
    }
  }
}

/* ──── Components ─────────────────────────────────────────────────────── */
@layer components {
  /* Sidebar */
  .sidebar__brand {
    padding: 0 var(--space-5) var(--space-5);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-4);
  }

  .brand {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
  }

  .brand__mark {
    font-family: var(--font-display);
    font-variation-settings: "opsz" 144, "wght" 700, "SOFT" 0;
    font-size: 2rem;
    color: var(--accent);
    line-height: 1;
  }

  .brand__name {
    font-family: var(--font-display);
    font-variation-settings: "opsz" 14, "wght" 500;
    font-size: 1.125rem;
    letter-spacing: -0.01em;
  }

  .sidebar__account-name {
    margin-top: var(--space-2);
    font-size: 0.75rem;
    color: var(--fg-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
  }

  .sidebar__nav { flex: 1; padding: 0 var(--space-3); }

  .nav-group { margin-top: var(--space-5); }
  .nav-group:first-child { margin-top: 0; }

  .nav-group__title {
    font-family: var(--font-body);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
    color: var(--fg-subtle);
    padding: 0 var(--space-3);
    margin-bottom: var(--space-2);
  }

  .nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--fg-muted);
    font-size: 0.875rem;
    transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
  }

  .nav-item:hover {
    background: oklch(from var(--fg) l c h / 0.04);
    color: var(--fg);
  }

  .nav-item.is-active {
    background: oklch(from var(--fg) l c h / 0.08);
    color: var(--fg);
    font-weight: 500;
  }

  .nav-item__count {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    color: var(--fg-subtle);
    background: oklch(from var(--fg) l c h / 0.04);
    padding: 1px 6px;
    border-radius: 10px;
  }

  /* Sidebar footer / user menu */
  .sidebar__footer {
    padding: var(--space-4) var(--space-3) 0;
    border-top: 1px solid var(--border);
    margin-top: var(--space-5);
  }

  .user-menu { position: relative; }
  .user-menu__trigger {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2);
    width: 100%;
    border-radius: var(--radius-sm);
    text-align: left;
    transition: background var(--duration-fast) var(--ease);
  }
  .user-menu__trigger:hover { background: oklch(from var(--fg) l c h / 0.04); }

  .user-menu__avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-fg);
    display: grid;
    place-items: center;
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 0.875rem;
  }

  .user-menu__email {
    font-size: 0.8125rem;
    color: var(--fg-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .user-menu__panel {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    margin-bottom: var(--space-2);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-2);
    box-shadow: 0 8px 24px -8px oklch(from var(--fg) l c h / 0.15);
  }

  .user-menu__signout {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    text-align: left;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--danger);
  }
  .user-menu__signout:hover { background: oklch(from var(--danger) l c h / 0.08); }

  /* Page header */
  .page-header__eyebrow {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--fg-subtle);
    margin-bottom: var(--space-2);
    font-weight: 500;
  }

  .page-header__title {
    margin-bottom: var(--space-2);
  }

  .page-header__description {
    color: var(--fg-muted);
    max-width: 56ch;
    font-size: 0.9375rem;
    line-height: 1.5;
  }

  /* Buttons */
  .button {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1;
    border: 1px solid transparent;
    transition: all var(--duration-fast) var(--ease);
    cursor: pointer;
    height: 36px;
  }

  .button--primary {
    background: var(--fg);
    color: var(--bg);
  }
  .button--primary:hover {
    background: oklch(from var(--fg) calc(l + 0.05) c h);
  }

  .button--accent {
    background: var(--accent);
    color: var(--accent-fg);
  }
  .button--accent:hover {
    background: oklch(from var(--accent) calc(l - 0.04) c h);
  }

  .button--secondary {
    background: var(--bg-elevated);
    color: var(--fg);
    border-color: var(--border);
  }
  .button--secondary:hover { border-color: var(--border-strong); }

  .button--ghost {
    background: transparent;
    color: var(--fg-muted);
  }
  .button--ghost:hover { background: oklch(from var(--fg) l c h / 0.05); color: var(--fg); }

  .button--small { height: 28px; padding: 0 var(--space-3); font-size: 0.8125rem; }

  /* Stats grid */
  .stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-5);
    padding: var(--space-5) 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin-bottom: var(--space-6);
  }

  .stat__label {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--fg-subtle);
    margin-bottom: var(--space-2);
  }

  .stat-value {
    font-family: var(--font-display);
    font-variation-settings: "opsz" 144, "wght" 400, "SOFT" 30;
    font-size: 2.25rem;
    line-height: 1;
    color: var(--fg);
    letter-spacing: -0.02em;
  }

  .stat-value--mono {
    font-family: var(--font-mono);
    font-size: 1.875rem;
    font-weight: 400;
  }

  .stat__delta {
    margin-top: var(--space-1);
    font-size: 0.75rem;
    color: var(--fg-muted);
  }

  /* Cards */
  .card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-5);
  }

  .card__title {
    font-family: var(--font-display);
    font-variation-settings: "opsz" 14, "wght" 600;
    font-size: 1rem;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--border);
  }

  /* Tables */
  .table-wrap {
    overflow-x: auto;
    margin: 0 calc(var(--space-7) * -1);
    padding: 0 var(--space-7);
  }

  table.data-table {
    width: 100%;
    border-spacing: 0;
  }

  .data-table thead th {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
    color: var(--fg-subtle);
    text-align: left;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-strong);
  }

  .data-table tbody td {
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
    color: var(--fg);
    font-size: 0.875rem;
    vertical-align: middle;
  }

  .data-table tbody tr {
    transition: background var(--duration-fast) var(--ease);
  }
  .data-table tbody tr:hover { background: oklch(from var(--fg) l c h / 0.025); }

  .data-table .col-meta {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--fg-muted);
    font-variant-numeric: tabular-nums;
  }

  .data-table .col-num {
    font-family: var(--font-mono);
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--fg);
  }

  /* Avatar in tables */
  .row-with-avatar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }

  .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: oklch(from var(--accent) calc(l + 0.3) calc(c * 0.6) h);
    color: var(--fg);
    display: grid;
    place-items: center;
    font-size: 0.75rem;
    font-weight: 500;
    flex-shrink: 0;
  }

  /* Status badges (rolled out / outdated / pending / running / scheduled / passed) */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    line-height: 1.6;
  }

  .badge::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
  }

  .badge--positive { background: var(--positive-soft); color: var(--positive); }
  .badge--warning  { background: var(--warning-soft); color: var(--warning); }
  .badge--accent   { background: var(--accent-soft); color: var(--accent); }
  .badge--muted    { background: oklch(from var(--fg) l c h / 0.07); color: var(--fg-muted); }

  /* Tabs / segment control */
  .tabs {
    display: flex;
    gap: var(--space-1);
    padding: var(--space-1);
    background: oklch(from var(--fg) l c h / 0.05);
    border-radius: var(--radius);
    width: fit-content;
  }

  .tab {
    padding: var(--space-2) var(--space-4);
    font-size: 0.8125rem;
    color: var(--fg-muted);
    border-radius: calc(var(--radius) - 2px);
    transition: all var(--duration-fast) var(--ease);
  }

  .tab:hover { color: var(--fg); }
  .tab.is-active {
    background: var(--bg-elevated);
    color: var(--fg);
    font-weight: 500;
    box-shadow: 0 1px 2px oklch(from var(--fg) l c h / 0.06);
  }

  /* Toolbar (search + filters) */
  .toolbar {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
  }

  .search-input {
    flex: 1;
    min-width: 240px;
    padding: var(--space-2) var(--space-4);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    border-radius: var(--radius);
    font-size: 0.875rem;
    height: 36px;
  }
  .search-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
  }

  /* Form fields */
  .field { margin-bottom: var(--space-5); }
  .field__label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--fg-muted);
    margin-bottom: var(--space-2);
  }
  .field__hint {
    font-size: 0.8125rem;
    color: var(--fg-subtle);
    margin-top: var(--space-2);
  }
  .field__error { color: var(--danger); margin-top: var(--space-2); font-size: 0.8125rem; }

  .input, .textarea, .select {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
  }
  .input:focus, .textarea:focus, .select:focus {
    outline: 2px solid var(--accent);
    outline-offset: -1px;
    border-color: var(--accent);
  }
  .textarea { font-family: var(--font-mono); font-size: 0.8125rem; min-height: 240px; line-height: 1.6; resize: vertical; }

  /* Empty states */
  .empty-state {
    padding: var(--space-8) var(--space-5);
    text-align: center;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    color: var(--fg-muted);
  }

  .empty-state__title {
    font-family: var(--font-display);
    font-variation-settings: "opsz" 72, "wght" 400, "SOFT" 50;
    font-size: 1.5rem;
    color: var(--fg);
    margin-bottom: var(--space-2);
  }

  /* Banner preview (Campaign cards) */
  .banner-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--bg-elevated);
    transition: border-color var(--duration-fast) var(--ease);
  }
  .banner-card:hover { border-color: var(--border-strong); }

  .banner-card__image {
    aspect-ratio: 4 / 1;
    background: oklch(from var(--fg) l c h / 0.05);
    display: grid;
    place-items: center;
    color: var(--fg-subtle);
  }
  .banner-card__image img { width: 100%; height: 100%; object-fit: contain; }

  .banner-card__body {
    padding: var(--space-4);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
  }

  .banner-card__name {
    font-weight: 500;
    margin-bottom: var(--space-1);
  }
  .banner-card__window {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--fg-subtle);
  }

  /* Signature live preview */
  .signature-preview {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: white;  /* Mail-like surface */
    padding: var(--space-6);
    min-height: 200px;
    box-shadow: 0 4px 24px -8px oklch(from var(--fg) l c h / 0.08);
  }

  /* Flash */
  .flash {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    margin-bottom: var(--space-5);
    font-size: 0.875rem;
    border: 1px solid;
    animation: flash-in var(--duration) var(--ease);
  }
  .flash--notice { background: var(--positive-soft); color: var(--positive); border-color: oklch(from var(--positive) l c h / 0.3); }
  .flash--alert  { background: oklch(from var(--danger) l c h / 0.1); color: var(--danger); border-color: oklch(from var(--danger) l c h / 0.3); }

  @keyframes flash-in {
    from { transform: translateY(-4px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }
}

/* ──── Utilities ──────────────────────────────────────────────────────── */
@layer utilities {
  .stack > * + * { margin-top: var(--gap, var(--space-4)); }
  .row { display: flex; gap: var(--space-3); align-items: center; }
  .row--between { justify-content: space-between; }
  .text-muted { color: var(--fg-muted); }
  .text-subtle { color: var(--fg-subtle); font-size: 0.8125rem; }
  .text-mono { font-family: var(--font-mono); }
  .text-display { font-family: var(--font-display); }
}

/* ──── Dark Mode ──────────────────────────────────────────────────────── */
@layer tokens {
  @media (prefers-color-scheme: dark) {
    :root {
      --bg:           oklch(15% 0.012 60);    /* deep warm black */
      --bg-elevated:  oklch(19% 0.014 60);    /* card surface */
      --bg-sunken:    oklch(12% 0.012 60);    /* sidebar */
      --fg:           oklch(94% 0.012 75);    /* warm cream text */
      --fg-muted:     oklch(70% 0.010 70);    /* secondary */
      --fg-subtle:    oklch(55% 0.010 70);    /* metadata */
      --border:       oklch(28% 0.012 60);    /* hairline */
      --border-strong: oklch(38% 0.012 60);
      --accent:       oklch(70% 0.18 28);     /* coral, lighter for dark */
      --accent-soft:  oklch(28% 0.10 28);
      --positive:     oklch(70% 0.14 145);
      --positive-soft: oklch(25% 0.08 145);
      --warning:      oklch(75% 0.15 70);
      --warning-soft: oklch(28% 0.08 70);
    }
  }
}

@layer components {
  /* Signature-Preview bleibt im Dark-Mode hell, weil Mails immer hell sind */
  @media (prefers-color-scheme: dark) {
    .signature-preview {
      background: oklch(98% 0.005 60);
      color: oklch(20% 0.014 60);
    }
  }
}

/* ──── Print ──────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar { display: none; }
  body { display: block; background: white; color: black; }
}
