:root {
    --bg: #f4f5f7;
    --panel: #ffffff;
    --input-bg: #ffffff;
    --border: #e2e4e9;
    --text: #1f2430;
    --text-muted: #6b7280;
    --primary: #2f5fed;
    --primary-dark: #1f45c4;
    --success: #1a9e5c;
    --error: #d94848;
    --success-bg: #e6f6ee;
    --error-bg: #fbe9e9;
    --info-bg: #eaf0fe;
    --low: #6b7280;
    --medium: #c07a1a;
    --high: #d94848;
    --open: #6b7280;
    --progress: #2f5fed;
    --blocked: #b0413e;
    --completed: #1a9e5c;
    --deprecated: #8b8f9a;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(20, 22, 28, 0.06);
}

[data-theme="dark"] {
    --bg: #14161c;
    --panel: #1c1f28;
    --input-bg: #22252f;
    --border: #2e3240;
    --text: #e7e9ee;
    --text-muted: #9aa1b2;
    --primary: #6f8fff;
    --primary-dark: #8ba3ff;
    --success: #3fca8b;
    --error: #f47272;
    --success-bg: #16301f;
    --error-bg: #3a1c1c;
    --info-bg: #1b2440;
    --low: #8a93a3;
    --medium: #e0a349;
    --high: #f47272;
    --open: #8a93a3;
    --progress: #6f8fff;
    --blocked: #e0605c;
    --completed: #3fca8b;
    --deprecated: #6b7280;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    transition: background-color 0.15s ease, color 0.15s ease;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}
.container-narrow { max-width: 720px; }

/* Top nav */
.topbar {
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}
.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 24px;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 16px; flex: 1; }
.topbar nav a { color: var(--text-muted); font-weight: 500; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; color: var(--text-muted); }

/* Auth pages */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    position: relative;
}
.auth-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 360px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 1.3rem; }
.auth-card h2 { margin: 0 0 20px; font-size: 1rem; color: var(--text-muted); font-weight: 500; }
.auth-link { margin-top: 16px; font-size: 0.9rem; }

/* Forms */
label {
    display: block;
    margin-bottom: 14px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}
input[type=text], input[type=email], input[type=password], select, textarea {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text);
    background: var(--input-bg);
}
textarea { resize: vertical; }
.required { color: var(--error); font-weight: 400; }
.optional { color: var(--text-muted); font-weight: 400; }

.btn {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.btn:hover { text-decoration: none; background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: transparent; border-color: var(--error); color: var(--error); }
.btn-danger:hover { background: var(--error-bg); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-active { background: var(--text); border-color: var(--text); color: var(--bg); }

/* Alerts */
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 0.9rem; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--error-bg); color: var(--error); }
.alert-info { background: var(--info-bg); color: var(--primary); }

/* Theme toggle */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
}
.theme-toggle:hover { background: var(--bg); color: var(--text); }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.auth-theme-toggle { position: absolute; top: 20px; right: 20px; }

