/* ============================================================================
   Component library (BUILD_PLAN §2.4)
   ========================================================================== */

/* Alpine: hide x-cloak elements until Alpine initializes (prevents FOUC). */
[x-cloak] { display: none !important; }

/* ---------------------------- buttons ---------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: 38px; padding: 0 var(--space-4); border-radius: var(--r-sm);
  font-size: var(--fs-sm); font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border);
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
}
.btn:hover { background: var(--surface-2); border-color: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; }
.btn-sm { height: 30px; padding: 0 var(--space-3); font-size: var(--fs-xs); }
.btn-lg { height: 44px; padding: 0 var(--space-5); font-size: var(--fs-base); }
.btn-icon { width: 38px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn-primary { background: var(--primary); border-color: transparent; color: #04140d;
  box-shadow: 0 1px 0 rgba(255,255,255,.2) inset, 0 6px 16px rgba(16,185,129,.28); }
.btn-primary:hover { background: var(--primary-strong); }
.btn-danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-outline { background: transparent; }
.btn:disabled { opacity: .5; pointer-events: none; }

/* ---------------------------- cards ---------------------------- */
.card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-1);
}
.card-pad { padding: var(--space-5); }
.card-head { display: flex; flex-wrap: wrap; 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-head h3 { font-size: var(--fs-base); font-weight: 650; }
.card-body { padding: var(--space-5); }
.card-hover { transition: border-color var(--t-med), transform var(--t-med), box-shadow var(--t-med); }
.card-hover:hover { border-color: var(--surface-3); transform: translateY(-2px); box-shadow: var(--shadow-2); }

/* ---------------------------- stat card ---------------------------- */
.stat {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--space-4) var(--space-5); position: relative; overflow: hidden;
}
.stat::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); opacity: .0; transition: opacity var(--t-med); }
.stat:hover::before { opacity: .8; }
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-label { color: var(--text-dim); font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat-ico { width: 34px; height: 34px; border-radius: var(--r-sm); display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); }
.stat-ico svg { width: 18px; height: 18px; }
.stat-val { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: var(--space-2); line-height: 1; }
.stat-foot { display: flex; align-items: center; gap: var(--space-2); margin-top: var(--space-2); font-size: var(--fs-xs); color: var(--text-mute); }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; padding: 1px 6px; border-radius: var(--r-full); }
.delta.up { color: var(--success); background: var(--success-soft); }
.delta.down { color: var(--danger); background: var(--danger-soft); }
.delta svg { width: 12px; height: 12px; }
.spark { height: 30px; width: 84px; }

/* ---------------------------- badges / pills ---------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px;
  font-size: var(--fs-xs); font-weight: 600; border-radius: var(--r-full);
  background: var(--surface-3); color: var(--text-dim); border: 1px solid var(--border);
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; }
.badge-primary { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge-vip { background: var(--vip-soft); color: var(--vip); border-color: transparent; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-mute { background: var(--surface-3); color: var(--text-mute); }

.health-dot { width: 9px; height: 9px; border-radius: 999px; position: relative; }
.health-dot.online { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.health-dot.offline { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.health-dot.warn { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }
.health-dot.online::after { content: ''; position: absolute; inset: -3px; border-radius: 999px; border: 1px solid var(--success); opacity: .5; animation: ping 2s var(--ease) infinite; }
@keyframes ping { 0% { transform: scale(.9); opacity: .6; } 100% { transform: scale(2.2); opacity: 0; } }

/* ---------------------------- progress / load bars ---------------------------- */
.bar { height: 8px; border-radius: 999px; background: var(--surface-inset); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: var(--primary); transition: width var(--t-med) var(--ease); }
.bar.warn > span { background: var(--warning); }
.bar.danger > span { background: var(--danger); }
.segbar { display: flex; gap: 3px; }
.segbar i { flex: 1; height: 8px; border-radius: 2px; background: var(--surface-inset); }
.segbar i.on { background: var(--success); }
.segbar i.on.warn { background: var(--warning); }
.segbar i.on.danger { background: var(--danger); }

