/* === Reset & Variables === */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #0f3460;
    --bg-input: #1a1a3e;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a0b0;
    --text-muted: #6a6a7a;
    --accent: #e94560;
    --accent-hover: #d63550;
    --success: #4caf50;
    --border: #2a2a4e;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --radius-sm: 4px;
    --drop-color: #5b9bd5;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

button {
    cursor: pointer;
    border: none;
    font: inherit;
    background: none;
    color: inherit;
}

input, textarea {
    font: inherit;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.8rem;
    width: 100%;
    outline: none;
    transition: border-color 0.2s;
}

input:focus, textarea:focus {
    border-color: var(--accent);
}

input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.7);
    cursor: pointer;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* === Login Page === */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    background: var(--bg-secondary);
    padding: 2.5rem 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
}

.login-title {
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    color: var(--accent);
    margin-bottom: 0.25rem;
}

.login-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-field label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 1rem;
    transition: background 0.2s;
    margin-top: 0.5rem;
}

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

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.login-switch {
    text-align: center;
    margin-top: 1.25rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.error-banner {
    background: rgba(233, 69, 96, 0.15);
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

/* === App Layout === */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-header {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    gap: 0.75rem;
    min-height: 56px;
}

.header-title {
    flex: 1;
    font-size: 1.1rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hamburger {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
}

.hamburger-line {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
}

.btn-logout {
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    min-height: 44px;
    display: flex;
    align-items: center;
}

.btn-logout:hover {
    color: var(--accent);
}

/* === App Body === */
.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* === Sidebar === */
.sidebar {
    width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    transition: transform 0.3s ease;
}

.sidebar-nav {
    flex: 1;
    padding: 0.5rem 0;
}

.list-items {
    list-style: none;
}

.list-item {
    padding: 0.7rem 1rem;
    cursor: grab;
    transition: background 0.15s;
    min-height: 44px;
    display: flex;
    align-items: center;
    position: relative;
}

.list-item:active {
    cursor: grabbing;
}

.list-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.list-item.selected {
    background: rgba(233, 69, 96, 0.15);
    border-right: 3px solid var(--accent);
}

.list-item.dragging {
    opacity: 0.35;
}

.list-item.drop-before {
    box-shadow: inset 0 2px 0 0 var(--drop-color);
}

.list-item.drop-after {
    box-shadow: inset 0 -2px 0 0 var(--drop-color);
}

.list-name {
    font-size: 0.95rem;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-item-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
}

.list-item:hover .list-item-actions {
    opacity: 1;
}

.list-action-btn {
    font-size: 0.8rem;
    color: var(--text-muted);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
}

.list-action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.list-delete-btn:hover {
    color: var(--accent);
    background: rgba(233, 69, 96, 0.15);
}

.add-list-section {
    border-top: 1px solid var(--border);
}

.sublist-hint {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem 0;
    font-size: 0.8rem;
    color: var(--accent);
}

.btn-cancel-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

.btn-cancel-sub:hover {
    color: var(--accent);
}

.add-list-form {
    display: flex;
    padding: 0.75rem;
    gap: 0.5rem;
}

.add-list-form input {
    flex: 1;
    font-size: 0.85rem;
    padding: 0.5rem 0.6rem;
}

.btn-add {
    background: var(--accent);
    color: #fff;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    display: none;
}

.sidebar-overlay.active {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9;
}

/* === Main Content === */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* === Task List === */
.task-list {
    max-width: 700px;
    margin: 0 auto;
}

.add-task-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.add-task-input {
    flex: 1;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border-radius: var(--radius);
}

.btn-add-task {
    background: var(--accent);
    color: #fff;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-weight: 600;
    white-space: nowrap;
}

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

.task-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* === Task Item === */
.task-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 0.75rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    cursor: grab;
    transition: background 0.15s, opacity 0.15s;
    min-height: 48px;
    position: relative;
}

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

.task-item:hover {
    background: var(--bg-card);
}

.task-item.completed {
    cursor: pointer;
}

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

.task-item.dragging {
    opacity: 0.35;
}

.task-item.drop-before {
    box-shadow: inset 0 2px 0 0 var(--drop-color);
}

.task-item.drop-after {
    box-shadow: inset 0 -2px 0 0 var(--drop-color);
}

.task-checkbox {
    font-size: 1.3rem;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.task-checkbox:hover {
    background: rgba(255, 255, 255, 0.1);
}

.task-title {
    flex: 1;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.task-due-date {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.task-delete {
    font-size: 0.9rem;
    color: var(--text-muted);
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.15s;
}

.task-item:hover .task-delete {
    opacity: 1;
}

.task-delete:hover {
    color: var(--accent);
    background: rgba(233, 69, 96, 0.15);
}

/* === Completed Section === */
.completed-section {
    margin-top: 1.5rem;
}

.completed-header {
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 0.5rem 0;
    cursor: pointer;
    user-select: none;
}

/* === Detail Panel === */
.detail-panel {
    width: 0;
    overflow: hidden;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    transition: width 0.3s ease;
}

.detail-panel.open {
    width: 320px;
}

.detail-content {
    padding: 1.25rem;
    width: 320px;
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.detail-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.btn-close {
    font-size: 1.2rem;
    color: var(--text-muted);
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-close:hover {
    color: var(--text-primary);
}

.detail-field {
    margin-bottom: 1.25rem;
}

.detail-field label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

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

/* === Toast === */
.toast-error {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 100;
    cursor: pointer;
    max-width: 90vw;
    font-size: 0.9rem;
}

.toast-close {
    color: rgba(255, 255, 255, 0.7);
    font-size: 1rem;
}

/* === Loading & Empty === */
.loading-indicator,
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* === Mobile (< 768px) === */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 56px;
        left: 0;
        bottom: 0;
        z-index: 10;
        transform: translateX(-100%);
    }

    .sidebar.sidebar-open {
        transform: translateX(0);
    }

    .detail-panel.open {
        position: fixed;
        top: 56px;
        right: 0;
        bottom: 0;
        width: 100%;
        z-index: 10;
    }

    .detail-content {
        width: 100%;
    }

    .task-delete {
        opacity: 1;
    }

    .list-item-actions {
        opacity: 1;
    }
}

/* === Desktop (>= 768px) === */
@media (min-width: 769px) {
    .hamburger {
        display: none;
    }

    .sidebar-overlay {
        display: none !important;
    }
}
