:root {
    --primary: #0f4c81;
    --primary-dark: #0a355c;
    --primary-light: #e6f0f9;
    --accent: #0284c7;
    --bg-body: #f1f5f9;
    --bg-surface: #ffffff;
    --bg-subtle: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text-main: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --success: #15803d;
    --success-bg: #dcfce7;
    --warning: #b45309;
    --warning-bg: #fef3c7;
    --danger: #b91c1c;
    --danger-bg: #fee2e2;
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.10);
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-body);
    color: var(--text-main);
    font-size: 14px;
    line-height: 1.5;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; }
a { color: var(--primary); }

/* Boot & Login */
.app-loading-shell, .auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: linear-gradient(140deg, #0b2e4f 0%, #0f4c81 55%, #155e75 100%);
}
.boot-spinner-card {
    background: var(--bg-surface);
    padding: 2rem 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    text-align: center;
}
.spinner {
    width: 34px;
    height: 34px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    margin: 0 auto 0.85rem;
    animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.auth-card {
    width: 100%;
    max-width: 430px;
    background: var(--bg-surface);
    border-radius: 16px;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.26);
    overflow: hidden;
}
.auth-brand {
    background: #0b3559;
    color: #fff;
    padding: 1.65rem 1.75rem;
    display: flex;
    align-items: center;
    gap: 0.9rem;
}
.auth-seal {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    background: rgba(255,255,255,0.14);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.15rem;
    flex-shrink: 0;
}
.auth-brand h1 { margin: 0; font-size: 1.18rem; line-height: 1.3; }
.auth-brand p { margin: 0.2rem 0 0; font-size: 0.82rem; opacity: 0.85; }
.auth-body { padding: 1.65rem 1.75rem; }

