/* ============================================================
   KEUSER INDUSTRIES — shared design system
   Source of truth: ~/keuser-theme/keuser-theme.css
   Reference: trading.keuser.org (/home/claudeuser/ib-paper-bot/dashboard/static/style.css)
   Spec: ~/keuser-theme/README.md

   When updating this file, sync to every consumer:
     ~/keuser-theme/sync.sh
   ============================================================ */

/* -------- color tokens -------- */
:root {
  --bg:        #0d0d0d;
  --surface:   #161616;
  --surface-2: #1f1f1f;
  --border:    #292929;
  --border-2:  #383838;
  --text:      #e8e8e8;
  --text-mid:  #a0a0a0;
  --text-dim:  #666666;

  /* Status colors — use ONLY when semantically meaningful.
     Green = positive/up/active, Red = negative/down/halt,
     Yellow = warning/pending, Purple = signal/AI */
  --green:     #34d399;
  --green-bg:  rgba(52, 211, 153, 0.12);
  --red:       #f87171;
  --red-bg:    rgba(248, 113, 113, 0.12);
  --yellow:    #fbbf24;
  --yellow-bg: rgba(251, 191, 36, 0.12);
  --purple:    #a78bfa;
  --purple-bg: rgba(167, 139, 250, 0.12);

  /* Steel-grey accent — used for primary buttons, focus rings, neutral chrome.
     Avoid bright blues; the palette is greyscale + status. */
  --accent:    #c8c8c8;
  --accent-2:  #888888;

  /* Geometry */
  --radius:    0px;        /* boxes are SQUARE — never rounded */
  --pill:      999px;      /* pills, buttons, dots, progress bars only */
  --grid-gap:  12px;
  --pad:       14px;

  /* Typography */
  --mono:      'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans:      'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --brand:     'Michroma', system-ui, sans-serif;
}

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

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  margin: 0;
  padding: 0;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--text); text-decoration: underline; }

::selection { background: var(--accent); color: var(--bg); }

/* -------- intro splash -------- */
#ki-splash {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  transition: opacity 0.6s ease;
}
#ki-splash.fade-out, #ki-splash.gone { opacity: 0; }
.ki-splash-inner {
  text-align: center;
  opacity: 0;
  animation: ki-splash-in 1.6s ease forwards;
}
.ki-splash-name {
  font-family: var(--brand);
  font-size: 4rem;
  letter-spacing: 0.4rem;
  color: var(--text);
}
.ki-splash-sub {
  font-family: var(--brand);
  font-size: 1.1rem;
  letter-spacing: 1.2rem;
  margin-top: 0.6rem;
  color: var(--text-mid);
  margin-left: 1.2rem;   /* compensate for letter-spacing */
}
@keyframes ki-splash-in {
  0%   { opacity: 0; transform: scale(0.95); }
  30%  { opacity: 1; transform: scale(1); }
  100% { opacity: 1; }
}

/* -------- top bar -------- */
.ki-topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
  flex-wrap: wrap;
}
.ki-brand { display: flex; align-items: baseline; gap: 6px; }

/* The KEUSER+INDUSTRIES wordmark wrapped as a link back to home.keuser.org.
   Used on every subdomain. Inherits color so the brand colors aren't blue-anchor;
   subtle hover shifts the wordmark to the accent. */
