:root {
    --brand: #1f5fbf;
    --brand-dark: #173f7a;
    --brand-accent: #2e7d56;
    --bg: #eef4fb;
    --bg-gradient: linear-gradient(155deg, #e8f2fc 0%, #f3f7ff 38%, #eef8f1 72%, #e6f0fa 100%);
    --login-gradient: linear-gradient(145deg, #0c3566 0%, #1a5fbf 42%, #1e6b48 88%, #2e8b57 100%);
    --sidebar: #123a6e;
    --sidebar-active: #1f5fbf;
    --text: #1f2733;
    --muted: #6b7480;
    --border: #d8e2ef;
    --danger: #c0392b;
    --success: #1e7e44;
    --panel-bg: rgba(255, 255, 255, 0.92);
    --pattern-url: url('/images/task-bg-pattern.svg');
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg-gradient);
    background-attachment: fixed;
    color: var(--text);
    min-height: 100vh;
}

h1:focus {
    outline: none;
}

a {
    color: var(--brand);
}

/* ---------- Login ---------- */
.empty-layout {
    min-height: 100vh;
}

.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
    background: var(--login-gradient);
    background-attachment: fixed;
}

.login-wrapper::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: var(--pattern-url);
    background-size: 420px 420px;
    opacity: 0.45;
    pointer-events: none;
}

.login-wrapper::after {
    content: "✓";
    position: absolute;
    right: -20px;
    bottom: -40px;
    font-size: 220px;
    line-height: 1;
    color: rgba(255, 255, 255, 0.06);
    pointer-events: none;
    font-weight: 700;
}

.login-card {
    position: relative;
    z-index: 1;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(8px);
    width: 100%;
    max-width: 400px;
    padding: 36px 32px;
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(8, 35, 70, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.6);
}

.login-brand {
    text-align: center;
    margin-bottom: 24px;
}

.login-logo {
    width: 64px;
    height: 64px;
    margin: 0 auto 12px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--brand), var(--brand-accent));
    color: #fff;
    font-weight: 700;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(31, 95, 191, 0.35);
}

.login-brand h1 {
    font-size: 22px;
    margin: 0;
}

.login-sub {
    color: var(--muted);
    margin: 4px 0 0;
}

.login-card .form-group {
    margin-bottom: 16px;
}

.login-card label {
    font-weight: 600;
    margin-bottom: 6px;
    display: block;
}

.login-hint {
    text-align: center;
    color: var(--muted);
    margin-top: 18px;
    font-size: 13px;
}

/* ---------- Shell ---------- */
.page {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    background: linear-gradient(180deg, #123a6e 0%, #0c2f5c 55%, #0a2848 100%);
    color: #fff;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px rgba(12, 47, 92, 0.15);
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    background: var(--bg-gradient);
}

.main::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: var(--pattern-url);
    background-size: 360px 360px;
    opacity: 0.35;
    pointer-events: none;
    z-index: 0;
}

.topbar {
    height: 64px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    padding: 0 24px;
    position: relative;
    z-index: 1;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.user-name {
    font-weight: 600;
}

.user-role {
    color: var(--muted);
    font-size: 13px;
}

.content {
    padding: 24px;
    flex: 1;
    position: relative;
    z-index: 1;
}

/* ---------- Nav ---------- */
.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,.12);
}

.nav-logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #fff;
    color: var(--brand-dark);
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-title {
    font-weight: 700;
}

.nav-links {
    display: flex;
    flex-direction: column;
    padding: 12px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 20px;
    color: rgba(255,255,255,.85);
    text-decoration: none;
    font-weight: 500;
}

.nav-item:hover {
    background: rgba(255,255,255,.08);
    color: #fff;
}

.nav-item.active {
    background: var(--sidebar-active);
    color: #fff;
}

.nav-icon {
    font-size: 18px;
}

/* ---------- Generic UI ---------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 {
    font-size: 26px;
    margin: 0;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    box-shadow: 0 4px 18px rgba(23, 63, 122, 0.06);
    backdrop-filter: blur(4px);
}

.stat-card .stat-value {
    font-size: 32px;
    font-weight: 700;
}

.stat-card .stat-label {
    color: var(--muted);
}

.panel {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 18px rgba(23, 63, 122, 0.06);
    backdrop-filter: blur(4px);
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th, .table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.table th {
    color: var(--muted);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.badge-pill {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge-active { background: #e3f5ea; color: var(--success); }
.badge-inactive { background: #fdecea; color: var(--danger); }
.badge-admin { background: #e7efff; color: var(--brand); }
.badge-worker { background: #fff2e0; color: #b9700f; }
.badge-urgent { background: #fdecea; color: var(--danger); }

.toolbar {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 16px;
}

.workspace-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.workspace-tab {
    padding: 8px 16px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.85);
    cursor: pointer;
    font-weight: 600;
}

.workspace-tab.active {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}

.text-muted { color: var(--muted); }
.empty-state { text-align: center; padding: 40px; color: var(--muted); }

/* ---------- Modal ---------- */
.modal-backdrop-custom {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1050;
    padding: 16px;
}

.modal-card {
    background: #fff;
    border-radius: 14px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
}

.modal-card h2 {
    margin-top: 0;
}

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1100;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.loading-progress { display: none; }
.loading-progress-text { display: none; }