/* ---------------------------- tables ---------------------------- */
.table-wrap { overflow-x: auto; border-radius: var(--r-lg); border: 1px solid var(--border); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); background: var(--surface-2); }
table.data thead th {
  position: sticky; top: 0; z-index: 2; text-align: left; font-weight: 600; color: var(--text-dim);
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em;
  padding: var(--space-3) var(--space-4); background: var(--surface-1); border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.data thead th.sortable { cursor: pointer; user-select: none; }
table.data thead th.sortable:hover { color: var(--text); }
table.data tbody td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table.data tbody tr { transition: background var(--t-fast); }
table.data tbody tr:hover { background: var(--surface-3); }
table.data tbody tr:last-child td { border-bottom: 0; }
.cell-id { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-dim); }
.row-actions { display: flex; gap: var(--space-1); justify-content: flex-end; opacity: .5; transition: opacity var(--t-fast); }
tr:hover .row-actions { opacity: 1; }

/* avatar */
.avatar { width: 32px; height: 32px; border-radius: var(--r-full); display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--primary)); color: #fff; font-weight: 700; font-size: var(--fs-xs); flex-shrink: 0; }
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }

/* ---------------------------- forms ---------------------------- */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field > label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-dim); }
.field .hint { font-size: var(--fs-xs); color: var(--text-mute); }
.input, .select, textarea.input {
  height: 38px; padding: 0 var(--space-3); width: 100%;
  background: var(--surface-inset); border: 1px solid var(--border); border-radius: var(--r-sm);
  color: var(--text); transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
textarea.input { height: auto; padding: var(--space-3); min-height: 90px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, textarea.input:focus { border-color: var(--primary); box-shadow: var(--ring); outline: none; }
.select { appearance: none; 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='%239aa9c2' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }
.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-mute); }
.input-icon .input { padding-left: 34px; }

/* toggle */
.toggle { position: relative; width: 40px; height: 22px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border); transition: background var(--t-fast); flex-shrink: 0; }
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 999px; background: var(--text-dim); transition: transform var(--t-fast), background var(--t-fast); }
.toggle[aria-checked="true"], .toggle.on { background: var(--primary); border-color: transparent; }
.toggle[aria-checked="true"]::after, .toggle.on::after { transform: translateX(18px); background: #fff; }

/* segmented control */
.segmented { display: inline-flex; flex-wrap: wrap; padding: 3px; background: var(--surface-inset); border-radius: var(--r-sm); border: 1px solid var(--border); gap: 2px; }
.segmented button, .segmented a { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 30px; padding: 0 var(--space-3); border-radius: 6px; font-size: var(--fs-xs); font-weight: 600; color: var(--text-dim); text-decoration: none; white-space: nowrap; transition: background var(--t-fast), color var(--t-fast); }
.segmented button:hover, .segmented a:hover { color: var(--text); }
.segmented button.active, .segmented a.active { background: var(--surface-2); color: var(--text); box-shadow: var(--shadow-1); }
.segmented svg { width: 15px; height: 15px; }

/* filter bar / chips */
.filter-bar { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 10px; border-radius: var(--r-full);
  background: var(--surface-2); border: 1px solid var(--border); font-size: var(--fs-xs); font-weight: 600; color: var(--text-dim); }
.chip.active { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* ---------------------------- overlays ---------------------------- */
.scrim { position: fixed; inset: 0; background: var(--scrim); backdrop-filter: blur(3px); z-index: 60; }
.modal { position: fixed; z-index: 61; inset: 0; display: grid; place-items: center; padding: var(--space-4); }
.modal-card { width: min(520px, 100%); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-2); overflow: hidden; }
.drawer { position: fixed; z-index: 61; top: 0; right: 0; height: 100%; width: min(560px, 100%); background: var(--surface-2); border-left: 1px solid var(--border); box-shadow: var(--shadow-2); display: flex; flex-direction: column; }
.drawer-head, .modal-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.drawer-body { padding: var(--space-5); overflow-y: auto; flex: 1; }
.drawer-foot, .modal-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); }

