:root {
    --bg: #f4f6f9;
    --card: #fff;
    --text: #1a2332;
    --muted: #5c6b7a;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --border: #dde3ea;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --critical: #7c3aed;
    --tagline: #1a5c38;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: "Segoe UI", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.5rem 1.5rem;
    background: #fff;
    color: var(--text);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 200;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.brand-block {
    display: flex;
    align-items: center;
    text-decoration: none;
    flex-shrink: 0;
}
.brand-logo {
    height: 44px;
    width: auto;
    display: block;
}
.topbar .brand-logo-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
}
.login-brand {
    text-align: center;
    margin-bottom: 1.5rem;
}
.brand-block-login {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.65rem;
}
.brand-logo-symbol {
    width: 120px;
    height: 120px;
    object-fit: contain;
    display: block;
}
.brand-wordmark {
    display: inline-block;
    max-width: 100%;
}
.brand-title {
    font-family: "Montserrat", "Segoe UI", system-ui, sans-serif;
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    line-height: 1.1;
    color: #111827;
    text-align: center;
    white-space: nowrap;
}
.brand-tagline-login {
    font-family: "Segoe UI", system-ui, sans-serif;
    font-size: 0.72rem;
    font-weight: 400;
    color: #9ca3af;
    text-align: center;
    white-space: nowrap;
    margin-top: 0.35rem;
    letter-spacing: 0.01em;
    line-height: 1.2;
    width: 100%;
}
.login-brand .brand-logo {
    height: 200px;
    max-width: 100%;
    width: auto;
    margin: 0 auto 0.75rem;
}
.login-card { max-width: 480px; }
.login-subtitle { margin: 0 0 0.5rem; font-size: 1.15rem; text-align: center; }
.totp-setup { display: flex; gap: 1.5rem; flex-wrap: wrap; align-items: flex-start; margin: 1rem 0; }
.totp-qr { border: 1px solid var(--border); border-radius: 8px; }
.totp-secret { word-break: break-all; font-size: 0.9rem; }
.backup-codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr)); gap: 0.5rem; list-style: none; padding: 0; margin: 1rem 0; }
.backup-codes code { display: block; padding: 0.35rem 0.5rem; background: #f8fafc; border-radius: 4px; text-align: center; }
.setup-steps { margin: 0 0 1rem 1.25rem; }
.form label.checkbox { display: flex; align-items: center; gap: 0.5rem; font-weight: 500; }
.form label.checkbox input { width: auto; margin: 0; }
.muted.small { font-size: 0.85rem; margin-top: 1rem; }
.form.inline-form { max-width: 28rem; }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar nav a { color: var(--muted); text-decoration: none; font-weight: 600; }
.topbar nav a.active, .topbar nav a:hover { color: var(--text); }
.topbar .user { display: flex; gap: 1rem; align-items: center; font-size: 0.9rem; }
.topbar .user a { color: var(--primary); }

.container { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}
.page-header h1 { margin: 0; font-size: 1.5rem; }
.page-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.card-flush { margin-bottom: 0; }
.card-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}
.card-toolbar h2 { margin: 0; font-size: 1.1rem; }
.legend-inline {
    display: flex;
    gap: 1.25rem;
    flex-wrap: wrap;
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.88rem;
    color: var(--muted);
    align-items: center;
}
.legend-inline li { display: flex; align-items: center; gap: 0.45rem; }
.legend-inline .badge.group { margin: 0; }

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal.is-open { display: flex; }
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}
.modal-dialog {
    position: relative;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1.25rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
    padding: 0 0.25rem;
}
.modal-close:hover { color: var(--text); }
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}
body.modal-open { overflow: hidden; }

.modal-dialog-wide { max-width: 520px; }
.modal-dialog-create { max-width: 640px; }
.modal-dialog-create fieldset {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    margin: 0.75rem 0 0;
}
.modal-dialog-create fieldset legend {
    font-weight: 600;
    padding: 0 0.35rem;
}

