/* Keep native hidden reliable for modal, toast and loaders. */
[hidden],
.modal-backdrop[hidden],
.toast[hidden],
.page-loader[hidden],
.local-loader[hidden] {
    display: none !important;
}

:root {
    --bg: #f7f8fb;
    --surface: #ffffff;
    --surface-soft: #f2f4f8;
    --surface-tint: #eef2ff;
    --border: #e3e7ee;
    --border-strong: #d2d8e3;
    --text: #1f2533;
    --muted: #687184;
    --muted-light: #9aa3b4;
    --primary: #4f66f0;
    --primary-dark: #3f54c8;
    --primary-soft: #eef1ff;
    --pending: #c47a25;
    --progress: #4f66f0;
    --completed: #2f9158;
    --danger: #ce4545;
    --success-bg: #ecf8f1;
    --radius: 16px;
    --radius-sm: 10px;
    --sidebar-width: 238px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: .48;
}

a {
    color: inherit;
    text-decoration: none;
}

.page-loader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 100;
    background: rgba(79, 102, 240, .14);
    overflow: hidden;
}

.page-loader span {
    display: block;
    width: 45%;
    height: 100%;
    background: var(--primary);
    animation: loading-bar .75s ease-in-out infinite;
}

@keyframes loading-bar {
    from { transform: translateX(-110%); }
    to { transform: translateX(260%); }
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 18px 14px;
    background: #fbfcff;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 4px 12px;
}

.brand-icon,
.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
    letter-spacing: -.02em;
}

.sidebar-brand strong {
    display: block;
    font-size: 15px;
}

.sidebar-brand span {
    display: block;
    margin-top: 2px;
    font-size: 12px;
    color: var(--muted);
}

.side-nav {
    display: grid;
    gap: 4px;
}

.nav-item,
.workspace-pill,
.back-link {
    border: 0;
    background: transparent;
    color: inherit;
    text-align: left;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 38px;
    padding: 9px 11px;
    border-radius: 12px;
    color: #4d5567;
    transition: background .16s ease, color .16s ease;
}

