/**
 * Shared UI — Sloth Mint / Wayflow brand components.
 */

/* ----- Buttons ----- */
.btn,
.btn-control {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.5rem 1rem;
    font-family: inherit;
    font-size: var(--wf-text-sm);
    font-weight: 600;
    line-height: 1.25;
    border-radius: var(--wf-radius-lg);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.btn-control {
    min-width: max-content;
    flex-shrink: 0;
}

.btn-primary,
.btn-control.btn-primary {
    background: var(--wf-accent);
    color: var(--wf-on-accent);
    border-color: var(--wf-accent);
    box-shadow: var(--wf-shadow);
}

.btn-primary:hover,
.btn-control.btn-primary:hover {
    background: var(--wf-accent-hover);
    border-color: var(--wf-accent-hover);
}

.btn-secondary,
.btn-control.btn-secondary {
    background: var(--wf-surface-card);
    color: var(--wf-heading);
    border-color: var(--wf-border);
    box-shadow: var(--wf-shadow);
}

.btn-secondary:hover:not(:disabled),
.btn-control.btn-secondary:hover:not(:disabled) {
    background: var(--wf-bg-hover);
    border-color: var(--brand-slate-400);
}

.btn-danger,
.btn-control.btn-danger {
    background: var(--wf-danger);
    color: var(--wf-on-accent);
    border-color: var(--wf-danger);
}

.btn-danger:hover,
.btn-control.btn-danger:hover {
    background: var(--wf-danger-hover);
    border-color: var(--wf-danger-hover);
}

.btn-secondary:disabled,
.btn-control:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn:focus-visible,
.btn-control:focus-visible {
    outline: none;
    box-shadow: var(--wf-focus-ring);
}

.btn-danger:focus-visible,
.btn-control.btn-danger:focus-visible {
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.2);
}

.btn-close {
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    border-radius: var(--wf-radius-md);
    background: transparent;
    color: var(--wf-close-icon);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.btn-close:hover {
    background: var(--wf-bg-hover);
    color: var(--wf-close-icon-hover);
}

/* ----- Forms ----- */
.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--brand-slate-ink);
    margin-bottom: 0.4rem;
}

.form-input {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: var(--wf-text-base);
    font-family: inherit;
    color: var(--wf-text);
    background: var(--wf-surface-card);
    border: 1px solid var(--wf-input-border);
    border-radius: var(--wf-radius-md);
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus {
    outline: none;
    border-color: var(--wf-input-focus);
    box-shadow: var(--wf-focus-ring);
}

.form-input::placeholder {
    color: var(--wf-muted);
}

.btn-signin {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: var(--wf-text-base);
    font-weight: 600;
    font-family: inherit;
    color: var(--wf-on-accent);
    background: var(--wf-btn-signin);
    border: none;
    border-radius: var(--wf-radius-lg);
    cursor: pointer;
    transition: background 0.15s;
    letter-spacing: 0.02em;
}

.btn-signin:hover {
    background: var(--wf-btn-signin-hover);
}

.btn-signin:disabled {
    background: var(--wf-muted);
    cursor: not-allowed;
}

.error-message {
    background: var(--wf-danger-surface);
    color: var(--wf-badge-danger-text);
    border: 1px solid var(--wf-badge-danger-border);
    padding: 0.75rem 1rem;
    border-radius: var(--wf-radius-lg);
    margin-bottom: 1.25rem;
    font-size: var(--wf-text-sm);
}

/* ----- Soft badges (brand book) ----- */
.wf-badge,
.status-badge,
.journey-badge,
.drawer-trip-badge,
.asset-label-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.625rem;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border-radius: var(--wf-radius-pill);
    border: 1px solid transparent;
    line-height: 1.3;
}

.status-badge.connected,
.status-badge.COMPLIANT,
.journey-badge.active,
.drawer-trip-badge.active {
    background: var(--wf-accent);
    color: var(--wf-on-accent);
    border-color: var(--wf-accent);
    gap: 0.35rem;
}

.journey-badge.active .journey-badge-dot,
.drawer-trip-badge.active::before {
    content: '';
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.95;
    animation: wf-status-pulse 2s ease-in-out infinite;
}

.journey-badge.completed {
    background: var(--wf-badge-neutral-bg);
    color: var(--wf-badge-neutral-text);
    border-color: var(--wf-badge-neutral-border);
}

.status-badge.APPROACHING {
    background: var(--wf-badge-warn-bg);
    color: var(--wf-badge-warn-text);
    border-color: var(--wf-badge-warn-border);
}

.status-badge.NON_COMPLIANT {
    background: var(--wf-badge-danger-bg);
    color: var(--wf-badge-danger-text);
    border-color: var(--wf-badge-danger-border);
}

