/* =================================================================
   components.css — canonical component library.

   Built on design tokens from input.css (:root). Every reusable UI
   primitive lives here so pages compose from a single language.

   Load order on every page:
     1. style.css            (legacy page-specific rules)
     2. components.css       (this file, design system primitives)
     3. tailwind.css         (Tailwind utilities layered on top)

   Newer pages should prefer .surface / .btn / .input primitives over
   legacy classes. The legacy classes still work and can co-exist.
   ================================================================= */


/* =========== Element resets ============================
   Tailwind's preflight is disabled (see tailwind.config.js), so the browser
   default button chrome — light grey/white background, 1px outset border,
   system font — leaks through on every <button> that doesn't explicitly set
   its own background. Rather than sprinkle `bg-transparent` across every
   call site, normalize here. Named classes (.btn, .btn-logout, .notif-bell,
   .login-btn, etc.) override by higher specificity. */
button {
    background: transparent;
    border: 0;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    cursor: pointer;
}

/* =========== Surfaces =================================== */

.surface {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.surface-elevated {
    background: var(--bg-elevated);
    box-shadow: var(--shadow-md);
}

.surface-secondary {
    background: var(--bg-secondary);
}

@media (hover: hover) {
    .surface-hover:hover {
        border-color: var(--border-light);
        box-shadow: var(--shadow);
        transform: translateY(-2px);
    }
}

.surface-row {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-3) var(--space-4);
    transition: background var(--transition), border-color var(--transition);
}

.surface-row-interactive {
    cursor: pointer;
}

.surface-row-interactive:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-light);
}

.surface-dense {
    padding: var(--space-2) var(--space-3);
}

.surface-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, var(--bg-tertiary) 0%, var(--bg-card) 100%);
}

.surface-body {
    padding: var(--space-3) var(--space-4);
}


/* =========== Buttons ==================================== *
 * .btn + size (.btn-sm/.btn-md/.btn-lg/.btn-icon) + variant
 * (.btn-primary/.btn-secondary/.btn-ghost/.btn-danger).
 *
 *   <button class="btn btn-primary">Save</button>
 *   <button class="btn btn-sm btn-ghost">Cancel</button>
 *   <button class="btn btn-icon btn-ghost" aria-label="Close">×</button>
 */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-family: inherit;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    text-decoration: none;
    transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition);
    font-size: 13px;
    padding: 8px 14px;
    min-height: 36px;
    touch-action: manipulation;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--accent-ring);
}

.btn:active {
    transform: scale(0.97);
}

.btn[disabled],
.btn.is-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* --- sizes --- */
.btn-sm {
    font-size: 12px;
    padding: 5px 10px;
    min-height: 28px;
    border-radius: var(--radius-sm);
}
.btn-md {
    font-size: 13px;
    padding: 8px 14px;
    min-height: 36px;
}
.btn-lg {
    font-size: 14px;
    padding: 12px 20px;
    min-height: 44px;
    border-radius: var(--radius);
}
.btn-icon {
    min-height: 36px;
    min-width: 36px;
    padding: 6px;
    border-radius: var(--radius);
}
.btn-icon-sm { min-height: 28px; min-width: 28px; padding: 4px; border-radius: var(--radius-sm); }
.btn-icon-lg { min-height: 44px; min-width: 44px; padding: 10px; }

/* --- variants --- */
.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active { background: var(--accent-active); }

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--border);
}
.btn-secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-light);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}
.btn-ghost:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.btn-danger {
    background: transparent;
    color: var(--red);
    border-color: var(--red-dim);
}
.btn-danger:hover {
    background: var(--red-dim);
    border-color: var(--red);
}
.btn-danger-filled {
    background: var(--red);
    color: #fff;
    border-color: var(--red);
}
.btn-danger-filled:hover { filter: brightness(1.08); }

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


/* =========== Inputs ===================================== *
 * .input base, .input-sm / .input-lg sizes, .input-block for full-width.
 */

.input,
.select,
.textarea {
    display: inline-block;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-family: inherit;
    font-size: 13px;
    line-height: 1.4;
    transition: border-color var(--transition), box-shadow var(--transition);
    min-height: 36px;
    width: auto;
}

