:root {
    --bg: #f5f5f7;
    --card-bg: #ffffff;
    --border: #e0e0e0;
    --text: #1d1d1f;
    --text-secondary: #6e6e73;
    --accent: #0071e3;
    --urgent: #ff3b30;
    --urgent-bg: #fff0ef;
    --deep: #5856d6;
    --deep-bg: #f0f0ff;
    --today: #ff9500;
    --today-bg: #fff8ef;
    --week: #34c759;
    --week-bg: #f0faf2;
    --done: #86868b;
    --tab-bg: #ffffff;
    --tab-active: #0071e3;
    --delete: #ff3b30;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --radius: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ── Tab Bar ── */
.tab-bar {
    display: flex;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.tab-bar button {
    flex: 1;
    padding: 14px 20px;
    border: none;
    background: none;
    font-size: 15px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab-bar button.active {
    color: var(--tab-active);
    border-bottom-color: var(--tab-active);
}

.tab-bar button:hover { background: var(--bg); }

.tab-archive {
    flex: 0 0 auto !important;
    padding: 14px 16px !important;
    font-size: 16px !important;
}

/* ── Layout ── */
.tab-content {
    padding: 16px 20px;
    max-width: 1600px;
    margin: 0 auto;
}

/* ── Weekly Goals ── */
.weekly-goals {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
    overflow: hidden;
}

.goals-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    user-select: none;
}

.goals-header:hover { background: var(--bg); }
.goals-icon { color: var(--accent); }
.goals-toggle { margin-left: auto; font-size: 10px; }

.goals-body { padding: 0 16px 12px; }

.goals-textarea {
    width: 100%;
    min-height: 60px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text);
    resize: vertical;
    outline: none;
    line-height: 1.5;
}

.goals-textarea:focus { border-color: var(--accent); }

/* ── Columns ── */
.columns-header {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-bottom: 12px;
}

.columns-header h2 {
    font-size: 18px;
    font-weight: 600;
    margin-right: auto;
}

.columns-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: flex-start;
}

.column-card {
    flex: 1 1 240px;
    max-width: calc(20% - 12px);
    min-width: 220px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
    display: flex;
    flex-direction: column;
}

.column-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
    min-height: 28px;
}

