/* ===================================================================
   Triage — Daily Command Center
   Clean, responsive, mobile-friendly task management
   =================================================================== */

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

:root {
    --bg: #F5F5F3;
    --surface: #FFFFFF;
    --surface-hover: #FAFAF8;
    --ink: #1A1A1A;
    --ink-secondary: #6B6B6B;
    --ink-muted: #9A9A9A;
    --border: #E5E5E2;
    --border-light: #F0F0ED;

    --accent: #2563EB;
    --accent-hover: #1D4FD7;
    --accent-light: #EFF6FF;

    --urgent: #DC2626;
    --urgent-light: #FEF2F2;
    --warning: #D97706;
    --warning-light: #FFFBEB;
    --success: #059669;
    --success-light: #ECFDF5;

    --radius: 8px;
    --radius-sm: 4px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);

    --nav-height: 56px;
    --mobile-nav-height: 64px;
}

html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
    font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
    min-height: 100vh;
    padding-bottom: 80px;
}

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

/* --- Navigation --- */
.nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    height: var(--nav-height);
}
.nav-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    align-items: center;
    height: 100%;
    gap: 24px;
}
.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--ink);
    letter-spacing: -0.02em;
}
.nav-brand:hover { text-decoration: none; }
.nav-links {
    display: flex;
    gap: 4px;
    flex: 1;
}
.nav-link {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.87rem;
    font-weight: 500;
    color: var(--ink-secondary);
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.nav-link.active { background: var(--accent-light); color: var(--accent); }
.nav-link-icon { font-size: 1.1rem; padding: 6px 8px; }
.nav-actions { display: flex; align-items: center; gap: 8px; }

/* Mobile bottom nav */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--surface);
    border-top: 1px solid var(--border);
    height: var(--mobile-nav-height);
    padding-bottom: env(safe-area-inset-bottom, 0);
}
.mobile-nav-link {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--ink-muted);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: none;
    padding: 4px;
}
.mobile-nav-link.active { color: var(--accent); }
.mobile-nav-icon { font-size: 1.2rem; line-height: 1; }
.mobile-nav-plus {
    background: var(--accent);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 300;
}
.mobile-nav-add { color: var(--accent); }

@media (max-width: 640px) {
    .nav-links, .nav-actions { display: none; }
    .mobile-nav { display: flex; }
    body { padding-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 16px)); }
}

/* --- Main content --- */
.main {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px;
}

/* --- Page Header --- */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    gap: 16px;
}
.page-date {
    font-size: 0.8rem;
    color: var(--ink-muted);
    margin-bottom: 4px;
    letter-spacing: 0.02em;
}
.page-title {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}
.page-meta {
    font-size: 0.8rem;
    color: var(--ink-secondary);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}
.page-intro {
    color: var(--ink-secondary);
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.breadcrumb {
    font-size: 0.8rem;
    color: var(--ink-muted);
    display: inline-block;
    margin-bottom: 8px;
}

/* --- Sections --- */
.section { margin-bottom: 32px; }
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-secondary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.section-header .section-title { margin-bottom: 0; }
.section-count {
    font-size: 0.7rem;
    background: var(--border-light);
    padding: 1px 7px;
    border-radius: 10px;
    color: var(--ink-muted);
    font-weight: 500;
}
.section-title-toggle {
    cursor: pointer;
    user-select: none;
}
.section-title-toggle::-webkit-details-marker { display: none; }
.section-title-toggle::before {
    content: '▸';
    display: inline-block;
    margin-right: 4px;
    transition: transform 0.15s;
}
details[open] > .section-title-toggle::before { transform: rotate(90deg); }

.section-completed { opacity: 0.7; }
.section-archived { opacity: 0.5; }

/* --- Cards --- */
.card-list { display: flex; flex-direction: column; gap: 2px; }

.card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    background: var(--surface);
    border-radius: var(--radius);
    transition: background 0.1s;
}
.card:hover { background: var(--surface-hover); }
a.card { text-decoration: none; color: inherit; }
a.card:hover { text-decoration: none; }

.card-body { flex: 1; min-width: 0; }
.card-title {
    font-size: 0.93rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}
