/* ===== Variables ===== */
:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --dark: #0f172a;
  --surface: #ffffff;
  --surface2: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --text2: #64748b;
  --danger: #ef4444;
  --success: #10b981;
  --p0: #dc2626;
  --p1: #ea580c;
  --p2: #2563eb;
  --p3: #6b7280;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.12);
  --transition: all 0.2s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; font-family: 'Inter', -apple-system, sans-serif; color: var(--text); background: var(--surface2); overflow: hidden; }

/* ===== Login ===== */
#login-screen { display: flex; align-items: center; justify-content: center; height: 100vh; background: var(--gradient); }
.login-card { background: white; border-radius: 20px; padding: 2.5rem; width: min(380px, 90vw); text-align: center; box-shadow: var(--shadow-lg); }
.login-card .logo { font-size: 2.5rem; font-weight: 800; background: var(--gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; margin-bottom: 0.5rem; }
.login-card h2 { font-size: 1.3rem; color: var(--text); margin-bottom: 0.5rem; }
.login-card p { color: var(--text2); font-size: 0.9rem; margin-bottom: 2rem; }
.pin-input { width: 100%; padding: 1rem; font-size: 1.5rem; text-align: center; letter-spacing: 0.5em; border: 2px solid var(--border); border-radius: var(--radius); margin-bottom: 1.5rem; transition: var(--transition); font-family: monospace; }
.pin-input:focus { outline: none; border-color: var(--primary); }
.btn-login { width: 100%; padding: 1rem; background: var(--gradient); color: white; border: none; border-radius: var(--radius); font-size: 1rem; font-weight: 600; cursor: pointer; transition: var(--transition); }
.btn-login:hover { opacity: 0.9; transform: translateY(-1px); }
.login-error { color: var(--danger); font-size: 0.9rem; margin-top: 1rem; display: none; }
.login-divider { display: flex; align-items: center; gap: 0.75rem; margin: 1.25rem 0 1rem; color: var(--text2); font-size: 0.8rem; letter-spacing: 0.03em; }
.login-divider::before, .login-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.btn-guest { width: 100%; padding: 0.75rem 1rem; background: var(--surface2); border: 1.5px solid var(--border); border-radius: var(--radius); cursor: pointer; transition: var(--transition); display: flex; align-items: center; gap: 0.85rem; text-align: left; }
.btn-guest:hover { border-color: var(--primary); background: rgba(99,102,241,0.04); box-shadow: 0 2px 12px rgba(99,102,241,0.08); }
.btn-guest-icon { width: 38px; height: 38px; background: var(--gradient); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: white; flex-shrink: 0; font-size: 0.95rem; }
.btn-guest-label { flex: 1; }
.btn-guest-label strong { display: block; font-size: 0.9rem; font-weight: 700; color: var(--text); }
.btn-guest-label small { font-size: 0.73rem; color: var(--text2); font-weight: 400; }
.btn-guest-arrow { color: var(--text2); font-size: 0.7rem; flex-shrink: 0; transition: var(--transition); }
.btn-guest:hover .btn-guest-arrow { color: var(--primary); transform: translateX(2px); }

/* Demo Banner */
.demo-banner { background: linear-gradient(90deg, #f59e0b, #f97316); color: white; padding: 0.6rem 1.5rem; display: flex; align-items: center; gap: 0.75rem; font-size: 0.85rem; flex-shrink: 0; }
.demo-banner i { flex-shrink: 0; }
.demo-banner span { flex: 1; }
.demo-banner-exit { background: rgba(255,255,255,0.2); border: 1px solid rgba(255,255,255,0.4); color: white; padding: 0.3rem 0.8rem; border-radius: 6px; font-size: 0.8rem; font-weight: 600; cursor: pointer; transition: var(--transition); white-space: nowrap; flex-shrink: 0; }
.demo-banner-exit:hover { background: rgba(255,255,255,0.35); }

/* ===== App Layout ===== */
#app { display: none; height: 100vh; flex-direction: column; }
.app-header { background: var(--dark); color: white; padding: 0 1.5rem; height: 56px; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; z-index: 100; }
.app-header .logo { font-size: 1.2rem; font-weight: 800; background: var(--gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.header-actions { display: flex; gap: 0.75rem; align-items: center; }
.btn-icon { background: rgba(255,255,255,0.1); border: none; color: white; width: 36px; height: 36px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: var(--transition); font-size: 0.9rem; }
.btn-icon:hover { background: rgba(255,255,255,0.2); }
.btn-new-task { background: var(--primary); border: none; color: white; padding: 0.5rem 1rem; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 0.9rem; display: flex; align-items: center; gap: 0.4rem; transition: var(--transition); }
.btn-new-task:hover { background: var(--primary-dark); }

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

.task-list-panel { width: 340px; min-width: 220px; max-width: 560px; flex-shrink: 0; background: var(--surface2); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }

/* ===== Resize Handle ===== */
.resize-handle { width: 5px; flex-shrink: 0; cursor: col-resize; background: transparent; position: relative; transition: background 0.15s; z-index: 10; }
.resize-handle:hover, .resize-handle.dragging { background: var(--primary); }
.resize-handle::after { content: ''; position: absolute; inset: 0 -4px; }

/* ===== Filter Bar ===== */
.filter-bar { padding: 0.85rem 1rem 0.65rem; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.filter-tabs { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.filter-tab { padding: 0.3rem 0.65rem; border-radius: 20px; border: 1.5px solid var(--border); background: transparent; color: var(--text2); font-size: 0.78rem; font-weight: 500; cursor: pointer; transition: var(--transition); }
.filter-tab.active, .filter-tab:hover { background: var(--primary); border-color: var(--primary); color: white; }

/* ===== Task List ===== */
.task-list-scroll { flex: 1; overflow-y: auto; padding: 0.85rem; display: flex; flex-direction: column; gap: 0.5rem; }
.task-card { background: var(--surface); border-radius: var(--radius); padding: 0.9rem 1.1rem; cursor: pointer; border: 2px solid transparent; transition: var(--transition); box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
.task-card:hover { box-shadow: var(--shadow); border-color: var(--border); }
.task-card.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,0.1); }
.task-card.done { opacity: 0.55; }
.task-card.overdue .task-due { color: var(--danger); }
.task-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.45rem; }
.task-title { font-weight: 600; font-size: 0.92rem; line-height: 1.3; flex: 1; }
.task-card.done .task-title { text-decoration: line-through; }
.priority-badge { font-size: 0.68rem; font-weight: 700; padding: 0.18rem 0.45rem; border-radius: 6px; flex-shrink: 0; color: white; }
.priority-badge.P0 { background: var(--p0); }
.priority-badge.P1 { background: var(--p1); }
.priority-badge.P2 { background: var(--p2); }
.priority-badge.P3 { background: var(--p3); }
.task-meta { display: flex; gap: 0.75rem; font-size: 0.75rem; color: var(--text2); align-items: center; }
.task-due { display: flex; align-items: center; gap: 0.25rem; }
.task-counts { display: flex; gap: 0.6rem; margin-left: auto; }
.task-count-item { display: flex; align-items: center; gap: 0.2rem; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text2); }
.empty-state i { font-size: 3rem; margin-bottom: 1rem; opacity: 0.4; display: block; }

/* ===== Detail Panel ===== */
.task-detail-panel { flex: 1; overflow-y: auto; background: var(--surface); display: flex; flex-direction: column; min-width: 0; }
.detail-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text2); flex-direction: column; gap: 1rem; }
.loading-tasks { display: flex; align-items: center; justify-content: center; padding: 2rem; color: var(--text2); font-size: 1.2rem; }
.detail-empty i { font-size: 4rem; opacity: 0.3; }
.detail-content { padding: 2rem 2.5rem; width: 100%; }

.detail-header { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.detail-title-area { flex: 1; }
.detail-title { font-size: 1.5rem; font-weight: 700; line-height: 1.3; margin-bottom: 0.75rem; border: none; outline: none; width: 100%; font-family: inherit; color: var(--text); background: transparent; }
.detail-title:focus { background: var(--surface2); border-radius: 8px; padding: 0.25rem 0.5rem; }
.detail-meta-row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.meta-select { padding: 0.4rem 0.7rem; border: 1.5px solid var(--border); border-radius: 8px; font-size: 0.85rem; font-family: inherit; color: var(--text); background: white; cursor: pointer; transition: var(--transition); }
.meta-select:focus { outline: none; border-color: var(--primary); }
.priority-select.P0 { border-color: var(--p0); color: var(--p0); }
.priority-select.P1 { border-color: var(--p1); color: var(--p1); }
.priority-select.P2 { border-color: var(--p2); color: var(--p2); }
.priority-select.P3 { border-color: var(--p3); color: var(--p3); }
.detail-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.btn-detail-action { padding: 0.5rem 0.9rem; border-radius: 8px; border: 1.5px solid var(--border); background: white; cursor: pointer; font-size: 0.85rem; font-weight: 500; display: flex; align-items: center; gap: 0.4rem; transition: var(--transition); color: var(--text); }
.btn-detail-action:hover { border-color: var(--primary); color: var(--primary); }
.btn-detail-action.danger:hover { border-color: var(--danger); color: var(--danger); }

/* ===== Detail Sections ===== */
.detail-section { margin-bottom: 2rem; }
.detail-section h3 { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text2); margin-bottom: 0.75rem; display: flex; align-items: center; gap: 0.4rem; }
.section-header-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.section-header-row h3 { margin-bottom: 0; }

.description-area { width: 100%; min-height: 90px; padding: 0.75rem 1rem; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: 0.95rem; font-family: inherit; color: var(--text); resize: vertical; transition: var(--transition); line-height: 1.6; }
.description-area:focus { outline: none; border-color: var(--primary); }

/* ===== Subtasks ===== */
.subtask-list { display: flex; flex-direction: column; gap: 0.35rem; }
.subtask-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.45rem 0.75rem; border-radius: 8px; transition: var(--transition); }
.subtask-item:hover { background: var(--surface2); }
.subtask-check { width: 16px; height: 16px; flex-shrink: 0; cursor: pointer; accent-color: var(--primary); }
.subtask-text { flex: 1; border: none; outline: none; background: transparent; font-family: inherit; font-size: 0.93rem; color: var(--text); padding: 0; }
.subtask-text.done { text-decoration: line-through; color: var(--text2); }
.subtask-delete { opacity: 0; background: none; border: none; color: var(--danger); cursor: pointer; padding: 0.2rem; border-radius: 4px; font-size: 0.8rem; transition: var(--transition); }
.subtask-item:hover .subtask-delete { opacity: 1; }
.add-subtask-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.45rem 0.75rem; margin-top: 0.2rem; }
.add-subtask-input { flex: 1; border: none; border-bottom: 1.5px dashed var(--border); outline: none; font-family: inherit; font-size: 0.93rem; color: var(--text); padding: 0.2rem 0; background: transparent; transition: var(--transition); }
.add-subtask-input:focus { border-color: var(--primary); }
.add-subtask-input::placeholder { color: var(--text2); }

