/* ==========================================================================
   Toolbox — shared stylesheet
   Every app links this file. Use the tokens and components below rather
   than hard-coding colors, spacing or fonts in individual apps.
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #dde1e8;
  --text: #1b1f27;
  --text-muted: #5d6676;
  --accent: #4f5bd5;
  --accent-hover: #3f4ac0;
  --accent-contrast: #ffffff;
  --accent-soft: #e8eaff;
  --success: #1f8a5b;
  --warning: #b7791f;
  --danger: #c93c3c;
  --focus: 0 0 0 3px rgba(79, 91, 213, 0.35);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.12);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;

  --content-width: 960px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12141a;
    --surface: #1b1e26;
    --surface-2: #242833;
    --border: #2f3442;
    --text: #e7e9ee;
    --text-muted: #9aa3b5;
    --accent: #8b94ff;
    --accent-hover: #a2a9ff;
    --accent-contrast: #12141a;
    --accent-soft: #262a4a;
    --success: #4cc38a;
    --warning: #e0a84a;
    --danger: #f07171;
    --focus: 0 0 0 3px rgba(139, 148, 255, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #12141a;
  --surface: #1b1e26;
  --surface-2: #242833;
  --border: #2f3442;
  --text: #e7e9ee;
  --text-muted: #9aa3b5;
  --accent: #8b94ff;
  --accent-hover: #a2a9ff;
  --accent-contrast: #12141a;
  --accent-soft: #262a4a;
  --success: #4cc38a;
  --warning: #e0a84a;
  --danger: #f07171;
  --focus: 0 0 0 3px rgba(139, 148, 255, 0.4);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 var(--space-3); font-weight: 650; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 var(--space-3); }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
code, kbd, pre { font-family: var(--font-mono); font-size: 0.92em; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-5) 0; }

:focus-visible { outline: none; box-shadow: var(--focus); }

.muted { color: var(--text-muted); }
.small { font-size: 0.875rem; }
.mono { font-family: var(--font-mono); }

/* ---------- Layout ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-header__inner {
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.app-header__title {
  font-size: 1.05rem;
  font-weight: 650;
  margin: 0;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-header__back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}
.app-header__back:hover { color: var(--text); background: var(--surface-2); }

.container {
  width: 100%;
  max-width: var(--content-width);
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-7);
  flex: 1;
}

.app-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: var(--space-4);
}

.stack > * + * { margin-top: var(--space-4); }
.row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.spacer { flex: 1; }

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow);
}
.card > :last-child { margin-bottom: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 550;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-contrast); }
.btn--danger { color: var(--danger); }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--sm { padding: 4px 10px; font-size: 0.85rem; }
.btn--icon { padding: 6px; width: 36px; height: 36px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: var(--space-1); }
.field > label, .label { font-size: 0.875rem; font-weight: 550; color: var(--text-muted); }

.input, .select, .textarea {
  font: inherit;
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: var(--focus); outline: none; }
.textarea { min-height: 120px; resize: vertical; }
input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--accent); }

/* ---------- Misc components ---------- */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th, .table td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-weight: 600; color: var(--text-muted); font-size: 0.85rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: var(--space-5);
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Home page: app tiles ---------- */
.tile {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.tile:hover { color: var(--text); transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--accent); }
.tile__icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  border-radius: var(--radius);
  background: var(--accent-soft);
}
.tile__name { font-weight: 650; font-size: 1.05rem; }
.tile__desc { color: var(--text-muted); font-size: 0.9rem; margin: 0; }

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: var(--space-7) var(--space-4);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
}

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .container { padding: var(--space-4) var(--space-4) var(--space-6); }
  .card { padding: var(--space-4); }
  h1 { font-size: 1.45rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
