/* =========================================================================
   TaskPilot — design tokens
   Palette: ink (#14161C), paper (#F6F5F1), signal (#5B5BD6 indigo — the
   single accent, reserved for the AI feature and primary actions),
   line (#E4E2DB), success (#1F8A5F), warning (#B8720A), danger (#C43D3D).
   Type: "Space Grotesk" for display/headings (geometric, engineered feel
   that suits a planning tool), "Inter" for body/UI, "IBM Plex Mono" for
   meta data — estimates, dates, counts — nodding to the idea that a plan
   is made of measurable units.
   ========================================================================= */

:root {
  --ink: #14161c;
  --ink-soft: #4a4d59;
  --paper: #f6f5f1;
  --paper-raised: #ffffff;
  --signal: #5b5bd6;
  --signal-soft: #ecebfb;
  --line: #e4e2db;
  --line-strong: #cfccc1;
  --success: #1f8a5f;
  --success-soft: #e5f4ee;
  --warning: #b8720a;
  --warning-soft: #fbf0dc;
  --danger: #c43d3d;
  --danger-soft: #fbeaea;

  --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-card: 0 1px 2px rgba(20, 22, 28, 0.04), 0 8px 24px rgba(20, 22, 28, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; letter-spacing: -0.01em; }

a { color: inherit; }

button {
  font-family: var(--font-body);
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

.mono { font-family: var(--font-mono); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: #2a2d38; }

.btn-signal { background: var(--signal); color: #fff; }
.btn-signal:hover { background: #4949c4; }

.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn-ghost:hover { background: var(--paper-raised); border-color: var(--ink); }

.btn-danger-ghost { background: transparent; border-color: var(--line-strong); color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
}
.btn-icon:hover { background: var(--line); }

/* ---------- Forms ---------- */

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], textarea, select {
  width: 100%;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--signal);
  outline: none;
  box-shadow: 0 0 0 3px var(--signal-soft);
}
textarea { resize: vertical; min-height: 70px; }

.field { margin-bottom: 16px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.form-error {
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.form-error.visible { display: block; }

/* =========================================================================
   Auth page
   ========================================================================= */

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
}

.auth-hero {
  background: var(--ink);
  color: var(--paper);
  padding: 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.auth-hero::after {
  content: "";
  position: absolute;
  right: -120px;
  bottom: -120px;
  width: 360px;
  height: 360px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(91,91,214,0.35), transparent 70%);
}

.auth-brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 20px; font-weight: 700; }
.auth-brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--signal); }

.auth-hero-copy h1 { font-size: 40px; line-height: 1.15; max-width: 460px; }
.auth-hero-copy p { color: #b9bac4; font-size: 16px; max-width: 420px; margin-top: 16px; }

.auth-hero-signature {
  font-family: var(--font-mono);
  font-size: 13px;
  color: #8f91a3;
  border-top: 1px solid #2a2d38;
  padding-top: 18px;
  max-width: 420px;
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { font-size: 26px; margin-bottom: 6px; }
.auth-card .sub { color: var(--ink-soft); font-size: 14px; margin-bottom: 28px; }

.auth-toggle { display: flex; gap: 24px; margin-bottom: 28px; border-bottom: 1px solid var(--line); }
.auth-toggle button {
  background: none; border: none; padding: 10px 2px; font-size: 15px; font-weight: 600;
  color: var(--ink-soft); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.auth-toggle button.active { color: var(--ink); border-bottom-color: var(--signal); }

.auth-form { display: none; }
.auth-form.active { display: block; }
.auth-form .btn { width: 100%; justify-content: center; margin-top: 6px; }

/* =========================================================================
   App shell
   ========================================================================= */

.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--ink);
  color: var(--paper);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
}

.sidebar-brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 18px; padding: 4px 8px 22px; }
.sidebar-brand .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--signal); }

.sidebar-section-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8f91a3;
  padding: 0 8px;
  margin: 18px 0 8px;
}

.project-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
.project-list li { margin-bottom: 2px; }

