:root {
    --ink-900: #1B2028;
    --ink-800: #242B36;
    --ink-700: #333A47;
    --muted: #8A90A0;
    --paper: #F5F3ED;
    --card: #FFFFFF;
    --line: #E6E1D6;
    --line-soft: #EEEAE0;
    --accent: #2F6F5E;
    --accent-dark: #25594B;
    --accent-soft: #E3EFEA;
    --warn: #B9782E;
    --warn-soft: #F5E9D8;
    --danger: #C1443A;
    --danger-soft: #F7E3E0;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-card: 0 1px 2px rgba(27, 32, 40, .04), 0 1px 1px rgba(27, 32, 40, .03);
    --shadow-pop: 0 12px 32px rgba(27, 32, 40, .18);
    --sidebar-w: 250px;
    --header-h: 64px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

svg {
    stroke: currentColor;
}

/* default: todo ícone herda a cor do elemento pai, a menos que seja sobrescrito abaixo */
body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--paper);
    color: var(--ink-800);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

button {
    font-family: inherit;
}

input,
textarea,
select {
    font-family: inherit;
}

::selection {
    background: var(--accent-soft);
    color: var(--accent-dark);
}

/* ---------- layout ---------- */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--header-h) 1fr;
    grid-template-areas: "header header" "sidebar main";
    height: 100vh;
    width: 100vw;
}

header.topbar {
    grid-area: header;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--line);
    background: var(--card);
    min-width: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: .55rem;
    flex: 0 0 auto;
    min-width: 0;
}

.brand .mark {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--ink-900);
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.brand .mark svg {
    width: 16px;
    height: 16px;
    stroke: var(--accent-soft);
}

.brand span {
    font-family: 'Fraunces', serif;
    font-weight: 600;
    font-size: 1.15rem;
    color: var(--ink-900);
    letter-spacing: -.01em;
    white-space: nowrap;
}

.searchwrap {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 520px;
    position: relative;
    display: flex;
    align-items: center;
}

.searchwrap svg {
    position: absolute;
    left: .75rem;
    width: 16px;
    height: 16px;
    stroke: var(--muted);
    pointer-events: none;
}

#search {
    width: 100%;
    height: 2.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--line);
    background: var(--paper);
    padding: 0 .85rem 0 2.25rem;
    font-size: .9rem;
    color: var(--ink-800);
    outline: none;
    transition: border-color .15s, background .15s;
    min-width: 0;
}

#search:focus {
    border-color: var(--accent);
    background: var(--card);
}

#search::placeholder {
    color: var(--muted);
}

.topbar-right {
    margin-left: auto;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: .6rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    height: 2.5rem;
    padding: 0 1rem;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border-color .15s, transform .05s, color .15s;
    flex: 0 0 auto;
}

.btn svg {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
}

.btn:active {
    transform: translateY(1px);
}

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

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

.btn-ghost {
    background: transparent;
    border-color: var(--line);
    color: var(--ink-700);
}

.btn-ghost:hover {
    background: var(--paper);
}

.btn-danger-ghost {
    background: transparent;
    border-color: var(--line);
    color: var(--danger);
}

.btn-danger-ghost:hover {
    background: var(--danger-soft);
    border-color: var(--danger-soft);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    height: 2.1rem;
    padding: 0 .75rem;
    font-size: .8rem;
}

/* ---------- sidebar ---------- */
nav.sidebar {
    grid-area: sidebar;
    border-right: 1px solid var(--line);
    background: var(--ink-900);
    color: #C6CCDA;
    padding: 1.25rem .9rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
    min-width: 0;
}

.side-section .side-label {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #69708A;
    font-weight: 600;
    padding: 0 .5rem .5rem;
}

.side-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem .6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: .86rem;
    font-weight: 500;
    color: #B7BECE;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    transition: background .12s, color .12s;
}

.side-item svg {
    width: 16px;
    height: 16px;
    stroke: #828AA3;
    flex: 0 0 auto;
    transition: stroke .12s;
}

.side-item .count {
    margin-left: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: .72rem;
    color: #7C859C;
    background: rgba(255, 255, 255, .05);
    padding: .1rem .4rem;
    border-radius: 999px;
    min-width: 1.4rem;
    text-align: center;
}

.side-item:hover {
    background: rgba(255, 255, 255, .05);
    color: #fff;
}

.side-item:hover svg {
    stroke: #fff;
}

.side-item.active {
    background: var(--accent);
    color: #fff;
}

.side-item.active svg {
    stroke: #fff;
}

.side-item.active .count {
    background: rgba(255, 255, 255, .18);
    color: #fff;
}

