/*
 * TOOL SHARED STYLES
 * ------------------
 * Shared design tokens, reset, and base components
 * used by dca-capital.html, dca-cost.html (and any future tool pages).
 *
 * What belongs here:
 *   - CSS custom properties (design tokens)
 *   - html.dark variable overrides
 *   - Box-model reset + base html/body
 *   - Navbar button reset (no Tailwind preflight)
 *   - Shared components: .card, button.add, input base, .loss/.profit/.brand
 *
 * What does NOT belong here:
 *   - Page-layout rules (.container, .tool-header, .summary, etc.)
 *   - Component styles unique to one page
 */

/* ── Design Tokens (Light) ────────────────────────────────── */
:root {
  --primary:        #ff8a00;
  --primary-soft:   #ffe2bf;
  --success:        #2e7d32;
  --danger:         #e53935;
  --warning:        #f59e0b;

  --bg-main:        #f5f5f5;
  --bg-card:        #ffffff;
  --bg-input:       #f1f5f9;
  --bg-hover:       #e2e8f0;

  --border:         rgba(0, 0, 0, 0.08);
  --border-focus:   rgba(255, 138, 0, 0.5);

  --text-primary:   #1e1e1e;
  --text-secondary: #475569;
  --text-muted:     #777;

  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 0.75rem;
  --space-lg: 1rem;
  --radius:   0.5rem;
}

/* ── Design Tokens (Dark) ─────────────────────────────────── */
html.dark {
  --bg-main:        #101522;
  --bg-card:        #1a202e;
  --bg-input:       #232c48;
  --bg-hover:       #2a3050;

  --border:         rgba(255, 255, 255, 0.08);
  --border-focus:   rgba(255, 138, 0, 0.6);

  --text-primary:   #e2e8f0;
  --text-secondary: #a0aec0;
  --text-muted:     #92a0c9;
}

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

/* ── Base HTML / Body ─────────────────────────────────────── */
html {
  font-size: 14px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

html.dark body {
  background: var(--bg-main);
  color: var(--text-primary);
}

/* ── Navbar Button Reset (no Tailwind preflight) ──────────── */
/*
 * :where() has specificity 0,0,0 so Tailwind utility classes
 * (e.g.  hover:bg-[#232c48]) can still override without !important.
 */
:where(#navbar-container) button {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0;
  font: inherit;
}

/* ── Scoped Tailwind Preflight for Navbar ─────────────────── */
/*
 * DCA pages disable Tailwind preflight (corePlugins.preflight: false)
 * to prevent it from resetting input/button/card styles defined here.
 * But Navbar.js uses Tailwind utility classes (border-b, ring-2, etc.)
 * that DEPEND on preflight having initialized:
 *   border-width: 0;  border-style: solid;  --tw-ring-* vars, etc.
 * Without this block, `border-solid` activates browser-default
 * border-width: medium (~3px) + color: currentColor (black) on all
 * four sides → visible black border around the navbar header.
 *
 * :where() keeps specificity at 0,0,0 so utility classes always win.
 */
:where(#navbar-container) *,
:where(#navbar-container) *::before,
:where(#navbar-container) *::after {
  border-width: 0;
  border-style: solid;
  border-color: currentColor;
  --tw-ring-inset: ;
  --tw-ring-offset-width: 0px;
  --tw-ring-offset-color: #fff;
  --tw-ring-color: rgb(59 130 246 / 0.5);
  --tw-ring-offset-shadow: 0 0 #0000;
  --tw-ring-shadow: 0 0 #0000;
  --tw-shadow: 0 0 #0000;
  --tw-shadow-colored: 0 0 #0000;
}

/* ── Card ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
}

html.dark .card {
  border-color: rgba(255, 255, 255, 0.06);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

/* ── Semantic Colour Helpers ──────────────────────────────── */
.loss   { color: var(--danger);  }
.profit { color: var(--success); }
.brand  { color: var(--primary); }
.muted  { color: var(--text-muted); }

/* ── Input Base ───────────────────────────────────────────── */
input {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #ddd;
  text-align: center;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

html.dark input {
  background: var(--bg-input);
  border-color: #344065;
  color: var(--text-primary);
}

input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

/* Hide native number spinners */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* Read-only calculated field */
.readonly,
input.readonly {
  background: var(--bg-input);
  border: none;
  color: var(--text-muted);
  cursor: default;
}

html.dark .readonly,
html.dark input.readonly {
  background: var(--bg-card);
  color: var(--text-muted);
}

/* ── Action Buttons ───────────────────────────────────────── */
.actions button {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: #999;
}
.actions button:hover { color: var(--danger); }

button.add {
  margin-top: 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
button.add:hover { opacity: 0.9; }