/* ===== Tables ===== */
.table-picker-wrapper { position: relative; }

.btn-add-table { display: flex; align-items: center; gap: 0.4rem; padding: 0.4rem 0.85rem; border: 1.5px solid var(--border); border-radius: 8px; background: white; color: var(--text2); font-size: 0.82rem; font-weight: 600; cursor: pointer; transition: var(--transition); }
.btn-add-table:hover { border-color: var(--primary); color: var(--primary); }

.table-picker { position: absolute; right: 0; top: calc(100% + 6px); background: white; border: 1px solid var(--border); border-radius: 12px; padding: 0.85rem; box-shadow: var(--shadow-lg); z-index: 200; display: none; min-width: 200px; }
.table-picker.open { display: block; }
.picker-grid { display: grid; grid-template-columns: repeat(8, 22px); gap: 3px; margin-bottom: 0.5rem; }
.picker-cell { width: 22px; height: 22px; border: 1.5px solid var(--border); border-radius: 4px; cursor: pointer; transition: var(--transition); background: var(--surface2); }
.picker-cell.highlighted { background: rgba(99,102,241,0.15); border-color: var(--primary); }
.picker-label { font-size: 0.78rem; color: var(--text2); text-align: center; font-weight: 500; }

.tables-list { display: flex; flex-direction: column; gap: 1.25rem; }

