/* ============================================================
   TradesBill Design System
   Shared tokens, typography, and utility classes used by
   both the landing page and the PWA app shell.
   ============================================================ */

/* ── Custom properties (tokens) ─────────────────────────────── */
:root {
  /* ── Sidebar zone ────────────────────────────────────────────── */
  --sidebar-bg:            #0f172a;
  --sidebar-text:          #94a3b8;
  --sidebar-text-active:   #f97316;
  --sidebar-active-bg:     rgba(249,115,22,0.12);
  --sidebar-hover-bg:      rgba(255,255,255,0.05);
  --sidebar-section-label: #475569;
  --sidebar-border:        #1e293b;

  /* ── Content zone ────────────────────────────────────────────── */
  --color-bg:              #f8fafc;
  --color-surface:         #ffffff;
  --color-surface-2:       #f1f5f9;
  --color-border:          #e2e8f0;
  --color-border-strong:   #cbd5e1;

  /* ── Text (content zone) ─────────────────────────────────────── */
  --color-text:            #0f172a;
  --color-text-muted:      #64748b;
  --color-text-faint:      #94a3b8;

  /* ── Brand ───────────────────────────────────────────────────── */
  --color-accent:          #f97316;
  --color-accent-hover:    #ea6c0a;
  --color-accent-soft:     #fff7ed;
  --color-accent-text:     #c2410c;

  /* ── Semantic ────────────────────────────────────────────────── */
  --color-success:         #16a34a;
  --color-success-bg:      #dcfce7;
  --color-warning:         #d97706;
  --color-warning-bg:      #fef9c3;
  --color-error:           #dc2626;
  --color-error-bg:        #fee2e2;
  --color-info:            #2563eb;
  --color-info-bg:         #dbeafe;

  /* ── Pro plan ────────────────────────────────────────────────── */
  --color-pro-bg:          #f97316;
  --color-pro-text:        #ffffff;
  --color-pro-banner-bg:   #16a34a;
  --color-pro-banner-text: #ffffff;

  /* ── Backwards-compat aliases (remove after app.css is updated) ─ */
  --accent:          var(--color-accent);
  --accent-hover:    var(--color-accent-hover);
  --accent-light:    var(--color-accent-soft);
  --accent-subtle:   #ffedd5;
  --bg-base:         var(--color-bg);
  --bg-surface:      var(--color-surface);
  --bg-elevated:     var(--color-surface-2);
  --bg-subtle:       var(--color-surface-2);
  --bg-input:        var(--color-surface);
  --border:          var(--color-border);
  --border-subtle:   #e2e8f0;
  --text-primary:    var(--color-text);
  --text-secondary:  var(--color-text-muted);
  --text-muted:      var(--color-text-faint);
  --text-inverse:    var(--sidebar-bg);
  --success:         var(--color-success);
  --success-bg:      var(--color-success-bg);
  --warning:         var(--color-warning);
  --warning-bg:      var(--color-warning-bg);
  --error:           var(--color-error);
  --error-bg:        var(--color-error-bg);
  --info:            var(--color-info);
  --info-bg:         var(--color-info-bg);
  --status-draft:    var(--color-text-muted);
  --status-sent:     var(--color-info);
  --status-partial:  var(--color-warning);
  --status-paid:     var(--color-success);
  --status-overdue:  var(--color-error);
  --status-void:     #475569;

  /* ── Spacing ─────────────────────────────────────────────────── */
  --sp-1:  0.25rem;
  --sp-2:  0.5rem;
  --sp-3:  0.75rem;
  --sp-4:  1rem;
  --sp-5:  1.25rem;
  --sp-6:  1.5rem;
  --sp-8:  2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;
  --sp-16: 4rem;
  --sp-20: 5rem;
  --sp-24: 6rem;

  /* ── Border radius ───────────────────────────────────────────── */
  --radius-sm:   0.25rem;   /* 4px  — badges, tags */
  --radius:      0.5rem;    /* 8px  — inputs, buttons */
  --radius-lg:   0.75rem;   /* 12px — cards, panels */
  --radius-xl:   1rem;      /* 16px — modals, drawers */
  --radius-full: 9999px;

  /* ── Typography ──────────────────────────────────────────────── */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;
  --text-4xl:  2.25rem;
  --text-5xl:  3rem;

  /* ── Shadows (light-theme opacity) ──────────────────────────── */
  --shadow-sm:  0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow:     0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg:  0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.07);
  --shadow-xl:  0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.05);

  /* ── Transitions ─────────────────────────────────────────────── */
  --transition:      150ms ease;
  --transition-slow: 300ms ease;

  /* ── Layout ──────────────────────────────────────────────────── */
  --sidebar-width:  240px;
  --topbar-height:  56px;
  --container-max:  1200px;
  --content-max:    720px;
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img, svg, video { display: block; max-width: 100%; }
button { cursor: pointer; font-family: inherit; border: none; background: none; }
input, textarea, select { font-family: inherit; font-size: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

/* ── Typography helpers ──────────────────────────────────────── */
.text-xs    { font-size: var(--text-xs); }
.text-sm    { font-size: var(--text-sm); }
.text-base  { font-size: var(--text-base); }
.text-lg    { font-size: var(--text-lg); }
.text-xl    { font-size: var(--text-xl); }
.text-2xl   { font-size: var(--text-2xl); }
.text-3xl   { font-size: var(--text-3xl); }
.text-muted { color: var(--text-secondary); }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), opacity var(--transition);
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover {
  background: var(--color-surface-2);
  border-color: var(--color-accent);
  color: var(--color-accent);
}

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

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

