@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --font-main: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg-app: #f6f8fa;
  --bg-card: #ffffff;
  --bg-section: #ffffff;

  --text-main: #111827;
  --text-muted: #6b7280;

  --border-light: rgba(0, 0, 0, 0.06);
  --border-focus: #6366f1;

  --color-todo: #6366f1;     --bg-todo: #e0e7ff;
  --color-doing: #f59e0b;    --bg-doing: #fef3c7;
  --color-done: #10b981;     --bg-done: #d1fae5;
  --color-danger: #ef4444;   --bg-danger: #fee2e2;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.05);
  --shadow-float: 0 12px 24px rgba(0,0,0,0.12);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font-main); background-color: var(--bg-app); color: var(--text-main); padding: 1.5rem; line-height: 1.5; }
.app-container { max-width: 1280px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.5rem; }

.icon { display: inline-flex; align-items: center; justify-content: center; width: 1em; min-width: 1em; font-style: normal; line-height: 1; }
.hidden { display: none !important; } /* Sửa lỗi không chuyển giao diện Popup đăng nhập */

/* Header & Stats */
.header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; margin-bottom: 0.25rem; }
.header-title h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text-main); }
.status-row { margin-top: 0.35rem; display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

.storage-status { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); display: inline-flex; align-items: center; gap: 0.35rem; }
.storage-status::before { content: '●'; font-size: 0.65rem; color: var(--color-done); }
.storage-status.error::before { color: var(--color-danger); }
.storage-status.saving::before { color: var(--color-doing); }

/* Compact Auth Button */
.auth-trigger-btn { background: #fff; border: 1px solid var(--border-light); border-radius: var(--radius-full); padding: 4px 12px 4px 8px; font-size: 0.8rem; font-weight: 600; color: var(--text-main); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; box-shadow: var(--shadow-sm); transition: all 0.2s; font-family: inherit; }
.auth-trigger-btn:hover { background: #f9fafb; border-color: #d1d5db; }
.auth-trigger-btn i { font-size: 1rem; color: var(--color-todo); }

.stats-line { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); background: var(--bg-card); padding: 0.6rem 1rem; border-radius: var(--radius-sm); border: 1px solid var(--border-light); display: inline-flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; box-shadow: var(--shadow-sm); letter-spacing: 0.02em; }
.stats-line span.val { font-size: 0.9rem; font-weight: 700; color: var(--text-main); margin-right: 2px; }
.text-danger { color: var(--color-danger) !important; font-weight: 700; display: inline-flex; align-items: center; }
.text-danger span.val { color: var(--color-danger); }
.text-warning { color: var(--color-doing) !important; font-weight: 700; display: inline-flex; align-items: center; }
.text-warning span.val { color: var(--color-doing); }

/* Section Styles */
.section { background: var(--bg-section); border-radius: var(--radius-lg); padding: 1.5rem; box-shadow: var(--shadow-sm); border: 1px solid var(--border-light); }
.section-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.25rem; }
.section-title { font-size: 1.1rem; font-weight: 600; display: flex; align-items: center; gap: 0.5rem; }