.task-table-wrapper { border: 1.5px solid var(--border); border-radius: var(--radius); overflow: hidden; background: white; }

.task-table-header { display: flex; align-items: center; justify-content: space-between; padding: 0.6rem 0.85rem; background: var(--surface2); border-bottom: 1px solid var(--border); gap: 0.75rem; }
.task-table-title { flex: 1; border: none; outline: none; font-family: inherit; font-size: 0.88rem; font-weight: 600; color: var(--text); background: transparent; }
.task-table-title::placeholder { color: var(--text2); font-weight: 400; }
.task-table-controls { display: flex; gap: 0.4rem; flex-shrink: 0; }
.btn-table-ctrl { display: flex; align-items: center; gap: 0.3rem; padding: 0.3rem 0.6rem; border: 1.5px solid var(--border); border-radius: 6px; background: white; color: var(--text2); font-size: 0.75rem; font-weight: 600; cursor: pointer; transition: var(--transition); white-space: nowrap; }
.btn-table-ctrl:hover { border-color: var(--primary); color: var(--primary); }
.btn-table-ctrl.del:hover { border-color: var(--danger); color: var(--danger); }

.task-table-scroll { overflow-x: auto; }

.task-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; table-layout: fixed; }
.task-table th, .task-table td { border: 1px solid var(--border); padding: 0; min-width: 100px; overflow: hidden; }
.task-table th { background: #f1f5f9; }
.task-table th input, .task-table td input { width: 100%; padding: 0.55rem 0.75rem; border: none; outline: none; font-family: inherit; font-size: 0.88rem; background: transparent; color: var(--text); }
.task-table th input { font-weight: 600; }
.task-table td:hover { background: #fafafa; }
.task-table th input:focus, .task-table td input:focus { background: rgba(99,102,241,0.05); }

/* Action cells — narrow, no border */
.col-del-cell, .row-del-cell { border: none !important; background: transparent !important; padding: 0 !important; text-align: center; vertical-align: middle; overflow: visible; }
.col-del-row .col-del-cell { padding: 2px 0 !important; }

.btn-del-col { width: 100%; height: 18px; border: none; background: transparent; color: transparent; font-size: 0.7rem; cursor: pointer; transition: var(--transition); display: flex; align-items: center; justify-content: center; }
.task-table-scroll:hover .btn-del-col { color: #cbd5e1; }
.btn-del-col:hover { color: var(--danger) !important; }

.btn-del-row { border: none; background: transparent; color: transparent; font-size: 0.75rem; cursor: pointer; padding: 0.25rem; transition: var(--transition); }
.task-table-scroll:hover .btn-del-row { color: #cbd5e1; }
.btn-del-row:hover { color: var(--danger) !important; }

/* ===== Attachments ===== */
.upload-zone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.5rem; text-align: center; cursor: pointer; transition: var(--transition); color: var(--text2); font-size: 0.9rem; }
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--primary); background: rgba(99,102,241,0.04); color: var(--primary); }
.upload-zone i { font-size: 1.5rem; margin-bottom: 0.5rem; display: block; }
#file-input, #new-file-input { display: none; }

.upload-zone-sm { padding: 0.75rem 1rem; font-size: 0.88rem; display: flex; align-items: center; gap: 0.5rem; flex-direction: row; justify-content: center; }
.upload-zone-sm i { font-size: 1rem; margin: 0; display: inline; }
.new-file-list { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.5rem; }
.new-file-item { display: flex; align-items: center; padding: 0.4rem 0.6rem; background: var(--surface2); border-radius: 8px; font-size: 0.85rem; color: var(--text); gap: 0.5rem; }
.new-file-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.new-file-remove { background: none; border: none; color: var(--danger); cursor: pointer; padding: 0.2rem 0.4rem; font-size: 0.8rem; flex-shrink: 0; }

.attachment-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.75rem; margin-top: 1rem; }
.attachment-item { position: relative; border-radius: var(--radius); overflow: hidden; border: 1.5px solid var(--border); background: var(--surface2); transition: var(--transition); }
.attachment-item:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.attachment-thumb { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; cursor: pointer; }
.attachment-file-icon { width: 100%; aspect-ratio: 4/3; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 0.4rem; font-size: 0.75rem; color: var(--text2); padding: 0.5rem; text-align: center; }
.attachment-file-icon i { font-size: 2rem; color: var(--primary); }
.attachment-heic-zone { width: 100%; aspect-ratio: 4/3; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 0.5rem; background: var(--surface2); }
.attachment-heic-zone i { font-size: 2rem; color: var(--text2); }
.attachment-heic-zone span { font-size: 0.7rem; color: var(--text2); }
.btn-heic-preview { padding: 0.3rem 0.8rem; border: 1.5px solid var(--primary); border-radius: 6px; background: white; color: var(--primary); font-size: 0.75rem; font-weight: 600; cursor: pointer; transition: var(--transition); }
.btn-heic-preview:hover { background: var(--primary); color: white; }
.attachment-footer { padding: 0.4rem 0.5rem; display: flex; align-items: center; justify-content: space-between; border-top: 1px solid var(--border); background: white; }
.attachment-name { font-size: 0.72rem; color: var(--text); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; margin-right: 0.4rem; }
.attachment-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }
.btn-attach-action { background: none; border: none; cursor: pointer; padding: 0.2rem; border-radius: 4px; font-size: 0.8rem; transition: var(--transition); }
.btn-attach-action.download { color: var(--primary); }
.btn-attach-action.delete { color: var(--danger); }
.btn-attach-action:hover { background: var(--surface2); }
.upload-progress { margin-top: 0.5rem; font-size: 0.85rem; color: var(--text2); display: none; }