.btn-sm { padding: var(--sp-2) var(--sp-3); font-size: var(--text-xs); }
.btn-lg { padding: var(--sp-4) var(--sp-8); font-size: var(--text-base); }
.btn-icon { padding: var(--sp-2); aspect-ratio: 1; }
.btn-full { width: 100%; }

/* ── Form controls ───────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: var(--sp-2); }

.label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
}

.input, .select, .textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: var(--text-sm);
  padding: var(--sp-3) var(--sp-4);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.textarea { resize: vertical; min-height: 80px; }

.input-error { border-color: var(--error); }
.field-error {
  font-size: var(--text-xs);
  color: var(--error);
  margin-top: var(--sp-1);
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
}

.card-sm { padding: var(--sp-4); border-radius: var(--radius); }

/* ── Status badges ───────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--sp-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge-draft   { background: var(--color-warning-bg);  color: var(--color-warning); }
.badge-sent    { background: var(--color-info-bg);     color: var(--color-info); }
.badge-partial { background: var(--color-warning-bg);  color: var(--color-warning); }
.badge-paid    { background: var(--color-success-bg);  color: var(--color-success); }
.badge-overdue { background: var(--color-error-bg);    color: var(--color-error); }
.badge-void    { background: var(--color-surface-2);   color: var(--color-text-muted); }

/* ── Toast / notification ────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: var(--sp-6);
  right: var(--sp-6);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  pointer-events: none;
  width: min(calc(100vw - var(--sp-8)), 400px);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in 200ms ease forwards;
  border: 1px solid transparent;
}

.toast-success { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success); }
.toast-warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: var(--color-warning); }
.toast-error   { background: var(--color-error-bg);   color: var(--color-error);   border-color: var(--color-error); }
.toast-info    { background: var(--color-info-bg);    color: var(--color-info);    border-color: var(--color-info); }
.toast-update  {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--accent);
  justify-content: space-between;
}

.toast-update .btn { pointer-events: auto; }

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

/* ── Divider ─────────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--sp-4) 0;
}

/* ── Loading spinner ─────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--bg-elevated);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
  flex-shrink: 0;
}

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

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-16) var(--sp-8);
  text-align: center;
  color: var(--text-secondary);
}

.empty-state svg { color: var(--text-muted); opacity: 0.5; }
.empty-state h3  { font-size: var(--text-lg); color: var(--text-primary); }

/* ── Modal ───────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.7);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

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

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--sp-6);
  animation: modal-in 200ms ease;
}

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

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

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-6);
}

.modal-title { font-size: var(--text-xl); font-weight: 700; }

/* ── Table ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }

table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }

thead tr { border-bottom: 1px solid var(--border); }
th {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--bg-surface);
}

td { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border-subtle); vertical-align: middle; }

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover td { background: var(--bg-surface); }

/* ── Currency / number alignment ────────────────────────────── */
.text-right { text-align: right; }
.text-mono  { font-family: var(--font-mono); font-size: var(--text-sm); }

/* ── Utility ─────────────────────────────────────────────────── */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border-width: 0;
}
.truncate    { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.items-center{ align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2       { gap: var(--sp-2); }
.gap-3       { gap: var(--sp-3); }
.gap-4       { gap: var(--sp-4); }
.mt-4        { margin-top: var(--sp-4); }
.mt-6        { margin-top: var(--sp-6); }
.mb-4        { margin-bottom: var(--sp-4); }
.w-full      { width: 100%; }

/* ── Pro badge ───────────────────────────────────────────────── */
.pro-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
}

/* ── iOS Safari install prompt ───────────────────────────────── */
.ios-install-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: 100;
  font-size: var(--text-sm);
}