@media (max-width: 768px) {
    .page { flex-direction: column; }
    .sidebar { width: 100%; }
    .nav-links { flex-direction: row; overflow-x: auto; }
}

/* ---------- Toast notifications ---------- */
.toast-host {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(420px, calc(100vw - 32px));
    pointer-events: none;
}

.toast-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    background: #fff;
    border: 1px solid var(--border);
    border-left: 4px solid var(--brand);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
    pointer-events: auto;
    animation: toast-in .2s ease-out;
}

.toast-icon {
    flex-shrink: 0;
}

.toast-text {
    flex: 1;
    font-size: 14px;
    line-height: 1.4;
}

.toast-close {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.task-html-editor-host {
    min-height: 180px;
    background: #fff;
    border-radius: 8px;
}

.task-html-editor-host .sun-editor {
    border-radius: 8px;
    overflow: hidden;
}

.task-html-editor-host .sun-editor .se-wrapper {
    min-height: 200px;
}

.task-instruction-view {
    margin-top: 12px;
    background: #f8fafc;
}

.instruction-html-content {
    line-height: 1.6;
    color: var(--text);
}

.instruction-html-content img {
    max-width: 100%;
    border-radius: 8px;
}

.instruction-html-content video {
    max-width: 100%;
    border-radius: 8px;
}

.instruction-html-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
}

.instruction-html-content th,
.instruction-html-content td {
    border: 1px solid #d0d7de;
    padding: 6px 8px;
}

.instruction-thumb {
    max-width: 160px;
    max-height: 160px;
    border-radius: 8px;
    object-fit: cover;
}

.instruction-video {
    max-height: 320px;
    border-radius: 8px;
}

/* ---------- Chat (Zalo-like) ---------- */
.chat-shell {
    display: grid;
    grid-template-columns: 340px 1fr;
    gap: 0;
    min-height: calc(100vh - 120px);
    background: var(--panel-bg);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: 0 8px 32px rgba(18, 58, 110, 0.08);
}

.chat-sidebar {
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: #f8fbff;
}

.chat-sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.chat-conversation-list {
    overflow-y: auto;
    flex: 1;
}

.chat-conversation-item {
    display: grid;
    grid-template-columns: 48px 1fr auto;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    border-bottom: 1px solid #eef2f8;
    transition: background 0.15s;
}

.chat-conversation-item:hover,
.chat-conversation-item.active {
    background: #e8f1fc;
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--brand), var(--brand-accent));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    position: relative;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.chat-online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--success);
    border: 2px solid #fff;
}

.chat-conv-title {
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conv-preview {
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conv-meta {
    text-align: right;
    font-size: 12px;
    color: var(--muted);
}

.chat-unread-badge {
    display: inline-block;
    min-width: 20px;
    padding: 2px 6px;
    border-radius: 10px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    margin-top: 6px;
}

.chat-thread {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #fff;
}

.chat-thread-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 18px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: linear-gradient(180deg, #f5f9ff 0%, #fff 100%);
}

.chat-bubble-row {
    display: flex;
    gap: 8px;
    max-width: 75%;
}

.chat-bubble-row.mine {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    line-height: 1.45;
    word-break: break-word;
}

.chat-bubble-row:not(.mine) .chat-bubble {
    background: #fff;
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chat-bubble-row.mine .chat-bubble {
    background: #d9ecff;
    border-bottom-right-radius: 4px;
}

.chat-bubble-time {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}

.chat-composer {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 8px;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    align-items: end;
}

.chat-composer textarea {
    resize: none;
    min-height: 44px;
    max-height: 120px;
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 10px 12px;
    font-family: inherit;
}

.chat-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    padding: 40px;
    text-align: center;
}

.chat-contact-picker {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.chat-contact-panel {
    background: #fff;
    border-radius: 16px;
    width: min(420px, 92vw);
    max-height: 70vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chat-contact-list {
    overflow-y: auto;
    padding: 8px;
}

.chat-contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 10px;
    cursor: pointer;
}

.chat-contact-item:hover {
    background: #eef4fb;
}

.call-incoming-banner {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    background: #fff;
    border: 1px solid #d0d7de;
    border-radius: 12px;
    padding: 12px 16px;
    display: flex;
    gap: 16px;
    align-items: center;
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
}

.call-overlay {
    position: fixed;
    inset: 0;
    z-index: 2100;
    background: rgba(10, 14, 20, .72);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.call-panel {
    width: min(920px, 100%);
    background: #1b2430;
    color: #fff;
    border-radius: 16px;
    padding: 16px;
}

.call-title {
    display: flex;
    justify-content: space-between;
    margin-bottom: 12px;
    font-weight: 600;
}

.call-remote-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
    min-height: 180px;
    margin-bottom: 12px;
}

.call-local-video {
    width: 160px;
    height: 120px;
    object-fit: cover;
    border-radius: 12px;
    background: #000;
    margin-bottom: 12px;
}

.call-audio-placeholder {
    padding: 48px 16px;
    text-align: center;
    font-size: 18px;
    opacity: .85;
}

.call-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.chat-call-system {
    font-style: italic;
    opacity: .9;
}

@media (max-width: 900px) {
    .chat-shell {
        grid-template-columns: 1fr;
    }

    .chat-sidebar.hidden-mobile {
        display: none;
    }
}
