/* =========================================================
   TaskFlow — Design Tokens
   ========================================================= */
:root {
  --color-primary: #14213D;
  --color-primary-light: #1D2E52;
  --color-accent: #3B5BDB;
  --color-accent-light: #E8ECFB;
  --color-success: #2F9E64;
  --color-success-light: #E6F6ED;
  --color-warning: #C97A17;
  --color-warning-light: #FBF0DD;
  --color-danger: #C4432F;
  --color-danger-light: #FBEAE6;
  --color-bg: #F5F6FA;
  --color-surface: #FFFFFF;
  --color-border: #E5E8F0;
  --color-text: #1B1F27;
  --color-text-muted: #667085;
  --color-whatsapp: #1F8A5A;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --shadow-card: 0 10px 30px rgba(20, 33, 61, 0.07);
  --shadow-modal: 0 24px 60px rgba(20, 33, 61, 0.25);

  --font-heading: 'Poppins', 'Segoe UI', sans-serif;
  --font-body: 'Inter', 'Segoe UI', sans-serif;

  --sidebar-w: 240px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body { min-height: 100vh; }

h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--color-primary);
  margin: 0;
  line-height: 1.25;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1rem; }

p { margin: 0; line-height: 1.55; }

.hidden { display: none !important; }

a { color: var(--color-accent); }

button { font-family: inherit; cursor: pointer; }

input, select, textarea {
  font-family: inherit;
  font-size: 0.95rem;
}

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 20px;
  font-size: 0.92rem;
  font-weight: 600;
  font-family: var(--font-body);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background-color .12s ease;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
}
.btn:active { transform: scale(0.98); }
.btn-block { width: 100%; }

.btn-primary {
  background: var(--color-accent);
  color: #fff;
  box-shadow: 0 8px 20px rgba(59, 91, 219, 0.28);
}
.btn-primary:hover { background: #3151C7; }

.btn-ghost {
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover { background: var(--color-accent-light); }

.btn-outline-danger {
  background: transparent;
  color: var(--color-danger);
  border: 1px solid #EFC9C0;
}
.btn-outline-danger:hover { background: var(--color-danger-light); }

.btn-whatsapp {
  background: var(--color-whatsapp);
  color: #fff;
}
.btn-whatsapp:hover { background: #197A4E; }

.link-btn {
  background: none;
  border: none;
  color: var(--color-accent);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0;
}
.link-btn.danger { color: var(--color-danger); }
.link-btn:hover { text-decoration: underline; }

.icon-btn {
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-primary);
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }

/* =========================================================
   Auth Screens
   ========================================================= */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 18px;
  background:
    radial-gradient(1200px 500px at 50% -10%, #1D2E52 0%, var(--color-primary) 45%, #0F1830 100%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  padding: 32px 26px;
}

.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand-mark { display: inline-flex; }
.brand-name { font-family: var(--font-heading); font-weight: 700; font-size: 1.1rem; color: var(--color-primary); }

.auth-title { font-size: 1.35rem; margin-bottom: 8px; }
.auth-subtitle { color: var(--color-text-muted); font-size: 0.92rem; margin-bottom: 24px; }

.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-switch { margin-top: 18px; font-size: 0.88rem; color: var(--color-text-muted); text-align: center; }

/* =========================================================
   Form Fields
   ========================================================= */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.85rem; font-weight: 600; color: var(--color-primary); }
.field input, .field select, .field textarea {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: #FCFCFD;
  color: var(--color-text);
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
  width: 100%;
  resize: vertical;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-light);
  background: #fff;
}
.field-hint { font-size: 0.78rem; color: var(--color-text-muted); }
.field-error { font-size: 0.78rem; color: var(--color-danger); min-height: 1em; display: none; }
.field-error.show { display: block; }
.field input.invalid, .field select.invalid, .field textarea.invalid { border-color: var(--color-danger); }

.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; min-width: 0; }

.select-field {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  background: #FCFCFD;
  color: var(--color-text);
}

/* =========================================================
   App Shell
   ========================================================= */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 26px; }
