/* ==========================================================================
   ClashBot AI — Component library
   Buttons · Cards · Stats · Tables · Forms · Badges · Alerts · Tabs · Misc
   ========================================================================== */

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.5rem 0.9rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--text-invert);
  font: inherit;
  font-weight: var(--weight-medium);
  font-size: var(--text-base);
  line-height: 1.4;
  white-space: nowrap;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--duration) var(--ease),
              border-color var(--duration) var(--ease),
              color var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease),
              transform var(--duration-s) var(--ease);
}

.btn:hover        { background: var(--accent-hover); color: var(--text-invert); text-decoration: none; }
.btn:active       { transform: translateY(1px); }
.btn:disabled,
.btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }

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

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

.btn-success { background: var(--success); }
.btn-success:hover { background: color-mix(in srgb, var(--success) 85%, black); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 85%, black); }

.btn-sm  { padding: 0.3rem 0.65rem; font-size: var(--text-sm); }
.btn-lg  { padding: 0.7rem 1.35rem; font-size: var(--text-md); border-radius: var(--radius-md); }
.btn-block { width: 100%; }

.btn-icon {
  padding: 0.45rem;
  width: 34px; height: 34px;
  border-radius: var(--radius);
}

/* --------------------------------------------------------------------------
   Card
   -------------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}
.card-title { margin: 0; font-size: var(--text-md); font-weight: var(--weight-semi); }
.card-subtitle { margin: 2px 0 0; font-size: var(--text-sm); color: var(--text-muted); }

.card-body   { padding: var(--space-5); }
.card-body-flush { padding: 0; }
.card-footer {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* --------------------------------------------------------------------------
   Stat tile
   -------------------------------------------------------------------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: var(--space-4);
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.stat-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.stat-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}
.stat-delta.up   { color: var(--success); }
.stat-delta.down { color: var(--danger); }
.stat-delta.flat { color: var(--text-muted); }

.stat-icon {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  flex: none;
}

/* --------------------------------------------------------------------------
   Table
   -------------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base);
}

.table th {
  text-align: left;
  font-weight: var(--weight-medium);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: var(--space-3) var(--space-5);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-hover); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------------------
   Activity feed
   A list, not a table — so the message can shrink and ellipsise cleanly
   while the label and timestamp keep their natural width.
   -------------------------------------------------------------------------- */

.feed { list-style: none; margin: 0; padding: 0; }

.feed li {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
  margin: 0;
}
.feed li:last-child { border-bottom: 0; }
.feed li:hover { background: var(--surface-hover); }

.feed .badge { flex: none; }

.feed-msg {
  flex: 1 1 auto;
  min-width: 0;            /* lets the flex item shrink below its content width */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.feed-time {
  flex: none;
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------------------
   Badges & pills
   -------------------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge-success { background: var(--success-bg); color: var(--success); border-color: transparent; }
.badge-warning { background: var(--warning-bg); color: var(--warning); border-color: transparent; }
.badge-danger  { background: var(--danger-bg);  color: var(--danger);  border-color: transparent; }
.badge-info    { background: var(--info-bg);    color: var(--info);    border-color: transparent; }
.badge-accent  { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.dot-pulse { animation: dot-pulse 1.8s var(--ease) infinite; }

@keyframes dot-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.82); }
}

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */

.field { margin-bottom: var(--space-4); }

.label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text);
}

.hint  { margin-top: var(--space-2); font-size: var(--text-xs); color: var(--text-muted); }
.error { margin-top: var(--space-2); font-size: var(--text-xs); color: var(--danger); }

.input, .select, .textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font: inherit;
  font-size: var(--text-base);
  transition: border-color var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease);
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.input::placeholder, .textarea::placeholder { color: var(--text-subtle); }
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--surface-alt);
  color: var(--text-muted);
  cursor: not-allowed;
}

.textarea { min-height: 110px; resize: vertical; font-family: var(--font-mono); }

select, .select {
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  appearance: none !important;
  width: 100%;
  height: 38px;
  line-height: 1.4;
  padding: 6px 36px 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background-color: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 12px center !important;
  background-size: 14px 14px !important;
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  transition: border-color var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease),
              background-color var(--duration) var(--ease);
}

select:hover, .select:hover {
  border-color: var(--accent);
}

select:focus, .select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

select option, .select option {
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
}

