:root {
    --bg: #f0f4f8;
    --surface: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --success: #059669;
    --success-bg: #ecfdf5;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.1);
    --radius: 12px;
    --radius-sm: 8px;
}

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

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

.app-header {
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: #fff;
    padding: 1.5rem 0;
    box-shadow: var(--shadow-lg);
}

.app-header .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 1rem;
    width: 100%;
}

.header-brand {
    flex: 1;
    min-width: 0;
}

.header-brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header-brand h1 span {
    opacity: 0.85;
    font-weight: 400;
    font-size: 0.95rem;
    display: block;
    margin-top: 0.15rem;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1.25rem;
}

main.container {
    padding-top: 2rem;
    padding-bottom: 3rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-primary:hover {
    background: #f8fafc;
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--border);
}

.btn-outline:hover {
    background: var(--bg);
    border-color: var(--primary);
}

.btn-success {
    background: var(--success-bg);
    color: var(--success);
}

.btn-success:hover {
    background: #d1fae5;
}

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

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

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.75rem;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.stat-card .label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
}

.stat-card .value {
    font-size: 2rem;
    font-weight: 700;
    margin-top: 0.25rem;
    line-height: 1.2;
}

.stat-card.total .value { color: var(--primary); }
.stat-card.pending .value { color: var(--warning); }
.stat-card.completed .value { color: var(--success); }
.stat-card.overdue .value { color: var(--danger); }

.toolbar {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.toolbar-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    flex: 1;
    min-width: 140px;
}

.toolbar-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.toolbar-group input,
.toolbar-group select {
    padding: 0.5rem 0.75rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    background: var(--surface);
    color: var(--text);
}

.toolbar-group input:focus,
.toolbar-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.task-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.task-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    align-items: start;
    transition: box-shadow 0.15s;
}

.task-card:hover {
    box-shadow: var(--shadow-lg);
}

.task-card.overdue {
    border-left: 4px solid var(--danger);
}

.task-card.completed {
    opacity: 0.75;
}

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

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

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-pending {
    background: var(--warning-bg);
    color: var(--warning);
}

.badge-completed {
    background: var(--success-bg);
    color: var(--success);
}

.badge-priority-low {
    background: #f1f5f9;
    color: #475569;
}

.badge-priority-medium {
    background: #eff6ff;
    color: #2563eb;
}

.badge-priority-high {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-category {
    background: #f5f3ff;
    color: #6d28d9;
}

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

.task-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
}

.task-description {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
}

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

.task-actions {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    align-items: flex-end;
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    background: var(--surface);
    border-radius: var(--radius);
    border: 2px dashed var(--border);
    color: var(--text-muted);
}

.empty-state h3 {
    color: var(--text);
    margin-bottom: 0.5rem;
}

.empty-state p {
    margin-bottom: 1.25rem;
}

.form-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    max-width: 560px;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
    color: var(--text);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
}

.form-group textarea {
    min-height: 100px;
    resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.page-title {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--text);
}

.alert {
    padding: 0.85rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #fecaca;
}

.alert-warning {
    background: var(--warning-bg);
    color: var(--warning);
    border: 1px solid #fde68a;
}

.alert-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid #a7f3d0;
}

.app-footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

body.logged-in .header-actions {
    padding-right: 0;
}

body.logged-in .app-header .container {
    padding-left: 3.5rem;
}

.user-greeting {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.1rem;
    font-size: 0.9rem;
    opacity: 0.95;
    font-weight: 500;
}

.user-email {
    font-size: 0.75rem;
    opacity: 0.85;
    font-weight: 400;
}

/* Toggle sidebar — blue box top-left */
.ts-menu-btn {
    position: fixed;
    top: 18px;
    left: 18px;
    z-index: 10001;
    width: 46px;
    height: 46px;
    padding: 0;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.45);
    transition: transform 0.2s, box-shadow 0.2s;
}

.ts-menu-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 18px rgba(79, 70, 229, 0.55);
}

.ts-menu-btn span {
    display: block;
    width: 20px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: transform 0.25s ease, opacity 0.2s ease;
}

.ts-menu-btn.is-open span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.ts-menu-btn.is-open span:nth-child(2) {
    opacity: 0;
}

.ts-menu-btn.is-open span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.ts-side-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.ts-side-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

.ts-side-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 270px;
    max-width: 88vw;
    height: 100vh;
    background: #fff;
    z-index: 9999;
    box-shadow: 4px 0 30px rgba(0, 0, 0, 0.18);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.ts-side-panel.is-open {
    transform: translateX(0);
}

.ts-side-panel-head {
    padding: 1.5rem 1.25rem;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    color: #fff;
    font-size: 1.15rem;
    font-weight: 700;
}

.ts-side-panel-nav {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.ts-side-panel-nav a {
    display: block;
    padding: 1.1rem 1.25rem;
    color: #1e293b;
    text-decoration: none;
    font-size: 1rem;
    font-weight: 500;
    border-bottom: 1px solid #e2e8f0;
    transition: background 0.15s, color 0.15s;
}

.ts-side-panel-nav a:hover {
    background: #eef2ff;
    color: #4f46e5;
}

.ts-side-panel-nav a.ts-logout {
    margin-top: auto;
    color: #dc2626;
    border-bottom: none;
    border-top: 1px solid #e2e8f0;
}

.ts-side-panel-nav a.ts-logout:hover {
    background: #fef2f2;
}

body.ts-panel-open {
    overflow: hidden;
}

.btn-header-outline {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 1.5px solid rgba(255, 255, 255, 0.4);
}

.btn-header-outline:hover {
    background: rgba(255, 255, 255, 0.25);
}

.auth-wrapper {
    display: flex;
    justify-content: center;
    padding: 1rem 0 2rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
}

.auth-card .page-title {
    margin-bottom: 0.35rem;
    text-align: center;
}

.auth-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.auth-hint {
    text-align: center;
    color: var(--primary);
    font-size: 0.8rem;
    margin-bottom: 1.25rem;
    background: #eef2ff;
    padding: 0.6rem 0.85rem;
    border-radius: var(--radius-sm);
}

.notify-bar {
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    color: #4338ca;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
}

.notification-panel {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-left: 4px solid #ea580c;
    border-radius: var(--radius-sm);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
}

.notification-panel h3 {
    font-size: 0.95rem;
    color: #c2410c;
    margin-bottom: 0.75rem;
}

.notification-item {
    background: #fff;
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #9a3412;
}

.notification-item:last-child {
    margin-bottom: 0;
}

.notification-time {
    display: block;
    font-size: 0.75rem;
    font-weight: 400;
    color: #fb923c;
    margin-top: 0.25rem;
}

.due-live-alert {
    animation: pulse-alert 1s ease-in-out 2;
}

@keyframes pulse-alert {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.auth-switch {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.auth-switch a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.activity-list {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    margin-top: 1.25rem;
}

.activity-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem 1.15rem;
}

.activity-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.activity-description {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.45;
}

.activity-page {
    width: 100%;
    max-width: 900px;
}

.activity-view-btn.is-active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.activity-viewer {
    margin-top: 1.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg);
}

.activity-viewer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.activity-viewer-head h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
}

.activity-viewer iframe {
    display: block;
    width: 100%;
    height: min(70vh, 720px);
    min-height: 420px;
    border: none;
    background: #fff;
}

@media (max-width: 600px) {
    .user-greeting {
        display: none;
    }

    .task-card {
        grid-template-columns: 1fr;
    }

    .task-actions {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }
}