.nav-item:hover,
.nav-item.active {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.nav-icon {
    width: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: inherit;
}

.sidebar-section {
    padding: 12px 6px 0;
    border-top: 1px solid var(--border);
    display: grid;
    gap: 10px;
}

.sidebar-section p {
    margin: 0;
    color: var(--muted-light);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.workspace-pill {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    color: var(--muted);
    background: var(--surface);
}

.workspace-pill small {
    display: block;
    margin-top: 4px;
    color: var(--muted-light);
}

.side-create {
    min-height: 36px;
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--primary-dark);
    background: var(--primary-soft);
    font-weight: 650;
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 12px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
}

.user-chip > span {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #eef1ff;
    color: var(--primary-dark);
    font-weight: 700;
}

.user-chip strong,
.user-chip small {
    display: block;
}

.user-chip small {
    color: var(--muted);
    margin-top: 2px;
}

.logout-link {
    padding: 9px 10px;
    color: var(--muted);
    border-radius: 11px;
    text-align: center;
    transition: background .16s ease;
}

.logout-link:hover {
    background: var(--surface-soft);
    color: var(--text);
}

.main-area {
    min-width: 0;
    padding: 18px 20px 24px;
}

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.topbar-left {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.back-link {
    min-width: max-content;
    padding: 8px 0 0;
    color: #353b4a;
    font-weight: 650;
}

.back-link:hover {
    color: var(--primary-dark);
}

.topbar h1 {
    margin: 0;
    font-size: 24px;
    line-height: 1.15;
    letter-spacing: -.03em;
}

.topbar p {
    margin: 5px 0 0;
    color: var(--muted);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.search-box {
    min-width: 300px;
    height: 38px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.search-box span {
    color: var(--muted-light);
}

.search-box input {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
}

.primary-btn,
.soft-btn,
.icon-btn,
.text-btn,
.mini-add,
.task-action,
.tab,
.stat-card,
.priority-pill {
    border: 0;
    border-radius: 11px;
    min-height: 38px;
    padding: 0 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    transition: background .16s ease, color .16s ease, border-color .16s ease, transform .16s ease;
}

.primary-btn {
    color: #fff;
    background: var(--primary);
}

.primary-btn:hover {
    background: var(--primary-dark);
}

.soft-btn {
    color: #394151;
    background: var(--surface);
    border: 1px solid var(--border);
}

.soft-btn:hover {
    background: var(--surface-soft);
}

.icon-btn,
.mini-add {
    width: 36px;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    color: #4d5567;
}

.icon-btn:hover,
.mini-add:hover {
    border-color: var(--border-strong);
    background: var(--surface-soft);
}

.text-btn {
    padding: 0;
    min-height: auto;
    background: transparent;
    color: var(--primary-dark);
    font-weight: 650;
}

.board-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.tabs {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-wrap: wrap;
}

.tab {
    background: transparent;
    color: var(--muted);
    min-height: 34px;
    padding: 0 10px;
    font-weight: 650;
}

.tab.active {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.month-picker {
    display: flex;
    align-items: center;
    gap: 8px;
}

.month-picker select,
.month-picker input,
.filters-panel select,
.task-form input,
.task-form select,
.task-form textarea,
.login-form input {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface);
    color: var(--text);
    padding: 0 11px;
    outline: 0;
    transition: border-color .16s ease, background .16s ease;
}

.month-picker select:focus,
.month-picker input:focus,
.filters-panel select:focus,
.task-form input:focus,
.task-form select:focus,
.task-form textarea:focus,
.login-form input:focus {
    border-color: var(--primary);
}

.month-picker select {
    width: 145px;
}

.month-picker input {
    width: 92px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 13px 14px;
    min-height: auto;
    align-items: flex-start;
    justify-content: flex-start;
    flex-direction: column;
    text-align: left;
}

.stat-card:hover {
    background: #fcfdff;
    border-color: var(--border-strong);
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.stat-card strong {
    display: block;
    margin-top: 4px;
    font-size: 24px;
    letter-spacing: -.03em;
}

.filters-panel {
    display: none;
    grid-template-columns: minmax(180px, 240px) minmax(180px, 240px) auto;
    align-items: end;
    gap: 10px;
    padding: 12px;
    margin-bottom: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.filters-panel.show {
    display: grid;
}

.filters-panel label,
.task-form label,
.login-form label {
    display: grid;
    gap: 7px;
}

.filters-panel span,
.task-form span,
.login-form span,
.setting-card > span,
.overview-card > span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
}

.view-panel {
    display: none;
}

.view-panel.active {
    display: block;
    animation: fade-in .18s ease;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.board-info,
.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.board-info h2,
.section-head h2 {
    margin: 0;
    font-size: 17px;
    letter-spacing: -.02em;
}

.board-info p,
.section-head p {
    margin: 4px 0 0;
    color: var(--muted);
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 14px;
    color: var(--muted);
    font-size: 12px;
}

.legend span,
.dot {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.dot.pending { background: var(--pending); }
.dot.progress { background: var(--progress); }
.dot.completed { background: var(--completed); }

.busy-wrap {
    position: relative;
}

.busy-wrap.is-busy .timeline-board,
.busy-wrap.is-busy + * {
    opacity: .72;
}

.local-loader {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .92);
    border: 1px solid var(--border);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 12px;
}

.spinner {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #d6dbea;
    border-top-color: var(--primary);
    animation: spin .7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.board-scroll {
    overflow-x: auto;
    padding-bottom: 10px;
    scrollbar-width: thin;
}

.timeline-board {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 276px;
    gap: 10px;
    min-height: 560px;
    transition: opacity .16s ease;
}

.day-column {
    min-width: 0;
    background: #f9fafc;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    display: flex;
    flex-direction: column;
}

.day-column.today {
    background: #f4f6ff;
    border-color: #cfd7ff;
}

.day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 2px 2px 10px;
}

.day-header strong {
    font-size: 18px;
    line-height: 1;
}

.day-header span {
    display: inline-block;
    margin-left: 5px;
    color: var(--muted);
    font-size: 12px;
}

.day-task-list {
    display: flex;
    flex-direction: column;
    gap: 9px;
    flex: 1;
    min-height: 120px;
    border-radius: 12px;
    transition: background .15s ease;
}

.day-task-list.drag-over {
    background: rgba(79, 102, 240, .07);
    outline: 1px dashed rgba(79, 102, 240, .35);
    outline-offset: 4px;
}

.task-card,
.list-card,
.overview-card,
.setting-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
}

.task-card {
    padding: 11px;
    cursor: grab;
}

.task-card:active {
    cursor: grabbing;
}

.task-card.dragging {
    opacity: .55;
}

.task-card.completed {
    background: #fbfffc;
    opacity: .84;
}

.task-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.badges {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-bottom: 8px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 21px;
    padding: 0 7px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 650;
    line-height: 1;
    border: 1px solid transparent;
}

.badge.low,
.priority-pill.low { background: #eef4ff; color: #4462a8; }
.badge.medium,
.priority-pill.medium { background: #fff7e8; color: #a96514; }
.badge.high,
.priority-pill.high { background: #eef9f1; color: #25764b; }
.badge.urgent,
.priority-pill.urgent { background: #fff0f0; color: #bd3d3d; }
.badge.pending { background: #fff7e8; color: #a96514; }
.badge.in_progress { background: #eef1ff; color: var(--primary-dark); }
.badge.completed { background: var(--success-bg); color: var(--completed); }

.task-title {
    margin: 0 0 5px;
    font-size: 14px;
    line-height: 1.32;
    letter-spacing: -.01em;
}

.task-client,
.task-note,
.task-date-line {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

.task-note {
    margin-top: 7px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.task-date-line {
    margin-top: 9px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.task-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 10px;
}

.task-action {
    min-height: 30px;
    padding: 0 9px;
    font-size: 12px;
    background: var(--surface-soft);
    color: #4b5364;
}

.task-action:hover {
    background: #e9edf5;
}

.task-action.complete {
    background: var(--success-bg);
    color: var(--completed);
}

.task-action.delete {
    background: #fff0f0;
    color: var(--danger);
}

.empty-state {
    border: 1px dashed var(--border-strong);
    border-radius: 12px;
    padding: 18px 10px;
    color: var(--muted-light);
    text-align: center;
    font-size: 12px;
    background: rgba(255, 255, 255, .45);
}

.list-card {
    padding: 6px;
    display: grid;
    gap: 6px;
}

.list-row {
    display: grid;
    grid-template-columns: minmax(260px, 1.6fr) minmax(130px, .7fr) minmax(180px, .9fr) auto;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid transparent;
}

.list-row:hover {
    background: #fafbfe;
    border-color: var(--border);
}

.list-main h3 {
    margin: 0 0 4px;
    font-size: 14px;
}

.list-main p,
.list-date small {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}

.list-date {
    color: var(--text);
    font-weight: 650;
    font-size: 13px;
}

.list-date small {
    display: block;
    margin-top: 3px;
    font-weight: 400;
}

.list-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.empty-list {
    padding: 26px;
    text-align: center;
    color: var(--muted);
}

.empty-list strong {
    display: block;
    color: var(--text);
    font-size: 16px;
}

.empty-list p {
    margin: 6px 0 16px;
}

.overview-grid,
.settings-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}

.overview-card,
.setting-card {
    padding: 15px;
}

.overview-card.wide {
    grid-column: span 2;
}

.overview-card.list-wide {
    grid-column: span 2;
}

.overview-card strong,
.setting-card strong {
    display: block;
    margin-top: 5px;
    font-size: 25px;
    letter-spacing: -.03em;
}

.setting-card strong {
    font-size: 16px;
}

.overview-card p,
.setting-card p {
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}

.progress-track {
    height: 9px;
    border-radius: 999px;
    background: #edf0f6;
    overflow: hidden;
    margin: 13px 0 0;
}

.progress-track i {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
}

.due-list {
    list-style: none;
    padding: 0;
    margin: 12px 0 0;
    display: grid;
    gap: 8px;
}

.due-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.due-list li:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.due-list button {
    border: 0;
    background: transparent;
    padding: 0;
    color: var(--text);
    text-align: left;
    font-weight: 650;
}

.due-list span,
.muted-line {
    color: var(--muted);
    font-size: 12px;
}

.priority-breakdown {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.priority-pill {
    min-height: 54px;
    padding: 8px;
    flex-direction: column;
    border: 1px solid transparent;
}

.priority-pill strong {
    margin: 0;
    font-size: 20px;
}

.actions-card {
    display: grid;
    gap: 10px;
    align-content: start;
}

.actions-card .soft-btn {
    width: 100%;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(25, 30, 44, .38);
    z-index: 50;
}

.modal-card {
    width: min(760px, 100%);
    max-height: min(92vh, 820px);
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 22px;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 20px 12px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 0;
    letter-spacing: -.02em;
}

.modal-header p {
    margin: 4px 0 0;
    color: var(--muted);
}

.task-form {
    padding: 18px 20px 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.form-grid .span-2 {
    grid-column: span 2;
}

.task-form textarea {
    min-height: 104px;
    padding: 10px 11px;
    resize: vertical;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    max-width: 360px;
    padding: 12px 14px;
    background: #1f2432;
    color: #fff;
    border-radius: 14px;
    z-index: 70;
}

.alert {
    border-radius: 12px;
    padding: 10px 12px;
    margin: 14px 0;
}

.alert.error {
    background: #fff0f0;
    color: #a83434;
    border: 1px solid #ffd3d3;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(180deg, #f8f9fc, #eef2ff);
}

.login-shell {
    width: min(420px, calc(100% - 32px));
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 28px;
}

.login-card h1 {
    margin: 16px 0 6px;
    letter-spacing: -.03em;
}

.muted,
.login-hint {
    color: var(--muted);
}

.login-form {
    display: grid;
    gap: 12px;
    margin-top: 18px;
}

.login-form .primary-btn {
    margin-top: 4px;
    width: 100%;
}

.login-hint {
    margin: 15px 0 0;
    font-size: 12px;
}

@media (max-width: 1180px) {
    .overview-grid,
    .settings-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 1100px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        padding: 12px 14px;
        flex-direction: row;
        align-items: center;
        flex-wrap: wrap;
    }

    .side-nav {
        grid-auto-flow: column;
        grid-auto-columns: max-content;
        overflow-x: auto;
        flex: 1;
    }

    .sidebar-section {
        display: none;
    }

    .sidebar-footer {
        margin-top: 0;
        margin-left: auto;
        grid-auto-flow: column;
        align-items: center;
    }

    .logout-link {
        white-space: nowrap;
    }
}

@media (max-width: 900px) {
    .list-row {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .list-actions {
        justify-content: flex-start;
    }
}

@media (max-width: 820px) {
    .main-area {
        padding: 14px;
    }

    .topbar,
    .board-toolbar,
    .board-info,
    .section-head {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar-left {
        flex-direction: column;
        gap: 8px;
    }

    .topbar-actions {
        justify-content: stretch;
    }

    .search-box {
        min-width: 0;
        flex: 1 1 100%;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .filters-panel {
        grid-template-columns: 1fr;
    }

    .timeline-board {
        grid-auto-columns: min(82vw, 300px);
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-grid .span-2 {
        grid-column: span 1;
    }

    .modal-actions {
        flex-direction: column-reverse;
    }

    .modal-actions button {
        width: 100%;
    }

    .sidebar-footer .user-chip {
        display: none;
    }
}

@media (max-width: 620px) {
    .overview-grid,
    .settings-grid,
    .overview-card.wide,
    .overview-card.list-wide {
        grid-template-columns: 1fr;
        grid-column: auto;
    }

    .priority-breakdown {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 520px) {
    .sidebar-brand {
        width: 100%;
    }

    .side-nav {
        width: 100%;
    }

    .nav-item {
        white-space: nowrap;
    }

    .month-picker {
        width: 100%;
    }

    .month-picker select,
    .month-picker input {
        flex: 1;
        width: auto;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}