.input::placeholder,
.textarea::placeholder {
    color: var(--text-muted);
}

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

.input-block,
.select-block,
.textarea-block {
    width: 100%;
}

.input-sm { padding: 5px 10px; font-size: 12px; min-height: 28px; border-radius: var(--radius-sm); }
.input-lg { padding: 12px 16px; font-size: 14px; min-height: 44px; }

.select {
    appearance: none;
    padding-right: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a7f96' stroke-width='2'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 14px;
}

.label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: var(--space-2);
}

.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}


/* =========== Empty state ================================ */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-7) var(--space-5);
    color: var(--text-muted);
    text-align: center;
    gap: var(--space-3);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    opacity: 0.35;
}

.empty-state h2,
.empty-state .empty-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary-strong);
}

.empty-state p {
    font-size: 13px;
    max-width: 420px;
    line-height: 1.55;
}

.empty-state--tight {
    padding: var(--space-5) var(--space-4);
    gap: var(--space-2);
}
.empty-state--tight svg { width: 32px; height: 32px; }

.empty-state--inline {
    padding: var(--space-3);
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--space-2);
    font-size: 12px;
}


/* =========== Skeletons ================================== */

.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-card) 0%,
        var(--bg-card-hover) 50%,
        var(--bg-card) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.6s linear infinite;
    border-radius: var(--radius-sm);
    display: block;
}

.skeleton-text {
    height: 12px;
    margin: 6px 0;
    width: 100%;
}

.skeleton-text-sm { height: 10px; }
.skeleton-text-lg { height: 16px; }
.skeleton-title { height: 20px; width: 60%; }
.skeleton-circle { border-radius: 50%; }
.skeleton-card {
    height: 120px;
    width: 100%;
    border-radius: var(--radius-lg);
}

.skeleton-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}


/* =========== Spinner =================================== */

.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border-light);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 600ms linear infinite;
}
.spinner-sm { width: 10px; height: 10px; border-width: 1.5px; }
.spinner-lg { width: 24px; height: 24px; border-width: 3px; }

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


/* =========== Badges ==================================== */

.badge-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 500;
    line-height: 1.5;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    white-space: nowrap;
}
.badge-pill-accent { background: var(--accent-dim); color: var(--accent-hover); }
.badge-pill-green  { background: var(--green-dim);  color: var(--green); }
.badge-pill-yellow { background: var(--yellow-dim); color: var(--yellow); }
.badge-pill-red    { background: var(--red-dim);    color: var(--red); }
.badge-pill-blue   { background: var(--blue-dim);   color: var(--blue); }


/* =========== Divider =================================== */

.hr {
    height: 1px;
    background: var(--border);
    border: 0;
    margin: var(--space-4) 0;
}


/* =========== Breadcrumbs =============================== */

.crumbs {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: var(--space-3);
    flex-wrap: wrap;
}
.crumbs a,
.crumbs button {
    color: var(--text-secondary);
    text-decoration: none;
    background: transparent;
    border: 0;
    padding: 2px 4px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    font-size: inherit;
    transition: background var(--transition), color var(--transition);
}
.crumbs a:hover,
.crumbs button:hover { color: var(--text-primary); background: var(--bg-card-hover); }
.crumbs .sep {
    color: var(--text-subtle);
    font-size: 11px;
    user-select: none;
}
.crumbs .current { color: var(--text-primary); font-weight: 500; }


/* =========== Global focus polish ======================== */

a:focus-visible,
button:focus-visible,
.nav-link:focus-visible,
.sidebar-nav-item:focus-visible,
.building-item:focus-visible,
[role="button"]:focus-visible {
    outline: 2px solid var(--accent-ring);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}


/* =========== Motion niceties ============================ */

.animate-fade-in { animation: fade-in 180ms ease both; }
.animate-scale-in { animation: scale-in 220ms cubic-bezier(0.4, 0, 0.2, 1) both; }
.animate-spring-pop { animation: spring-pop 320ms cubic-bezier(0.34, 1.56, 0.64, 1) both; }

/* Respect user preference. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}


/* =========== Sync indicator (header chip) =============== */