/* Dashboard user cards */
.user-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 28px;
}
.user-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    color: var(--text);
}
.user-card:hover { text-decoration: none; border-color: var(--primary); }
.user-card.active { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.user-card-name { font-weight: 700; margin-bottom: 8px; }
.user-card-stats { display: flex; flex-direction: column; gap: 3px; font-size: 0.8rem; color: var(--text-muted); }
.stat-blocked { color: var(--blocked); font-weight: 600; }

/* Task list */
.task-list-section { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.task-list-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.task-list-header h2 { margin: 0; font-size: 1.1rem; }
.task-count { color: var(--text-muted); font-weight: 400; font-size: 0.9rem; }
.task-list-filters { display: flex; gap: 6px; flex-wrap: wrap; }

.task-table { width: 100%; border-collapse: collapse; }
.task-table th, .task-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.task-table th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.sort-th { color: inherit; user-select: none; white-space: nowrap; }
.sort-th:hover { color: var(--text); text-decoration: none; }
.sort-th.active-sort { color: var(--primary); }
.empty-row { text-align: center; color: var(--text-muted); padding: 24px; }

/* Badges */
.badge { display: inline-block; padding: 3px 9px; border-radius: 100px; font-size: 0.75rem; font-weight: 600; color: #fff; white-space: nowrap; }
.badge-weight-low { background: var(--low); }
.badge-weight-medium { background: var(--medium); }
.badge-weight-high { background: var(--high); }
.badge-status-open { background: var(--open); }
.badge-status-in_progress { background: var(--progress); }
.badge-status-blocked { background: var(--blocked); }
.badge-status-completed { background: var(--completed); }
.badge-status-deprecated { background: var(--deprecated); text-decoration: line-through; }

/* Task detail */
.back-link { display: inline-block; margin-bottom: 14px; font-size: 0.9rem; }
.task-header { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.task-header h1 { margin: 0; }
.task-badges { display: flex; gap: 8px; }
.task-description { color: var(--text-muted); margin: 14px 0; }
.task-meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 20px 0; font-size: 0.9rem; }
.task-meta dt { color: var(--text-muted); }
.task-meta dd { margin: 0; }

.action-panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin: 24px 0; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.panel h3 { margin-top: 0; font-size: 0.95rem; }

/* Journal */
.journal h3 { margin-bottom: 10px; }
.journal-list { list-style: none; padding: 0; margin: 0; }
.journal-entry {
    background: var(--panel);
    border: 1px solid var(--border);
    border-left: 3px solid var(--primary);
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 8px;
    font-size: 0.9rem;
}
.journal-meta { color: var(--text-muted); font-size: 0.8rem; margin-bottom: 4px; }
.journal-change { font-weight: 600; margin-bottom: 4px; }
.journal-note { color: var(--text); }

@media (max-width: 640px) {
    .topbar-inner { flex-wrap: wrap; }
    .task-table { font-size: 0.8rem; }
    .task-table th:nth-child(5), .task-table td:nth-child(5) { display: none; }
}

/* Quick add (My Tasks landing page) */
.quick-add-panel { margin-bottom: 24px; }
.quick-add-panel h3 { margin-top: 0; }
.quick-add-form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}
.quick-add-form input[type=text] {
    flex: 1 1 220px;
    margin-top: 0;
}
.quick-add-form select,
.quick-add-form input[type=date] {
    width: auto;
    margin-top: 0;
    flex: 0 0 auto;
}
.quick-add-form .btn { flex: 0 0 auto; }

/* My Tasks cards */
.my-task-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-left: 3px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 8px;
}
.my-task-card.overdue { border-left-color: var(--error); }

.my-task-title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.my-task-title-row .my-task-title { flex: 1 1 auto; min-width: 0; }
.my-task-title-row .badge { flex: 0 0 auto; }
.my-task-title { font-weight: 600; color: var(--text); font-size: 0.95rem; line-height: 1.3; }
.my-task-title:hover { color: var(--primary); }

.my-task-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 5px; font-size: 0.78rem; }
.my-task-from { color: var(--text-muted); }

.due-chip {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 100px;
    font-size: 0.72rem;
    font-weight: 600;
    background: var(--bg);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.due-chip.overdue { background: var(--error-bg); color: var(--error); border-color: transparent; }
.overdue-cell { color: var(--error); font-weight: 600; }

.quick-status-form {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}
.quick-status-form select {
    width: auto;
    flex: 0 0 auto;
    margin-top: 0;
    font-size: 0.82rem;
    padding: 5px 6px;
}
.quick-status-form input[type=text] {
    flex: 1 1 auto;
    min-width: 0;
    margin-top: 0;
    font-size: 0.82rem;
    padding: 5px 8px;
}
.quick-status-form .btn { flex: 0 0 auto; }

.sort-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
    font-size: 0.82rem;
}
.sort-row-label { color: var(--text-muted); font-weight: 600; }
.sort-link { color: var(--text-muted); font-weight: 500; }
.sort-link:hover { color: var(--text); text-decoration: none; }
.sort-link.active-sort { color: var(--primary); font-weight: 700; }

/* Company page */
.form-section-title {
    margin: 20px 0 8px;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    padding-top: 16px;
}
.form-section-title:first-of-type { border-top: none; padding-top: 0; }

.member-list { list-style: none; padding: 0; margin: 12px 0 0; }
.member-list li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.member-list li:last-child { border-bottom: none; }