/* dropdown menu */
.menu { min-width: 180px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-2); padding: var(--space-1); }
.menu a, .menu button { display: flex; align-items: center; gap: var(--space-2); width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px; font-size: var(--fs-sm); color: var(--text-dim); }
.menu a:hover, .menu button:hover { background: var(--surface-3); color: var(--text); }
.menu a svg, .menu button svg { width: 15px; height: 15px; }
.menu .danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: var(--space-1) 0; }

/* notification dropdown */
.notif-menu .notif-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.notif-menu .notif-clearall { width: auto; padding: 3px 8px; font-size: 11px; font-weight: 700; color: var(--primary); text-transform: none; letter-spacing: normal; }
.notif-menu .notif-clearall:hover { background: var(--surface-3); }
.notif-row { display: flex; align-items: stretch; gap: 2px; }
.notif-row .notif-row-link { flex: 1; min-width: 0; }
.notif-row-link span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif-menu .notif-clear { width: 28px; flex-shrink: 0; padding: 0; justify-content: center; opacity: .55; }
.notif-menu .notif-clear:hover { opacity: 1; }
.notif-clear svg { width: 13px; height: 13px; }
.notif-empty { padding: 18px 10px; text-align: center; }
.notif-menu .notif-viewall { justify-content: center; font-weight: 600; color: var(--primary); border-top: 1px solid var(--border); margin-top: 4px; padding-top: 10px; }

/* tooltip (pure CSS, shows attr(data-tip) on hover/focus, above the trigger) */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; left: 50%; bottom: calc(100% + 7px); transform: translateX(-50%) translateY(2px);
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
  font-size: var(--fs-xs); font-weight: 500; white-space: nowrap; padding: 5px 9px;
  border-radius: var(--r-sm); box-shadow: var(--shadow-2); pointer-events: none;
  opacity: 0; visibility: hidden; transition: opacity var(--t-fast), transform var(--t-fast);
  z-index: 75;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }
@media (max-width: 767px) { [data-tip]::after { display: none; } }

/* toast */
.toast-stack { position: fixed; bottom: var(--space-5); right: var(--space-5); z-index: 80; display: flex; flex-direction: column; gap: var(--space-2); }
.toast { display: flex; align-items: center; gap: var(--space-2); padding: 10px 14px; border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--border); box-shadow: var(--shadow-2); font-size: var(--fs-sm); }
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--info); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ---------------------------- empty / states ---------------------------- */
.empty { display: grid; place-items: center; text-align: center; padding: var(--space-9) var(--space-5); color: var(--text-mute); gap: var(--space-3); }
.empty svg { width: 40px; height: 40px; opacity: .5; }
.empty h3 { color: var(--text-dim); }

/* banner */
.banner { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--r-md); font-size: var(--fs-sm); }
.banner-info { background: var(--info-soft); color: var(--info); }
.banner-warn { background: var(--warning-soft); color: var(--warning); }
.banner svg { width: 18px; height: 18px; }
.banner-close { flex-shrink: 0; width: 26px; height: 26px; border-radius: var(--r-sm); display: grid; place-items: center; color: inherit; opacity: .7; }
.banner-close:hover { opacity: 1; background: rgba(0, 0, 0, .08); }
.banner-close svg { width: 15px; height: 15px; }

/* key-value */
.kv { display: grid; grid-template-columns: 130px 1fr; gap: var(--space-2) var(--space-4); font-size: var(--fs-sm); }
.kv dt { color: var(--text-mute); }
.kv dd { color: var(--text); font-weight: 500; }

/* tabs */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--border); }
.tabs button { padding: 10px var(--space-3); font-size: var(--fs-sm); font-weight: 600; color: var(--text-dim); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--primary); }

/* timeline */
.timeline { position: relative; padding-left: var(--space-6); }
.timeline::before { content: ''; position: absolute; left: 7px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.tl-item { position: relative; padding-bottom: var(--space-4); }
.tl-item::before { content: ''; position: absolute; left: -22px; top: 4px; width: 10px; height: 10px; border-radius: 999px; background: var(--surface-1); border: 2px solid var(--primary); }