.sync-dot {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 11px;
    color: var(--text-muted);
    padding: 4px 8px;
    border-radius: var(--radius-full);
    background: var(--bg-card);
    border: 1px solid var(--border);
}
.sync-dot::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    box-shadow: 0 0 0 0 currentColor;
}
.sync-dot[data-state="live"]::before {
    background: var(--green);
    animation: pulse-dot 2.4s ease-in-out infinite;
}
.sync-dot[data-state="polling"]::before { background: var(--yellow); }
.sync-dot[data-state="offline"]::before { background: var(--red); }


/* =========== Error banner =============================== */

.error-banner {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--red-dim);
    border: 1px solid rgba(248, 113, 113, 0.3);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    margin-bottom: var(--space-4);
}
.error-banner .error-icon {
    width: 18px;
    height: 18px;
    color: var(--red);
    flex-shrink: 0;
}
.error-banner button {
    margin-left: auto;
}


/* =========== Command palette =========================== */

.cmdk-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal-backdrop);
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
}
.cmdk-backdrop.is-open { opacity: 1; pointer-events: auto; }

.cmdk-panel {
    position: fixed;
    z-index: var(--z-modal);
    top: 12vh;
    left: 50%;
    transform: translate(-50%, -8px);
    width: min(560px, calc(100vw - 32px));
    max-height: min(560px, calc(100vh - 24vh));
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease, transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
}
.cmdk-panel.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, 0);
}
.cmdk-search {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
}
.cmdk-search input {
    flex: 1;
    background: transparent;
    border: 0;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    font-family: inherit;
}
.cmdk-search .cmdk-icon {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
}
.cmdk-search kbd {
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg-card);
    color: var(--text-muted);
}
.cmdk-list {
    overflow-y: auto;
    padding: var(--space-2);
    flex: 1;
}
.cmdk-group-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: var(--space-2) var(--space-3) var(--space-1);
}
.cmdk-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary-strong);
    transition: background var(--transition), color var(--transition);
    user-select: none;
}
.cmdk-item .cmdk-item-icon {
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
}
.cmdk-item:hover,
.cmdk-item.is-active {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}
.cmdk-item.is-active .cmdk-item-icon { color: var(--accent); }
.cmdk-item-meta {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
}
.cmdk-empty {
    padding: var(--space-5);
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}
.cmdk-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) var(--space-4);
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-muted);
    gap: var(--space-3);
    flex-wrap: wrap;
}
.cmdk-footer kbd {
    font-family: var(--font-mono);
    font-size: 10px;
    padding: 2px 5px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg-card);
}


/* =========== Page title (standardized) ================= */

.page-title {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: var(--text-primary);
    font-family: var(--font-display);
}
.page-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}


/* =========== Keyboard shortcuts help overlay ========= */

.kbd-help-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal-backdrop);
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.kbd-help-backdrop.is-open { opacity: 1; pointer-events: auto; }

.kbd-help-panel {
    width: min(520px, calc(100vw - 32px));
    max-height: min(640px, calc(100vh - 64px));
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
}
.kbd-help-backdrop.is-open .kbd-help-panel { transform: scale(1); }

.kbd-help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border);
}
.kbd-help-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.kbd-help-body {
    padding: var(--space-4);
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-5);
    overflow-y: auto;
}
@media (max-width: 560px) {
    .kbd-help-body { grid-template-columns: 1fr; }
}

.kbd-help-group-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: var(--space-2);
}

.kbd-help-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: 6px 0;
    font-size: 13px;
    color: var(--text-secondary-strong);
}
.kbd-help-row span { flex: 1; }

.kbd-help-backdrop kbd,
.kbd-help-panel kbd,
kbd.kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    padding: 2px 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-bottom-width: 2px;
    border-radius: var(--radius-sm);
}

/* =========== Characters page ========================== */

.chars-intro {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-4);
    margin-bottom: var(--space-5);
}
.chars-intro-inner { min-width: 0; }
.chars-stats {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.chars-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--space-4);
}

.chars-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    box-shadow: var(--shadow-sm);
    transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    position: relative;
    overflow: hidden;
}
@media (hover: hover) {
    .chars-card:hover {
        border-color: var(--border-light);
        box-shadow: var(--shadow);
        transform: translateY(-2px);
    }
}
.chars-card.is-active {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent), var(--shadow);
}
.chars-card.is-active::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