a.ki-brand-home {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
a.ki-brand-home:hover {
  text-decoration: none;
  opacity: 0.92;
}
a.ki-brand-home:hover .ki-brand-name { color: var(--accent); }

.ki-brand-name {
  font-family: var(--brand);
  font-size: 1.1rem;
  letter-spacing: 0.2rem;
  color: var(--text);
  transition: color 0.15s ease;
}
.ki-brand-sub {
  font-family: var(--brand);
  font-size: 0.55rem;
  letter-spacing: 0.4rem;
  color: var(--text-mid);
}
.ki-brand-divider { color: var(--text-dim); margin: 0 4px; }
.ki-brand-app {
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.05rem;
  color: var(--text-mid);
  text-transform: uppercase;
}
.ki-brand-link {
  margin-left: 12px;
  padding: 3px 9px;
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.1rem;
  color: var(--text);
  text-decoration: none;
  border-radius: 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.ki-brand-link:hover { background: var(--accent); color: var(--bg); text-decoration: none; }

.ki-topbar-spacer { margin-left: auto; }

.ki-nav {
  display: flex; gap: 4px;
  font-family: var(--mono);
}
.ki-nav a {
  color: var(--text-mid);
  text-decoration: none;
  padding: 6px 12px;
  font-size: 0.72rem;
  letter-spacing: 0.08rem;
  text-transform: uppercase;
  border: 1px solid transparent;
  border-bottom: 2px solid transparent;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.ki-nav a:hover { color: var(--text); text-decoration: none; }
.ki-nav a.active { color: var(--text); border-bottom-color: var(--accent); }

/* -------- pills + status dots -------- */
.ki-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 10px;
  border: 1px solid var(--border-2);
  background: var(--surface-2);
  border-radius: var(--pill);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.05rem;
  text-transform: uppercase;
  color: var(--text-mid);
}
.ki-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-dim);
  flex: 0 0 auto;
}
.ki-pill.pos     { color: var(--green);  border-color: rgba(52,211,153,0.4);  background: var(--green-bg); }
.ki-pill.pos .dot{ background: var(--green);  box-shadow: 0 0 8px var(--green); }
.ki-pill.neg     { color: var(--red);    border-color: rgba(248,113,113,0.4); background: var(--red-bg); }
.ki-pill.neg .dot{ background: var(--red);    box-shadow: 0 0 8px var(--red); }
.ki-pill.warn    { color: var(--yellow); border-color: rgba(251,191,36,0.4);  background: var(--yellow-bg); }
.ki-pill.warn .dot{ background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
.ki-pill.info    { color: var(--purple); border-color: rgba(167,139,250,0.4); background: var(--purple-bg); }
.ki-pill.info .dot{ background: var(--purple); box-shadow: 0 0 8px var(--purple); }

/* -------- panel -------- */
.ki-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--pad);
  display: flex; flex-direction: column;
  min-width: 0;
}
.ki-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.ki-panel-head h2,
.ki-panel-head h3 {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: 0.18rem;
  font-weight: 600;
  color: var(--text-mid);
  margin: 0;
  text-transform: uppercase;
}

.ki-muted {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.75rem;
}

/* -------- KPI -------- */
.ki-kpi {
  display: flex; flex-direction: column; align-items: flex-start;
  min-width: 90px;
}
.ki-kpi-label {
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.1rem;
  color: var(--text-dim);
  text-transform: uppercase;
}
.ki-kpi-value {
  font-family: var(--mono);
  font-size: 1.05rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
  color: var(--text);
}
.ki-kpi.pos .ki-kpi-value { color: var(--green); }
.ki-kpi.neg .ki-kpi-value { color: var(--red); }

/* -------- buttons -------- */
.ki-btn,
button.ki-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-2);
  padding: 7px 14px;
  font: inherit;
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.08rem;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: var(--pill);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.ki-btn:hover { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.ki-btn.primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 600;
}
.ki-btn.primary:hover { filter: brightness(1.1); }
.ki-btn.danger {
  color: var(--red);
  border-color: rgba(248,113,113,0.4);
}
.ki-btn.danger:hover {
  background: var(--red);
  color: var(--bg);
  border-color: var(--red);
}
.ki-btn.ghost {
  background: transparent;
  color: var(--text-mid);
}
.ki-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* segmented button group (e.g. range pickers) */
.ki-seg {
  display: inline-flex; gap: 4px;
}
.ki-seg button {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border-2);
  border-radius: 0;
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 3px 8px;
  cursor: pointer;
  letter-spacing: 0.05rem;
  text-transform: uppercase;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.ki-seg button:hover  { background: var(--surface-2); color: var(--text); }
.ki-seg button.active { background: var(--surface-2); color: var(--text); border-color: var(--accent); }

/* -------- inputs -------- */
.ki-input,
input[type="text"].ki-input,
input[type="search"].ki-input,
input[type="email"].ki-input,
input[type="number"].ki-input,
input[type="date"].ki-input,
input[type="password"].ki-input,
select.ki-input,
textarea.ki-input {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-2);
  border-radius: 0;
  font-family: var(--sans);
  font-size: 0.85rem;
  padding: 7px 10px;
  outline: none;
  transition: border-color 0.15s ease;
}
.ki-input:focus { border-color: var(--accent); }
.ki-input::placeholder { color: var(--text-dim); }
textarea.ki-input { min-height: 64px; resize: vertical; }

