/* ============================================================
   BitTool.ai — Base styles & shared components
   ============================================================ */

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv05' 1, 'cv11' 1, 'ss01' 1;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

::selection { background: var(--selection); }

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; line-height: 1.25; letter-spacing: -0.015em; }
p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: inherit; }
code, kbd, pre { font-family: var(--font-mono); }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

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

/* ---------- Scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--scrollbar-thumb) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }

/* ---------- Utilities ---------- */
.mono { font-family: var(--font-mono); font-size: 0.92em; }
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.truncate { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.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;
}
.nowrap { white-space: nowrap; }

/* ---------- Logo lockup ---------- */
.logo {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  text-decoration: none !important;
  user-select: none;
}
.logo img, .logo svg { width: 27px; height: 27px; flex: none; }
.logo .logo-word {
  font-size: 1.0625rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1;
}
.logo .logo-word em { font-style: normal; color: var(--text-3); font-weight: 550; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: var(--text-base);
  font-weight: 550;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  text-decoration: none !important;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:active { transform: scale(0.985); }
.btn:disabled, .btn[aria-disabled='true'] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn svg { width: 16px; height: 16px; flex: none; }

.btn-primary { background: var(--text); color: var(--bg); }
.btn-primary:hover { opacity: 0.88; }

.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-accent:active { background: var(--accent-active); }

.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }

.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-danger-soft:hover { background: var(--danger); color: #fff; }

.btn-lg { height: 44px; padding: 0 22px; font-size: var(--text-md); border-radius: var(--radius-md); }
.btn-sm { height: 30px; padding: 0 10px; font-size: var(--text-sm); border-radius: var(--radius-xs); }
.btn-block { width: 100%; }

.btn-icon {
  width: 32px; height: 32px; padding: 0;
  border-radius: var(--radius-sm);
  background: transparent; border: none;
  color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon svg { width: 17px; height: 17px; }

.btn.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 15px; height: 15px;
  border: 2px solid currentColor;
  border-color: var(--text-3) var(--text-3) transparent transparent;
  border-radius: 50%;
  animation: bt-spin 0.7s linear infinite;
}
.btn-primary.is-loading::after, .btn-accent.is-loading::after, .btn-danger.is-loading::after {
  border-color: rgba(255,255,255,0.8) rgba(255,255,255,0.8) transparent transparent;
}

@keyframes bt-spin { to { transform: rotate(360deg); } }

/* ---------- Spinner ---------- */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: bt-spin 0.7s linear infinite;
}
.spinner-lg { width: 24px; height: 24px; border-width: 2.5px; }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: var(--text-sm); font-weight: 550; color: var(--text-2); }
.field-hint { font-size: var(--text-xs); color: var(--text-3); }
.field-error { font-size: var(--text-xs); color: var(--danger); }

.input {
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.is-invalid { border-color: var(--danger); }
.input.is-invalid:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.input:disabled { opacity: 0.55; cursor: not-allowed; background: var(--surface-2); }

textarea.input { height: auto; padding: 10px 12px; resize: vertical; min-height: 80px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 550;
  line-height: 1;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.badge-accent { background: var(--accent-soft); color: var(--accent-text); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-outline { background: transparent; border: 1px solid var(--border-strong); }

.status-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.status-dot.running { background: var(--accent); animation: bt-pulse 1.6s var(--ease) infinite; }
.status-dot.waiting { background: var(--warning); animation: bt-pulse 1.6s var(--ease) infinite; }
.status-dot.completed { background: var(--success); }
.status-dot.failed { background: var(--danger); }
.status-dot.cancelled, .status-dot.queued { background: var(--text-3); }

@keyframes bt-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* ---------- Keyboard hint ---------- */
kbd {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--kbd-bg);
  font-size: var(--text-xs);
  line-height: 1.4;
  text-align: center;
  color: var(--text-2);
}

/* ---------- Dividers ---------- */
.divider { height: 1px; background: var(--border); border: none; margin: 0; }

/* ---------- Avatar ---------- */
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--brand-gradient);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: 600;
  flex: none;
  overflow: hidden;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 44px; height: 44px; font-size: var(--text-lg); }