.chars-card-head {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}
.chars-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    color: #fff;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
    flex-shrink: 0;
    box-shadow: var(--shadow-xs);
}
.chars-card-title {
    flex: 1;
    min-width: 0;
}
.chars-card-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chars-card-meta {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-muted);
}
.chars-card-sep { opacity: 0.5; padding: 0 2px; }

.chars-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-subtle);
    display: inline-block;
    margin-right: 2px;
    flex-shrink: 0;
}
.chars-dot.is-online {
    background: var(--green);
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.55);
    animation: pulse-dot 2.4s ease-in-out infinite;
}

.chars-card-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
    margin: 0;
    padding: var(--space-3);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12px;
}
.chars-card-stats > div { min-width: 0; }
.chars-card-stats dt {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 2px;
    font-weight: 600;
}
.chars-card-stats dd {
    margin: 0;
    color: var(--text-secondary-strong);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chars-card-actions {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    margin-top: auto;
}

/* --- Detail mode --- */

/* Mobile: three stacked rows — back button (left), identity block (full
   width), select button (full width). Desktop: three columns in one row. */
.chars-detail-head {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas:
        "back"
        "identity"
        "select";
    row-gap: var(--space-3);
    column-gap: var(--space-3);
    padding-bottom: var(--space-4);
    margin-bottom: var(--space-4);
    border-bottom: 1px solid var(--border);
}
.chars-detail-head > #charsBackBtn { grid-area: back; justify-self: start; }
.chars-detail-head > .chars-detail-identity { grid-area: identity; }
.chars-detail-head > #charsSelectBtn { grid-area: select; justify-self: stretch; }

.chars-detail-identity {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}
.chars-detail-text {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.chars-detail-name {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.2px;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--font-display);
}
.chars-detail-meta {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 12px;
    color: var(--text-muted);
    flex-wrap: wrap;
    line-height: 1.4;
}
/* First span after the status dot ("Online"/"Offline") glues to the dot;
   subsequent metadata items use the normal 8px gap. */
.chars-detail-meta .chars-dot { margin-right: -2px; }

/* Desktop: lay the head out as a single row. The select button sits on
   the right, the back button on the left, identity takes the middle. */
@media (min-width: 640px) {
    .chars-detail-head {
        grid-template-columns: auto 1fr auto;
        grid-template-areas: "back identity select";
        align-items: center;
    }
    .chars-detail-head > #charsSelectBtn { justify-self: end; }
}

.chars-tabs {
    display: flex;
    gap: var(--space-1);
    margin-bottom: var(--space-4);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
}
.chars-tabs::-webkit-scrollbar { display: none; }
.chars-tab {
    position: relative;
    background: transparent;
    border: 0;
    color: var(--text-secondary);
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: color var(--transition);
    white-space: nowrap;
}
.chars-tab::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -1px;
    width: 0;
    height: 2px;
    background: var(--accent);
    border-radius: 2px;
    transform: translateX(-50%);
    transition: width 220ms cubic-bezier(0.4, 0, 0.2, 1);
}
.chars-tab:hover { color: var(--text-primary); }
.chars-tab:hover::after { width: 30%; }
.chars-tab.is-active {
    color: var(--accent-hover);
    font-weight: 600;
}
.chars-tab.is-active::after { width: 70%; }

/* --- Keys tab --- */

.keys-newkey {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--space-4) var(--space-4);
    margin-bottom: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    box-shadow: var(--shadow-xs);
}
.keys-newkey-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    letter-spacing: -0.1px;
}
.keys-newkey-hint {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.6;
    max-width: 62ch;
}
.keys-newkey-hint strong {
    color: var(--text-primary);
    font-weight: 600;
}
.keys-newkey-form {
    display: flex;
    gap: var(--space-2);
    align-items: stretch;
    flex-wrap: wrap;
    padding-top: var(--space-1);
}
.keys-newkey-form .input {
    flex: 1;
    min-width: 240px;
    min-height: 40px;
    padding: 10px 14px;
}
.keys-newkey-form .btn {
    min-height: 40px;
    padding: 10px 18px;
}

.keys-section-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin: var(--space-5) 0 var(--space-2);
}

