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

/* ── Custom properties (tokens) ─────────────────────────────── */
:root {
  /* Brand */
  --accent:        #f97316; /* orange-500 — trades/energy feel */
  --accent-hover:  #ea580c; /* orange-600 */
  --accent-light:  #fff7ed; /* orange-50 */
  --accent-subtle: #ffedd5; /* orange-100 */

  /* Neutrals (dark-first palette) */
  --bg-base:       #0f172a; /* slate-900 */
  --bg-surface:    #1e293b; /* slate-800 */
  --bg-elevated:   #334155; /* slate-700 */
  --bg-input:      #1e293b;
  --border:        #334155;
  --border-subtle: #1e293b;

  /* Text */
  --text-primary:  #f1f5f9; /* slate-100 */
  --text-secondary:#94a3b8; /* slate-400 */
  --text-muted:    #64748b; /* slate-500 */
  --text-inverse:  #0f172a;

  /* Semantic */
  --success:       #22c55e; /* green-500 */
  --success-bg:    #052e16;
  --warning:       #f59e0b; /* amber-500 */
  --warning-bg:    #1c1404;
  --error:         #ef4444; /* red-500 */
  --error-bg:      #1c0202;
  --info:          #3b82f6; /* blue-500 */
  --info-bg:       #0c1a3d;

  /* Status colours for invoice badges */
  --status-draft:    #64748b;
  --status-sent:     #3b82f6;
  --status-partial:  #f59e0b;
  --status-paid:     #22c55e;
  --status-overdue:  #ef4444;
  --status-void:     #475569;

  /* Spacing scale */
  --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.375rem;
  --radius:     0.5rem;
  --radius-lg:  0.75rem;
  --radius-xl:  1rem;
  --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 */
  --shadow-sm:  0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow:     0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.4);
  --shadow-lg:  0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.4);
  --shadow-xl:  0 20px 25px -5px rgb(0 0 0 / 0.5), 0 8px 10px -6px rgb(0 0 0 / 0.4);

  /* 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: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover { background: #475569; }

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

.btn-danger {
  background: var(--error-bg);
  color: var(--error);
  border-color: var(--error);
}
.btn-danger:hover { background: #3b0000; }

.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: #1e293b; color: var(--status-draft); }
.badge-sent    { background: #0c1a3d; color: var(--status-sent); }
.badge-partial { background: #1c1404; color: var(--status-partial); }
.badge-paid    { background: #052e16; color: var(--status-paid); }
.badge-overdue { background: #1c0202; color: var(--status-overdue); }
.badge-void    { background: #1e293b; color: var(--status-void); }

/* ── Toast / notification ────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: var(--sp-6);
  left: 50%;
  transform: translateX(-50%);
  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(--success-bg); color: var(--success); border-color: #166534; }
.toast-error   { background: var(--error-bg);   color: var(--error);   border-color: #991b1b; }
.toast-info    { background: var(--info-bg);    color: var(--info);    border-color: #1d4ed8; }
.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-full);
  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);
}