.column-card-header h3 {
    font-size: 14px;
    font-weight: 600;
    flex: 1;
    cursor: text;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.drag-handle { cursor: grab; }

.project-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.loose-card { border-left: 3px solid var(--accent); }

/* ── Buttons ── */
.btn-add {
    padding: 6px 14px;
    border: 1px solid var(--accent);
    background: none;
    color: var(--accent);
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
}

.btn-add:hover { background: var(--accent); color: white; }

.btn-icon {
    width: 24px;
    height: 24px;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-icon:hover { background: var(--bg); }
.btn-delete:hover { color: var(--delete); }
.btn-toggle { font-size: 14px; }

.btn-clear {
    padding: 4px 10px;
    border: 1px solid var(--border);
    background: none;
    color: var(--text-secondary);
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    margin-top: 6px;
    align-self: flex-start;
}

.btn-clear:hover { background: var(--bg); }

.btn-save {
    padding: 6px 16px;
    border: none;
    background: var(--accent);
    color: white;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
}

.btn-save:hover { opacity: 0.9; }

.btn-restore {
    padding: 3px 10px;
    border: 1px solid var(--accent);
    background: none;
    color: var(--accent);
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
}

.btn-restore:hover { background: var(--accent); color: white; }

/* ── Two-Row Task Item ── */
.task-list { min-height: 4px; flex: 1; }

.task-item-wrap, .topic-item {
    border-radius: 6px;
    margin-bottom: 3px;
    padding: 6px 8px;
    transition: background 0.15s;
    position: relative;
}

.task-item-wrap:hover, .topic-item:hover { background: var(--bg); }
.task-item-wrap.sortable-ghost, .topic-item.sortable-ghost { opacity: 0.4; }
.task-item-wrap.sortable-chosen, .topic-item.sortable-chosen { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }

/* Top row: grip + checkbox + title */
.task-row-top {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Bottom row: badges left, action buttons right */
.task-row-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 3px;
    min-height: 22px;
    padding-left: 36px;  /* align under title (grip + checkbox width) */
}

/* Hide bottom row when empty and not hovered */
.task-item-wrap .task-actions {
    opacity: 0;
    transition: opacity 0.15s;
}

.task-item-wrap:hover .task-actions { opacity: 1; }

/* Topic items (agenda) — single row */
.topic-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.topic-item .task-actions { opacity: 0; transition: opacity 0.15s; }
.topic-item:hover .task-actions { opacity: 1; }

.subtask-list {
    margin-left: 8px;
    border-left: 2px solid var(--border);
}

.subtask { padding-left: 16px; }

.drag-grip {
    color: var(--border);
    cursor: grab;
    font-size: 11px;
    user-select: none;
    flex-shrink: 0;
}

.task-title {
    flex: 1;
    font-size: 13px;
    cursor: text;
    min-width: 0;
    word-break: break-word;
    line-height: 1.4;
}

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

input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: var(--accent);
    flex-shrink: 0;
}

/* ── Multi-label highlights on task wrapper ── */
.task-item-wrap.has-urgent { border-left: 3px solid var(--urgent); background: var(--urgent-bg); }
.task-item-wrap.has-deep_work { border-right: 3px solid var(--deep); }
.task-item-wrap.has-deep_work:not(.has-urgent):not(.has-today):not(.has-this_week) { background: var(--deep-bg); }
.task-item-wrap.has-today { box-shadow: inset 0 -2px 0 var(--today); }
.task-item-wrap.has-today:not(.has-urgent) { background: var(--today-bg); }
.task-item-wrap.has-this_week { box-shadow: inset 0 2px 0 var(--week); }
.task-item-wrap.has-this_week.has-today { box-shadow: inset 0 2px 0 var(--week), inset 0 -2px 0 var(--today); }

/* ── Label Badges ── */
.label-badges {
    display: flex;
    gap: 3px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.badge {
    font-size: 9px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.badge-urgent { background: var(--urgent); color: white; }
.badge-deep_work { background: var(--deep); color: white; }
.badge-today { background: var(--today); color: white; }
.badge-this_week { background: var(--week); color: white; }

/* ── Label Toggle Buttons ── */
.label-btn {
    width: 20px;
    height: 20px;
    border: 1px solid var(--border);
    background: none;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.3;
    transition: all 0.15s;
    flex-shrink: 0;
}

.task-item-wrap:hover .label-btn, .label-btn.active { opacity: 1; }

.label-urgent { color: var(--urgent); border-color: var(--urgent); }
.label-urgent.active { background: var(--urgent); color: white; }

.label-deep { color: var(--deep); border-color: var(--deep); }
.label-deep.active { background: var(--deep); color: white; }

.label-today { color: var(--today); border-color: var(--today); }
.label-today.active { background: var(--today); color: white; }

.label-week { color: var(--week); border-color: var(--week); }
.label-week.active { background: var(--week); color: white; }

.task-actions {
    display: flex;
    gap: 2px;
    align-items: center;
    flex-shrink: 0;
}

.btn-subtask { font-size: 10px; color: var(--accent); }

/* ── Edit Input ── */
.edit-input {
    flex: 1;
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 3px 6px;
    font-size: 13px;
    outline: none;
    font-family: inherit;
    min-width: 0;
}

.new-task-input {
    width: 100%;
    border: 1px dashed var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 13px;
    background: none;
    color: var(--text);
    outline: none;
    margin-top: 6px;
    font-family: inherit;
}

.new-task-input:focus { border-color: var(--accent); border-style: solid; }
.new-task-input::placeholder { color: var(--text-secondary); }

/* ── Modal (Project Notes) ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    width: 480px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

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

.modal-header h3 { font-size: 15px; font-weight: 600; }

.modal-textarea {
    flex: 1;
    min-height: 200px;
    border: none;
    padding: 14px 16px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    resize: vertical;
    outline: none;
    line-height: 1.6;
}

.modal-footer {
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

/* ── Toast (Undo) ── */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #1d1d1f;
    color: white;
    padding: 10px 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    z-index: 300;
}

.toast-undo {
    background: none;
    border: 1px solid rgba(255,255,255,0.4);
    color: #5ac8fa;
    padding: 4px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
}

.toast-undo:hover { background: rgba(255,255,255,0.1); }

.toast-dismiss {
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
}

/* ── Archive Panel ── */
.archive-panel {
    position: fixed;
    top: 50px;
    right: 0;
    width: 360px;
    max-width: 90vw;
    max-height: calc(100vh - 50px);
    background: var(--card-bg);
    box-shadow: -4px 0 16px rgba(0,0,0,0.1);
    z-index: 150;
    overflow-y: auto;
    border-left: 1px solid var(--border);
}

.archive-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--card-bg);
}

.archive-header h3 { font-size: 16px; font-weight: 600; }

.archive-list { padding: 12px 16px; }

.archive-section { margin-bottom: 16px; }

.archive-section h4 {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.archive-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid var(--bg);
    font-size: 13px;
}

.archive-item span { flex: 1; }

.archive-empty {
    color: var(--text-secondary);
    font-size: 13px;
    text-align: center;
    padding: 24px 0;
}

/* ── Responsive ── */
@media (max-width: 1200px) {
    .column-card { max-width: calc(33.333% - 10px); }
}

@media (max-width: 900px) {
    .column-card { max-width: calc(50% - 8px); }
}

@media (max-width: 600px) {
    .column-card { max-width: 100%; flex-basis: 100%; }
    .tab-content { padding: 10px; }
    .task-item-wrap .task-actions { opacity: 1; }
    .topic-item .task-actions { opacity: 1; }
    .archive-panel { width: 100%; }
}

.sortable-drag {
    opacity: 0.9;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