.keys-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.keys-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color var(--transition);
}
@media (hover: hover) {
    .keys-row:hover { border-color: var(--border-light); }
}
.keys-row.is-revoked { opacity: 0.55; }
.keys-row-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.keys-row-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}
.keys-row-meta {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 11px;
    color: var(--text-muted);
    flex-wrap: wrap;
}
.keys-row-prefix {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary-strong);
    padding: 2px 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
}
.keys-row-actions {
    flex-shrink: 0;
}

.keys-created {
    background: var(--green-dim);
    border: 1px solid rgba(74, 222, 128, 0.35);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
    animation: scale-in 240ms cubic-bezier(0.4, 0, 0.2, 1) both;
}
.keys-created-head {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
}
.keys-created-head svg { color: var(--green); flex-shrink: 0; margin-top: 2px; }
.keys-created-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
}
.keys-created-hint {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
}
.keys-created-box {
    margin-top: var(--space-3);
    display: flex;
    gap: var(--space-2);
    align-items: stretch;
}
.keys-created-value {
    flex: 1;
    min-width: 0;
    font-family: var(--font-mono);
    font-size: 13px;
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    line-height: 1.4;
    outline: none;
    user-select: all;
    cursor: text;
    /* Native <input> handles its own overflow; keep text on a single line
       and let the user scroll horizontally if the key is long. */
    white-space: nowrap;
    text-overflow: clip;
}
.keys-created-value:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-ring);
}

.keys-revoked {
    margin-top: var(--space-4);
    border-top: 1px solid var(--border);
    padding-top: var(--space-3);
}
.keys-revoked summary {
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    list-style: none;
    padding: var(--space-2);
    border-radius: var(--radius-sm);
}
.keys-revoked summary:hover { background: var(--bg-card-hover); color: var(--text-secondary); }
.keys-revoked summary::-webkit-details-marker { display: none; }
.keys-list-revoked { margin-top: var(--space-2); }

/* =========== Settings page ============================= *
 *
 * Deliberately simple structure so nothing can overlap:
 *   .st-page      — max-width wrapper, vertical flow
 *     .st-header  — title + subtitle (+ optional badges)
 *     .st-tabs    — horizontal tab strip (always horizontal, mobile + desktop)
 *     .st-body    — the active panel
 *       .st-panel
 *         .st-panel-head   (section title + description)
 *         #keysContent / #accountContent
 *
 * No sidebar <aside>, no grid, no position:sticky — just block flow. This
 * avoids collisions with style.css's bare `aside { width: 260px … }` rule and
 * the mobile-nav sidebar auto-toggler.
 */

.st-page {
    max-width: 880px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.st-header {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.st-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
    max-width: 68ch;
}
.st-badges {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    margin-top: var(--space-1);
}
.st-badges:empty { display: none; }

.st-tabs {
    display: flex;
    gap: var(--space-1);
    padding: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    scrollbar-width: none;
}
.st-tabs::-webkit-scrollbar { display: none; }

.st-tab {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: 0;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition), color var(--transition);
    min-height: 36px;
}
.st-tab:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}
.st-tab.is-active {
    background: var(--accent-dim);
    color: var(--accent-hover);
}

.st-body {
    min-width: 0;
}
.st-panel {
    display: none;
}
.st-panel.is-active {
    display: block;
    animation: fade-in 200ms ease both;
}
.st-panel-head {
    display: block;
    margin-bottom: var(--space-4);
    padding: 0;
    height: auto;
    min-height: 0;
    background: transparent;
    border: 0;
}
.st-panel-head h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.2px;
    margin-bottom: 4px;
}
.st-panel-head p {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.55;
    max-width: 64ch;
}

/* =========== Mobile drawer: Account section ========== */

.mobile-nav-account-section {
    border-top: 1px solid var(--border);
    padding: var(--space-3) var(--space-2) var(--space-2);
}
.mobile-nav-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 0 var(--space-3) var(--space-2);
}
.mobile-nav-account-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    border-radius: var(--radius);
    background: var(--bg-card);
    border: 1px solid var(--border);
    text-decoration: none;
    color: var(--text-primary);
    transition: background var(--transition), border-color var(--transition);
}
.mobile-nav-account-link:hover,
.mobile-nav-account-link:active,
.mobile-nav-account-link.is-active {
    background: var(--bg-card-hover);
    border-color: var(--border-light);
    color: var(--text-primary);
}
.mobile-nav-account-link.is-active {
    border-color: var(--accent);
    background: var(--accent-dim);
}
.mobile-nav-account-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    background: var(--accent-dim);
    color: var(--accent-hover);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.mobile-nav-account-icon svg { width: 20px; height: 20px; }