.gantt-task-detail { font-size: 0.9rem; }
.gantt-task-detail dl {
    display: grid;
    grid-template-columns: 7.5rem 1fr;
    gap: 0.35rem 0.75rem;
    margin: 0 0 1rem;
}
.gantt-task-detail dt {
    margin: 0;
    color: var(--muted);
    font-weight: 600;
}
.gantt-task-detail dd { margin: 0; }
.gantt-task-desc {
    margin: 0 0 1rem;
    padding: 0.65rem 0.75rem;
    background: #f8fafc;
    border-radius: 6px;
    white-space: pre-wrap;
}
.gantt-task-deps { margin: 0; padding-left: 1.1rem; }
.gantt-task-deps li { margin-bottom: 0.25rem; }
.gantt-badge {
    display: inline-block;
    padding: 0.1rem 0.45rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
}
.gantt-badge.critical { background: #ede9fe; color: #5b21b6; }
.gantt-badge.group { background: #e2e8f0; color: #475569; }
.gantt-badge.milestone { background: #fef3c7; color: #92400e; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.card.narrow { max-width: 420px; margin: 4rem auto; }
.card h2 { margin: 0 0 1rem; font-size: 1.1rem; }

.subtitle { color: var(--muted); margin-top: -0.5rem; }

.form label { display: block; margin-bottom: 0.75rem; font-size: 0.9rem; font-weight: 600; }
.form input, .form select, .form textarea {
    display: block; width: 100%; margin-top: 0.25rem;
    padding: 0.5rem 0.65rem; border: 1px solid var(--border);
    border-radius: 6px; font: inherit;
}
.form.compact label { margin-bottom: 0.5rem; }
.task-type-fieldset {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.65rem 0.85rem;
    margin: 0.5rem 0 0.75rem;
}
.task-type-fieldset legend {
    font-weight: 600;
    padding: 0 0.35rem;
}
.task-type-options {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 1.25rem;
    align-items: center;
}
.task-type-default { font-size: 0.8rem; color: var(--muted); }
.form .row { display: flex; gap: 1rem; flex-wrap: wrap; }
.form .row label { flex: 1; min-width: 120px; }
.form .check { font-weight: 500; display: flex; align-items: center; gap: 0.4rem; }
.form .check input { width: auto; margin: 0; }
.input-short { max-width: 5rem; }

.btn, button.btn {
    display: inline-block; padding: 0.5rem 1rem;
    border-radius: 6px; border: 1px solid var(--border);
    background: #fff; color: var(--text); text-decoration: none;
    cursor: pointer; font: inherit;
}
.btn.primary, button.btn.primary {
    background: var(--primary); color: #fff; border-color: var(--primary);
}
.btn.danger, button.btn.danger {
    background: var(--danger); color: #fff; border-color: var(--danger);
}
.btn.danger:hover { filter: brightness(1.05); }
.btn.danger:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn.primary:hover { background: var(--primary-hover); }
button.link { background: none; border: none; color: var(--primary); cursor: pointer; padding: 0; font: inherit; }
button.link.danger { color: var(--danger); }
form.inline { display: inline; }

.alert.error {
    background: #fef2f2; color: var(--danger);
    border: 1px solid #fecaca; padding: 0.6rem 0.8rem;
    border-radius: 6px; margin-bottom: 1rem;
}
.alert.success {
    background: #ecfdf5; color: #065f46;
    border: 1px solid #a7f3d0; padding: 0.6rem 0.8rem;
    border-radius: 6px; margin-bottom: 1rem;
}
.alert-warn {
    background: #fffbeb; color: #92400e;
    border: 1px solid #fcd34d; padding: 0.6rem 0.8rem;
    border-radius: 6px; margin-bottom: 1rem;
}
.alert-warn code { font-size: 0.85em; }
.hint { font-size: 0.85rem; color: var(--muted); margin-top: 0.5rem; margin-bottom: 0.75rem; }
.schedule-readonly input[disabled] {
    background: #f8fafc;
    color: var(--text);
    cursor: default;
}

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.data th, table.data td { padding: 0.55rem 0.65rem; border-bottom: 1px solid var(--border); text-align: left; }
table.data th { background: #f8fafc; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dep-table-wrap { overflow-x: auto; margin-top: 0.5rem; }
.dep-table select { width: 100%; min-width: 4.5rem; padding: 0.35rem; font: inherit; }
.dep-table td, .dep-table th { vertical-align: middle; }
.row-group td:first-child { font-weight: 600; }
.tree-row-hidden { display: none; }
.tree-drag-handle {
    display: inline-block;
    width: 1.1rem;
    margin-right: 0.25rem;
    color: #94a3b8;
    cursor: grab;
    user-select: none;
    vertical-align: middle;
    line-height: 1;
    font-size: 0.95rem;
}
.tree-drag-handle:active { cursor: grabbing; }
.tree-drag-handle.is-disabled {
    opacity: 0.35;
    cursor: not-allowed;
}
.tree-drag-handle.legend-handle {
    width: auto;
    margin-right: 0.35rem;
    cursor: default;
}
tr.is-dragging { opacity: 0.45; }
tr.drag-over td { box-shadow: inset 0 2px 0 0 var(--primary); }
.task-tree td:first-child { white-space: nowrap; }
.tree-group-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: none;
    border: none;
    font: inherit;
    font-weight: 600;
    color: inherit;
    cursor: pointer;
    padding: 0;
    text-align: left;
    max-width: 100%;
}
.tree-group-toggle:hover .tree-group-name { color: var(--primary); }
.tree-chevron {
    display: inline-block;
    width: 0.85rem;
    font-size: 0.65rem;
    color: var(--muted);
    transition: transform 0.15s ease;
    flex-shrink: 0;
}
.tree-group-toggle.is-open .tree-chevron { transform: rotate(90deg); }
.tree-group-name { line-height: 1.3; }
.row-done { opacity: 0.65; }
.row-critical { background: #faf5ff; }
.badge.group { font-size: 0.7rem; background: #e0e7ff; color: #3730a3; padding: 0.1rem 0.35rem; border-radius: 4px; margin-right: 0.35rem; }
.badge.milestone { font-size: 0.7rem; background: #fef3c7; color: #92400e; padding: 0.1rem 0.35rem; border-radius: 4px; margin-right: 0.35rem; }
.badge.overdue { font-size: 0.7rem; background: #fee2e2; color: #991b1b; padding: 0.1rem 0.35rem; border-radius: 4px; margin-left: 0.25rem; }
.row-overdue:not(.row-done) { background: #fff1f2; }
.task-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    align-items: flex-end;
}
.task-filters label {
    margin-bottom: 0;
    font-size: 0.88rem;
    min-width: 8rem;
}
.task-filters select {
    display: block;
    width: 100%;
    min-width: 9rem;
    margin-top: 0.25rem;
    padding: 0.45rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
}
.task-filters .filter-overdue {
    min-width: auto;
    padding-bottom: 0.45rem;
}
.actions { white-space: nowrap; }

.legend ul { list-style: none; padding: 0; margin: 0; }
.legend li { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }
.dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.dot.critical { background: var(--critical); }
.dot.done { background: var(--success); }
.dot.open { background: var(--primary); }

fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin: 1rem 0; }
fieldset legend { font-weight: 600; padding: 0 0.4rem; }

.gantt-toolbar { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.gantt-toolbar label { font-size: 0.9rem; font-weight: 600; }
.gantt-toolbar select { margin-left: 0.35rem; padding: 0.35rem; }

.doc-search-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
}
.doc-search-form label { flex: 1; min-width: 220px; margin-bottom: 0; }

.doc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.doc-list-item {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--border);
}
.doc-list-item:last-child { border-bottom: none; }
.doc-list-main {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
    flex: 1;
}
.doc-list-meta { font-size: 0.82rem; color: var(--muted); }
.doc-list-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}
.doc-list-compact .doc-list-item { padding: 0.45rem 0; }
.doc-preview-thumb {
    flex-basis: 100%;
    margin-top: 0.35rem;
}
.doc-preview-thumb img {
    max-width: 100%;
    max-height: 180px;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.task-documents-body { min-height: 4rem; }
.task-documents-fieldset { margin-top: 1rem; }

.activity-feed { display: flex; flex-direction: column; gap: 0; }
.activity-item {
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    font-size: 0.82rem;
    color: var(--muted);
    margin-bottom: 0.35rem;
}
.activity-meta time { font-variant-numeric: tabular-nums; }
.activity-user { font-weight: 600; color: var(--text); }
.activity-main {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 0.75rem;
    align-items: baseline;
}
.activity-action { font-size: 0.95rem; }
.activity-entity a { font-weight: 600; }
.activity-changes {
    list-style: none;
    margin: 0.5rem 0 0;
    padding: 0.65rem 0.75rem;
    background: #f8fafc;
    border-radius: 6px;
    font-size: 0.88rem;
}
.activity-changes li { margin-bottom: 0.3rem; }
.activity-changes li:last-child { margin-bottom: 0; }
.activity-field { font-weight: 600; color: var(--muted); margin-right: 0.35rem; }
.activity-old { color: #94a3b8; text-decoration: line-through; }
.activity-arrow { margin: 0 0.35rem; color: var(--muted); }
.activity-new { font-weight: 600; }
.activity-context { color: var(--muted); font-size: 0.9rem; }
.activity-context a { font-weight: 600; }
.activity-document_uploaded .activity-action { color: #0369a1; }
.activity-document_downloaded .activity-action { color: #0f766e; }
.activity-document_viewed .activity-action { color: #7c3aed; }
.activity-document_deleted .activity-action { color: var(--danger); }
.activity-task_deleted .activity-action { color: var(--danger); }

.task-delete-body p { margin-top: 0; }
.task-delete-warn { margin: 0.75rem 0; }
.task-delete-download-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin: 0.75rem 0;
}
.task-delete-consent {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-top: 1rem;
    font-weight: 500;
}
.task-delete-consent input { margin-top: 0.2rem; }