/* Main Workspace Layout */
.workspace {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

.nav-rail {
    width: 230px;
    background: #0b2942;
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid rgba(255,255,255,0.08);
}
.nav-header {
    padding: 1.1rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 0.7rem;
}
.nav-logo {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    background: #1d6fa5;
    color: #fff;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.nav-title { font-weight: 700; font-size: 0.93rem; color: #fff; line-height: 1.25; }
.nav-sub { font-size: 0.74rem; color: #94a3b8; }

.conn-pill {
    margin: 0.65rem 0.85rem 0.25rem;
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    font-size: 0.74rem;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    background: rgba(255,255,255,0.06);
}
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; }
.conn-pill.reconnecting .conn-dot { background: #f59e0b; }
.conn-pill.offline .conn-dot { background: #ef4444; }

.nav-links {
    flex: 1;
    padding: 0.6rem 0.65rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.22rem;
}
.nav-btn {
    width: 100%;
    background: transparent;
    color: #cbd5e1;
    border: 0;
    border-radius: 8px;
    padding: 0.62rem 0.75rem;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}
.nav-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-btn.active { background: #165b8c; color: #fff; font-weight: 600; }
.nav-btn-left { display: flex; align-items: center; gap: 0.65rem; }
.nav-badge {
    background: #ef4444;
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    min-width: 20px;
    text-align: center;
}

.nav-footer {
    padding: 0.85rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.nav-user-meta { min-width: 0; flex: 1; }
.nav-user-name { font-weight: 600; font-size: 0.85rem; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-user-dept { font-size: 0.73rem; color: #94a3b8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main-stage {
    flex: 1;
    min-width: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-body);
}

/* Chat Split Layout */
.chat-shell {
    display: flex;
    flex: 1;
    height: 100%;
    overflow: hidden;
    background: var(--bg-surface);
}
.chat-list-col {
    width: 330px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    background: var(--bg-surface);
}
.chat-list-header {
    padding: 0.9rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}
.chat-list-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.chat-list-title-row h2 { margin: 0; font-size: 1.05rem; }
.chat-items {
    flex: 1;
    overflow-y: auto;
}
.chat-item {
    width: 100%;
    border: 0;
    border-bottom: 1px solid #f1f5f9;
    background: transparent;
    padding: 0.8rem 1rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    text-align: left;
    transition: background 0.12s;
}
.chat-item:hover { background: var(--bg-subtle); }
.chat-item.active { background: var(--primary-light); }
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #dbeafe;
    color: var(--primary);
    font-weight: 700;
    font-size: 0.88rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.online-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #fff;
    position: absolute;
    bottom: 0;
    right: 0;
}
.chat-item-body { flex: 1; min-width: 0; }
.chat-item-top { display: flex; justify-content: space-between; align-items: baseline; gap: 0.4rem; }
.chat-item-name { font-weight: 600; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 0.73rem; color: var(--text-muted); flex-shrink: 0; }
.chat-item-bottom { display: flex; justify-content: space-between; align-items: center; gap: 0.4rem; margin-top: 0.2rem; }
.chat-item-preview { font-size: 0.81rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chat-main-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: #f4f7fb;
}
.chat-topbar {
    background: var(--bg-surface);
    padding: 0.75rem 1.15rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}
.chat-topbar-info { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.chat-topbar-title { font-weight: 700; font-size: 0.98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-topbar-sub { font-size: 0.78rem; color: var(--text-muted); }

.messages-viewport {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}
.msg-row {
    display: flex;
    flex-direction: column;
    max-width: 76%;
}
.msg-row.mine { align-self: flex-end; align-items: flex-end; }
.msg-row.theirs { align-self: flex-start; align-items: flex-start; }
.msg-row.system { align-self: center; max-width: 90%; }
.msg-system-pill {
    background: #e2e8f0;
    color: #475569;
    font-size: 0.76rem;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
}

.msg-bubble {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.6rem 0.85rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    word-break: break-word;
}
.msg-row.mine .msg-bubble {
    background: #dff0ff;
    border-color: #bae0fd;
}
.msg-sender {
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.2rem;
}
.msg-reply-box {
    background: rgba(15, 23, 42, 0.05);
    border-left: 3px solid var(--primary);
    border-radius: 4px;
    padding: 0.3rem 0.55rem;
    margin-bottom: 0.4rem;
    font-size: 0.78rem;
}
.msg-text { white-space: pre-wrap; color: var(--text-main); }
.msg-deleted { font-style: italic; color: var(--text-muted); }
.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.4rem;
    margin-top: 0.3rem;
    font-size: 0.71rem;
    color: var(--text-muted);
}
.msg-actions-bar {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.22rem;
    opacity: 0.75;
}
.msg-actions-bar button {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.12rem 0.42rem;
    font-size: 0.72rem;
    color: var(--text-secondary);
}
.msg-actions-bar button:hover { background: var(--primary-light); color: var(--primary); }

.reactions-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0.28rem;
    margin-top: 0.3rem;
}
.reaction-chip {
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    padding: 0.1rem 0.48rem;
    font-size: 0.76rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}
.reaction-chip.active { background: var(--primary-light); border-color: var(--primary); font-weight: 600; }

.att-grid {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    margin-top: 0.45rem;
}
.att-img-thumb {
    max-width: 260px;
    max-height: 200px;
    border-radius: 8px;
    border: 1px solid var(--border);
    cursor: pointer;
    display: block;
}
.att-file-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
    padding: 0.45rem 0.65rem;
    background: rgba(255,255,255,0.85);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.8rem;
}

.typing-bar {
    min-height: 22px;
    padding: 0.15rem 1.25rem;
    font-size: 0.77rem;
    color: var(--primary);
    font-style: italic;
}

.composer-wrap {
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    padding: 0.75rem 1rem;
}
.composer-context-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-subtle);
    border-left: 3px solid var(--primary);
    padding: 0.35rem 0.65rem;
    margin-bottom: 0.5rem;
    border-radius: 6px;
    font-size: 0.8rem;
}
.composer-files-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}
.pending-file-pill {
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 0.22rem 0.6rem;
    border-radius: 999px;
    font-size: 0.78rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.composer-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    position: relative;
}
.composer-row textarea {
    flex: 1;
    resize: none;
    min-height: 42px;
    max-height: 130px;
    padding: 0.58rem 0.8rem;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
}
.emoji-popover {
    position: absolute;
    bottom: 54px;
    left: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    padding: 0.6rem;
    width: 280px;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.25rem;
    z-index: 30;
}
.emoji-btn {
    border: 0;
    background: transparent;
    font-size: 1.2rem;
    padding: 0.25rem;
    border-radius: 6px;
}
.emoji-btn:hover { background: var(--bg-subtle); }

.chat-detail-drawer {
    width: 300px;
    border-left: 1px solid var(--border);
    background: var(--bg-surface);
    overflow-y: auto;
    padding: 1rem;
    flex-shrink: 0;
}

/* Page Containers (Beranda, Broadcast, Tasks, Notif, Profile, Admin) */
.page-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 1.35rem 1.65rem;
}
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.85rem;
    margin-bottom: 1.25rem;
}
.page-header h1 { margin: 0; font-size: 1.3rem; color: var(--text-main); }
.page-header p { margin: 0.2rem 0 0; color: var(--text-muted); font-size: 0.85rem; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
    gap: 0.9rem;
    margin-bottom: 1.35rem;
}
.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow-sm);
}
.stat-label { font-size: 0.79rem; color: var(--text-muted); font-weight: 600; }
.stat-value { font-size: 1.55rem; font-weight: 800; color: var(--primary); margin-top: 0.25rem; }

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem;
    box-shadow: var(--shadow-sm);
    margin-bottom: 1rem;
}
.card h3 { margin: 0 0 0.75rem; font-size: 1rem; }