.mobile-nav-account-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}
.mobile-nav-account-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}
.mobile-nav-account-sub {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.3;
}
.mobile-nav-account-chevron {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
}

/* =========== Logistics hub ============================= */

.logistics-group {
    margin-bottom: var(--space-6);
}
.logistics-group-label {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-2);
    border-bottom: 1px solid var(--border);
}

.logistics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-3);
}

.logistics-card {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    text-decoration: none;
    color: inherit;
    transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
    position: relative;
    overflow: hidden;
}
@media (hover: hover) {
    .logistics-card:hover {
        border-color: var(--border-light);
        box-shadow: var(--shadow);
        transform: translateY(-2px);
    }
    .logistics-card:hover .logistics-card-title { color: var(--accent-hover); }
}
.logistics-card:active { transform: scale(0.98); }

.logistics-card-icon {
    --icon-bg: var(--accent-dim);
    --icon-fg: var(--accent-hover);
    width: 42px;
    height: 42px;
    border-radius: var(--radius);
    background: var(--icon-bg);
    color: var(--icon-fg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: var(--shadow-xs);
}
.logistics-card-icon svg { width: 22px; height: 22px; }

.logistics-card-body {
    flex: 1;
    min-width: 0;
}
.logistics-card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    letter-spacing: -0.1px;
    transition: color var(--transition);
}
.logistics-card-desc {
    font-size: 12px;
    line-height: 1.55;
    color: var(--text-secondary);
}

/* =========== Alert groups ============================= */

.alert-group {
    margin-bottom: var(--space-3);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: var(--bg-card);
    box-shadow: var(--shadow-xs);
}
.alert-group-summary {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary-strong);
    background: linear-gradient(180deg, var(--bg-tertiary) 0%, var(--bg-card) 100%);
    list-style: none;
    user-select: none;
}
.alert-group-summary::-webkit-details-marker { display: none; }
.alert-group-summary::marker { display: none; content: ''; }
.alert-group-summary::after {
    content: '';
    margin-left: auto;
    width: 10px;
    height: 10px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: rotate(-45deg);
    transition: transform 220ms ease;
}
.alert-group[open] > .alert-group-summary::after { transform: rotate(45deg); }
.alert-group-label { font-weight: 600; }
.alert-group-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}
.alert-group-critical .alert-group-dot { background: var(--red); box-shadow: 0 0 10px rgba(248, 113, 113, 0.6); }
.alert-group-warning .alert-group-dot { background: var(--yellow); }
.alert-group-info .alert-group-dot { background: var(--blue); }
.alert-group-unacked {
    font-size: 11px;
    color: var(--accent-hover);
    font-weight: 500;
}
.alert-group-list {
    display: flex;
    flex-direction: column;
    padding: var(--space-2);
    gap: var(--space-2);
}
.alert-row.is-acked { opacity: 0.5; }

/* =========== Card-appearing animation (staggered) ===== */

.stagger-in > * {
    animation: fade-in 280ms ease backwards;
}
.stagger-in > *:nth-child(1)  { animation-delay: 20ms; }
.stagger-in > *:nth-child(2)  { animation-delay: 50ms; }
.stagger-in > *:nth-child(3)  { animation-delay: 80ms; }
.stagger-in > *:nth-child(4)  { animation-delay: 110ms; }
.stagger-in > *:nth-child(5)  { animation-delay: 140ms; }
.stagger-in > *:nth-child(6)  { animation-delay: 170ms; }
.stagger-in > *:nth-child(7)  { animation-delay: 200ms; }
.stagger-in > *:nth-child(8)  { animation-delay: 230ms; }
.stagger-in > *:nth-child(9)  { animation-delay: 260ms; }
.stagger-in > *:nth-child(10) { animation-delay: 290ms; }
.stagger-in > *:nth-child(n+11) { animation-delay: 320ms; }
