:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --ink: #17202a;
    --muted: #667085;
    --subtle: #98a2b3;
    --line: #d9e0ea;
    --line-soft: #edf1f6;
    --accent: #0f766e;
    --accent-strong: #115e59;
    --accent-soft: #e7f5f2;
    --blue: #2563eb;
    --blue-soft: #e8f0ff;
    --amber: #b7791f;
    --amber-soft: #fff6df;
    --danger: #b42318;
    --danger-soft: #fff1f0;
    --success: #067647;
    --success-soft: #ecfdf3;
    --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
    --shadow-soft: 0 1px 2px rgba(15, 23, 42, 0.06);
    --radius: 8px;
}

* {
    letter-spacing: 0;
}

body.auth-page,
body.app-page {
    color: var(--ink);
    background:
        linear-gradient(180deg, rgba(231, 245, 242, 0.72), rgba(245, 247, 251, 0) 340px),
        var(--bg);
}

body.auth-page {
    align-items: center;
    padding: 24px;
}

.auth-page .container {
    width: min(420px, 100%);
    padding: 32px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.brand-mark {
    width: 44px;
    height: 44px;
    margin: 0 auto 14px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-weight: 800;
    font-size: 14px;
    border: 1px solid rgba(15, 118, 110, 0.22);
}

.auth-page h1 {
    font-size: 24px;
}

.auth-page .subtitle {
    color: var(--muted);
}

.auth-page input,
.auth-page select,
.search-form input,
.chat-input input,
.upload-controls select {
    border-color: var(--line);
    border-radius: var(--radius);
    color: var(--ink);
}

.auth-page input:focus,
.auth-page select:focus,
.search-form input:focus,
.chat-input input:focus,
.upload-controls select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.auth-page button[type="submit"],
.btn,
.btn-primary,
.btn-green,
.chat-input button {
    border-radius: var(--radius);
}

.btn {
    min-height: 38px;
    padding: 9px 14px;
    border: 1px solid transparent;
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.auth-page button[type="submit"],
.btn-primary,
.btn-green,
.chat-input button {
    background: var(--accent);
    color: #fff;
}

.auth-page button[type="submit"]:hover,
.btn-primary:hover,
.btn-green:hover,
.chat-input button:hover {
    background: var(--accent-strong);
}

.btn-primary:disabled,
.btn-green:disabled,
.chat-input button:disabled {
    background: var(--line);
    color: var(--muted);
    cursor: not-allowed;
}

.auth-page .links a,
.back-link,
.chat-msg.bot a {
    color: var(--accent);
}

.auth-page .lang-switch {
    border: 1px solid var(--line);
    background: var(--surface-muted);
}

.header {
    background: rgba(255, 255, 255, 0.94);
    color: var(--ink);
    border-bottom: 1px solid var(--line);
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(10px);
}

.header h1 {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--ink);
}

.header h1::before {
    content: "MC";
    width: 30px;
    height: 30px;
    display: inline-grid;
    place-items: center;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 11px;
    font-weight: 800;
    border: 1px solid rgba(15, 118, 110, 0.22);
}

.user-badge,
.lang-switch,
.logout-btn,
.nav-link {
    background: var(--surface-muted);
    color: var(--ink);
    border: 1px solid var(--line);
}

.lang-switch:hover,
.logout-btn:hover,
.nav-link:hover {
    background: var(--accent-soft);
    border-color: rgba(15, 118, 110, 0.35);
}

.nav-link {
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: var(--radius);
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
}

.container {
    max-width: 1220px;
}

.stats {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.stat-card,
.section,
.dept-header,
.modal,
.chat-panel {
    border-radius: var(--radius);
    border: 1px solid var(--line-soft);
    box-shadow: var(--shadow-soft);
}

.stat-card {
    padding: 20px;
}

.stat-card:hover {
    transform: translateY(-1px);
    border-color: rgba(15, 118, 110, 0.35);
    box-shadow: var(--shadow);
}

.stat-card h3,
.section h2,
.section h3 {
    color: var(--ink);
}

.stat-card .number {
    color: var(--accent);
}

.stat-card .arrow {
    color: var(--accent);
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    background: var(--accent-soft);
}

.stat-card .arrow::before {
    content: "";
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg);
}

.upload-zone {
    background: var(--surface-muted);
    border-color: var(--line);
}

.upload-zone:hover,
.upload-zone.dragover {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.upload-glyph,
.empty-state-mark,
.file-type-badge,
.chat-avatar {
    display: grid;
    place-items: center;
    font-weight: 800;
}

.upload-glyph {
    width: 56px;
    height: 40px;
    margin: 0 auto 12px;
    border-radius: 8px;
    background: var(--surface);
    color: var(--accent);
    border: 1px solid var(--line);
    font-size: 12px;
}

.empty-state-mark {
    width: 42px;
    height: 32px;
    margin: 0 auto 10px;
    border-radius: 8px;
    background: var(--surface-muted);
    color: var(--muted);
    border: 1px solid var(--line);
    font-size: 11px;
}

.file-type-badge {
    width: 42px;
    height: 30px;
    border-radius: 8px;
    margin-right: 12px;
    font-size: 11px;
    flex-shrink: 0;
    border: 1px solid transparent;
}

.file-type-badge.excel {
    background: var(--success-soft);
    color: var(--success);
    border-color: rgba(6, 118, 71, 0.18);
}

.file-type-badge.word {
    background: var(--blue-soft);
    color: var(--blue);
    border-color: rgba(37, 99, 235, 0.18);
}

.file-type-badge.other {
    background: var(--amber-soft);
    color: var(--amber);
    border-color: rgba(183, 121, 31, 0.2);
}

.upload-status.success {
    background: var(--success-soft);
    color: var(--success);
    border-color: rgba(6, 118, 71, 0.2);
}

.upload-status.error {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: rgba(180, 35, 24, 0.2);
}

.upload-status.loading {
    background: var(--blue-soft);
    color: var(--blue);
    border-color: rgba(37, 99, 235, 0.2);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    background: currentColor;
}

.progress-bar .fill {
    background: var(--accent);
}

.result-item:hover,
.docs-table tbody tr:hover {
    background: var(--accent-soft);
    border-color: rgba(15, 118, 110, 0.35);
}

.modal-overlay {
    background: rgba(15, 23, 42, 0.5);
}

.modal-close {
    color: var(--muted);
}

.modal-body h3,
.doc-section {
    color: var(--accent);
}

.doc-section {
    background: var(--accent-soft);
    border-radius: 6px;
}

.dept-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 24px;
    align-items: end;
}

.dept-kicker {
    margin-bottom: 8px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.dept-metrics,
.department-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    gap: 12px;
}

.dept-metric,
.summary-metric {
    padding: 12px 14px;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    background: var(--surface-muted);
}

.dept-metric strong,
.summary-metric strong {
    display: block;
    color: var(--ink);
    font-size: 18px;
    line-height: 1.2;
}

.dept-metric span,
.summary-metric span {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.department-docs-section {
    display: grid;
    gap: 18px;
}

.department-docs-section h3 {
    margin: 0;
    padding: 0;
    border: 0;
}

.section-top {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line-soft);
}

.section-subtitle {
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
}

.dept-toolbar {
    width: min(360px, 100%);
}

.dept-search {
    width: 100%;
    min-height: 40px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
}

.dept-search:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.department-summary {
    padding: 12px;
    border-radius: var(--radius);
    background: var(--surface-muted);
    border: 1px solid var(--line-soft);
}

.department-summary[hidden] {
    display: none;
}

.doc-card-list {
    display: grid;
    gap: 12px;
}

.doc-card {
    display: grid;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    background: var(--surface);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.doc-card:hover {
    border-color: rgba(15, 118, 110, 0.35);
    box-shadow: var(--shadow-soft);
    transform: translateY(-1px);
}

.doc-card-header {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.doc-card-title-block {
    min-width: 0;
    flex: 1;
}

.doc-card-title-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
}

.doc-card h4 {
    margin: 0;
    color: var(--ink);
    font-size: 15px;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.doc-card-meta,
.doc-card-stats,
.doc-card-footer,
.preview-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.doc-card-meta {
    margin-top: 5px;
    color: var(--muted);
    font-size: 12px;
}

.doc-card-stats {
    padding: 10px 0;
    border-top: 1px solid var(--line-soft);
    border-bottom: 1px solid var(--line-soft);
}

.doc-pill,
.section-pill {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 9px;
    border-radius: 999px;
    background: var(--surface-muted);
    color: var(--muted);
    border: 1px solid var(--line-soft);
    font-size: 12px;
    font-weight: 600;
}

.section-pill {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: rgba(15, 118, 110, 0.16);
}

.preview-list {
    display: grid;
    gap: 8px;
}

.preview-title {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.preview-row {
    align-items: flex-start;
    padding: 10px;
    border-radius: var(--radius);
    background: var(--surface-muted);
}

.preview-row p {
    flex: 1;
    min-width: 220px;
    margin: 0;
    color: #344054;
    font-size: 13px;
    line-height: 1.45;
}

.doc-card-footer {
    justify-content: flex-end;
}

.btn-secondary {
    background: var(--surface);
    color: var(--accent);
    border: 1px solid rgba(15, 118, 110, 0.24);
}

.btn-secondary:hover {
    background: var(--accent-soft);
    border-color: rgba(15, 118, 110, 0.4);
}

.admin-shell {
    display: grid;
    gap: 20px;
    min-width: 0;
}

.admin-hero {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(520px, 0.9fr);
    gap: 24px;
    align-items: end;
    min-width: 0;
}

.admin-section {
    display: grid;
    gap: 18px;
    min-width: 0;
}

.admin-section h3 {
    margin: 0;
    padding: 0;
    border: 0;
}

.admin-hero > *,
.admin-section > *,
.section-top > *,
.top-user-row > * {
    min-width: 0;
}

.admin-filters {
    width: min(720px, 100%);
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(150px, 0.6fr) minmax(150px, 0.6fr) auto;
    gap: 10px;
    min-width: 0;
}

.top-users {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.top-user-row {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(120px, 0.35fr) minmax(180px, 0.55fr);
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    background: var(--surface-muted);
}

.top-user-row strong {
    display: block;
    color: var(--ink);
    font-size: 14px;
}

.top-user-row span {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 12px;
}

.audit-table-wrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
}

.audit-table {
    width: 100%;
    min-width: 960px;
    border-collapse: collapse;
}

.audit-table th,
.audit-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--line-soft);
    font-size: 13px;
    vertical-align: top;
}

.audit-table th {
    background: var(--surface-muted);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.audit-table tbody tr:hover {
    background: var(--accent-soft);
}

.agent-cell {
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
}

.status-badge {
    display: inline-flex;
    min-height: 24px;
    align-items: center;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}

.status-badge.success {
    background: var(--success-soft);
    color: var(--success);
}

.status-badge.failed {
    background: var(--danger-soft);
    color: var(--danger);
}

.chat-fab {
    width: 58px;
    height: 58px;
    background: var(--accent);
    box-shadow: 0 12px 30px rgba(15, 118, 110, 0.28);
    font-size: 14px;
    font-weight: 800;
}

.chat-fab:hover {
    background: var(--accent-strong);
    box-shadow: 0 16px 36px rgba(15, 118, 110, 0.32);
}

.chat-fab.active {
    transform: none;
}

.chat-header {
    background: var(--ink);
}

.chat-avatar {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    font-size: 11px;
}

.chat-msg.user {
    background: var(--accent);
}

.chat-input button {
    width: auto;
    min-width: 92px;
    padding: 0 14px;
    font-size: 13px;
    font-weight: 700;
}

.chat-suggestions button:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-soft);
}

.docs-table th {
    background: var(--surface-muted);
}

@media (max-width: 760px) {
    body.auth-page {
        align-items: stretch;
        padding: 16px;
    }

    .auth-page .container {
        margin: auto 0;
        padding: 24px;
    }

    .header {
        padding: 14px 16px;
        align-items: flex-start;
        gap: 12px;
        flex-direction: column;
    }

    .user-info {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .container {
        margin: 16px auto;
        padding: 0 14px;
    }

    .section,
    .dept-header {
        padding: 18px;
    }

    .dept-hero,
    .admin-hero,
    .section-top {
        grid-template-columns: 1fr;
        flex-direction: column;
        align-items: stretch;
    }

    .dept-metrics,
    .department-summary {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .doc-card-title-row,
    .doc-card-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .admin-filters,
    .top-user-row {
        grid-template-columns: 1fr;
    }

    .preview-row p {
        min-width: 0;
    }

    .upload-controls,
    .search-form {
        flex-direction: column;
        align-items: stretch;
    }

    .chat-panel {
        left: 12px;
        right: 12px;
        bottom: 86px;
        width: auto;
        height: min(560px, calc(100vh - 112px));
    }

    .chat-fab {
        right: 16px;
        bottom: 16px;
    }

    .docs-table {
        min-width: 760px;
    }

    #documentsList {
        overflow-x: auto;
    }
}