/* Buttons & Inputs */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.52rem 0.95rem;
    border-radius: 8px;
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 0.86rem;
    text-decoration: none;
    transition: opacity 0.15s, background 0.15s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--bg-surface); border-color: var(--border-strong); color: var(--text-main); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-subtle); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.32rem 0.65rem; font-size: 0.78rem; }

.input, select.input, textarea.input {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--text-main);
}
.input:focus { outline: 2px solid #93c5fd; border-color: var(--primary); }
.form-group { margin-bottom: 0.9rem; }
.form-group label { display: block; font-weight: 600; font-size: 0.82rem; margin-bottom: 0.3rem; color: var(--text-secondary); }

/* Badges & Progress */
.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.73rem;
    font-weight: 600;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-neutral { background: #e2e8f0; color: #334155; }

.progress-track {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--primary);
    transition: width 0.25s ease;
}

/* Kanban & Tables */
.kanban-board {
    display: grid;
    grid-template-columns: repeat(3, minmax(260px, 1fr));
    gap: 1rem;
    align-items: start;
}
.kanban-col {
    background: #e9eff6;
    border-radius: var(--radius);
    padding: 0.8rem;
}
.kanban-col h4 { margin: 0 0 0.7rem; font-size: 0.88rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.03em; }
.task-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 0.85rem;
    margin-bottom: 0.65rem;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}
.task-card:hover { border-color: var(--primary); }

.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
table.data-table th, table.data-table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
table.data-table th { background: var(--bg-subtle); font-weight: 700; color: var(--text-secondary); }

.tabs-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1rem;
}
.tab-pill {
    padding: 0.42rem 0.85rem;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--bg-surface);
    font-size: 0.81rem;
    font-weight: 600;
    color: var(--text-secondary);
}
.tab-pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Modal & Toast */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.52);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 100;
}
.modal-box {
    background: var(--bg-surface);
    border-radius: 14px;
    width: 100%;
    max-width: 580px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
}
.modal-box.wide { max-width: 780px; }
.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1.2rem 1.25rem; overflow-y: auto; }
.modal-footer { padding: 0.85rem 1.25rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 0.5rem; }

.toast-container {
    position: fixed;
    bottom: 1.15rem;
    right: 1.15rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 200;
}
.toast {
    background: #0f172a;
    color: #fff;
    padding: 0.7rem 1rem;
    border-radius: 9px;
    box-shadow: var(--shadow-md);
    font-size: 0.84rem;
    max-width: 340px;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

.empty-state {
    text-align: center;
    padding: 2.5rem 1.25rem;
    color: var(--text-muted);
}

/* Mobile Responsive */
.mobile-only { display: none; }
@media (max-width: 900px) {
    .workspace { flex-direction: column; }
    .nav-rail {
        width: 100%;
        height: auto;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
        border-right: 0;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }
    .nav-header, .conn-pill, .nav-footer { display: none; }
    .nav-links { flex-direction: row; padding: 0.4rem; overflow-x: auto; }
    .nav-btn { width: auto; white-space: nowrap; padding: 0.48rem 0.7rem; font-size: 0.8rem; }
    .main-stage { height: calc(100vh - 50px); }
    .chat-list-col { width: 100%; }
    .chat-shell.has-active-chat .chat-list-col { display: none; }
    .chat-shell:not(.has-active-chat) .chat-main-col { display: none; }
    .chat-detail-drawer { position: fixed; inset: 0; width: 100%; z-index: 60; }
    .kanban-board { grid-template-columns: 1fr; }
    .mobile-only { display: inline-flex; }
}