.sidebar-brand .brand-name { color: #fff; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: transparent;
  border: none;
  color: #C7CEE0;
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-weight: 500;
  text-align: left;
}
.nav-item .nav-icon { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active { background: var(--color-accent); color: #fff; }

.sidebar-logout { color: #fff; border-color: rgba(255,255,255,0.2); }
.sidebar-logout:hover { background: rgba(255,255,255,0.08); }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-menu { display: none; }
.topbar-title { font-family: var(--font-heading); font-weight: 600; color: var(--color-primary); flex: 1; }
.user-chip {
  background: var(--color-accent-light);
  color: var(--color-accent);
  font-weight: 600;
  font-size: 0.82rem;
  padding: 8px 14px;
  border-radius: 999px;
}

.content { padding: 24px; flex: 1; }

.app-footer {
  text-align: center;
  padding: 18px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
}

.bottom-nav { display: none; }

.view { display: none; }
.view.active { display: block; animation: fadein .18s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: translateY(0);} }

/* =========================================================
   Page Head
   ========================================================= */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-head h1 { margin-bottom: 4px; }
.page-sub { color: var(--color-text-muted); font-size: 0.92rem; }
.page-head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.back-link { display: inline-block; margin-bottom: 8px; }

/* =========================================================
   Stat Cards
   ========================================================= */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 22px;
}
.stat-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stat-label { font-size: 0.8rem; color: var(--color-text-muted); font-weight: 600; }
.stat-value { font-family: var(--font-heading); font-size: 1.7rem; font-weight: 700; color: var(--color-primary); }
.stat-value-sm { font-size: 1.05rem; }
.stat-card-warn .stat-value { color: var(--color-warning); }
.stat-card-success .stat-value { color: var(--color-success); }
.stat-card-danger .stat-value { color: var(--color-danger); }

/* =========================================================
   Panels
   ========================================================= */
.panel-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.panel {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px;
  margin-bottom: 16px;
}
.panel-danger { border: 1px solid #F0D2CB; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }

.list-stack { display: flex; flex-direction: column; gap: 10px; }

/* =========================================================
   Cards: Projects / Tasks
   ========================================================= */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.project-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 20px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: box-shadow .15s ease, transform .15s ease;
}
.project-card:hover { box-shadow: 0 16px 34px rgba(20,33,61,.12); transform: translateY(-2px); }
.project-card h3 { font-size: 1.02rem; }
.project-card p { color: var(--color-text-muted); font-size: 0.85rem; }

.progress-track {
  height: 8px;
  border-radius: 99px;
  background: #EEF0F6;
  overflow: hidden;
}
.progress-fill { height: 100%; background: var(--color-accent); border-radius: 99px; transition: width .2s ease; }

.project-card-foot { display: flex; align-items: center; justify-content: space-between; font-size: 0.78rem; color: var(--color-text-muted); }

.list-item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.list-item-main { min-width: 0; }
.list-item-title { font-weight: 600; font-size: 0.92rem; color: var(--color-primary); margin-bottom: 3px; }
.list-item-sub { font-size: 0.8rem; color: var(--color-text-muted); }

.status-badge {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-todo { background: #EEF0F6; color: #4A5163; }
.badge-doing { background: var(--color-accent-light); color: var(--color-accent); }
.badge-done { background: var(--color-success-light); color: var(--color-success); }
.badge-overdue { background: var(--color-danger-light); color: var(--color-danger); }
.badge-soon { background: var(--color-warning-light); color: var(--color-warning); }

/* =========================================================
   Empty State
   ========================================================= */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--color-text-muted);
}
.empty-icon { font-size: 2.2rem; margin-bottom: 10px; }
.empty-state h3 { color: var(--color-primary); margin-bottom: 6px; }
.empty-state p { max-width: 360px; margin: 0 auto 18px; font-size: 0.9rem; }

/* =========================================================
   Kanban
   ========================================================= */
.pd-meta { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.meta-chip {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-primary);
}

.kanban {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  align-items: start;
}
.kanban-col {
  background: #EEF0F6;
  border-radius: var(--radius-lg);
  padding: 14px;
  min-height: 120px;
}
.kanban-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 0.86rem;
  color: var(--color-primary);
  margin-bottom: 12px;
  padding: 0 4px;
}
.count-badge {
  background: #fff;
  border-radius: 999px;
  font-size: 0.75rem;
  padding: 2px 9px;
  color: var(--color-text-muted);
  font-weight: 700;
}
.kanban-list { display: flex; flex-direction: column; gap: 10px; min-height: 40px; }
.kanban-list.drag-over { outline: 2px dashed var(--color-accent); outline-offset: 4px; border-radius: var(--radius-md); }