.inline-form { display: flex; gap: 8px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.inline-form input[type=text] { margin-top: 0; width: auto; flex: 1 1 200px; }

.cell-form { display: inline-block; }
.cell-form select { margin-top: 0; width: auto; font-size: 0.85rem; padding: 5px 6px; }

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}
.pagination-status { font-size: 0.85rem; color: var(--text-muted); }
.btn-disabled { opacity: 0.4; cursor: default; pointer-events: none; }

/* Sub task checklist */
.subtasks { margin: 0; }
.subtask-list { list-style: none; padding: 0; margin: 0 0 12px; }
.subtask-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--panel);
    margin-bottom: 6px;
}
.subtask-toggle-form { flex: 1; min-width: 0; }
.subtask-checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    font-weight: 400;
    font-size: 0.92rem;
    color: var(--text);
    cursor: pointer;
}
.subtask-checkbox-label input[type=checkbox] { width: 16px; height: 16px; margin: 0; flex: 0 0 auto; cursor: pointer; }
.subtask-item.complete .subtask-checkbox-label span { color: var(--text-muted); text-decoration: line-through; }
.subtask-delete-form { flex: 0 0 auto; }
.subtask-delete-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}
.subtask-delete-btn:hover { color: var(--error); background: var(--error-bg); }
.subtask-add-form { display: flex; gap: 8px; }
.subtask-add-form input[type=text] { flex: 1; margin-top: 0; }

@media (max-width: 480px) {
    .quick-status-form { flex-wrap: wrap; }
    .quick-status-form input[type=text] { flex: 1 1 100%; order: 3; }
    .quick-status-form select { flex: 1 1 auto; }
    .quick-status-form .btn { flex: 1 1 auto; }
}

/* Task description + inline edit */
.task-description-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin: 14px 0 20px;
}
.task-description-wrap { flex: 1; min-width: 0; }
.task-description { margin: 0; }
.task-description-empty { color: var(--text-muted); font-style: italic; }

.desc-expand-toggle { position: absolute; opacity: 0; pointer-events: none; }
.task-description-wrap.is-collapsible .task-description {
    max-height: 7.5em;
    overflow: hidden;
    position: relative;
    -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 2.2em), transparent 100%);
    mask-image: linear-gradient(to bottom, black calc(100% - 2.2em), transparent 100%);
}
.desc-expand-toggle:checked ~ .task-description {
    max-height: none;
    -webkit-mask-image: none;
    mask-image: none;
}
.desc-expand-label {
    display: inline-block;
    margin-top: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    cursor: pointer;
}
.desc-expand-label:hover { text-decoration: underline; }
.desc-expand-label .show-less { display: none; }
.desc-expand-toggle:checked ~ .desc-expand-label .show-more { display: none; }
.desc-expand-toggle:checked ~ .desc-expand-label .show-less { display: inline; }

.description-edit { flex: 0 0 auto; position: relative; }
.description-edit summary {
    list-style: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text-muted);
    cursor: pointer;
}
.description-edit summary::-webkit-details-marker { display: none; }
.description-edit summary:hover { color: var(--text); background: var(--bg); }
.description-edit[open] summary { color: var(--primary); border-color: var(--primary); }
.description-edit-form {
    position: absolute;
    right: 0;
    top: 34px;
    z-index: 5;
    width: 420px;
    max-width: 90vw;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px;
}
.description-edit-form textarea { margin-top: 0; margin-bottom: 8px; }

/* Task detail tabs (CSS-only, via radio inputs) */
.task-tabs { margin: 8px 0 24px; }
.task-tab-radio { position: absolute; opacity: 0; pointer-events: none; }
.task-tab-nav {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 18px;
    overflow-x: auto;
    overflow-y: hidden;
}
.task-tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 14px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    margin-bottom: -1px;
}
.task-tab-btn:hover { color: var(--text); }
.task-tab-count {
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--text-muted);
    background: var(--bg);
    border-radius: 100px;
    padding: 1px 7px;
}
.task-tab-panel { display: none; }
#task-tab-subtasks:checked ~ .task-tab-nav label[for="task-tab-subtasks"],
#task-tab-note:checked ~ .task-tab-nav label[for="task-tab-note"],
#task-tab-status:checked ~ .task-tab-nav label[for="task-tab-status"],
#task-tab-priority:checked ~ .task-tab-nav label[for="task-tab-priority"],
#task-tab-reassign:checked ~ .task-tab-nav label[for="task-tab-reassign"] {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
#task-tab-subtasks:checked ~ #task-panel-subtasks,
#task-tab-note:checked ~ #task-panel-note,
#task-tab-status:checked ~ #task-panel-status,
#task-tab-priority:checked ~ #task-panel-priority,
#task-tab-reassign:checked ~ #task-panel-reassign {
    display: block;
}

