/* ==========================================================================
   PERUN — Components
   ========================================================================== */

/* ---- Rail nav ----------------------------------------------------------- */
.rail-logo {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  margin-bottom: 14px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  box-shadow: var(--sh-glow);
  color: var(--text-on-brand);
}
.rail-logo svg { width: 22px; height: 22px; }
.rail-spacer { flex: 1; }

.nav-btn {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  position: relative;
  border-radius: var(--r-md);
  color: var(--text-2);
  transition: color var(--dur-1), background var(--dur-1), transform var(--dur-1);
}
.nav-btn svg { width: 21px; height: 21px; }
.nav-btn:hover { color: var(--text-0); background: var(--bg-2); }
.nav-btn.active { color: var(--brand); background: var(--brand-soft); }
.nav-btn.active::before {
  content: ""; position: absolute; left: -14px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 22px; border-radius: var(--r-full);
  background: var(--brand); box-shadow: 0 0 12px var(--brand-glow);
}
.nav-btn .tip {
  position: absolute; left: calc(100% + 12px); top: 50%;
  transform: translateY(-50%) translateX(-4px);
  padding: 5px 10px; border-radius: var(--r-sm);
  background: var(--bg-3); color: var(--text-0);
  font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
  opacity: 0; pointer-events: none;
  box-shadow: var(--sh-md);
  transition: opacity var(--dur-1), transform var(--dur-1);
  z-index: 40;
}
.nav-btn:hover .tip { opacity: 1; transform: translateY(-50%) translateX(0); }
@media (max-width: 720px) {
  .nav-btn.active::before { left: 50%; top: -6px; transform: translateX(-50%); width: 20px; height: 3px; }
  .nav-btn .tip { display: none; }
}

/* ---- Topbar ------------------------------------------------------------- */
.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  z-index: 15;
}
.topbar .crumb { font-weight: 680; font-size: var(--fs-lg); letter-spacing: -0.01em; }
.topbar .spacer { flex: 1; }

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px;
  border-radius: var(--r-sm);
  font-size: var(--fs-sm); font-weight: 640;
  color: var(--text-0);
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  transition: background var(--dur-1), border-color var(--dur-1), transform var(--dur-1), box-shadow var(--dur-1);
  white-space: nowrap; user-select: none;
}
.btn:hover { background: var(--bg-3); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn.sm { height: 30px; padding: 0 11px; font-size: var(--fs-xs); }
.btn.lg { height: 46px; padding: 0 22px; font-size: var(--fs-md); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.45; pointer-events: none; }

.btn.primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  border-color: transparent; color: var(--text-on-brand);
  box-shadow: 0 6px 18px -6px var(--brand-glow);
}
.btn.primary:hover { box-shadow: 0 8px 26px -6px var(--brand-glow); filter: brightness(1.06); }
.btn.up { background: var(--up); border-color: transparent; color: white; }
.btn.up:hover { background: var(--up-strong); }
.btn.down { background: var(--down); border-color: transparent; color: white; }
.btn.down:hover { background: var(--down-strong); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-1); }
.btn.ghost:hover { background: var(--bg-2); color: var(--text-0); }
.btn.outline { background: transparent; }

.icon-btn {
  width: 38px; height: 38px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  color: var(--text-1);
  border: 1px solid var(--line);
  transition: background var(--dur-1), color var(--dur-1);
}
.icon-btn:hover { background: var(--bg-2); color: var(--text-0); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.bare { border-color: transparent; }

/* ---- Cards / panels ----------------------------------------------------- */
.card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
}
.card.pad { padding: 18px; }
.card.glass {
  background: var(--glass);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-color: var(--glass-brdr);
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 15px 18px; border-bottom: 1px solid var(--line);
}
.card-head .h3 { flex: 1; }

.grid { display: grid; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; }
.wrap { flex-wrap: wrap; }
.gap-sm { gap: 8px; } .gap-lg { gap: 20px; }
.between { justify-content: space-between; }
.center { align-items: center; justify-content: center; }

/* ---- Stat tiles --------------------------------------------------------- */
.stat {
  padding: 16px 18px;
  border-radius: var(--r-lg);
  background: var(--bg-1);
  border: 1px solid var(--line);
  position: relative; overflow: hidden;
}
.stat .k { font-size: var(--fs-2xs); font-weight: 620; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); }
.stat .v { font-size: var(--fs-2xl); font-weight: 720; letter-spacing: -0.02em; margin-top: 6px; }
.stat .sub { font-size: var(--fs-xs); color: var(--text-2); margin-top: 3px; }
.stat .spark-line { position: absolute; right: 0; bottom: 0; opacity: 0.5; }