.side-footer {
    margin-top: auto;
    padding: .9rem .6rem 0;
    border-top: 1px solid rgba(255, 255, 255, .08);
    font-size: .72rem;
    color: #616A82;
    line-height: 1.5;
}

/* ---------- main ---------- */
main.content {
    grid-area: main;
    overflow-y: auto;
    padding: 1.75rem clamp(1rem, 3vw, 2.5rem) 3rem;
    min-width: 0;
}

.content-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.content-head h1 {
    font-family: 'Fraunces', serif;
    font-size: clamp(1.4rem, 2.4vw, 1.85rem);
    font-weight: 600;
    margin: 0;
    color: var(--ink-900);
    letter-spacing: -.01em;
}

.content-head p {
    margin: .2rem 0 0;
    color: var(--muted);
    font-size: .85rem;
}

.task-list {
    display: flex;
    flex-direction: column;
    gap: .7rem;
    max-width: 900px;
}

.task-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow-card);
    transition: border-color .15s;
}

.task-card:hover {
    border-color: #D9D3C4;
}

.task-card.completed {
    opacity: .85;
    background: var(--accent-soft);
    border-color: #CFE3DA;
    border-left: 4px solid var(--accent);
}

.task-row {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
}

.checkbox {
    appearance: none;
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    flex: 0 0 auto;
    border-radius: 6px;
    border: 1.5px solid #C9C2AE;
    margin-top: .15rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card);
    transition: background .12s, border-color .12s;
}

.checkbox:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.checkbox:checked::after {
    content: "";
    width: 6px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) translate(-1px, -1px);
}

.checkbox.sm {
    width: 16px;
    height: 16px;
    border-radius: 5px;
    margin-top: .1rem;
}

.checkbox.sm:checked::after {
    width: 4px;
    height: 8px;
}

.task-main {
    flex: 1 1 auto;
    min-width: 0;
}

.task-title-row {
    display: flex;
    align-items: center;
    gap: .55rem;
    flex-wrap: wrap;
}

.task-title {
    font-family: 'Fraunces', serif;
    font-size: 1.02rem;
    font-weight: 600;
    color: var(--ink-900);
    word-break: break-word;
}

.task-card.completed .task-title {
    text-decoration: line-through;
    color: var(--muted);
}

.task-desc {
    margin: .3rem 0 0;
    font-size: .84rem;
    color: var(--ink-700);
    line-height: 1.5;
    word-break: break-word;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: .68rem;
    font-weight: 600;
    padding: .22rem .5rem;
    border-radius: 999px;
    white-space: nowrap;
    flex: 0 0 auto;
}

.badge svg {
    width: 11px;
    height: 11px;
}

.badge.ok {
    background: var(--accent-soft);
    color: var(--accent-dark);
}

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

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

.badge.done {
    background: #EFEDE6;
    color: var(--muted);
}

.badge.repeat {
    background: #EFEDE6;
    color: var(--ink-700);
}

.task-meta-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-top: .55rem;
    flex-wrap: wrap;
}

.progress-pill {
    font-family: 'JetBrains Mono', monospace;
    font-size: .68rem;
    color: var(--muted);
    background: var(--paper);
    border: 1px solid var(--line);
    padding: .2rem .5rem;
    border-radius: 999px;
}

.task-actions {
    display: flex;
    align-items: center;
    gap: .15rem;
    flex: 0 0 auto;
}

.icon-btn {
    width: 2rem;
    height: 2rem;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .12s, color .12s;
}

.icon-btn svg {
    width: 16px;
    height: 16px;
}

.icon-btn:hover {
    background: var(--paper);
    color: var(--ink-800);
}

.icon-btn.danger:hover {
    background: var(--danger-soft);
    color: var(--danger);
}

.icon-btn.rotate svg {
    transition: transform .15s;
}

.icon-btn.rotate.open svg {
    transform: rotate(180deg);
}

.subtasks {
    margin: .75rem 0 0 2.05rem;
    padding-top: .65rem;
    border-top: 1px dashed var(--line-soft);
    display: flex;
    flex-direction: column;
    gap: .45rem;
}

.subtasks.hidden {
    display: none;
}

.subtask-row {
    display: flex;
    align-items: center;
    gap: .55rem;
}

.subtask-title {
    font-size: .83rem;
    color: var(--ink-800);
    flex: 1 1 auto;
    min-width: 0;
    word-break: break-word;
}

.subtask-row.completed {
    background: var(--accent-soft);
    border-radius: var(--radius-sm);
    margin: 0 -.35rem;
    padding: .15rem .35rem;
}

