/* ForecastPro — shared base styles (auth pages + app).
 *
 * Builds on tokens.css (canonical, copied verbatim from design/). Anything here that is a
 * new value is declared as an extension token below instead of repurposing a canonical one.
 */

:root {
  /* Extension tokens (app only). --text-subtle is the AA-safe secondary text colour:
     5.2:1 on --bg-card, 6.3:1 on --bg-input (--text-dim is 3.7:1 on cards, so it is only
     used for placeholders and decorative marks). */
  --text-subtle:      #9ba0a9;
  --btn-danger-bg:    #c63133;   /* white text 5.4:1 (the brighter --danger is 3.8:1) */
  --btn-danger-hover: #a82a2c;
  --line:             rgba(255, 255, 255, 0.06);
  --line-strong:      rgba(255, 255, 255, 0.1);
  --neutral-soft:     rgba(128, 132, 142, 0.18);
  --warning-text:     #f0b132;
  --topbar-h:         60px;
  --sidebar-w:        248px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading);
  background: var(--bg-deepest);
  color: var(--text-default);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { color: var(--text-primary); margin: 0; font-weight: 650; letter-spacing: -0.01em; line-height: 1.25; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
a { color: var(--text-link); text-decoration: none; text-underline-offset: 2px; }
a:hover { text-decoration: underline; }
strong { color: var(--text-primary); font-weight: 600; }
code, .mono { font-family: var(--font-mono); font-size: 0.92em; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft); color: var(--text-primary); }

/* Focus: visible, consistent ring on keyboard focus only. */
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }
/* Programmatic focus targets (headings/main moved to for screen readers) need no ring. */
[tabindex="-1"]:focus, [tabindex="-1"]:focus-visible { box-shadow: none; }

.skip-link {
  position: absolute; left: var(--space-3); top: -60px; z-index: 1000;
  background: var(--accent); color: #fff; padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-input); font-weight: 600;
  transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: var(--space-3); text-decoration: none; }

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

.num, .tabular { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* ---- Icons ------------------------------------------------------------------ */
.icon { width: 18px; height: 18px; flex: none; display: inline-block; vertical-align: middle; }
.icon svg { width: 100%; height: 100%; }
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 22px; height: 22px; }

