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


/* ── FONT IMPORT ── */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap');


/* ── 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);
  min-height: 100vh;
  -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 (for iOS PWAs) ── */
.safe-top    { padding-top: env(safe-area-inset-top); }
.safe-bottom { padding-bottom: env(safe-area-inset-bottom); }


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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