/* ===== Lightbox ===== */
#lightbox { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 9999; align-items: center; justify-content: center; }
#lightbox.open { display: flex; }
#lightbox img { max-width: 92vw; max-height: 88vh; border-radius: var(--radius); object-fit: contain; }
.lightbox-close { position: absolute; top: 1rem; right: 1.5rem; color: white; font-size: 2rem; cursor: pointer; line-height: 1; }

/* ===== Create Modal ===== */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 2000; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal-box { background: white; border-radius: 16px; padding: 2rem; width: min(480px, 94vw); box-shadow: var(--shadow-lg); max-height: 90vh; overflow-y: auto; }
.modal-box h2 { font-size: 1.25rem; margin-bottom: 1.5rem; }
.form-field { margin-bottom: 1.25rem; }
.form-field label { display: block; font-size: 0.78rem; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.4rem; }
.form-input { width: 100%; padding: 0.75rem 1rem; border: 1.5px solid var(--border); border-radius: 10px; font-size: 0.95rem; font-family: inherit; color: var(--text); transition: var(--transition); }
.form-input:focus { outline: none; border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.5rem; }
.btn-cancel { padding: 0.75rem 1.5rem; border: 1.5px solid var(--border); background: white; border-radius: 10px; font-size: 0.95rem; cursor: pointer; transition: var(--transition); }
.btn-cancel:hover { border-color: var(--text2); }
.btn-create { padding: 0.75rem 1.5rem; background: var(--gradient); color: white; border: none; border-radius: 10px; font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: var(--transition); }
.btn-create:hover { opacity: 0.9; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* ===== Mobile ===== */
@media (max-width: 768px) {
  html, body { overflow: auto; }
  #app { height: auto; min-height: 100vh; overflow: visible; }
  .app-body { flex-direction: column; overflow: visible; }
  .task-list-panel { width: 100% !important; min-width: unset; max-width: unset; border-right: none; border-bottom: 1px solid var(--border); max-height: none; overflow: visible; }
  .task-list-scroll { overflow: visible; max-height: none; }
  .resize-handle { display: none; }
  .task-detail-panel { overflow: visible; min-height: 60vh; }
  .detail-content { padding: 1.25rem; }
  .detail-header { flex-direction: column; }
  .detail-actions { flex-wrap: wrap; }
  .form-row { grid-template-columns: 1fr; }
  .attachment-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .picker-grid { grid-template-columns: repeat(6, 22px); }
}