/* ---- Buttons ---------------------------------------------------------------- */
.btn {
  --btn-bg: var(--bg-active);
  --btn-fg: var(--text-primary);
  --btn-border: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: 36px; padding: 0 var(--space-4);
  border-radius: var(--radius-input);
  border: 1px solid var(--btn-border);
  background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 550; font-size: var(--text-base); line-height: 1;
  cursor: pointer; white-space: nowrap; user-select: none;
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
              border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:active:not(:disabled):not([aria-disabled="true"]) { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.btn:focus-visible { border-radius: var(--radius-input); }
.btn .icon { width: 16px; height: 16px; }

.btn-primary { --btn-bg: var(--accent); --btn-fg: #fff; }
.btn-primary:hover:not(:disabled):not([aria-disabled="true"]) { --btn-bg: var(--accent-hover); }
.btn-secondary { --btn-bg: var(--bg-active); --btn-fg: var(--text-primary); }
.btn-secondary:hover:not(:disabled):not([aria-disabled="true"]) { --btn-bg: #4a4c54; }
.btn-outline { --btn-bg: transparent; --btn-fg: var(--text-default); --btn-border: var(--border-soft); }
.btn-outline:hover:not(:disabled):not([aria-disabled="true"]) { --btn-bg: var(--bg-hover); --btn-fg: var(--text-primary); }
.btn-outline[aria-pressed="true"] { --btn-bg: var(--accent-soft); --btn-border: rgba(88, 101, 242, 0.6); --btn-fg: var(--text-primary); }
.btn-ghost { --btn-bg: transparent; --btn-fg: var(--text-muted); }
.btn-ghost:hover:not(:disabled):not([aria-disabled="true"]) { --btn-bg: var(--bg-hover); --btn-fg: var(--text-primary); }
.btn-danger { --btn-bg: var(--btn-danger-bg); --btn-fg: #fff; }
.btn-danger:hover:not(:disabled):not([aria-disabled="true"]) { --btn-bg: var(--btn-danger-hover); }
.btn-danger-outline { --btn-bg: transparent; --btn-fg: var(--danger-text); --btn-border: rgba(242, 63, 67, 0.45); }
.btn-danger-outline:hover:not(:disabled):not([aria-disabled="true"]) { --btn-bg: var(--danger-soft); }

.btn-sm { height: 30px; padding: 0 var(--space-3); font-size: var(--text-sm); gap: 6px; }
.btn-sm .icon { width: 14px; height: 14px; }
.btn-xs { height: 24px; padding: 0 var(--space-2); font-size: var(--text-xs); gap: 4px; }
.btn-xs .icon { width: 12px; height: 12px; }
.btn-lg { height: 44px; padding: 0 var(--space-5); font-size: var(--text-md); }
.btn-block { width: 100%; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }

.btn.is-loading { position: relative; pointer-events: none; }
.btn.is-loading > :not(.spinner) { opacity: 0.85; }

/* ---- Spinner / skeleton ------------------------------------------------------ */
.spinner {
  width: 14px; height: 14px; flex: none;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: fp-spin 0.8s linear infinite;
}
.spinner-lg { width: 22px; height: 22px; border-width: 2.5px; }
@keyframes fp-spin { to { transform: rotate(360deg); } }

.skeleton {
  display: block;
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.09) 40%, rgba(255,255,255,0.04) 80%);
  background-size: 300% 100%;
  animation: fp-shimmer 1.6s ease-in-out infinite;
  min-height: 12px;
}
.skeleton-text { height: 12px; margin: 6px 0; }
.skeleton-title { height: 20px; width: 40%; margin-bottom: 12px; }
.skeleton-block { height: 64px; border-radius: var(--radius-card); }
@keyframes fp-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .skeleton { animation: none; }
  *, *::before, *::after { scroll-behavior: auto !important; }
}

/* ---- Forms ------------------------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field + .field { margin-top: var(--space-4); }
.field-row { display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-3); }
.label, label.label {
  color: var(--text-default); font-size: var(--text-sm); font-weight: 600;
  letter-spacing: 0.01em;
}
.label .opt { color: var(--text-subtle); font-weight: 400; margin-left: 4px; }
.hint { color: var(--text-subtle); font-size: var(--text-sm); line-height: 1.45; }
.hint-warning { display: flex; gap: 6px; align-items: flex-start; color: var(--warning-text); margin-top: var(--space-1); }
.hint-warning .icon { margin-top: 2px; flex: none; }
.field-error {
  display: flex; align-items: flex-start; gap: 6px;
  color: var(--danger-text); font-size: var(--text-sm); font-weight: 500;
}
.field-error .icon { width: 14px; height: 14px; margin-top: 1px; }

.input, .select, .textarea {
  width: 100%; min-width: 0;
  height: 40px; padding: 0 var(--space-3);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-input);
  color: var(--text-primary);
  font-size: var(--text-base);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.textarea { height: auto; min-height: 88px; padding: var(--space-2) var(--space-3); resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--text-dim); }
.input:hover, .select:hover, .textarea:hover { border-color: #2c2e33; }
.input:focus, .select:focus, .textarea:focus,
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  border-radius: var(--radius-input);
}
.input[aria-invalid="true"], .select[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}
.input:disabled, .select:disabled { opacity: 0.6; cursor: not-allowed; }
.select {
  appearance: none; -webkit-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b5bac1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
  cursor: pointer;
}
.select option { background: var(--bg-card); color: var(--text-primary); }

.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-right: 44px; }
.input-group .input.has-prefix { padding-left: 28px; }
.input-prefix {
  position: absolute; left: 12px; color: var(--text-subtle); pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.input-suffix {
  position: absolute; right: 12px; color: var(--text-subtle); pointer-events: none;
  font-size: var(--text-sm);
}
.input-affix-btn {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 32px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-muted);
  display: grid; place-items: center; cursor: pointer;
}
.input-affix-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.input-affix-btn .icon { width: 17px; height: 17px; }

/* Checkbox */
.check {
  display: flex; align-items: flex-start; gap: var(--space-3);
  color: var(--text-default); font-size: var(--text-base); line-height: 1.5; cursor: pointer;
}
.check input {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 18px; height: 18px; margin: 2px 0 0;
  border: 1.5px solid #6d717b; border-radius: 5px; background: var(--bg-input);
  display: grid; place-items: center; cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.check input::after {
  content: ""; width: 10px; height: 6px; margin-top: -2px;
  border-left: 2px solid #fff; border-bottom: 2px solid #fff;
  transform: rotate(-45deg) scale(0); transition: transform var(--dur-fast) var(--ease);
}
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after { transform: rotate(-45deg) scale(1); }
.check input:focus-visible { box-shadow: var(--focus-ring); border-radius: 5px; }
.check input[aria-invalid="true"] { border-color: var(--danger); }

/* Segmented control (radio group styled as segments; native arrow-key behaviour) */
.segmented {
  display: inline-flex; padding: 3px; gap: 3px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: calc(var(--radius-input) + 3px);
  max-width: 100%;
}
.segmented label {
  position: relative; flex: 1 1 0; min-width: 0;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 var(--space-4);
  border-radius: var(--radius-input);
  color: var(--text-muted); font-weight: 550; font-size: var(--text-sm);
  cursor: pointer; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.segmented label:hover { color: var(--text-primary); background: var(--bg-hover); }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--bg-active); color: var(--text-primary); box-shadow: 0 1px 2px rgba(0,0,0,0.3); }
.segmented label:has(input:focus-visible) { box-shadow: var(--focus-ring); }
.segmented label:has(input:disabled) { opacity: 0.45; cursor: not-allowed; }
.segmented label:has(input:disabled):hover { background: transparent; color: var(--text-muted); }
.segmented.block { display: flex; width: 100%; }

/* Password strength meter */
.strength { display: flex; flex-direction: column; gap: 6px; }
.strength-bars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.strength-bars span { height: 4px; border-radius: 2px; background: var(--bg-active); transition: background var(--dur) var(--ease); }
.strength[data-score="1"] .strength-bars span:nth-child(-n+1) { background: var(--danger); }
.strength[data-score="2"] .strength-bars span:nth-child(-n+2) { background: var(--warning); }
.strength[data-score="3"] .strength-bars span:nth-child(-n+3) { background: #7ccf5c; }
.strength[data-score="4"] .strength-bars span { background: var(--success); }
.strength-label { display: flex; justify-content: space-between; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-subtle); }
.strength-label b { font-weight: 600; color: var(--text-muted); }
.strength[data-score="1"] .strength-label b { color: var(--danger-text); }
.strength[data-score="2"] .strength-label b { color: var(--warning-text); }
.strength[data-score="3"] .strength-label b,
.strength[data-score="4"] .strength-label b { color: var(--success-text); }

/* ---- Alerts / callouts ------------------------------------------------------ */
.alert {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-input);
  border: 1px solid transparent;
  font-size: var(--text-base); line-height: 1.5;
  color: var(--text-default);
}
.alert > .icon { margin-top: 1px; }
.alert-body { flex: 1; min-width: 0; }
.alert-body > strong { display: block; margin-bottom: 2px; }
.alert-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-2); }
.alert-error   { background: var(--danger-soft);  border-color: rgba(242, 63, 67, 0.3); }
.alert-error > .icon { color: var(--danger-text); }
.alert-success { background: var(--success-soft); border-color: rgba(35, 165, 89, 0.3); }
.alert-success > .icon { color: var(--success-text); }
.alert-warning { background: var(--warning-soft); border-color: rgba(240, 177, 50, 0.3); }
.alert-warning > .icon { color: var(--warning-text); }
.alert-info    { background: var(--info-soft);    border-color: rgba(0, 168, 252, 0.28); }
.alert-info > .icon { color: var(--info-text); }
.alert-accent  { background: var(--accent-soft);  border-color: rgba(88, 101, 242, 0.35); }
.alert-accent > .icon { color: var(--accent-text); }

