/* =============================================================
   base_styles.css — shared foundation for Just___ apps
   Override anything in a per-app styles.css by redefining the
   CSS custom properties below or targeting the same selectors.

   Theme handling:
     - Dark is the default (:root)
     - :root[data-theme="light"] forces light
     - :root[data-theme="dark"]  forces dark
     - If no data-theme attribute is set, the user's system
       preference is honored via prefers-color-scheme.

   To override the accent per-app, set --accent / --accent-hover
   inside BOTH the :root and :root[data-theme="light"] blocks
   (and the matching media query) so both themes look right.
   ============================================================= */

/* ---------- Design tokens (dark = default) ---------- */
:root {
  color-scheme: dark;

  /* Accent — override per app */
  --accent: #7dd3fc;
  --accent-hover: #38bdf8;
  --accent-contrast: #0b0f14;

  /* Surfaces */
  --bg: #0b0f14;
  --bg-elev: #121821;
  --bg-elev-2: #1a222e;
  --border: #273240;
  --border-strong: #3a4757;

  /* Text */
  --text: #e6edf3;
  --text-muted: #96a3b2;
  --text-dim: #5f6e80;

  /* Feedback */
  --danger: #f87171;
  --success: #4ade80;
  --warning: #fbbf24;

  /* Shadows — dark mode uses deep blacks */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

/* ---------- Light theme tokens ---------- */
:root[data-theme="light"] {
  color-scheme: light;

  --accent: #0284c7;
  --accent-hover: #0369a1;
  --accent-contrast: #ffffff;

  --bg: #ffffff;
  --bg-elev: #f5f6f8;
  --bg-elev-2: #eaecef;
  --border: #e2e5ea;
  --border-strong: #c9ced6;

  --text: #0f1720;
  --text-muted: #55616f;
  --text-dim: #8a95a3;

  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;

  --shadow-sm: 0 1px 2px rgba(15, 23, 32, 0.06);
  --shadow: 0 4px 12px rgba(15, 23, 32, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 32, 0.12);
}

/* Honor system preference when the user hasn't picked explicitly */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;

    --accent: #0284c7;
    --accent-hover: #0369a1;
    --accent-contrast: #ffffff;

    --bg: #ffffff;
    --bg-elev: #f5f6f8;
    --bg-elev-2: #eaecef;
    --border: #e2e5ea;
    --border-strong: #c9ced6;

    --text: #0f1720;
    --text-muted: #55616f;
    --text-dim: #8a95a3;

    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;

    --shadow-sm: 0 1px 2px rgba(15, 23, 32, 0.06);
    --shadow: 0 4px 12px rgba(15, 23, 32, 0.08);
    --shadow-lg: 0 12px 32px rgba(15, 23, 32, 0.12);
  }
}

/* Smooth theme transitions (but not on initial paint) */
:root.theme-ready,
:root.theme-ready body,
:root.theme-ready .card,
:root.theme-ready button,
:root.theme-ready .btn,
:root.theme-ready input,
:root.theme-ready textarea,
:root.theme-ready select {
  transition:
    background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease);
}

/* ---------- Non-themed tokens (same in light and dark) ---------- */
:root {
  /* Typography */
  --font-ui: "Outfit", system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Fira Code",
    Menlo, Consolas, monospace;

  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-base: 1rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.375rem;
  --fs-2xl: 1.75rem;
  --fs-3xl: 2.25rem;
  --fs-4xl: 3rem;

  /* Spacing (4px scale) */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;
  --sp-8: 4rem;

  /* Radius / motion */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-full: 999px;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 120ms;
  --dur: 200ms;

  /* Layout */
  --container: 680px;
  --tap: 44px; /* minimum touch target */
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: 1.5;
  font-weight: 400;
  /* Respect notches / PWA safe areas */
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

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

/* ---------- Typography ---------- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-ui);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--text);
}

h1 { font-size: var(--fs-3xl); letter-spacing: -0.02em; }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }
h5 { font-size: var(--fs-base); }
h6 { font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }

p {
  color: var(--text);
}

small, .text-sm { font-size: var(--fs-sm); }
.text-muted { color: var(--text-muted); }
.text-dim   { color: var(--text-dim); }
.text-mono  { font-family: var(--font-mono); }

/* Big numeric displays (timers, counters) */
.display {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  letter-spacing: -0.02em;
  font-size: var(--fs-4xl);
  line-height: 1;
  color: var(--text);
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease);
}
a:hover { color: var(--accent-hover); }
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 0.95em;
}

code {
  background: var(--bg-elev);
  padding: 0.1em 0.35em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

pre {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-4);
  overflow-x: auto;
}
pre code { background: none; border: none; padding: 0; }

hr {
  border: none;
  height: 1px;
  background: var(--border);
  margin: var(--sp-5) 0;
}

ul, ol { padding-left: 1.25rem; }
li + li { margin-top: var(--sp-1); }

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding: var(--sp-5) var(--sp-4);
}