/* ---------- Dropdown menu ---------- */
.menu {
  position: fixed;
  z-index: 1000;
  min-width: 200px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  animation: bt-pop var(--dur-fast) var(--ease);
}
@keyframes bt-pop {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: var(--radius-xs);
  background: none;
  font-size: var(--text-base);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  text-decoration: none !important;
  transition: background-color var(--dur-fast) var(--ease);
}
.menu-item:hover { background: var(--surface-2); }
.menu-item svg { width: 16px; height: 16px; color: var(--text-3); flex: none; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger svg { color: var(--danger); }
.menu-item.danger:hover { background: var(--danger-soft); }
.menu-sep { height: 1px; background: var(--border); margin: 5px 6px; }
.menu-header { padding: 8px 10px 6px; font-size: var(--text-xs); color: var(--text-3); }
.menu-item .check { margin-left: auto; color: var(--accent); }
/* long menus (e.g. 24 dashboard versions) scroll inside the viewport instead of clipping */
.menu { max-height: calc(100vh - 16px); overflow-y: auto; }
.menu-item:focus-visible { outline: 2px solid var(--border-focus); outline-offset: -2px; background: var(--surface-2); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: bt-fade var(--dur) var(--ease);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
@keyframes bt-fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%;
  max-width: 440px;
  max-height: min(85vh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  animation: bt-rise var(--dur) var(--ease);
}
@keyframes bt-rise {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}
.modal-lg { max-width: 620px; }
.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px 0;
}
.modal-title { font-size: var(--text-lg); font-weight: 600; flex: 1; letter-spacing: -0.01em; }
.modal-body { padding: 12px 20px 20px; overflow-y: auto; font-size: var(--text-base); color: var(--text-2); }
.modal-body > * + * { margin-top: 12px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  padding: 0 20px 18px;
}

/* ---------- Toast ---------- */
.toast-region {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: min(92vw, 480px);
  padding: 10px 16px;
  background: var(--text);
  color: var(--bg);
  font-size: var(--text-base);
  font-weight: 500;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: bt-toast-in var(--dur) var(--ease);
}
.toast.leaving { animation: bt-toast-out var(--dur) var(--ease) forwards; }
.toast svg { width: 16px; height: 16px; flex: none; }
.toast.success svg { color: var(--success); }
.toast.error svg { color: var(--danger); }
.toast.warning svg { color: var(--warning); }
@keyframes bt-toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes bt-toast-out {
  from { opacity: 1; transform: none; }
  to { opacity: 0; transform: translateY(8px) scale(0.97); }
}

/* ---------- Skeleton ---------- */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--radius-xs);
  min-height: 12px;
}
.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--surface-3), transparent);
  animation: bt-shimmer 1.4s var(--ease) infinite;
  transform: translateX(-100%);
}
@keyframes bt-shimmer { to { transform: translateX(100%); } }

/* ---------- Segmented control ---------- */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border-radius: var(--radius-md);
}
.seg button {
  border: none;
  background: none;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--text-2);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}
.seg button[aria-pressed='true'] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ---------- Empty state ---------- */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 44px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: var(--text-base);
}
.empty svg { width: 28px; height: 28px; opacity: 0.5; }

/* ---------- Offline banner ---------- */
.net-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1400;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: var(--radius-full);
  background: var(--text);
  color: var(--bg);
  font-size: var(--text-sm);
  font-weight: 550;
  box-shadow: var(--shadow-lg);
  animation: bt-toast-in var(--dur) var(--ease);
}
.net-banner .status-dot { background: var(--warning); }
.net-banner.online .status-dot { background: var(--success); }