.card-title a { color: inherit; }
.card-title-done { text-decoration: line-through; color: var(--ink-muted); }
.card-meta {
    font-size: 0.78rem;
    color: var(--ink-muted);
    margin-top: 2px;
}
.card-description {
    font-size: 0.82rem;
    color: var(--ink-secondary);
    margin-top: 4px;
}

.card-left {
    min-width: 60px;
    flex-shrink: 0;
}
.event-time {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ink-secondary);
}

.card-action {
    font-size: 0.9rem;
    color: var(--ink-muted);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    opacity: 0;
    transition: opacity 0.15s;
    text-decoration: none;
    flex-shrink: 0;
    align-self: center;
}
.card:hover .card-action { opacity: 1; }
.card-action-delete { border: none; background: none; cursor: pointer; font-size: 1.2rem; }

.card-actions-group {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.card-done { opacity: 0.6; }
.card-archived { opacity: 0.4; }

/* Touch: always show actions */
@media (hover: none) {
    .card-action { opacity: 0.5; }
}

/* --- Task checkbox --- */
.task-check {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
    transition: border-color 0.15s, background 0.15s;
    padding: 0;
}
.task-check:hover { border-color: var(--accent); }
.check-icon {
    font-size: 0.65rem;
    color: transparent;
    font-weight: 700;
    transition: color 0.15s;
}
.task-check:hover .check-icon { color: var(--accent); }
.task-check.checked {
    background: var(--success);
    border-color: var(--success);
}
.task-check.checked .check-icon { color: white; }
.task-check.archived {
    background: var(--ink-muted);
    border-color: var(--ink-muted);
}

/* --- Priority dots --- */
.priority-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.priority-high { background: var(--urgent); }
.priority-medium { background: var(--warning); }
.priority-low { background: var(--border); }

.priority-label { font-size: 0.75rem; font-weight: 500; }
.priority-label.priority-high { color: var(--urgent); }
.priority-label.priority-medium { color: var(--warning); }
.priority-label.priority-low { color: var(--ink-muted); }

/* --- Status labels --- */
.status-label {
    font-size: 0.75rem;
    font-weight: 500;
    padding: 1px 6px;
    border-radius: var(--radius-sm);
}
.status-active { background: var(--success-light); color: var(--success); }
.status-on-hold { background: var(--warning-light); color: var(--warning); }
.status-completed { background: var(--border-light); color: var(--ink-muted); }

/* --- Badges --- */
.badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge-muted { background: var(--border-light); color: var(--ink-muted); }

/* --- Deadline bands --- */
.deadline-band { margin-bottom: 16px; }
.deadline-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    display: inline-block;
    margin-bottom: 8px;
}
.deadline-urgent .deadline-label { background: var(--urgent-light); color: var(--urgent); }
.deadline-soon .deadline-label { background: var(--warning-light); color: var(--warning); }
.deadline-upcoming .deadline-label { background: var(--accent-light); color: var(--accent); }

/* --- Project groups (week view) --- */
.project-group { margin-bottom: 24px; }
.project-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.project-group-name {
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}
.project-group-name a { color: inherit; }
.project-group-category {
    font-size: 0.72rem;
    color: var(--ink-muted);
    background: var(--border-light);
    padding: 1px 8px;
    border-radius: 10px;
}

/* --- Filters --- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}
.filter-group { display: flex; gap: 4px; flex-wrap: wrap; }
.filter-pill {
    font-size: 0.78rem;
    font-weight: 500;
    padding: 5px 12px;
    border-radius: 20px;
    color: var(--ink-secondary);
    background: var(--surface);
    border: 1px solid var(--border);
    transition: all 0.15s;
}
.filter-pill:hover { background: var(--bg); text-decoration: none; }
.filter-pill.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* --- Forms --- */
.form-page { max-width: 560px; }
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--ink-secondary);
    margin-bottom: 4px;
}
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.93rem;
    font-family: inherit;
    background: var(--surface);
    color: var(--ink);
    transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
