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

:root {
    --bg-base: #0f131a;
    --bg-wash: linear-gradient(170deg, #0f131a 0%, #141922 55%, #12161f 100%);
    --surface-1: #191e29;
    --surface-2: #212735;
    --surface-3: #2a3141;
    --border: rgba(217, 226, 236, 0.08);
    --border-strong: rgba(217, 226, 236, 0.15);
    --border-accent: rgba(224, 93, 43, 0.35);
    --text-primary: #d9e2ec;
    --text-secondary: #9fb3c8;
    --text-muted: #627d98;
    --accent: #e05d2b;
    --accent-strong: #f36f41;
    --accent-soft: rgba(224, 93, 43, 0.12);
    --success: #2f9e6e;
    --warning: #c8912e;
    --danger: #d1493b;
    --warm: #e05d2b;
    --logo-dot: #e05d2b;
    --nav-height: 56px;
    --container-max: 1180px;
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.25);
}

[data-theme="light"] {
    --bg-base: #f4f6f9;
    --bg-wash: linear-gradient(170deg, #f4f6f9 0%, #ebedf2 55%, #f4f6f8 100%);
    --surface-1: #fafbfd;
    --surface-2: #f4f6f9;
    --surface-3: #e2e6ed;
    --border: rgba(0, 0, 0, 0.06);
    --border-strong: rgba(0, 0, 0, 0.13);
    --border-accent: rgba(194, 101, 67, 0.3);
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent: #c26543;
    --accent-strong: #aa5232;
    --accent-soft: rgba(194, 101, 67, 0.08);
    --warm: #c26543;
    --success: #1e7d52;
    --warning: #a27526;
    --danger: #b83a2e;
    --logo-dot: #c26543;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
}

body {
    font-family: Seravek, "Gill Sans Nova", Ubuntu, Calibri, "DejaVu Sans", "Noto Sans", "Liberation Sans", sans-serif;
    background: var(--bg-base);
    background-image: var(--bg-wash);
    color: var(--text-primary);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.15s ease, color 0.15s ease;
}

::selection {
    background: var(--accent);
    color: #fff;
}

a {
    color: inherit;
    text-decoration: none;
}

.container {
    width: 100%;
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 1.5rem;
}

.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    height: var(--nav-height);
    padding: 0 1.5rem;
    background: var(--surface-1);
    box-shadow: inset 0 -1px 0 var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.logo span {
    color: var(--logo-dot);
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.nav-menu-toggle {
    display: none;
}

.sidebar-logo {
    display: none;
}

.user-email {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.btn,
.theme-toggle {
    transition: color 0.12s ease, border-color 0.12s ease, background-color 0.12s ease;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    padding: 0.5rem 1rem;
    min-width: 120px;
    cursor: pointer;
}

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

.btn-sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
    min-width: auto;
}

.btn-loading {
    position: relative;
}

.btn-loading .btn-text {
    visibility: visible;
}

.btn-loading .btn-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    display: none;
    animation: spin 0.7s linear infinite;
}

.btn-loading:disabled .btn-text {
    visibility: hidden;
}

.btn-loading:disabled .btn-spinner {
    display: block;
}

.btn-primary,
.btn-accent {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.btn-primary:hover,
.btn-accent:hover {
    color: #fff;
    background: var(--accent-strong);
    border-color: var(--accent-strong);
    box-shadow: var(--shadow-sm);
}

.btn-outline {
    color: var(--text-secondary);
    border-color: var(--border-strong);
    background: transparent;
}

.btn-outline:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
}

/* Quiet borderless buttons for dense/inline actions */
.btn-icon {
    min-width: auto;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
}

.btn-icon svg {
    width: 15px;
    height: 15px;
    display: block;
}

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

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

.btn-ghost-success {
    color: var(--success);
    background: transparent;
    border-color: transparent;
}

.btn-ghost-success:hover {
    color: var(--success);
    background: rgba(47, 158, 110, 0.12);
}

.btn-ghost-danger {
    color: var(--danger);
    background: transparent;
    border-color: transparent;
}

.btn-ghost-danger:hover {
    color: var(--danger);
    background: rgba(209, 73, 59, 0.12);
}

.spinner {
    width: 1em;
    height: 1em;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    gap: 1rem;
}

.loading-spinner {
    width: 28px;
    height: 28px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.loading-text {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 0.75rem;
}

.skeleton-card {
    background: var(--surface-2);
    border-radius: var(--radius-md);
    padding: 1rem 1.1rem;
}

.skeleton {
    background: linear-gradient(90deg, var(--surface-3) 25%, var(--border) 50%, var(--surface-3) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-avatar {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
}

.skeleton-text {
    height: 14px;
    margin-top: 0.5rem;
}

.skeleton-text.short {
    width: 60%;
}

.skeleton-text.medium {
    width: 80%;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Native date/time picker theming */
[data-theme="dark"] input[type="date"],
[data-theme="dark"] input[type="time"] {
    color-scheme: dark;
}

.badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding: 0.15rem 0.5rem;
    border: 1px solid transparent;
}

.badge-accent {
    color: var(--accent-strong);
    background: var(--accent-soft);
    border-color: rgba(42, 157, 143, 0.2);
}

.badge-success {
    color: var(--success);
    background: rgba(47, 158, 110, 0.1);
    border-color: rgba(47, 158, 110, 0.2);
}

.badge-warning {
    color: var(--warning);
    background: rgba(200, 145, 46, 0.1);
    border-color: rgba(200, 145, 46, 0.2);
}

.card {
    background: var(--surface-2);
    border-radius: var(--radius-md);
    padding: 1.25rem;
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.kpi-label,
.ribbon-label,
.panel-title {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
}

.panel-note,
.request-meta,
.timeline-item p {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.theme-toggle {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.theme-toggle:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
}

.theme-toggle svg {
    width: 16px;
    height: 16px;
}

.theme-toggle .sun-icon { display: none; }
.theme-toggle .moon-icon { display: block; }
[data-theme="light"] .theme-toggle .sun-icon { display: block; }
[data-theme="light"] .theme-toggle .moon-icon { display: none; }

/* App shell layout */
.app-layout {
    display: flex;
    flex: 1;
    min-height: calc(100dvh - var(--nav-height));
}

.sidebar {
    width: 240px;
    background: var(--surface-1);
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    top: var(--nav-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 0.85rem;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    transition: color 0.12s ease, background-color 0.12s ease;
}

.nav-link:hover {
    color: var(--text-secondary);
    background: var(--surface-2);
}

.nav-link.active {
    color: var(--text-primary);
    background: var(--surface-3);
}

.main-content {
    flex: 1;
    padding: 1.75rem 1.5rem 2.5rem;
}

@media (max-width: 820px) {
    .navbar {
        height: auto;
        flex-wrap: wrap;
        padding: 0.75rem 1rem;
    }

    .navbar .logo-auth {
        display: none;
    }

    .nav-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        background: none;
        border: none;
        color: var(--text-secondary);
        cursor: pointer;
        border-radius: var(--radius-sm);
    }

    .nav-menu-toggle:hover {
        background: var(--surface-2);
        color: var(--text-primary);
    }

    .app-layout {
        flex-direction: column;
    }

    .main-content {
        padding-top: 1rem;
    }

    .sidebar {
        position: fixed;
        top: var(--nav-height);
        left: 0;
        height: calc(100dvh - var(--nav-height));
        width: 260px;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        border-bottom: none;
        border-right: 1px solid var(--border);
        padding: 1rem 0.75rem;
        flex-direction: column;
        gap: 0.2rem;
        overflow-y: auto;
    }

    .sidebar-logo {
        display: block;
        font-size: 1.1rem;
        font-weight: 700;
        letter-spacing: -0.03em;
        color: var(--text-primary);
        padding: 0.25rem 0.75rem;
        margin-bottom: 0.5rem;
    }

    .sidebar-logo span {
        color: var(--logo-dot);
    }

    .sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-open .sidebar-backdrop {
        display: block;
    }

    .sidebar-nav {
        flex-direction: column;
        overflow-x: visible;
        gap: 0.2rem;
        width: auto;
        align-items: stretch;
    }

    .org-switcher {
        margin-bottom: 0;
        padding-bottom: 0;
        border-bottom: none;
    }

    .org-switcher-dropdown {
        z-index: 150;
    }

    .sidebar-separator {
        display: block;
    }

    .form-grid.form-grid-org,
    .form-grid.form-grid-user {
        grid-template-columns: 1fr;
    }

    .form-panel .btn {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition: none !important;
        animation: none !important;
    }
}

/* Placeholder pages */
.placeholder-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 60vh;
    padding: 2rem 1rem;
    gap: 1.25rem;
}

.placeholder-icon {
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2);
    border-radius: var(--radius-lg);
    color: var(--text-muted);
}

.placeholder-title {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.placeholder-description {
    font-size: 1rem;
    color: var(--text-secondary);
    max-width: 420px;
    line-height: 1.6;
}

.placeholder-status {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.status-badge {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--accent-strong);
    background: var(--accent-soft);
    border: 1px solid rgba(42, 157, 143, 0.25);
    border-radius: var(--radius-sm);
    padding: 0.2rem 0.6rem;
}

/* Quiet dot status (no box) for dense lists */
.status-dot {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    font-weight: 500;
    white-space: nowrap;
}

.status-dot::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.status-dot.status-Pending,
.status-dot.status-Approved,
.status-dot.status-Rejected,
.status-dot.status-Cancelled {
    background: transparent;
    border-color: transparent;
}

.status-dot.status-Pending { color: var(--warning); }
.status-dot.status-Approved { color: var(--success); }
.status-dot.status-Rejected { color: var(--danger); }
.status-dot.status-Cancelled { color: var(--text-muted); }

.status-Pending {
    color: var(--warning);
    background: rgba(200, 145, 46, 0.1);
    border-color: rgba(200, 145, 46, 0.25);
}

.status-Approved {
    color: var(--success);
    background: rgba(47, 158, 110, 0.1);
    border-color: rgba(47, 158, 110, 0.25);
}

.status-Rejected {
    color: var(--danger);
    background: rgba(209, 73, 59, 0.1);
    border-color: rgba(209, 73, 59, 0.25);
}

.status-Cancelled {
    color: var(--text-muted);
    background: var(--surface-3);
    border-color: var(--border-strong);
}

/* --- Flat Form System --- */
.form-panel {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.form-grid {
    display: grid;
    gap: 0.75rem;
    align-items: end;
}

.form-grid-org {
    grid-template-columns: 1fr 1fr auto;
}

.form-grid-user {
    grid-template-columns: 1fr 1fr 1fr auto;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.form-field label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.form-field input,
.form-field select {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text-primary);
    font-size: 0.9rem;
    width: 100%;
    font-family: inherit;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.form-field select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.65rem center;
    padding-right: 2rem;
}

.form-field input:focus,
.form-field select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.form-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.form-error {
    color: var(--danger, #e5484d);
    font-size: 0.82rem;
    margin-top: 0.5rem;
    min-height: 1.2rem;
}

/* Button color variants */
.btn-danger-text { color: var(--danger); }
.btn-danger-text:hover { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn-success-text { color: var(--success); }
.btn-success-text:hover { color: #fff; background: var(--success); border-color: var(--success); }

/* Inline edit form (used by user edit + org chart edit) */
.create-user-form {
    padding: 0.75rem;
    background: var(--surface-1);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 0.5rem;
}

.edit-form-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

.edit-form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.6rem;
}

@@media (max-width: 820px) {
    .edit-form-fields {
        grid-template-columns: 1fr;
    }
}

/* Confirmation dialog (user create enable-confirmation) */
.confirmation-banner {
    background: rgba(200, 145, 46, 0.08);
    border: 1px solid rgba(200, 145, 46, 0.25);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    margin-top: 0.75rem;
}

.confirmation-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.confirmation-icon {
    width: 18px;
    height: 18px;
    color: var(--warning);
    flex-shrink: 0;
}

.confirmation-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--warning);
}

.confirmation-message {
    color: var(--text-secondary);
    font-size: 0.88rem;
    line-height: 1.5;
    margin-bottom: 0.9rem;
}

.confirmation-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

/* User table */
.user-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.user-table th {
    text-align: left;
    padding: 0.6rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}

.user-table td {
    padding: 0.7rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.user-table tbody tr:hover {
    background: var(--surface-2);
}

.user-cell {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar-wrapper {
    position: relative;
    flex-shrink: 0;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-strong);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
}

.presence-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--success);
    border: 2px solid var(--surface-1);
    display: none;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 500;
    color: var(--text-primary);
}

.user-created {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.user-actions {
    display: flex;
    gap: 0.4rem;
    justify-content: flex-end;
}

.user-row-edit td {
    padding: 0 !important;
    border: none !important;
}

.status-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Filter controls */
.user-filters, .org-filters {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.search-icon {
    position: absolute;
    left: 0.65rem;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 0.5rem 0.65rem 0.5rem 2.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.filter-tabs {
    display: flex;
    gap: 0.25rem;
}

.filter-tab {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.12s ease, background-color 0.12s ease, border-color 0.12s ease;
}

.filter-tab:hover {
    color: var(--text-secondary);
    background: var(--surface-2);
}

.filter-tab.active {
    color: var(--text-primary);
    background: var(--surface-3);
    border-color: var(--border-strong);
}

.filter-count {
    font-size: 0.7rem;
    opacity: 0.7;
}

/* Sort controls */
.sort-header {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.sort-header:hover {
    color: var(--text-primary);
}

.sort-indicator {
    font-size: 0.65rem;
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 3rem 1rem;
    gap: 0.75rem;
    color: var(--text-muted);
}

.empty-state h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.empty-state p {
    font-size: 0.875rem;
    max-width: 320px;
}

/* Chat */
.chat-workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 16rem;
    gap: 1.25rem;
    height: calc(100dvh - var(--nav-height) - 3.5rem);
    max-width: var(--container-max);
    margin: 0 auto;
    overflow: hidden;
}

.chat-container {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.1rem 0;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chat-members-toggle {
    display: none;
}

.chat-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.chat-room-kicker {
    margin-bottom: 0.1rem;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.chat-room-live {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
}

.chat-room-live-dot {
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 15%, transparent);
}

.chat-ephemeral {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 0 0.7rem;
    margin-bottom: 0.5rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.chat-messages::-webkit-scrollbar,
.chat-members-list::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track,
.chat-members-list::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.chat-members-list::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 999px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.chat-members-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

#chat-messages-inner {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.chat-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
    font-size: 0.9rem;
}

.chat-message-self {
    text-align: right;
    max-width: min(88%, 50rem);
    margin-left: auto;
}

.chat-message-header {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.15rem;
    padding-left: 0.25rem;
}

.chat-message-self .chat-message-header {
    justify-content: flex-end;
}

.chat-message-self .chat-message-author-wrapper {
    display: none;
}

.chat-message-self .chat-message-time::before {
    content: "You · ";
    color: var(--text-muted);
}

.chat-message-author-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.chat-message-author {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.presence-dot-inline {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    flex-shrink: 0;
    display: none;
}

.chat-message-time {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.chat-message-body {
    max-width: min(82%, 42rem);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text-primary);
    word-break: break-word;
    white-space: pre-wrap;
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.chat-message-self .chat-message-body {
    display: inline-block;
    text-align: left;
    color: var(--accent-text-on-solid, #fff);
    background: var(--accent);
    border: 1px solid var(--accent);
    border-bottom-right-radius: 0.2rem;
    max-width: 100%;
}

.chat-ai-badge {
    display: inline-flex;
    align-items: center;
    padding: 0 0.3rem;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #fff;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    border-radius: 3px;
    line-height: 1.25rem;
    flex-shrink: 0;
    margin-right: 0.25rem;
}

.chat-message-ai .chat-message-body {
    background: var(--surface-2);
    border: 1px solid var(--border);
}

.chat-members {
    display: flex;
    flex-direction: column;
    align-self: stretch;
    overflow: hidden;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.chat-members-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.chat-members-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-members-title { font-size: 0.85rem; font-weight: 700; color: var(--text-primary); }
.chat-members-count { margin-top: 0.15rem; font-size: 0.75rem; color: var(--text-muted); }
.chat-members-count-badge { min-width: 1.5rem; padding: 0.15rem 0.4rem; border-radius: 999px; background: var(--surface-3); color: var(--text-muted); font-size: 0.7rem; font-weight: 700; text-align: center; }

.chat-members-close {
    display: none;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-muted);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

.chat-members-close:hover {
    background: var(--surface-2);
    color: var(--text-primary);
}

.chat-members-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0.45rem; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
.chat-member { display: grid; grid-template-columns: 2rem minmax(0, 1fr); align-items: center; column-gap: 0.6rem; padding: 0.55rem; border-radius: var(--radius-sm); }
.chat-member:hover { background: var(--surface-2); }
.chat-member-avatar { position: relative; display: inline-flex; width: 2rem; height: 2rem; align-items: center; justify-content: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); font-size: 0.65rem; font-weight: 700; }
.chat-member-presence { position: absolute; right: -0.05rem; bottom: -0.05rem; width: 0.65rem; height: 0.65rem; border: 2px solid var(--surface-1); border-radius: 50%; background: var(--text-muted); }
.chat-member-presence.is-online { background: var(--success); }
.chat-member-name { min-width: 0; overflow: hidden; color: var(--text-primary); font-size: 0.8rem; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.chat-member-status { grid-column: 2; color: var(--text-muted); font-size: 0.7rem; }

.chat-input {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

.chat-input .form-field-input {
    flex: 1;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-1);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.chat-input textarea.form-field-input {
    resize: none;
    field-sizing: content;
    max-height: 10rem;
    overflow-y: auto;
    font-family: inherit;
    line-height: 1.4;
}

.chat-input .form-field-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

.chat-input-help { margin: 0.35rem 0 0; color: var(--text-muted); font-size: 0.7rem; }
.chat-input-help kbd { padding: 0.05rem 0.25rem; border: 1px solid var(--border); border-radius: 3px; background: var(--surface-2); font-family: inherit; font-size: inherit; }

@media (max-width: 900px) {
    .chat-workspace { display: flex; flex-direction: column; height: auto; min-height: calc(100dvh - var(--nav-height) - 3.5rem); }
    .chat-container { min-height: 34rem; }
    .chat-members { max-height: 15rem; }
    .chat-members-list { max-height: 10.5rem; }
}

@media (max-width: 600px) {
    .chat-workspace { gap: 0.75rem; }
    .chat-container { min-height: calc(100dvh - var(--nav-height) - 2.5rem); }
    .chat-message-self, .chat-message-body { max-width: 92%; }
    .chat-members {
        display: none;
        position: fixed;
        inset: var(--nav-height) 0 0 0;
        z-index: 100;
        max-height: none;
        border-radius: 0;
    }
    .chat-members.chat-members-open-mobile { display: flex; flex-direction: column; }
    .chat-members-list { max-height: none; }
    .chat-members-toggle { display: inline-flex; }
    .chat-members-close { display: inline-flex; }
}

/* Org Switcher */
.org-switcher {
    position: relative;
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.org-switcher-current {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: none;
    min-width: 0;
    width: 100%;
    text-align: left;
    font: inherit;
    color: inherit;
    cursor: default;
    outline: none;
}

.org-switcher-current.org-switcher-clickable {
    cursor: pointer;
}

.org-switcher-current.org-switcher-clickable:hover {
    background: var(--surface-3);
}

.org-switcher-chevron {
    margin-left: auto;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.org-switcher-name {
    font-weight: 600;
    font-size: 0.88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.org-avatar-sm {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    flex-shrink: 0;
}

.org-switcher-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 0.25rem;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 100;
    max-height: 260px;
    overflow-y: auto;
}

.org-switcher-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: background 0.1s;
}

.org-switcher-option:hover {
    background: var(--surface-2);
}

.org-switcher-option.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.org-switcher-option-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.org-switcher-option-count {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.org-switcher-create {
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
    font-size: 0.82rem;
}

.org-switcher-create:hover {
    color: var(--accent);
}

.sidebar-separator {
    height: 1px;
    background: var(--border);
    margin: 0.5rem 0.5rem 0.25rem;
}

.nav-link-secondary {
    color: var(--text-muted);
    font-size: 0.82rem;
}

.nav-link-secondary:hover {
    color: var(--text-secondary);
    background: var(--surface-2);
}