/* ---- Badges / pills ----------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px;
  border-radius: var(--r-full);
  font-size: var(--fs-2xs); font-weight: 660; letter-spacing: 0.02em;
  background: var(--bg-3); color: var(--text-1);
}
.badge.up { background: var(--up-soft); color: var(--up); }
.badge.down { background: var(--down-soft); color: var(--down); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }
.badge.spark { background: var(--spark-soft); color: var(--spark); }
.badge .dot { width: 6px; height: 6px; border-radius: var(--r-full); background: currentColor; }
.badge .dot.live { animation: pulse 1.6s var(--ease-in-out) infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px; padding: 0 12px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 600;
  background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text-1);
  transition: all var(--dur-1);
}
.chip:hover { color: var(--text-0); border-color: var(--line-strong); }
.chip.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }

/* ---- Inputs ------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > .lbl { font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); }
.input, .select {
  height: 40px; padding: 0 13px;
  border-radius: var(--r-sm);
  background: var(--bg-inset);
  border: 1px solid var(--line-strong);
  color: var(--text-0); font-size: var(--fs-md);
  transition: border-color var(--dur-1), box-shadow var(--dur-1);
  width: 100%;
}
.input:focus, .select:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.input::placeholder { color: var(--text-3); }
textarea.input { height: auto; padding: 11px 13px; resize: vertical; line-height: 1.5; }
.input.mono { font-family: var(--font-mono); }
.input-group { position: relative; display: flex; align-items: center; }
.input-group .suffix { position: absolute; right: 12px; color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; pointer-events: none; }
.input-group .input { padding-right: 52px; }

/* Segmented control */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--bg-inset); border-radius: var(--r-sm); border: 1px solid var(--line); }
.seg button {
  height: 30px; padding: 0 13px; border-radius: var(--r-xs);
  font-size: var(--fs-xs); font-weight: 640; color: var(--text-2);
  transition: all var(--dur-1);
}
.seg button:hover { color: var(--text-0); }
.seg button.active { background: var(--bg-3); color: var(--text-0); box-shadow: var(--sh-sm); }
.seg.up button.active { color: var(--up); }
.seg.down button.active { color: var(--down); }

/* Toggle */
.toggle { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.toggle input { position: absolute; opacity: 0; }
.toggle .track {
  position: absolute; inset: 0; border-radius: var(--r-full);
  background: var(--bg-3); transition: background var(--dur-2);
}
.toggle .track::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: var(--r-full);
  background: white; box-shadow: var(--sh-sm);
  transition: transform var(--dur-2) var(--ease);
}
.toggle input:checked + .track { background: var(--brand); }
.toggle input:checked + .track::after { transform: translateX(18px); }

/* Range slider */
.range { -webkit-appearance: none; appearance: none; width: 100%; height: 5px; border-radius: var(--r-full); background: var(--bg-3); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: var(--r-full);
  background: var(--brand); cursor: pointer; box-shadow: 0 0 0 4px var(--brand-soft), var(--sh-sm);
  transition: box-shadow var(--dur-1);
}
.range::-webkit-slider-thumb:hover { box-shadow: 0 0 0 6px var(--brand-soft), var(--sh-sm); }

/* ---- Tables ------------------------------------------------------------- */
.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.tbl th {
  text-align: left; font-size: var(--fs-2xs); font-weight: 620; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-2);
  padding: 9px 12px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--bg-1); z-index: 1;
}
.tbl th.num, .tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line); }
.tbl tbody tr { transition: background var(--dur-1); }
.tbl tbody tr:hover { background: var(--bg-2); }
.tbl tbody tr:last-child td { border-bottom: none; }

/* ---- Progress / meters -------------------------------------------------- */
.meter { height: 6px; border-radius: var(--r-full); background: var(--bg-3); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: var(--r-full); background: var(--brand); transition: width var(--dur-3) var(--ease); }
.meter.up > i { background: var(--up); }
.meter.down > i { background: var(--down); }

/* ---- Tooltip helper ----------------------------------------------------- */
[data-tip] { position: relative; }

/* ---- Empty state -------------------------------------------------------- */
.empty { text-align: center; padding: 52px 20px; color: var(--text-2); }
.empty .ico { width: 52px; height: 52px; margin: 0 auto 14px; color: var(--text-3); }
.empty .h3 { color: var(--text-1); margin-bottom: 6px; }

/* ---- Modal / sheet ------------------------------------------------------ */
.scrim {
  position: fixed; inset: 0; z-index: 100;
  background: hsl(240 40% 3% / 0.6);
  backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 20px;
  animation: fade-up var(--dur-2) var(--ease);
}
.modal {
  width: min(560px, 100%); max-height: 88vh; overflow-y: auto;
  background: var(--bg-1); border: 1px solid var(--glass-brdr-strong);
  border-radius: var(--r-xl); box-shadow: var(--sh-lg);
  animation: fade-up var(--dur-3) var(--ease);
}
.modal.wide { width: min(920px, 100%); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.modal-head .h2 { flex: 1; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 22px; border-top: 1px solid var(--line); }

/* ---- Toast -------------------------------------------------------------- */
.toasts { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
  display: flex; align-items: center; gap: 11px;
  min-width: 260px; max-width: 380px; padding: 13px 15px;
  background: var(--bg-2); border: 1px solid var(--line-strong);
  border-radius: var(--r-md); box-shadow: var(--sh-lg);
  animation: fade-up var(--dur-3) var(--ease);
}
.toast .ico { width: 20px; height: 20px; flex-shrink: 0; }
.toast.ok .ico { color: var(--up); } .toast.err .ico { color: var(--down); }
.toast.warn .ico { color: var(--warn); } .toast.info .ico { color: var(--spark); }
.toast .msg { font-size: var(--fs-sm); flex: 1; }
@media (max-width: 720px) { .toasts { left: 14px; right: 14px; bottom: 84px; } .toast { max-width: none; } }

/* ---- Tabs --------------------------------------------------------------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); }
.tabs button {
  padding: 11px 15px; font-size: var(--fs-sm); font-weight: 620; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color var(--dur-1);
}
.tabs button:hover { color: var(--text-0); }
.tabs button.active { color: var(--text-0); border-bottom-color: var(--brand); }

/* ---- Divider ------------------------------------------------------------ */
.hr { height: 1px; background: var(--line); border: none; margin: 4px 0; }
.vr { width: 1px; align-self: stretch; background: var(--line); }