/* Filters */
.task-filters { display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; }
.filter-label { font-size: 0.78rem; font-weight: 700; color: var(--text-muted); letter-spacing: 0.02em; text-transform: uppercase; }
.filter-control { display: inline-flex; align-items: center; gap: 0.25rem; }
.filter-select { height: 34px; padding: 0 0.75rem; border-radius: var(--radius-sm); border: 1px solid #e5e7eb; background: #f9fafb; color: var(--text-main); font-family: inherit; font-size: 0.82rem; font-weight: 600; outline: none; min-width: 120px; }
.filter-select:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--bg-todo); background: var(--bg-card); }
.filter-clear { width: 28px; height: 34px; border-radius: var(--radius-sm); border: 1px solid #e5e7eb; background: var(--bg-card); color: var(--text-muted); cursor: pointer; font-size: 1rem; font-weight: 700; display: none; align-items: center; justify-content: center; }
.filter-clear:hover { background: #f3f4f6; color: var(--color-danger); border-color: #fecaca; }
.filter-control.active .filter-clear { display: inline-flex; }

/* Modal / Popup Styles */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(17, 24, 39, 0.4); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 9999; opacity: 0; pointer-events: none; transition: opacity 0.2s ease; }
.modal-overlay.show { opacity: 1; pointer-events: auto; }
.modal-content { background: var(--bg-card); width: 100%; max-width: 520px; border-radius: var(--radius-lg); box-shadow: var(--shadow-float); transform: translateY(20px) scale(0.95); transition: transform 0.2s ease; overflow: hidden; display: flex; flex-direction: column; margin: 1rem; }
.modal-overlay.show .modal-content { transform: translateY(0) scale(1); }
.modal-header { padding: 1.25rem 1.5rem; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-light); }
.modal-header h3 { font-size: 1.1rem; font-weight: 700; }
.modal-body { padding: 1.5rem; display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; max-height: 70vh; overflow-y: auto; }
.full-width { grid-column: 1 / -1; }
.modal-footer { padding: 1rem 1.5rem; display: flex; justify-content: flex-end; gap: 0.75rem; background: #f9fafb; border-top: 1px solid var(--border-light); }

/* Form Elements */
.input-group { display: flex; flex-direction: column; gap: 0.4rem; }
.input-group label { font-size: 0.8rem; font-weight: 600; color: var(--text-muted); }
.modern-input { height: 40px; padding: 0 1rem; border-radius: var(--radius-sm); border: 1px solid #e5e7eb; background: #f9fafb; font-family: inherit; font-size: 0.9rem; transition: all 0.2s ease; width: 100%; outline: none; }
.modern-input:focus { background: var(--bg-card); border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--bg-todo); }
.duration-picker { display: flex; align-items: center; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: var(--radius-sm); height: 40px; overflow: hidden; }
.duration-picker button { width: 36px; height: 100%; border: none; background: transparent; cursor: pointer; font-size: 1.2rem; color: var(--text-muted); transition: background 0.2s; }
.duration-picker button:hover { background: #e5e7eb; color: var(--text-main); }
.duration-picker input { flex: 1; min-width: 40px; text-align: center; border: none; background: transparent; font-family: var(--font-main); font-weight: 500; font-size: 0.9rem; color: var(--text-main); outline: none; appearance: textfield; -moz-appearance: textfield; }
.duration-picker input::-webkit-outer-spin-button, .duration-picker input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.btn-primary { height: 40px; padding: 0 1.25rem; background: var(--color-todo); color: #fff; border: none; border-radius: var(--radius-sm); font-weight: 600; font-size: 0.9rem; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; transition: transform 0.1s, background 0.2s; }
.btn-primary:hover { background: #4f46e5; }
.btn-primary:active { transform: scale(0.97); }
.btn-cancel { height: 40px; padding: 0 1.25rem; background: transparent; color: var(--text-muted); border: 1px solid var(--border-light); border-radius: var(--radius-sm); font-weight: 600; cursor: pointer; transition: all 0.2s; }
.btn-cancel:hover { background: #f3f4f6; color: var(--text-main); }

/* Kanban Board General with Scroll Snap */
.kanban-board { display: grid; grid-template-columns: repeat(3, minmax(280px, 1fr)); gap: 1.25rem; overflow-x: auto; padding-bottom: 0.5rem; overscroll-behavior-x: contain; scrollbar-width: thin; scroll-snap-type: x mandatory; }
.kanban-col { display: flex; flex-direction: column; background: #f3f4f6; border-radius: var(--radius-md); padding: 0.5rem; min-height: 200px; min-width: 280px; scroll-snap-align: start; }
.col-header { padding: 0.75rem; font-size: 0.9rem; font-weight: 600; display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; border-radius: var(--radius-sm); }
.kanban-col[data-status="todo"] .col-header { color: var(--color-todo); background: var(--bg-todo); }
.kanban-col[data-status="doing"] .col-header { color: var(--color-doing); background: var(--bg-doing); }
.kanban-col[data-status="done"] .col-header { color: var(--color-done); background: var(--bg-done); }
.col-count { background: rgba(255,255,255,0.7); padding: 0.1rem 0.6rem; border-radius: var(--radius-full); font-size: 0.75rem; color: inherit; margin-left: 6px; }
.kanban-list { flex: 1; display: flex; flex-direction: column; gap: 0.75rem; min-height: 80px; }
.empty-hint { color: var(--text-muted); font-size: 0.82rem; padding: 0.9rem; border: 1px dashed #d1d5db; border-radius: var(--radius-sm); text-align: center; background: rgba(255,255,255,0.5); }

/* Add Button in Kanban */
.add-col-btn { width: 28px; height: 28px; border-radius: var(--radius-sm); border: none; background: rgba(255,255,255,0.6); color: inherit; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.2s; font-weight: 800; font-size: 1rem; }
.add-col-btn:hover { background: #fff; transform: scale(1.05); }

/* Modern Card */
.card { background: var(--bg-card); border-radius: var(--radius-md); padding: 1rem 1rem 1rem 2.55rem; box-shadow: var(--shadow-sm); border: 1px solid var(--border-light); position: relative; overflow: visible; transition: box-shadow 0.2s, transform 0.2s; touch-action: pan-y; user-select: none; }
.card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; border-radius: 4px 0 0 4px; }
.card.todo::before { background: var(--color-todo); }
.card.doing::before { background: var(--color-doing); }
.card.done::before { background: var(--color-done); }
.card.overdue::before { background: var(--color-danger); }
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

/* Drag Handle */
/* Drag handle — chỉ làm visual indicator, không dùng để giới hạn vùng kéo */
.drag-handle { position: absolute; left: 0.7rem; top: 0.95rem; width: 20px; height: 32px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--text-muted); opacity: 0.3; pointer-events: none; }
.card:hover .drag-handle { opacity: 0.6; }
.drag-handle span { display: block; width: 14px; height: 2px; background: currentColor; border-radius: 1px; }
/* Toàn bộ card là vùng kéo — giống Trello */
.t-kanban-list .card,
.p-kanban-list .card { cursor: grab; }
.t-kanban-list .card:active,
.p-kanban-list .card:active { cursor: grabbing; }
/* Nút edit/delete không trigger kéo */
.card-actions, .icon-btn { cursor: pointer; }

.card-title { font-size: 0.9rem; font-weight: 600; color: var(--text-main); margin-bottom: 0.75rem; padding-right: 50px; line-height: 1.4; word-break: break-word; }
.card-actions { position: absolute; right: 0.5rem; top: 0.75rem; display: flex; gap: 0.25rem; opacity: 0; transition: opacity 0.2s; }
.card:hover .card-actions { opacity: 1; }
.icon-btn { width: 28px; height: 28px; border-radius: var(--radius-sm); border: none; background: transparent; color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.2s; font-weight: 700; }
.icon-btn:hover { background: #f3f4f6; color: var(--text-main); }
.icon-btn.delete:hover { background: var(--bg-danger); color: var(--color-danger); }
.icon-btn.edit:hover { background: var(--bg-todo); color: var(--color-todo); }
.badges-wrap { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.75rem; }
.badge { font-size: 0.7rem; font-weight: 600; padding: 0.2rem 0.5rem; border-radius: var(--radius-sm); display: inline-flex; align-items: center; gap: 0.25rem; }
.badge.project { background: #f3f4f6; color: var(--text-muted); }
.card-footer { display: flex; align-items: center; font-size: 0.75rem; color: var(--text-muted); font-weight: 500; }
.card-footer .icon { margin-right: 0.25rem; }
.overdue-text { color: var(--color-danger); font-weight: 600; margin-left: auto; }
.risk-text { color: var(--color-doing); font-weight: 600; margin-left: auto; }

/* Pointer Drag System */
.drag-ghost { position: fixed !important; z-index: 10000 !important; pointer-events: none !important; box-shadow: var(--shadow-float) !important; transform: scale(1.02) rotate(2deg); opacity: 0.95; background: var(--bg-card); }
body.dragging-active { cursor: grabbing; overscroll-behavior: none; }
body.dragging-active .card:not(.drag-ghost) { transition: none; }
.kanban-list.drag-over { outline: 2px dashed rgba(99, 102, 241, 0.35); outline-offset: 4px; border-radius: var(--radius-sm); }
.drop-indicator { position: absolute; left: 0; right: 0; height: 2px; background: var(--color-todo); pointer-events: none; z-index: 20; display: none; }
.drop-indicator.top { top: -7px; display: block; }
.drop-indicator.bottom { bottom: -7px; display: block; }

/* Sortable.js drag states — giống Trello */
.sortable-ghost {
  opacity: 0.35;
  background: var(--bg-todo) !important;
  border: 2px dashed var(--color-todo) !important;
  box-shadow: none !important;
}
.sortable-chosen {
  box-shadow: 0 8px 24px rgba(0,0,0,0.18) !important;
  transform: rotate(1.5deg) scale(1.02) !important;
  cursor: grabbing !important;
}
.sortable-drag {
  opacity: 0 !important;
}

/* Timeline */
.timeline-scroll { overflow-x: auto; padding-bottom: 1rem; }
.timeline-track { position: relative; min-width: max-content; padding-top: 30px; }
.timeline-grid { display: flex; border-bottom: 1px solid #e5e7eb; padding-bottom: 0.5rem; }
.t-day { width: 48px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; position: relative; }
.t-day span { font-size: 0.7rem; color: var(--text-muted); font-weight: 500; margin-bottom: 8px; }
.t-dot { width: 6px; height: 6px; background: #d1d5db; border-radius: 50%; }
.t-day.today span { color: var(--color-todo); font-weight: 700; }
.t-day.today .t-dot { background: var(--color-todo); box-shadow: 0 0 0 4px var(--bg-todo); width: 8px; height: 8px; }
.today-line { position: absolute; width: 2px; background: var(--color-todo); opacity: 0.28; top: 0; bottom: 0; z-index: 1; pointer-events: none; }
.timeline-bars { position: relative; margin-top: 1rem; min-height: 60px; z-index: 2; }
.t-bar { position: absolute; height: 28px; border-radius: 6px; display: flex; align-items: center; padding: 0 8px; font-size: 0.75rem; font-weight: 600; color: #fff; box-shadow: var(--shadow-sm); transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); cursor: pointer; overflow: hidden; white-space: nowrap; }
.t-bar:hover { filter: brightness(1.1); transform: translateY(-2px); z-index: 10; box-shadow: var(--shadow-md); }
.t-bar.todo { background: var(--color-todo); }
.t-bar.doing { background: var(--color-doing); }
.t-bar.done { background: var(--color-done); opacity: 0.6; }
.t-bar.overdue { background: var(--color-danger); }

/* Cloud Auth Form — luôn single-column, không dùng grid của modal-body */
.auth-body-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
}
.auth-intro {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}
.auth-btn-row {
  display: flex;
  gap: 0.5rem;
}
.auth-btn-row .btn-cancel,
.auth-btn-row .btn-primary {
  flex: 1;
}
.auth-box { text-align: center; padding: 1.5rem; }
.auth-box h4 { margin-bottom: 0.5rem; }
.auth-box p { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.5rem; }

@media (max-width: 1024px) {
  .modal-body { grid-template-columns: 1fr; }
  .section-header { align-items: flex-start; flex-direction: column; }
  .task-filters { justify-content: flex-start; width: 100%; }
}

@media (max-width: 640px) {
  body { padding: 1rem; }
  .header { flex-direction: column; align-items: flex-start; }
  .section { padding: 1rem; }
  .stats-line { width: 100%; justify-content: space-between; }
  .filter-select { flex: 1; min-width: 130px; }
  .kanban-board { margin-inline: -0.25rem; padding-inline: 0.25rem; }
}
