/* ── Utility ───────────────────────────────────────────────────────────────── */
.hidden { display: none; }

/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: #1a1a2e;
    min-height: 100vh;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
#app {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 0 80px;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 1.3rem;
    font-weight: 700;
    color: #1a1a2e;
    flex-shrink: 0;
}

input.header-add-input {
    flex: 1;
    padding: 9px 14px;
    border: 1.5px solid #d0d4de;
    border-radius: 8px;
    font-size: 0.95rem;
    color: #1a1a2e;
    background: #f7f8fb;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
    font-family: inherit;
}

input.header-add-input:focus {
    border-color: #4361ee;
    background: #fff;
}

/* ── Todo List ─────────────────────────────────────────────────────────────── */
.todo-list {
    padding: 8px 12px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.empty-state {
    text-align: center;
    padding: 48px 16px;
    color: #888;
    font-size: 1rem;
}

/* ── Todo Item ─────────────────────────────────────────────────────────────── */
.todo-item {
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
    overflow: hidden;
    transition: box-shadow 0.15s;
}

.todo-item:hover { box-shadow: 0 3px 10px rgba(0,0,0,0.12); }

.todo-item.finished { opacity: 0.6; }
.todo-item.finished .todo-title { text-decoration: line-through; }

/* Main row (priority bar + drag handle + body + actions) */
.todo-main {
    display: flex;
    align-items: center;
}

/* Left priority bar */
.todo-priority-bar {
    width: 5px;
    align-self: stretch;
    flex-shrink: 0;
    background: #4361ee;
}

.todo-item.deadline-soon .todo-priority-bar {
    width: 10px;
    background: #ff6b35;
}

/* Drag handle */
.drag-handle {
    padding: 0 8px;
    cursor: grab;
    color: #bbb;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    user-select: none;
    flex-shrink: 0;
}

.drag-handle:hover { color: #888; }
.drag-handle:active { cursor: grabbing; }

.todo-item.dragging { opacity: 0.45; }
.todo-item.drop-before { box-shadow: 0 -3px 0 0 #4361ee, 0 1px 4px rgba(0,0,0,0.07); }
.todo-item.drop-after  { box-shadow: 0  3px 0 0 #4361ee, 0 1px 4px rgba(0,0,0,0.07); }

/* Body (clickable) */
.todo-body {
    flex: 1;
    padding: 7px 8px;
    cursor: pointer;
    min-width: 0;
}

/* Title row: priority badge + title */
.todo-title-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    min-width: 0;
}

.todo-priority-badge {
    font-size: 1.05rem;
    font-weight: 700;
    color: #4361ee;
    flex-shrink: 0;
    white-space: nowrap;
}

.todo-item.deadline-soon .todo-priority-badge { color: #ff6b35; }

.todo-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #1a1a2e;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.todo-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
    font-size: 0.78rem;
    color: #666;
}

.todo-deadline { color: #d62828; }

.todo-category {
    background: #f0f2f5;
    border-radius: 4px;
    padding: 1px 6px;
}

/* Action buttons */
.todo-actions {
    padding: 6px 8px 6px 4px;
    display: flex;
    align-items: center;
}

.btn-status {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
    background: transparent;
}

.btn-status:active { transform: scale(0.9); }

.btn-start { border-color: #4361ee; color: #4361ee; }
.btn-start:hover { background: #4361ee; color: #fff; }

.btn-finish { border-color: #2ec4b6; color: #2ec4b6; }
.btn-finish:hover { background: #2ec4b6; color: #fff; }

.status-done { font-size: 1.3rem; }

/* ── Inline Details Panel ──────────────────────────────────────────────────── */
.todo-details {
    border-top: 1.5px solid #e8eaf0;
    background: #f7f8fb;
    padding: 16px 16px 16px 21px;
    overflow: hidden;
    transition: height 0.3s ease;
}

.todo-details.hidden { display: none; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

input[type="text"],
input[type="datetime-local"],
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid #d0d4de;
    border-radius: 8px;
    font-size: 0.95rem;
    color: #1a1a2e;
    background: #fff;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
}

input:focus, textarea:focus, select:focus {
    border-color: #4361ee;
}

textarea { resize: vertical; }

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

.btn-primary {
    padding: 10px 22px;
    background: #4361ee;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-primary:hover { background: #3451d1; }

.btn-secondary {
    padding: 10px 18px;
    background: #f0f2f5;
    color: #444;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-secondary:hover { background: #e0e2e8; }

.btn-danger {
    padding: 10px 18px;
    background: #fef0f2;
    color: #ef233c;
    border: 1.5px solid #ef233c;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    margin-right: auto;
}

.btn-danger:hover { background: #fcdde2; }

/* ── Details ───────────────────────────────────────────────────────────────── */
.details-timestamps {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 0.78rem;
    color: #888;
    margin-bottom: 16px;
}

/* ── History ───────────────────────────────────────────────────────────────── */
.history-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e8eaf0;
}

.history-section h3 {
    font-size: 0.85rem;
    font-weight: 700;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
}

.history-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.history-entry {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 0.82rem;
    padding: 6px 10px;
    background: #f7f8fb;
    border-radius: 6px;
    align-items: baseline;
}

.history-time {
    color: #999;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.history-details {
    color: #333;
    flex: 1;
}

.history-change {
    color: #4361ee;
    font-size: 0.78rem;
    background: #eef0fd;
    padding: 1px 6px;
    border-radius: 4px;
}

.history-empty {
    font-size: 0.85rem;
    color: #aaa;
    text-align: center;
    padding: 10px 0;
}

/* ── Error Toast ───────────────────────────────────────────────────────────── */
.error-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: #ef233c;
    color: #fff;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(239,35,60,0.35);
    z-index: 999;
    max-width: 90vw;
    text-align: center;
}

.error-toast.hidden { display: none; }

/* ── Responsive (desktop) ──────────────────────────────────────────────────── */
@media (min-width: 720px) {
    header { padding: 12px 20px; }
    .todo-list { padding: 12px 0 0; }
}