/* ---- Badges / pills --------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-sm); font-weight: 600; line-height: 1;
  background: var(--neutral-soft); color: var(--text-muted);
  white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.badge-neutral { background: var(--neutral-soft); color: var(--text-muted); }
.badge-info    { background: var(--info-soft);    color: var(--info-text); }
.badge-success { background: var(--success-soft); color: var(--success-text); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger-text); }
.badge-warning { background: var(--warning-soft); color: var(--warning-text); }
.badge-accent  { background: var(--accent-soft);  color: var(--accent-text); }
.badge-sm { height: 20px; padding: 0 8px; font-size: var(--text-xs); }
.badge .dot.pulse { box-shadow: 0 0 0 0 currentColor; animation: fp-pulse 2s var(--ease) infinite; }
@keyframes fp-pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); }
  70%  { box-shadow: 0 0 0 6px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) { .badge .dot.pulse { animation: none; } }

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  height: 22px; padding: 0 8px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs); font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  white-space: nowrap;
}
.pill-buy  { background: var(--success-soft); color: var(--success-text); }
.pill-sell { background: var(--danger-soft);  color: var(--danger-text); }
.pill-hold { background: var(--neutral-soft); color: var(--text-muted); }
.pill-stop { background: var(--warning-soft); color: var(--warning-text); }

/* ---- Toasts ----------------------------------------------------------------- */
.toasts {
  position: fixed; z-index: 900;
  right: var(--space-5); bottom: var(--space-5);
  display: flex; flex-direction: column-reverse; gap: var(--space-2);
  width: min(380px, calc(100vw - 2 * var(--space-4)));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  background: #313338;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-pop);
  color: var(--text-primary); font-size: var(--text-base);
  animation: fp-toast-in var(--dur-slow) var(--ease);
}
.toast.leaving { animation: fp-toast-out var(--dur) var(--ease) forwards; }
.toast > .icon { margin-top: 1px; }
.toast-success > .icon { color: var(--success-text); }
.toast-error > .icon   { color: var(--danger-text); }
.toast-warning > .icon { color: var(--warning-text); }
.toast-info > .icon    { color: var(--accent-text); }
.toast-body { flex: 1; min-width: 0; line-height: 1.45; overflow-wrap: anywhere; }
.toast-body small { display: block; color: var(--text-muted); font-size: var(--text-sm); margin-top: 2px; }
.toast-action {
  border: 0; background: transparent; color: var(--accent-text); font-weight: 600; cursor: pointer;
  padding: 2px 6px; border-radius: var(--radius-sm);
}
.toast-action:hover { background: var(--bg-hover); }
.toast-close {
  border: 0; background: transparent; color: var(--text-subtle); cursor: pointer;
  width: 24px; height: 24px; border-radius: var(--radius-sm); display: grid; place-items: center; flex: none;
}
.toast-close:hover { color: var(--text-primary); background: var(--bg-hover); }
.toast-close .icon { width: 14px; height: 14px; }
@keyframes fp-toast-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes fp-toast-out { to { opacity: 0; transform: translateY(6px); } }

