/* ─────────────────────────────────────────────────────────────
   MANGONESE.CSS
   Shared brand stylesheet for all Mangonese apps.
   Hosted at: https://mangonese.dev/shared/mangonese.css
   Last updated: May 2026

   Cascade contract:
   - Everything below is wrapped in `@layer mangonese`.
   - Vanilla apps that load this file via plain <link> get every rule
     applied as expected — layered rules still apply when nothing else
     is competing for the property.
   - Apps that pair this file with a utility framework (Tailwind v4,
     Open Props, etc.) get the utility classes winning on conflict
     because their layers (theme, base, components, utilities) are
     declared AFTER `mangonese` and the cascade order is by first
     declaration — later layers win.
   - The @media (prefers-reduced-motion) rule at the bottom is left
     UNLAYERED on purpose so its !important resets always trump any
     framework's transition / animation utilities (a11y-first).
   ───────────────────────────────────────────────────────────── */


/* @import must be the very first rule (after @charset). The font
   stylesheet contains only @font-face declarations, which are not
   subject to the cascade — layering it doesn't matter. */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap');


@layer mangonese {

  /* ── DESIGN TOKENS ── */
  :root {
    /* Backgrounds (dark mode default) */
    --bg-primary:   #0d1117;
    --bg-surface:   #0f1923;
    --bg-elevated:  #161f2e;

    /* Text */
    --text-primary:   #e8f0ea;
    --text-secondary: #5a6a7e;
    --text-muted:     #4a5a6a;

    /* Brand */
    --mango:      #f0a500;
    --mango-warm: #f8c820;
    --teal:       #3dd6ac;

    /* States */
    --error:   #e85a5a;
    --warning: #f8c820;
    --success: #3dd6ac;

    /* Borders */
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.12);

    /* Type */
    --font-sans: 'DM Sans', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    --font-mono: ui-monospace, 'SF Mono', Menlo, monospace;

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 40px;

    /* Spacing scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 16px 32px rgba(0,0,0,0.5);
    --shadow-xl: 0 40px 80px rgba(0,0,0,0.6);

    /* Transitions */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: 120ms var(--ease);
    --transition-base: 200ms var(--ease);
    --transition-slow: 320ms var(--ease);
  }


  /* ── LIGHT MODE OVERRIDES ── */
  @media (prefers-color-scheme: light) {
    :root {
      --bg-primary:   #fafaf7;
      --bg-surface:   #ffffff;
      --bg-elevated:  #f0efe9;

      --text-primary:   #0d1117;
      --text-secondary: #5a6a7e;
      --text-muted:     #8a9aa8;

      --border-subtle: rgba(0, 0, 0, 0.06);
      --border-strong: rgba(0, 0, 0, 0.12);

      --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
      --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
      --shadow-lg: 0 16px 32px rgba(0,0,0,0.14);
      --shadow-xl: 0 40px 80px rgba(0,0,0,0.18);
    }
  }


  /* ── MANUAL THEME OVERRIDES ──
     Apps wire up a toggle that sets data-theme="light" or data-theme="dark"
     on the <html> element, overriding the system preference. */

  [data-theme="light"] {
    --bg-primary:   #fafaf7;
    --bg-surface:   #ffffff;
    --bg-elevated:  #f0efe9;
    --text-primary:   #0d1117;
    --text-secondary: #5a6a7e;
    --text-muted:     #8a9aa8;
    --border-subtle: rgba(0, 0, 0, 0.06);
    --border-strong: rgba(0, 0, 0, 0.12);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
    --shadow-lg: 0 16px 32px rgba(0,0,0,0.14);
    --shadow-xl: 0 40px 80px rgba(0,0,0,0.18);
  }

  [data-theme="dark"] {
    --bg-primary:   #0d1117;
    --bg-surface:   #0f1923;
    --bg-elevated:  #161f2e;
    --text-primary:   #e8f0ea;
    --text-secondary: #5a6a7e;
    --text-muted:     #4a5a6a;
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.12);
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 16px 32px rgba(0,0,0,0.5);
    --shadow-xl: 0 40px 80px rgba(0,0,0,0.6);
  }


  /* ── BASE RESET ── */
  *, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
  }

  body {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    /* dvh accounts for the iOS Safari URL bar — vh would overshoot. */
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  img, svg, video {
    display: block;
    max-width: 100%;
  }

  button, input, textarea, select {
    font: inherit;
    color: inherit;
  }

  a {
    color: var(--mango);
    text-decoration: none;
    transition: color var(--transition-fast);
  }

  a:hover {
    color: var(--mango-warm);
  }


  /* ── TYPOGRAPHY ── */
  h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
    color: var(--text-primary);
  }

  h1 { font-size: 28px; font-weight: 700; }
  h2 { font-size: 22px; }
  h3 { font-size: 18px; }
  h4 { font-size: 16px; }
  h5 { font-size: 14px; }
  h6 { font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; }

  .text-secondary { color: var(--text-secondary); }
  .text-muted     { color: var(--text-muted); }
  .text-mango     { color: var(--mango); }
  .text-teal      { color: var(--teal); }
  .text-error     { color: var(--error); }
  .text-success   { color: var(--success); }

  .text-xs { font-size: 11px; }
  .text-sm { font-size: 13px; }
  .text-md { font-size: 15px; }
  .text-lg { font-size: 18px; }


  /* ── LAYOUT UTILITIES ── */
  .container {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding: 0 var(--space-4);
  }

  @media (min-width: 768px) {
    .container { max-width: 720px; }
  }

  .flex      { display: flex; }
  .flex-col  { display: flex; flex-direction: column; }
  .items-center { align-items: center; }
  .justify-between { justify-content: space-between; }
  .gap-1 { gap: var(--space-1); }
  .gap-2 { gap: var(--space-2); }
  .gap-3 { gap: var(--space-3); }
  .gap-4 { gap: var(--space-4); }


  /* ── SURFACE / CARD ── */
  .surface {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    padding: var(--space-4);
  }

  .card {
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    border: 1px solid var(--border-subtle);
  }


  /* ── BUTTON ── */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    height: 44px;
    padding: 0 var(--space-5);
    font-size: 15px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: background var(--transition-fast),
                transform var(--transition-fast);
    user-select: none;
    -webkit-user-select: none;
  }

  .btn:active { transform: scale(0.97); }

  .btn-primary {
    background: var(--mango);
    color: #1a1208;
  }
  .btn-primary:hover { background: var(--mango-warm); }

  .btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
  }
  .btn-secondary:hover { background: var(--border-subtle); }

  .btn-ghost {
    background: transparent;
    color: var(--text-secondary);
  }
  .btn-ghost:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
  }

  .btn-danger {
    background: var(--error);
    color: #fff;
  }


  /* ── INPUTS ── */
  .input,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="search"],
  textarea,
  select {
    width: 100%;
    height: 44px;
    padding: 0 var(--space-3);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 16px;
    transition: border-color var(--transition-fast);
    outline: none;
  }

  textarea {
    height: auto;
    min-height: 88px;
    padding: var(--space-3);
    line-height: 1.5;
    resize: vertical;
  }

  .input:focus,
  input:focus,
  textarea:focus,
  select:focus {
    border-color: var(--mango);
  }

  label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
  }


  /* ── TOAST ── */
  #toast-host {
    position: fixed;
    bottom: var(--space-6);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    z-index: 9999;
    pointer-events: none;
    width: 100%;
    max-width: 420px;
    padding: 0 var(--space-4);
  }

  .toast {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    pointer-events: auto;
    animation: toast-in 240ms var(--ease);
  }

  .toast-error   { border-left: 4px solid var(--error); }
  .toast-success { border-left: 4px solid var(--success); }
  .toast-warning { border-left: 4px solid var(--warning); }

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


  /* ── MODAL ── */
  .modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 1000;
    animation: fade-in 200ms var(--ease);
  }

  @media (min-width: 640px) {
    .modal-backdrop { align-items: center; }
  }

  .modal {
    background: var(--bg-surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: var(--space-6);
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow-xl);
    animation: modal-in 280ms var(--ease);
  }

  @media (min-width: 640px) {
    .modal { border-radius: var(--radius-lg); }
  }

  @keyframes fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
  }

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


  /* ── LOADING SPINNER ── */
  .spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--mango);
    border-radius: 50%;
    animation: spin 720ms linear infinite;
  }

  @keyframes spin {
    to { transform: rotate(360deg); }
  }


  /* ── SAFE-AREA HELPERS ── prefer the Capacitor-injected --safe-area-inset-*
     custom props (Android 15+ edge-to-edge, older WebViews), fall back to
     env() (iOS / modern WebViews), then 0. */
  .safe-top    { padding-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px)); }
  .safe-bottom { padding-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)); }


  /* ── ACCESSIBILITY ── */
  :focus-visible {
    outline: 2px solid var(--mango);
    outline-offset: 2px;
  }


  /* ════════════════════════════════════════════════════════════════
     EXPANSION (2026-06) — additive component classes for @mangonese/ds.
     New selectors only; nothing above this line is modified.
     ════════════════════════════════════════════════════════════════ */

  /* ── FORMS ── */
  .select {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    font: inherit;
  }
  .select:focus { outline: none; border-color: var(--mango); }

  .textarea {
    width: 100%;
    min-height: 80px;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    font: inherit;
    resize: vertical;
  }
  .textarea:focus { outline: none; border-color: var(--mango); }

  .label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
  }
  .field { display: block; }
  .field-help { font-size: 12px; color: var(--text-muted); margin-top: var(--space-1); }
  .field-error { font-size: 12px; color: var(--error); margin-top: var(--space-1); }

  .checkbox, .radio { width: 18px; height: 18px; accent-color: var(--mango); }

  .switch { position: relative; display: inline-block; width: 40px; height: 24px; }
  .switch input { opacity: 0; width: 0; height: 0; }
  .switch .switch-track {
    position: absolute; inset: 0;
    background: var(--border-strong);
    border-radius: 999px;
    transition: var(--transition-base);
  }
  .switch .switch-track::before {
    content: ""; position: absolute;
    height: 18px; width: 18px; left: 3px; top: 3px;
    background: #fff; border-radius: 50%;
    transition: var(--transition-base);
  }
  .switch input:checked + .switch-track { background: var(--mango); }
  .switch input:checked + .switch-track::before { transform: translateX(16px); }

  .slider { width: 100%; accent-color: var(--mango); }

  /* ── FEEDBACK ── */
  .badge {
    display: inline-flex; align-items: center;
    padding: 2px 8px;
    font-size: 11px; font-weight: 600;
    border-radius: 999px;
    background: var(--bg-elevated); color: var(--text-secondary);
  }
  .badge-mango   { background: var(--mango);   color: #1a1205; }
  .badge-teal    { background: var(--teal);    color: #04211a; }
  .badge-error   { background: var(--error);   color: #fff; }
  .badge-warning { background: var(--warning); color: #1a1205; }
  .badge-success { background: var(--success); color: #04211a; }

  .chip {
    display: inline-flex; align-items: center; gap: var(--space-2);
    padding: 4px 10px;
    font-size: 13px;
    border-radius: 999px;
    background: var(--bg-elevated); color: var(--text-primary);
    border: 1px solid var(--border-subtle);
  }
  .chip-dismiss { cursor: pointer; opacity: 0.6; line-height: 1; }
  .chip-dismiss:hover { opacity: 1; }

  .tooltip {
    display: inline-block;
    padding: 6px 10px;
    font-size: 12px;
    background: var(--bg-elevated); color: var(--text-primary);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
  }

  .progress { width: 100%; height: 8px; background: var(--bg-elevated); border-radius: 999px; overflow: hidden; }
  .progress-bar { height: 100%; background: var(--mango); border-radius: 999px; transition: width var(--transition-base); }

  .skeleton {
    background: linear-gradient(90deg, var(--bg-elevated) 25%, var(--bg-surface) 50%, var(--bg-elevated) 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease infinite;
    border-radius: var(--radius-sm);
  }
  @keyframes skeleton-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

  .alert {
    display: flex; gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    border-left: 4px solid var(--text-muted);
  }
  .alert-info    { border-left-color: var(--teal); }
  .alert-success { border-left-color: var(--success); }
  .alert-warning { border-left-color: var(--warning); }
  .alert-error   { border-left-color: var(--error); }

  .empty-state {
    display: flex; flex-direction: column; align-items: center; text-align: center;
    gap: var(--space-3);
    padding: var(--space-8) var(--space-4);
    color: var(--text-secondary);
  }

  /* ── NAVIGATION ── */
  .tabs { display: flex; gap: var(--space-4); border-bottom: 1px solid var(--border-subtle); }
  .tab {
    padding: var(--space-3) 0;
    font-size: 14px; color: var(--text-secondary);
    border: none; border-bottom: 2px solid transparent;
    background: none; cursor: pointer;
  }
  .tab[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--mango); }
  .tab-panel { padding-top: var(--space-4); }

  .segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--bg-elevated); border-radius: var(--radius-md); }
  .segmented-option {
    padding: 6px 14px;
    font-size: 13px;
    border: none; background: none; cursor: pointer;
    border-radius: calc(var(--radius-md) - 3px);
    color: var(--text-secondary);
  }
  .segmented-option[aria-selected="true"] { background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-sm); }

  .bottom-nav {
    display: flex; justify-content: space-around;
    padding: var(--space-2) 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
  }
  .bottom-nav-item {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 11px; color: var(--text-muted);
    background: none; border: none; cursor: pointer;
  }
  .bottom-nav-item[aria-current="page"] { color: var(--mango); }

  /* ── LAYOUT ── */
  .divider { border: none; border-top: 1px solid var(--border-subtle); margin: 0; }
  .divider[data-orientation="vertical"] { border-top: none; border-left: 1px solid var(--border-subtle); align-self: stretch; }

  /* ── DATA ── */
  .list { display: flex; flex-direction: column; background: var(--bg-surface); border-radius: var(--radius-md); overflow: hidden; }
  .list-item {
    display: flex; align-items: center; gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
  }
  .list-item:last-child { border-bottom: none; }
  .list-item-body { flex: 1; min-width: 0; }
  .list-item-title { color: var(--text-primary); font-size: 15px; }
  .list-item-subtitle { color: var(--text-muted); font-size: 13px; }
  .list-item-trailing { color: var(--text-secondary); }

  .avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--bg-elevated); color: var(--text-secondary);
    font-weight: 600; overflow: hidden;
  }
  .avatar img { width: 100%; height: 100%; object-fit: cover; }

  .stat { display: flex; flex-direction: column; gap: 2px; }
  .stat-label { font-size: 12px; color: var(--text-muted); }
  .stat-value { font-size: 24px; font-weight: 700; color: var(--text-primary); }
  .stat-delta-up   { color: var(--success); font-size: 13px; }
  .stat-delta-down { color: var(--error);   font-size: 13px; }

  /* ── OVERLAYS ── */
  .sheet {
    background: var(--bg-surface);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: var(--space-6);
    width: 100%; max-width: 480px;
    box-shadow: var(--shadow-xl);
  }
  .sheet-handle { width: 36px; height: 4px; border-radius: 999px; background: var(--border-strong); margin: 0 auto var(--space-4); }

  .menu {
    display: flex; flex-direction: column;
    min-width: 180px; padding: var(--space-2);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
  }
  .menu-item {
    display: flex; align-items: center; gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    font-size: 14px; color: var(--text-primary);
    border: none; background: none; text-align: left;
    border-radius: var(--radius-sm); cursor: pointer;
  }
  .menu-item:hover { background: var(--bg-surface); }

  .action-sheet { display: flex; flex-direction: column; gap: var(--space-2); width: 100%; max-width: 420px; }
  .action-sheet-item {
    padding: var(--space-4); text-align: center;
    font-size: 16px; color: var(--mango);
    background: var(--bg-elevated); border: none;
    border-radius: var(--radius-md); cursor: pointer;
  }
  .action-sheet-cancel { color: var(--text-secondary); font-weight: 600; }

  .popover {
    display: inline-block;
    padding: var(--space-4);
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
  }

}


/* ── REDUCED MOTION (a11y) ──
   Intentionally OUTSIDE @layer mangonese. Per the CSS Cascade Layers
   spec, !important rules in unlayered position trump !important rules
   inside any layer — so this stays the highest-priority a11y override
   regardless of what utility framework an app pairs us with. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