/* -------- tables -------- */
table.ki-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 0.78rem;
}
table.ki-table th {
  text-align: left;
  font-weight: 500;
  letter-spacing: 0.08rem;
  font-size: 0.65rem;
  color: var(--text-dim);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0;
  text-transform: uppercase;
}
table.ki-table th.num,
table.ki-table td.num { text-align: right; }
table.ki-table td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
}
table.ki-table tr:last-child td { border-bottom: none; }
table.ki-table tbody tr:hover td { background: rgba(255,255,255,0.018); }
table.ki-table tr.empty td {
  text-align: center;
  color: var(--text-dim);
  padding: 20px;
  font-style: italic;
}
table.ki-table.compact th,
table.ki-table.compact td { padding: 4px 8px; }
table.ki-table .pos { color: var(--green); }
table.ki-table .neg { color: var(--red); }

/* -------- progress bar -------- */
.ki-bar {
  position: relative;
  height: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
  border-radius: var(--pill);
}
.ki-bar-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: var(--accent);
  transition: width 0.7s cubic-bezier(.25,.8,.25,1), background 0.4s ease;
}
.ki-bar-fill.pos  { background: var(--green); }
.ki-bar-fill.warn { background: var(--yellow); }
.ki-bar-fill.crit { background: var(--red); }

/* -------- footer -------- */
.ki-footer {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  margin-top: 20px;
  border-top: 1px solid var(--border);
  color: var(--text-dim);
}
.ki-footer-name {
  font-family: var(--brand);
  font-size: 0.8rem;
  letter-spacing: 0.2rem;
  color: var(--text-mid);
}
.ki-footer-sub {
  font-family: var(--brand);
  font-size: 0.5rem;
  letter-spacing: 0.4rem;
  color: var(--text-dim);
}
.ki-footer-meta {
  margin-left: 20px;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
}

/* -------- scrollbars -------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* -------- motion -------- */
@keyframes ki-flash-pos {
  0%   { background-color: rgba(52,211,153,0.0); box-shadow: 0 0 0 0 rgba(52,211,153,0); }
  18%  { background-color: rgba(52,211,153,0.22); box-shadow: 0 0 18px 2px rgba(52,211,153,0.25); }
  100% { background-color: rgba(52,211,153,0.0); box-shadow: 0 0 0 0 rgba(52,211,153,0); }
}
@keyframes ki-flash-neg {
  0%   { background-color: rgba(248,113,113,0.0); box-shadow: 0 0 0 0 rgba(248,113,113,0); }
  18%  { background-color: rgba(248,113,113,0.22); box-shadow: 0 0 18px 2px rgba(248,113,113,0.25); }
  100% { background-color: rgba(248,113,113,0.0); box-shadow: 0 0 0 0 rgba(248,113,113,0); }
}
.ki-flash-pos { animation: ki-flash-pos 1.4s ease-out; }
.ki-flash-neg { animation: ki-flash-neg 1.4s ease-out; }

@keyframes ki-dot-pulse-green {
  0%, 100% { box-shadow: 0 0 0 0 rgba(52,211,153,0.5), 0 0 8px var(--green); }
  50%      { box-shadow: 0 0 0 9px rgba(52,211,153,0), 0 0 8px var(--green); }
}
@keyframes ki-dot-pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248,113,113,0.55), 0 0 8px var(--red); }
  50%      { box-shadow: 0 0 0 9px rgba(248,113,113,0), 0 0 8px var(--red); }
}
@keyframes ki-dot-pulse-yellow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251,191,36,0.5), 0 0 8px var(--yellow); }
  50%      { box-shadow: 0 0 0 8px rgba(251,191,36,0), 0 0 8px var(--yellow); }
}
.ki-pill.pos  .dot { animation: ki-dot-pulse-green  2.6s ease-in-out infinite; }
.ki-pill.neg  .dot { animation: ki-dot-pulse-red    1.6s ease-in-out infinite; }
.ki-pill.warn .dot { animation: ki-dot-pulse-yellow 2.0s ease-in-out infinite; }

@keyframes ki-cfin {
  0%   { opacity: 0; transform: translateY(4px); }
  100% { opacity: 1; transform: translateY(0); }
}
.ki-cfin    { animation: ki-cfin 0.55s ease-out both; }
.ki-cfin-1  { animation-delay: 0.05s; }
.ki-cfin-2  { animation-delay: 0.12s; }
.ki-cfin-3  { animation-delay: 0.19s; }
.ki-cfin-4  { animation-delay: 0.26s; }

@keyframes ki-fade-in {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ki-fade-in {
  opacity: 0;
  animation: ki-fade-in 0.7s ease forwards;
}

/* -------- a11y: reduced motion -------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