@media (max-width: 480px) {
    .form-row { grid-template-columns: 1fr; }
}
.form-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}
.form-actions-right { display: flex; gap: 8px; }
.form-help-link {
    font-size: 0.75rem;
    display: inline-block;
    margin-top: 4px;
}
.form-help {
    font-size: 0.78rem;
    color: var(--ink-muted);
    margin-top: 6px;
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-weight: 500 !important;
}
.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.inline-form { margin-bottom: 20px; }
.inline-form-inner {
    display: flex;
    gap: 8px;
    align-items: center;
}
.inline-form-inner input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.87rem;
    font-family: inherit;
}
.inline-form-inner input:focus {
    outline: none;
    border-color: var(--accent);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 0.87rem;
    font-weight: 500;
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    text-decoration: none;
    white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: scale(0.98); }

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg); color: var(--ink-secondary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border-light); }
.btn-ghost { background: none; color: var(--ink-secondary); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--urgent); color: white; }
.btn-danger:hover { background: #B91C1C; }
.btn-danger-ghost { background: none; color: var(--urgent); }
.btn-danger-ghost:hover { background: var(--urgent-light); }
.btn-sm { padding: 4px 10px; font-size: 0.78rem; }
.btn-full { width: 100%; }

/* --- Modal --- */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}
@media (min-width: 641px) {
    .modal { align-items: center; }
}
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
}
.modal-content {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
}
@media (min-width: 641px) {
    .modal-content {
        border-radius: var(--radius);
        box-shadow: var(--shadow), 0 8px 32px rgba(0,0,0,0.12);
    }
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.modal-header h3 {
    font-size: 1.05rem;
    font-weight: 600;
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--ink-muted);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

/* --- Flash messages --- */
.flash-container {
    max-width: 960px;
    margin: 0 auto;
    padding: 8px 16px 0;
}
.flash {
    padding: 10px 16px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 8px;
    animation: flashIn 0.3s ease;
}
.flash-success { background: var(--success-light); color: var(--success); }
.flash-error { background: var(--urgent-light); color: var(--urgent); }
@keyframes flashIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* --- Empty states --- */
.empty-state {
    font-size: 0.85rem;
    color: var(--ink-muted);
    padding: 16px;
    text-align: center;
}
.empty-state-large {
    text-align: center;
    padding: 48px 24px;
}
.empty-state-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 8px;
}
.empty-state-large p {
    color: var(--ink-secondary);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

/* --- Login --- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}
.login-container {
    width: 100%;
    max-width: 320px;
    text-align: center;
}
.login-title {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: 4px;
}
.login-subtitle {
    color: var(--ink-muted);
    font-size: 0.9rem;
    margin-bottom: 32px;
}
.login-form { margin-top: 8px; }
.login-form .form-group { margin-bottom: 12px; }
.login-form input {
    text-align: center;
}

/* --- Settings --- */
.settings-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.87rem;
    font-weight: 500;
    margin-bottom: 12px;
}
.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.status-indicator.connected { background: var(--success); }
.settings-info {
    color: var(--ink-secondary);
    font-size: 0.87rem;
    margin-bottom: 12px;
}
.settings-help {
    margin-top: 16px;
    font-size: 0.85rem;
}
.settings-help summary {
    cursor: pointer;
    color: var(--accent);
    font-weight: 500;
}
.settings-help-content {
    margin-top: 12px;
    color: var(--ink-secondary);
    line-height: 1.7;
}
.settings-help-content ol { padding-left: 20px; }
.settings-help-content li { margin-bottom: 4px; }
.settings-help-content code {
    background: var(--border-light);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
}
.settings-help-content pre {
    background: var(--ink);
    color: #E5E5E5;
    padding: 12px;
    border-radius: var(--radius);
    margin: 8px 0;
    overflow-x: auto;
    font-size: 0.8rem;
}

/* --- Categories --- */
.categories-list { display: flex; flex-direction: column; gap: 12px; }
.category-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
}
.category-header h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 8px;
}
.subcategory-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}
.subcategory-tag {
    font-size: 0.78rem;
    padding: 3px 10px;
    background: var(--border-light);
    border-radius: 12px;
    color: var(--ink-secondary);
}
.subcategory-form { margin-top: 8px; }
.subcategory-form input { max-width: 200px; }

/* --- Project description --- */
.project-description {
    color: var(--ink-secondary);
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 24px;
    max-width: 600px;
}

/* --- Section danger --- */
.section-danger { margin-top: 48px; opacity: 0.7; }
.section-danger:hover { opacity: 1; }

/* --- Utilities --- */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}