main { display: block; }

.stack > * + * { margin-top: var(--sp-4); }
.stack-sm > * + * { margin-top: var(--sp-2); }
.stack-lg > * + * { margin-top: var(--sp-6); }

.row {
  display: flex;
  gap: var(--sp-3);
  flex-wrap: wrap;
  align-items: center;
}

.center {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Buttons ---------- */
button,
.btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: var(--sp-3) var(--sp-5);
  background: var(--bg-elev);
  color: var(--text);
  font-family: inherit;
  font-size: var(--fs-base);
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease);
}

button:hover,
.btn:hover {
  background: var(--bg-elev-2);
  border-color: var(--border-strong);
}

button:active,
.btn:active {
  transform: translateY(1px);
}

button:focus-visible,
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:disabled,
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

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

.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--bg-elev);
  border-color: var(--border);
}

.btn-block {
  width: 100%;
}

/* ---------- Forms ---------- */
input,
textarea,
select {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-height: var(--tap);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg-elev);
  color: var(--text);
  font-family: inherit;
  font-size: var(--fs-base); /* 16px — prevents iOS auto-zoom */
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition:
    border-color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-dim);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-elev-2);
}

textarea {
  resize: vertical;
  min-height: 6rem;
  line-height: 1.5;
}

label {
  display: block;
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-bottom: var(--sp-1);
}

/* ---------- Cards / surfaces ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
}

/* ---------- Header / footer (most apps have these) ---------- */
header.site-header {
  padding: var(--sp-5) 0 var(--sp-4);
  text-align: center;
}
header.site-header h1 {
  color: var(--accent);
}
header.site-header p {
  color: var(--text-muted);
  font-size: var(--fs-sm);
  margin-top: var(--sp-1);
}

footer.site-footer {
  padding: var(--sp-6) var(--sp-4);
  text-align: center;
  color: var(--text-dim);
  font-size: var(--fs-xs);
}

/* ---------- Utilities ---------- */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden { display: none !important; }

.text-center { text-align: center; }
.text-left   { text-align: left; }
.text-right  { text-align: right; }

.full-w { width: 100%; }

/* ---------- Selection ---------- */
::selection {
  background: var(--accent);
  color: var(--accent-contrast);
}

/* ---------- Scrollbar (subtle) ---------- */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg);
}

/* ---------- App branding ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--container);
  margin-inline: auto;
  padding: var(--sp-5) var(--sp-4) var(--sp-2);
}

.app-title {
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}

/* The "just" prefix — identical across every just* app */
.brand-just {
  color: var(--text-muted);
  font-weight: 400;
}

.app-tagline {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 var(--sp-4) var(--sp-5);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-style: italic;
}

/* ---------- Theme toggle button ---------- */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  cursor: pointer;
  transition:
    background var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease);
}
.theme-toggle:hover {
  background: var(--bg-elev);
  color: var(--text);
  border-color: var(--border-strong);
}

/* Show moon in light mode, sun in dark mode */
.theme-toggle .icon-sun  { display: none; }
.theme-toggle .icon-moon { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun  { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* ---------- Tabs (reusable nav pattern) ---------- */
.tab-nav {
  display: flex;
  gap: var(--sp-1);
  max-width: var(--container);
  margin: 0 auto var(--sp-5);
  padding: 0 var(--sp-4);
  border-bottom: 1px solid var(--border);
}

.tab-nav .tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: var(--sp-3) var(--sp-4);
  min-height: auto;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: -1px; /* overlap the container's bottom border */
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  transition:
    color var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease);
}

.tab-nav .tab:hover {
  background: transparent;
  color: var(--text);
  border-bottom-color: var(--border-strong);
  transform: none;
}

.tab-nav .tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-nav .tab.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tab-nav .tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Small badge for "soon" / "beta" etc. */
.tab-nav .tab .badge {
  font-size: var(--fs-xs);
  padding: 0.1em 0.5em;
  background: var(--bg-elev-2);
  color: var(--text-muted);
  border-radius: var(--radius-full);
  font-weight: 400;
}

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

/* ---------- Small screens ---------- */
@media (max-width: 480px) {
  :root {
    --fs-3xl: 1.875rem;
    --fs-4xl: 2.5rem;
  }
  .container { padding: var(--sp-4) var(--sp-3); }
  .card { padding: var(--sp-4); }
}

/*--Center Dialog boxes --*/
dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  /* Move it back 50% relative to self */
  -webkit-transform: translateX(-50%) translateY(-50%);
  -moz-transform: translateX(-50%) translateY(-50%);
  -ms-transform: translateX(-50%) translateY(-50%);
  transform: translateX(-50%) translateY(-50%);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Push the delete button to the far left, Cancel/Save stay on the right */
.modal-actions .btn-delete {
  margin-right: auto;
}

.btn-danger {
  background: #b33a3a;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}

.btn-danger:hover {
  background: #c84646;
}

.btn-danger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--sp-3);
}