/* Rich text description editor (Quill) */
.rich-editor { background: var(--input-bg); border-radius: 0 0 6px 6px; }
.rich-editor-compact .ql-editor { min-height: 90px; font-size: 0.88rem; }
.rich-editor .ql-editor { min-height: 160px; font-size: 0.95rem; }

/* Quill ships a light-only theme by default — repoint its colors at our
   own variables so it doesn't look like a foreign white box, especially
   in dark mode. */
.ql-toolbar.ql-snow {
    border-color: var(--border);
    border-radius: 6px 6px 0 0;
    background: var(--panel);
}
.ql-container.ql-snow { border-color: var(--border); }
.ql-snow .ql-stroke { stroke: var(--text-muted); }
.ql-snow .ql-fill, .ql-snow .ql-stroke.ql-fill { fill: var(--text-muted); }
.ql-snow .ql-picker { color: var(--text-muted); }
.ql-snow .ql-picker-options { background: var(--panel); border-color: var(--border) !important; }
.ql-editor { color: var(--text); }
.ql-editor.ql-blank::before { color: var(--text-muted); font-style: normal; }
.ql-snow .ql-tooltip {
    background: var(--panel);
    border-color: var(--border);
    color: var(--text);
    box-shadow: var(--shadow);
}
.ql-snow .ql-tooltip input[type=text] { background: var(--input-bg); color: var(--text); border-color: var(--border); }

/* Rendered description content (already-sanitized HTML) */
.task-description ol, .task-description ul { padding-left: 22px; margin: 0 0 10px; }
.task-description li { margin-bottom: 3px; }
.task-description h1, .task-description h2, .task-description h3 { margin: 14px 0 8px; line-height: 1.3; }
.task-description h1:first-child, .task-description h2:first-child, .task-description h3:first-child { margin-top: 0; }
.task-description blockquote {
    margin: 10px 0;
    padding-left: 14px;
    border-left: 3px solid var(--border);
    color: var(--text-muted);
}
.task-description p { margin: 0 0 10px; }
.task-description p:last-child { margin-bottom: 0; }
.task-description a { color: var(--primary); }

/* Admin — All Users list (two lines per user, replaces the old wide table) */
.admin-user-list { display: flex; flex-direction: column; gap: 0; }
.admin-user-card {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}
.admin-user-card:last-child { border-bottom: none; }
.admin-user-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
}
.admin-user-row-primary { margin-bottom: 6px; }
.admin-user-name { font-weight: 600; font-size: 0.92rem; }
.admin-user-email { color: var(--text-muted); font-size: 0.85rem; }
.admin-user-row-secondary { font-size: 0.85rem; }
.admin-user-row-secondary select { width: auto; margin-top: 0; font-size: 0.82rem; padding: 5px 6px; }

.admin-role-badge-admin { background: var(--primary); }
.admin-role-badge-user { background: var(--text-muted); }
.admin-status-badge-approved { background: var(--completed); }
.admin-status-badge-pending { background: var(--medium); }

.admin-reset-password { position: relative; }
.admin-reset-password summary { list-style: none; }
.admin-reset-password summary::-webkit-details-marker { display: none; }
.admin-reset-password[open] summary { color: var(--primary); border-color: var(--primary); }
.admin-reset-password-form {
    position: absolute;
    right: 0;
    top: 32px;
    z-index: 6;
    width: 260px;
    max-width: 85vw;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px;
}
.admin-reset-password-form label { margin-bottom: 10px; }
.admin-reset-password-form label:last-of-type { margin-bottom: 10px; }

@media (max-width: 640px) {
    .admin-user-row-secondary { gap: 6px 8px; }
}