.project-list button {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #c7c8d3;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.project-list button:hover { background: #22242e; color: #fff; }
.project-list button.active { background: var(--signal-soft); color: var(--ink); background: var(--signal); color: #fff; }
.project-list .count { font-family: var(--font-mono); font-size: 11px; opacity: 0.7; }

.sidebar-footer { border-top: 1px solid #262832; padding-top: 14px; margin-top: 12px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.sidebar-user .avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--signal);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.sidebar-user .who { flex: 1; min-width: 0; }
.sidebar-user .who .name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .who .email { font-size: 11px; color: #8f91a3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .logout { background: none; border: none; color: #8f91a3; font-size: 12px; padding: 8px; }
.sidebar-footer .logout:hover { color: #fff; }

/* ---------- Main content ---------- */

.main { padding: 28px 36px 60px; overflow-y: auto; }

.main-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.main-header h1 { font-size: 24px; }
.main-header .project-desc { color: var(--ink-soft); font-size: 14px; margin-top: 6px; max-width: 620px; }
.main-header-actions { display: flex; gap: 10px; flex-shrink: 0; }

.empty-state { text-align: center; padding: 100px 20px; color: var(--ink-soft); }
.empty-state h2 { font-size: 20px; margin-bottom: 8px; color: var(--ink); }
.empty-state .btn { margin-top: 18px; }

/* View toggle + filters */

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.view-toggle { display: inline-flex; background: var(--line); border-radius: var(--radius-sm); padding: 3px; }
.view-toggle button {
  background: none; border: none; padding: 7px 14px; font-size: 13px; font-weight: 600; color: var(--ink-soft); border-radius: 5px;
}
.view-toggle button.active { background: var(--paper-raised); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select { width: auto; padding: 7px 10px; font-size: 13px; }

/* ---------- List view ---------- */

.task-table { width: 100%; border-collapse: collapse; background: var(--paper-raised); border-radius: var(--radius-md); overflow: hidden; box-shadow: var(--shadow-card); }
.task-table thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-soft); font-weight: 700; padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: #fbfaf7;
}
.task-table tbody td { padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.task-table tbody tr:last-child td { border-bottom: none; }
.task-table tbody tr:hover { background: #fbfaf7; cursor: pointer; }
.task-title-cell { font-weight: 600; }
.task-title-cell .ai-tag { font-size: 10px; color: var(--signal); font-family: var(--font-mono); margin-left: 6px; }

/* ---------- Badges ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-status-todo { background: var(--line); color: var(--ink-soft); }
.badge-status-in_progress { background: var(--warning-soft); color: var(--warning); }
.badge-status-done { background: var(--success-soft); color: var(--success); }

.badge-priority-low { background: var(--line); color: var(--ink-soft); }
.badge-priority-medium { background: #eef0fb; color: #4949c4; }
.badge-priority-high { background: var(--danger-soft); color: var(--danger); }

.due-date { font-family: var(--font-mono); font-size: 12.5px; color: var(--ink-soft); }
.due-date.overdue { color: var(--danger); font-weight: 700; }

.assignee-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.assignee-chip .avatar-sm { width: 20px; height: 20px; border-radius: 50%; background: var(--signal-soft); color: var(--signal); font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

/* ---------- Kanban view ---------- */

.kanban { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; align-items: start; }

.kanban-col { background: #fbfaf7; border-radius: var(--radius-lg); border: 1px solid var(--line); min-height: 200px; }
.kanban-col-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; }
.kanban-col-head h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; }
.kanban-col-head .count { font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft); background: var(--line); padding: 1px 8px; border-radius: 999px; }

.kanban-col.drag-over { outline: 2px dashed var(--signal); outline-offset: -6px; background: var(--signal-soft); }

.kanban-cards { padding: 4px 12px 14px; display: flex; flex-direction: column; gap: 10px; min-height: 60px; }

.kanban-card {
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius-md);
  padding: 12px 13px; box-shadow: var(--shadow-card); cursor: grab;
}
.kanban-card:active { cursor: grabbing; }
.kanban-card .kc-title { font-weight: 600; font-size: 13.5px; margin-bottom: 8px; }
.kanban-card .kc-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.kanban-card .ai-tag { display: inline-block; font-size: 10px; color: var(--signal); font-family: var(--font-mono); margin-top: 6px; }

/* =========================================================================
   Modals
   ========================================================================= */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 22, 28, 0.5);
  display: none; align-items: flex-start; justify-content: center; padding: 6vh 20px; overflow-y: auto; z-index: 100;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--paper-raised); border-radius: var(--radius-lg); width: 100%; max-width: 520px;
  padding: 26px; box-shadow: 0 20px 60px rgba(20,22,28,0.25);
}
.modal.modal-wide { max-width: 720px; }

.modal-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.modal-head h2 { font-size: 19px; }
.modal-head .sub { color: var(--ink-soft); font-size: 13px; margin-top: 4px; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--ink-soft); line-height: 1; padding: 4px; }
.modal-close:hover { color: var(--ink); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.modal-actions.split { justify-content: space-between; }

/* AI breakdown modal specifics */

.ai-goal-row { display: flex; gap: 10px; align-items: flex-end; }
.ai-goal-row .field { flex: 1; margin-bottom: 0; }

.ai-loading { display: none; align-items: center; gap: 10px; padding: 30px 0; color: var(--ink-soft); font-size: 14px; }
.ai-loading.visible { display: flex; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--line-strong); border-top-color: var(--signal);
  animation: spin 0.7s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.subtask-list { list-style: none; margin: 18px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; max-height: 45vh; overflow-y: auto; }
.subtask-row { border: 1px solid var(--line); border-radius: var(--radius-md); padding: 12px; }
.subtask-row .st-top { display: flex; gap: 10px; align-items: center; }
.subtask-row input[type="text"] { font-weight: 600; }
.subtask-row .st-desc { margin-top: 8px; }
.subtask-row .st-meta { display: flex; gap: 10px; margin-top: 8px; }
.subtask-row .st-meta > div { flex: 1; }
.subtask-row .st-remove { flex-shrink: 0; }

.ai-summary-bar {
  display: flex; align-items: center; gap: 8px; background: var(--signal-soft); color: var(--signal);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; font-weight: 600; margin-top: 16px;
}

/* Empty column / list */
.kanban-empty, .table-empty { color: var(--ink-soft); font-size: 13px; padding: 20px 14px; text-align: center; }

.toast-region { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  background: var(--ink); color: var(--paper); padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,0.2); max-width: 320px;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* Responsive */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .kanban { grid-template-columns: 1fr; }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
}