.status-badge.DEFAULT {
    background: var(--wf-badge-neutral-bg);
    color: var(--wf-badge-neutral-text);
    border-color: var(--wf-badge-neutral-border);
}

.drawer-trip-badge.done {
    background: var(--wf-badge-neutral-bg);
    color: var(--wf-badge-neutral-text);
    border-color: var(--wf-badge-neutral-border);
    text-transform: uppercase;
}

.btn--outline.btn-danger {
    background: var(--wf-surface-card);
    color: var(--wf-danger);
    border: 1px solid var(--wf-badge-danger-border);
}

.btn--outline.btn-danger:hover {
    background: var(--wf-danger-surface);
    color: var(--wf-danger-hover);
    border-color: var(--wf-danger-hover);
}

.asset-label-pill {
    text-transform: none;
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: 0;
    background: var(--wf-badge-primary-bg);
    color: var(--wf-badge-primary-text);
    border-color: var(--wf-badge-primary-border);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.asset-label-pill:hover {
    background: var(--brand-blue-100);
    border-color: var(--brand-blue-200);
}

/* ----- Header toggle pills ----- */
.toggle-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.75rem;
    font-size: var(--wf-text-xs);
    font-weight: 600;
    font-family: inherit;
    color: var(--wf-toggle-text);
    background: var(--wf-toggle-bg);
    border: 1px solid var(--wf-toggle-border);
    border-radius: var(--wf-radius-pill);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    box-shadow: var(--wf-shadow);
}

.toggle-track {
    position: relative;
    flex-shrink: 0;
    width: 1.75rem;
    height: 1rem;
    border-radius: var(--wf-radius-pill);
    background: var(--wf-toggle-track);
    transition: background 0.15s;
}

.toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--wf-toggle-thumb);
    box-shadow: 0 1px 2px rgba(10, 10, 10, 0.15);
    transition: transform 0.2s;
}

.toggle-pill.is-on {
    background: var(--wf-accent) !important;
    border-color: var(--wf-accent) !important;
    color: var(--wf-on-accent) !important;
}

.toggle-pill.is-on .toggle-track {
    background: var(--wf-overlay-on-dark) !important;
}

.toggle-pill.is-on .toggle-thumb {
    transform: translateX(12px) !important;
}

/* ----- App header (carbon + navy brand bar) ----- */
.dashboard-header {
    position: sticky;
    top: 0;
    z-index: 50;
    flex-shrink: 0;
    min-height: 4rem;
    padding: 0 var(--wf-space-xl);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--wf-space-lg);
    color: var(--wf-header-text);
    background: linear-gradient(180deg, var(--wf-header-bg-top) 0%, var(--wf-header-bg) 100%);
    border-bottom: 1px solid var(--wf-header-border);
    box-shadow: 0 1px 3px rgba(10, 10, 10, 0.2);
}

.dashboard-header::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: var(--wf-header-accent);
}

.header-brand {
    position: relative;
    z-index: 1;
    min-width: 0;
}

.header-brand-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: inherit;
}

.header-brand-link:hover .header-brand-name {
    color: var(--wf-header-link);
}

.header-logomark {
    flex-shrink: 0;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background: var(--brand-blue-500);
    color: var(--wf-on-accent);
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    display: grid;
    place-items: center;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.15), 0 4px 12px rgba(29, 78, 216, 0.45);
}

.header-brand-text {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.header-brand-name {
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: var(--wf-letter-tight-sm);
    color: var(--wf-header-text);
    line-height: 1.15;
    transition: color 0.15s;
}

.header-brand-tag {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--wf-header-muted);
    line-height: 1.2;
}

.header-info {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: var(--wf-space-sm);
    flex-wrap: wrap;
    justify-content: flex-end;
}

.header-toolbar {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem;
    background: var(--wf-header-toolbar-bg);
    border: 1px solid var(--wf-header-chrome-border);
    border-radius: var(--wf-radius-pill);
}

.header-divider {
    width: 1px;
    height: 1.75rem;
    background: var(--wf-header-chrome-border);
    flex-shrink: 0;
}

.dashboard-header .toggle-pill {
    color: rgba(255, 255, 255, 0.92);
    background: transparent;
    border-color: transparent;
    box-shadow: none;
}

.dashboard-header .toggle-pill:hover {
    background: var(--wf-header-chrome-hover);
    border-color: transparent;
}

.dashboard-header .toggle-track {
    background: rgba(255, 255, 255, 0.28);
}

.dashboard-header .toggle-thumb {
    background: #fff;
}