.select-sm, select.select-sm {
  height: 28px;
  padding: 2px 26px 2px 10px;
  font-size: var(--text-xs);
  background-position: right 8px center !important;
  background-size: 12px 12px !important;
  border-radius: 6px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
}

/* Switch ------------------------------------------------------------------ */

.switch { display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }

.switch-track {
  width: 38px; height: 22px;
  border-radius: var(--radius-full);
  background: var(--switch-off);
  position: relative;
  flex: none;
  transition: background var(--duration) var(--ease);
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--switch-knob);
  box-shadow: var(--shadow-xs);
  transition: transform var(--duration) var(--ease), background var(--duration) var(--ease);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { background: #fff; }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px var(--focus-ring); }

/* Settings row ------------------------------------------------------------ */

.setting {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-5);
  padding: var(--space-4) 0;
  border-bottom: 1px solid var(--border);
}
.setting:last-child { border-bottom: 0; padding-bottom: 0; }
.setting-text { max-width: 60ch; }
.setting-text strong { display: block; font-weight: var(--weight-medium); }
.setting-text span   { font-size: var(--text-sm); color: var(--text-muted); }
.setting-control { flex: none; min-width: 220px; max-width: 360px; }

/* --------------------------------------------------------------------------
   Alerts
   -------------------------------------------------------------------------- */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: var(--text-base);
  margin-bottom: var(--space-4);
}
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-warning { background: var(--warning-bg); color: var(--warning); }
.alert-danger  { background: var(--danger-bg);  color: var(--danger); }
.alert-info    { background: var(--info-bg);    color: var(--info); }

/* --------------------------------------------------------------------------
   Tabs & segmented control
   -------------------------------------------------------------------------- */

.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-5);
  overflow-x: auto;
}

.tab {
  padding: var(--space-3) var(--space-4);
  border: 0;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-weight: var(--weight-medium);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  transition: color var(--duration) var(--ease), border-color var(--duration) var(--ease);
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

.segmented {
  display: inline-flex;
  padding: 3px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  gap: 2px;
}
.segmented button {
  border: 0; background: none;
  padding: 0.25rem 0.7rem;
  border-radius: var(--radius-sm);
  font: inherit; font-size: var(--text-sm);
  color: var(--text-muted);
  cursor: pointer;
}
.segmented button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }

/* --------------------------------------------------------------------------
   Progress & meters
   -------------------------------------------------------------------------- */

.progress {
  height: 7px;
  background: var(--surface-alt);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
  transition: width 400ms var(--ease);
}
.progress-bar.is-success { background: var(--success); }
.progress-bar.is-warning { background: var(--warning); }
.progress-bar.is-danger  { background: var(--danger); }

/* --------------------------------------------------------------------------
   Log console
   -------------------------------------------------------------------------- */

.console {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: 1.7;
  background: var(--console-bg);
  color: #cbd5e1;
  padding: var(--space-4);
  height: 480px;
  overflow-y: auto;
  border-radius: 0;
}

.log-line { display: flex; gap: var(--space-3); padding: 1px 0; white-space: pre-wrap; word-break: break-word; }
.log-time  { color: #64748b; flex: none; }
.log-level { flex: none; width: 52px; font-weight: var(--weight-semi); }
.log-level.info  { color: #38bdf8; }
.log-level.ok    { color: #4ade80; }
.log-level.warn  { color: #fbbf24; }
.log-level.error { color: #f87171; }
.log-msg { flex: 1 1 auto; }

/* --------------------------------------------------------------------------
   Empty state
   -------------------------------------------------------------------------- */

.empty {
  text-align: center;
  padding: var(--space-12) var(--space-5);
  color: var(--text-muted);
}
.empty-icon {
  width: 46px; height: 46px;
  margin: 0 auto var(--space-4);
  display: grid; place-items: center;
  border-radius: var(--radius-lg);
  background: var(--surface-alt);
  color: var(--text-subtle);
}
.empty h3 { color: var(--text); margin-bottom: var(--space-2); }

/* --------------------------------------------------------------------------
   Avatar
   -------------------------------------------------------------------------- */

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--text-sm);
  font-weight: var(--weight-semi);
  flex: none;
}

/* --------------------------------------------------------------------------
   Access key input
   -------------------------------------------------------------------------- */

.key-input {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  letter-spacing: 0.08em;
  text-align: center;
  text-transform: uppercase;
  padding-block: 0.7rem;
}
.key-input::placeholder {
  letter-spacing: 0.08em;
  text-transform: none;
  color: var(--text-subtle);
}