.task-card {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 14px;
  cursor: grab;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.task-card:active { cursor: grabbing; }
.task-card-title { font-weight: 600; font-size: 0.9rem; color: var(--color-primary); }
.task-card-meta { display: flex; align-items: center; justify-content: space-between; font-size: 0.76rem; color: var(--color-text-muted); }
.task-card-select { width: 100%; margin-top: 2px; font-size: 0.78rem; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--color-border); background: #FCFCFD; }
.kanban-empty { text-align: center; color: var(--color-text-muted); font-size: 0.8rem; padding: 14px 6px; }

/* =========================================================
   Calendar
   ========================================================= */
.cal-nav { display: flex; align-items: center; gap: 12px; }
.cal-month-label { font-family: var(--font-heading); font-weight: 600; color: var(--color-primary); min-width: 140px; text-align: center; }

.calendar-wrap {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 16px;
  margin-bottom: 16px;
}
.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-cell {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 0.82rem;
  color: var(--color-text);
  background: #FAFAFC;
  cursor: pointer;
  position: relative;
}
.cal-cell.empty { background: transparent; cursor: default; }
.cal-cell:not(.empty):hover { border-color: var(--color-accent); }
.cal-cell.today { border-color: var(--color-accent); font-weight: 700; }
.cal-cell.selected { background: var(--color-accent); color: #fff; }
.cal-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--color-accent); }
.cal-cell.selected .cal-dot { background: #fff; }

/* =========================================================
   Modal
   ========================================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 35, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}
.modal-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 24px 22px 28px;
  box-shadow: var(--shadow-modal);
  animation: slideup .2s ease;
}
@keyframes slideup { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.modal-actions-split { justify-content: space-between; flex-wrap: wrap; }
.modal-actions-right { display: flex; gap: 10px; flex-wrap: wrap; }

.task-detail-body { display: flex; flex-direction: column; gap: 14px; }
.td-row { display: flex; align-items: center; justify-content: space-between; font-size: 0.88rem; padding: 4px 0; border-bottom: 1px solid var(--color-border); }
.td-label { color: var(--color-text-muted); font-weight: 600; }

/* =========================================================
   Toast
   ========================================================= */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 16px);
  background: var(--color-primary);
  color: #fff;
  padding: 13px 22px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-modal);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast.toast-error { background: var(--color-danger); }
.toast.toast-success { background: var(--color-success); }

.filter-row { margin-bottom: 16px; }

/* =========================================================
   Responsive: Tablet
   ========================================================= */
@media (max-width: 1024px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-grid { grid-template-columns: 1fr; }
}

/* =========================================================
   Responsive: Mobile
   ========================================================= */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .topbar-menu { display: inline-flex; }
  .content { padding: 16px 14px 90px; }
  .kanban { grid-template-columns: 1fr; }
  .field-row { flex-direction: column; gap: 16px; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-value { font-size: 1.4rem; }
  h1 { font-size: 1.25rem; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head-actions { flex-direction: column; }
  .page-head-actions .btn { width: 100%; }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    justify-content: space-around;
    padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
    z-index: 20;
  }
  .bnav-item {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    color: var(--color-text-muted);
    font-size: 0.66rem;
    font-weight: 600;
    padding: 4px 6px;
  }
  .bnav-item .nav-icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; }
  .bnav-item.active { color: var(--color-accent); }

  .app-footer { padding-bottom: 90px; }

  .modal-card { max-height: 88vh; }

  .auth-card { padding: 26px 20px; }
}

@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .cards-grid { grid-template-columns: 1fr; }
}

/* Focus visibility for accessibility */
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