.subtask-row.completed .subtask-title {
    text-decoration: line-through;
    color: var(--muted);
}

.empty-state {
    text-align: center;
    padding: 4rem 1rem 2rem;
    color: var(--muted);
    max-width: 420px;
    margin: 0 auto;
}

.empty-state .mark {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    background: var(--accent-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
}

.empty-state .mark svg {
    width: 24px;
    height: 24px;
    stroke: var(--accent-dark);
}

.empty-state h3 {
    font-family: 'Fraunces', serif;
    color: var(--ink-900);
    font-size: 1.15rem;
    margin: 0 0 .35rem;
}

.empty-state p {
    font-size: .85rem;
    margin: 0 0 1.25rem;
    line-height: 1.5;
}

/* ---------- modal ---------- */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(27, 32, 40, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s;
}

.overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 560px;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: var(--shadow-pop);
    transform: translateY(8px) scale(.98);
    transition: transform .15s;
}

.overlay.show .modal {
    transform: translateY(0) scale(1);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    background: var(--card);
    z-index: 1;
}

.modal-head h2 {
    font-family: 'Fraunces', serif;
    font-size: 1.15rem;
    margin: 0;
    color: var(--ink-900);
}

.modal-body {
    padding: 1.1rem 1.25rem 1.4rem;
}

.field {
    margin-bottom: 1rem;
}

.field label {
    display: block;
    font-size: .76rem;
    font-weight: 600;
    color: var(--ink-700);
    margin-bottom: .35rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.field input[type="text"],
.field input[type="date"],
.field input[type="time"],
.field textarea,
.field select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: .6rem .7rem;
    font-size: .88rem;
    color: var(--ink-800);
    background: var(--paper);
    outline: none;
    transition: border-color .15s;
    min-width: 0;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
    border-color: var(--accent);
    background: var(--card);
}

.field textarea {
    resize: vertical;
    min-height: 64px;
}

.row2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .7rem;
}

.row3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: .7rem;
}

.subtask-editor {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: .6rem;
    margin-bottom: .55rem;
    background: var(--paper);
}

.subtask-editor .se-top {
    display: flex;
    gap: .5rem;
    align-items: center;
    margin-bottom: .5rem;
}

.subtask-editor .se-top input[type="text"] {
    flex: 1 1 auto;
    min-width: 0;
}

.subtask-editor .se-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: .5rem;
}

.subtask-editor input,
.subtask-editor select {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: .45rem .5rem;
    font-size: .8rem;
    background: var(--card);
    min-width: 0;
    width: 100%;
}

.add-subtask-btn {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .82rem;
    font-weight: 600;
    color: var(--accent-dark);
    background: var(--accent-soft);
    border: 1px dashed #BFDACF;
    border-radius: var(--radius-md);
    padding: .55rem .75rem;
    cursor: pointer;
    width: 100%;
    justify-content: center;
    margin-top: .2rem;
}

.add-subtask-btn svg {
    width: 15px;
    height: 15px;
}

.add-subtask-btn:hover {
    background: #D7EBE2;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: .6rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--line);
    position: sticky;
    bottom: 0;
    background: var(--card);
}

.toast {
    position: fixed;
    bottom: 1.25rem;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: var(--ink-900);
    color: #fff;
    font-size: .82rem;
    padding: .65rem 1rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-pop);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s, transform .2s;
    z-index: 80;
    max-width: 90vw;
    text-align: center;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ---------- responsive ---------- */
@media (max-width:860px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: var(--header-h) auto 1fr;
        grid-template-areas: "header" "sidebar" "main";
    }

    nav.sidebar {
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
        overflow-y: hidden;
        padding: .7rem .9rem;
        gap: .6rem;
        white-space: nowrap;
    }

    .side-section {
        display: flex;
        gap: .5rem;
    }

    .side-label {
        display: none;
    }

    .side-item {
        width: auto;
        flex: 0 0 auto;
        padding: .5rem .75rem;
    }

    .side-footer {
        display: none;
    }

    .brand span {
        display: none;
    }

    .row2,
    .row3 {
        grid-template-columns: 1fr;
    }

    .subtask-editor .se-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width:520px) {
    header.topbar {
        padding: 0 .8rem;
        gap: .6rem;
    }

    .btn span.btn-label {
        display: none;
    }

    .btn {
        padding: 0 .7rem;
    }

    main.content {
        padding: 1.25rem .9rem 3rem;
    }

    .task-card {
        padding: .85rem;
    }

    .subtasks {
        margin-left: 1.6rem;
    }
}