/* ---- Dialog ----------------------------------------------------------------- */
dialog.dialog {
  width: min(480px, calc(100vw - 2 * var(--space-4)));
  max-height: calc(100dvh - 2 * var(--space-6));
  padding: 0; margin: auto;
  background: var(--bg-card); color: var(--text-default);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  overflow: auto;
}
dialog.dialog[open] { animation: fp-dialog-in var(--dur-slow) var(--ease); }
dialog.dialog::backdrop { background: rgba(8, 9, 11, 0.66); backdrop-filter: blur(2px); }
.dialog-inner { padding: var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); }
.dialog-head { display: flex; gap: var(--space-3); align-items: flex-start; }
.dialog-head .dialog-icon {
  width: 40px; height: 40px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-text);
}
.dialog-head .dialog-icon.danger { background: var(--danger-soft); color: var(--danger-text); }
.dialog-head h2 { font-size: var(--text-lg); }
.dialog-head p { color: var(--text-muted); margin-top: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap; margin-top: var(--space-2); }
@keyframes fp-dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---- Misc ------------------------------------------------------------------- */
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.pos { color: var(--success-text); }
.neg { color: var(--danger-text); }
.small { font-size: var(--text-sm); }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.divider { height: 1px; background: var(--line); border: 0; margin: var(--space-4) 0; }
.kbd {
  display: inline-block; padding: 1px 6px; border-radius: 4px;
  background: var(--bg-input); border: 1px solid var(--border-soft);
  font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text-muted);
}
.link-button {
  border: 0; background: none; padding: 0; color: var(--text-link); cursor: pointer; font: inherit;
}
.link-button:hover { text-decoration: underline; }
.link-button:disabled { color: var(--text-subtle); cursor: default; text-decoration: none; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-active); border-radius: 8px; border: 2px solid var(--bg-deepest); }
::-webkit-scrollbar-thumb:hover { background: #50535b; }