.dashboard-header .toggle-pill.is-on {
    background: var(--brand-blue-500) !important;
    border-color: var(--brand-blue-500) !important;
}

.dashboard-header .header-link {
    display: inline-flex;
    align-items: center;
    padding: 0.45rem 0.85rem;
    font-size: var(--wf-text-sm);
    font-weight: 600;
    color: var(--wf-header-link);
    text-decoration: none;
    border: 1px solid var(--wf-header-chrome-border);
    border-radius: var(--wf-radius-lg);
    background: var(--wf-header-chrome-bg);
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.dashboard-header .header-link:hover {
    background: var(--wf-header-chrome-hover);
    color: #fff;
    text-decoration: none;
}

.dashboard-header .header-link--back::before {
    content: '←';
    margin-right: 0.35rem;
    opacity: 0.85;
}

.dashboard-header .profile-button {
    background: var(--wf-header-chrome-bg);
    border-color: var(--wf-header-chrome-border);
    box-shadow: none;
}

.dashboard-header .profile-button:hover {
    background: var(--wf-header-chrome-hover);
    border-color: rgba(255, 255, 255, 0.2);
}

.dashboard-header .profile-avatar {
    background: var(--brand-blue-400);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.12);
}

.dashboard-header .profile-email {
    color: rgba(255, 255, 255, 0.92);
    font-weight: 600;
}

.dashboard-header .status-badge {
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.dashboard-header .status-badge--live {
    background: rgba(20, 184, 166, 0.18);
    border: 1px solid rgba(45, 212, 191, 0.45);
    color: #A7F3D0;
}

.dashboard-header .status-badge.connected,
.dashboard-header .status-badge.COMPLIANT {
    background: rgba(20, 184, 166, 0.18);
    border-color: rgba(45, 212, 191, 0.45);
    color: #A7F3D0;
}

.status-dot {
    width: 0.4rem;
    height: 0.4rem;
    border-radius: 50%;
    background: var(--wf-success);
    box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.35);
    animation: wf-status-pulse 2s ease-in-out infinite;
}

@keyframes wf-status-pulse {
    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.65;
        transform: scale(0.92);
    }
}

@media (max-width: 900px) {
    .dashboard-header {
        padding: 0.65rem var(--wf-space-md);
        flex-wrap: wrap;
        align-content: center;
    }

    .header-brand-tag {
        display: none;
    }

    .profile-email {
        display: none;
    }
}

/* ----- Profile dropdown ----- */
.profile-dropdown {
    position: relative;
    display: inline-block;
}

.profile-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem 0.65rem 0.35rem 0.35rem;
    background: var(--wf-profile-bg);
    border: 1px solid var(--wf-profile-border);
    border-radius: var(--wf-radius-pill);
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s, border-color 0.15s;
    box-shadow: var(--wf-shadow);
}

.profile-button:hover {
    background: var(--wf-profile-hover);
}

.profile-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--wf-accent);
    color: var(--wf-on-accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.profile-email {
    font-size: var(--wf-text-sm);
    font-weight: 500;
    color: var(--wf-profile-text);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.profile-menu {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    min-width: 220px;
    padding: 0.35rem 0;
    background: var(--wf-menu-bg);
    border: 1px solid var(--wf-menu-border);
    border-radius: var(--wf-radius-xl);
    box-shadow: var(--wf-shadow-lift);
    display: none;
    z-index: 1000;
}

.profile-menu.show {
    display: block;
}

.profile-menu-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--wf-menu-divider);
}

.profile-menu-email {
    font-size: var(--wf-text-sm);
    font-weight: 600;
    color: var(--wf-heading);
}

.profile-menu-item {
    padding: 0.65rem 1rem;
    font-size: var(--wf-text-sm);
    color: var(--wf-heading);
    cursor: pointer;
    transition: background 0.12s;
}

.profile-menu-item:hover {
    background: var(--wf-selected-bg);
}

.profile-menu-item.logout {
    color: var(--wf-danger);
    border-top: 1px solid var(--wf-menu-divider);
    margin-top: 0.25rem;
}

.profile-menu-item.logout:hover {
    background: var(--wf-danger-surface);
}

/* ----- Loading / info states ----- */
.loading,
.info-message {
    text-align: center;
    padding: var(--wf-space-xl) var(--wf-space-md);
    color: var(--wf-text-muted);
    font-size: var(--wf-text-sm);
}

.info-message--compact,
.info-message--compact-lg {
    text-align: center;
}

.loading-spinner {
    display: inline-block;
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid var(--wf-border);
    border-top-color: var(--wf-accent);
    border-radius: 50%;
    animation: wf-spin 0.8s linear infinite;
}

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