/* ============================================================
   ScopeCreep Tracker — Styles
   Mobile-first. Light mode only.
   ============================================================ */

/* ---- CSS Custom Properties ---- */
:root {
  --color-bg:              #ffffff;
  --color-surface:         #f5f5f5;
  --color-surface-raised:  #eeeeee;
  --color-text:            #1a1a1a;
  --color-text-secondary:  #666666;
  --color-border:          #e0e0e0;
  --color-primary:         #2563eb;
  --color-primary-hover:   #1d4ed8;
  --color-danger:          #dc2626;
  --color-danger-hover:    #b91c1c;
  --color-warning:         #d97706;
  --color-success:         #16a34a;
  --color-muted:           #9ca3af;
  --color-secondary:       #6b7280;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:   12px;

  --shadow-sm:   0 1px 3px rgba(0,0,0,.08);
  --shadow-md:   0 4px 12px rgba(0,0,0,.12);

  --top-bar-height:    56px;
  --filter-bar-height: 48px;
  --panel-width:       420px;

  --transition: 0.2s ease;
}

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

[hidden] { display: none !important; }

html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

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

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-hover); }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover { background: var(--color-danger-hover); }

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}
.btn-ghost:hover {
  background: var(--color-surface);
  color: var(--color-text);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.btn-secondary:hover { background: var(--color-surface-raised); }

.btn-full { width: 100%; justify-content: center; }

.btn:disabled,
button:disabled {
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  color: var(--color-text-secondary);
  font-size: 16px;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.btn-icon:hover {
  background: var(--color-surface);
  color: var(--color-text);
}

/* ---- Form Elements ---- */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 16px;
}

label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
}

.hint {
  font-weight: 400;
  color: var(--color-text-secondary);
  font-size: 12px;
}

.required { color: var(--color-danger); }

input[type="text"],
input[type="password"],
input[type="date"],
select,
textarea {
  font-family: var(--font);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  transition: border-color var(--transition);
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

textarea { resize: vertical; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.error-message {
  padding: 8px 12px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  color: var(--color-danger);
  font-size: 13px;
}

/* ---- Login View ---- */
.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: var(--color-surface);
}

.login-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}

.login-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 28px;
  text-align: center;
  color: var(--color-text);
}

/* ---- App Shell Layout ---- */
#app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---- Top Bar ---- */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--top-bar-height);
  padding: 0 16px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  gap: 12px;
}

.top-bar-left,
.top-bar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}
.top-bar-right { justify-content: flex-end; }
.top-bar-center { flex-shrink: 0; }

.app-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
}

.user-name {
  font-size: 13px;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.view-toggle {
  display: flex;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.view-btn {
  padding: 5px 12px;
  border: none;
  background: transparent;
  border-radius: calc(var(--radius-sm) - 1px);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.view-btn:hover { color: var(--color-text); background: var(--color-surface-raised); }
.view-btn.active {
  background: var(--color-bg);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

/* ---- Filter Bar ---- */
.filter-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  min-height: var(--filter-bar-height);
}

.filter-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-select {
  width: auto;
  height: 32px;
  padding: 0 8px;
  font-size: 13px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
}

.filter-input {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  width: 150px;
}

.filter-toggles {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--color-text-secondary);
  cursor: pointer;
  font-weight: 400;
  white-space: nowrap;
}

/* Filter chips */
.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: var(--color-primary);
  color: #fff;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.filter-chip button {
  background: none;
  border: none;
  color: rgba(255,255,255,.8);
  cursor: pointer;
  padding: 0;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
}
.filter-chip button:hover { color: #fff; }

/* ---- Main Content Area ---- */
.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--color-surface);
}

/* ---- Kanban Board ---- */
.kanban-board {
  display: flex;
  gap: 16px;
  padding: 16px;
  min-height: 100%;
  align-items: flex-start;
  overflow-x: auto;
}

.kanban-column {
  flex: 0 0 280px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
}

.column-header {
  padding: 12px 14px;
  font-weight: 600;
  font-size: 13px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
}
.column-header:hover {
  background: var(--color-surface);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

/* Collapsed column — narrow vertical strip */
.kanban-column.collapsed {
  flex: 0 0 44px;
}

.kanban-column.collapsed .column-header {
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: none;
  border-radius: var(--radius-md);
  min-height: 140px;
}

.kanban-column.collapsed .column-header:hover {
  border-radius: var(--radius-md);
}

.column-collapse-icon {
  font-size: 10px;
}

.column-label-vertical {
  writing-mode: vertical-lr;
  font-weight: 600;
  font-size: 11px;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: .06em;
  flex: 1;
  display: flex;
  align-items: center;
  padding: 6px 0;
}

.column-count {
  background: var(--color-surface);
  color: var(--color-text-secondary);
  border-radius: 20px;
  padding: 1px 7px;
  font-size: 12px;
  font-weight: 500;
}

.column-cards {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Drop target highlight */
.column-cards.drag-over {
  background: rgba(37, 99, 235, 0.05);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* ---- Task Cards ---- */
.task-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: grab;
  transition: box-shadow var(--transition), transform var(--transition);
  user-select: none;
}
.task-card:hover { box-shadow: var(--shadow-sm); }
.task-card:active { cursor: grabbing; }
.task-card.dragging { opacity: .5; transform: rotate(1deg); }

.card-name {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
  line-height: 1.4;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

.card-project {
  font-size: 11px;
  color: var(--color-text-secondary);
  background: var(--color-surface);
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.card-due-row {
  margin: 2px 0 4px;
}

.card-due {
  font-size: 11px;
  color: var(--color-text-secondary);
}
.card-due.upcoming {
  color: var(--color-warning);
  font-weight: 500;
}
.card-due.overdue {
  color: var(--color-danger);
  font-weight: 500;
}

.card-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  flex-shrink: 0;
}

/* ---- Priority Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 3px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.badge-high     { background: #fef2f2; color: var(--color-danger); }
.badge-medium   { background: #fffbeb; color: var(--color-warning); }
.badge-low      { background: #eff6ff; color: var(--color-primary); }
.badge-optional { background: var(--color-surface); color: var(--color-muted); }

/* Status badges */
.badge-backlog     { background: #f5f3ff; color: #6d28d9; }
.badge-todo        { background: var(--color-surface); color: var(--color-text-secondary); }
.badge-in_progress { background: #eff6ff; color: var(--color-primary); }
.badge-blocked     { background: #fef2f2; color: var(--color-danger); }
.badge-done        { background: #f0fdf4; color: var(--color-success); }
.badge-abandoned   { background: var(--color-surface); color: var(--color-muted); }

/* ---- Task List (table view) ---- */
.task-list-container {
  padding: 16px;
}

.task-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-bg);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}

.task-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
  user-select: none;
}
.task-table th[data-sort] { cursor: pointer; }
.task-table th[data-sort]:hover { color: var(--color-text); }
.task-table th.sort-asc::after  { content: ' ↑'; }
.task-table th.sort-desc::after { content: ' ↓'; }

.task-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
  vertical-align: middle;
}

.task-table tr:last-child td { border-bottom: none; }

.task-table tr:hover td { background: var(--color-surface); }
.task-table tr.overdue td:first-child { border-left: 3px solid var(--color-danger); }

/* ---- Projects Board ---- */
.projects-board {
  display: flex;
  gap: 16px;
  padding: 16px;
  min-height: 100%;
  align-items: flex-start;
  overflow-x: auto;
}

.project-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: grab;
  transition: box-shadow var(--transition);
  user-select: none;
}
.project-card:hover { box-shadow: var(--shadow-sm); }
.project-card:active { cursor: grabbing; }
.project-card.dragging { opacity: .5; transform: rotate(1deg); }

.project-card-name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.project-card-stats {
  font-size: 12px;
  color: var(--color-text-secondary);
}

.project-card-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.project-card-summary span {
  font-size: 11px;
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 1px 5px;
}

/* ---- Slide-out Edit Panel ---- */
.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.panel-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.edit-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  height: 100vh;
  background: var(--color-bg);
  border-left: 1px solid var(--color-border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  box-shadow: var(--shadow-md);
}
.edit-panel.open {
  transform: translateX(0);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.panel-title {
  font-size: 16px;
  font-weight: 600;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
  background: var(--color-bg);
}

.panel-footer-right {
  display: flex;
  gap: 8px;
}

/* Type toggle (Task / Project) */
.type-toggle {
  display: flex;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.type-btn {
  flex: 1;
  padding: 6px 16px;
  border: none;
  background: transparent;
  border-radius: calc(var(--radius-sm) - 1px);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.type-btn:hover { color: var(--color-text); }
.type-btn.active {
  background: var(--color-bg);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

/* Panel metadata footer */
.panel-meta {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--color-border);
}

.meta-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 12px;
}

.meta-label { color: var(--color-text-secondary); }
.meta-value { color: var(--color-text); }

/* Child tasks list (in project panel) */
.child-tasks-list {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.child-task-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
  transition: background var(--transition);
}
.child-task-item:last-child { border-bottom: none; }
.child-task-item:hover { background: var(--color-surface); }

.child-task-name {
  flex: 1;
  cursor: pointer;
  color: var(--color-primary);
}
.child-task-name:hover { text-decoration: underline; }

.child-task-select {
  width: auto;
  height: 28px;
  padding: 0 6px;
  font-size: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  color: var(--color-text);
  cursor: pointer;
  flex-shrink: 0;
}

.no-tasks-message {
  padding: 16px;
  color: var(--color-text-secondary);
  font-size: 13px;
  text-align: center;
}

/* ---- Deletion Dialog ---- */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.dialog {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  padding: 28px;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-md);
}

.dialog-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 10px;
}

.dialog-message {
  color: var(--color-text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
  line-height: 1.5;
}

.dialog-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

/* ---- Tag chips (list view) ---- */
.tag-chip {
  display: inline-block;
  padding: 2px 7px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  font-size: 11px;
  color: var(--color-text-secondary);
  margin: 1px 2px 1px 0;
  white-space: nowrap;
}

.tags-cell { max-width: 200px; }
.task-name-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted { color: var(--color-text-secondary); }

/* ---- Loading / Empty States ---- */
.loading-state,
.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--color-text-secondary);
  font-size: 14px;
}

/* ---- Dark Mode ---- */
body.dark-mode {
  --color-bg:             #1a1a1a;
  --color-surface:        #242424;
  --color-surface-raised: #2e2e2e;
  --color-text:           #f0f0f0;
  --color-text-secondary: #a0a0a0;
  --color-border:         #3a3a3a;
  --color-primary:        #3b82f6;
  --color-primary-hover:  #2563eb;
  --color-danger:         #ef4444;
  --color-danger-hover:   #dc2626;
  --color-warning:        #f59e0b;
  --color-success:        #22c55e;
  --color-muted:          #6b7280;
  --shadow-sm:            0 1px 3px rgba(0,0,0,.3);
  --shadow-md:            0 4px 12px rgba(0,0,0,.5);
}

/* Badge backgrounds use hardcoded hex so must be overridden explicitly */
body.dark-mode .badge-high        { background: #3f1010; color: #f87171; }
body.dark-mode .badge-medium      { background: #3d2700; color: #fbbf24; }
body.dark-mode .badge-low         { background: #0f2040; color: #60a5fa; }
body.dark-mode .badge-optional    { background: var(--color-surface-raised); color: var(--color-muted); }
body.dark-mode .badge-backlog     { background: #2d1b5e; color: #a78bfa; }
body.dark-mode .badge-todo        { background: var(--color-surface-raised); color: var(--color-text-secondary); }
body.dark-mode .badge-in_progress { background: #0f2040; color: #60a5fa; }
body.dark-mode .badge-blocked     { background: #3f1010; color: #f87171; }
body.dark-mode .badge-done        { background: #0f2d1a; color: #4ade80; }
body.dark-mode .badge-abandoned   { background: var(--color-surface-raised); color: var(--color-muted); }

/* Error message uses hardcoded light-red colors */
body.dark-mode .error-message {
  background: #3f1010;
  border-color: #7f1d1d;
}

/* ---- Mobile Responsive ---- */
@media (min-width: 640px) {
  .edit-panel {
    width: var(--panel-width);
  }
}

@media (max-width: 639px) {
  /* Stack top bar on small screens */
  .top-bar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 12px;
    gap: 8px;
  }

  .top-bar-left  { order: 1; flex: 1; }
  .top-bar-right { order: 2; flex: 0; }
  .top-bar-center {
    order: 3;
    width: 100%;
    overflow-x: auto;
  }

  .view-toggle { width: max-content; }

  /* Stack Kanban columns vertically */
  .kanban-board,
  .projects-board {
    flex-direction: column;
    overflow-x: hidden;
  }

  .kanban-column {
    flex: none;
    width: 100%;
    max-height: none;
  }

  /* Filter bar scrolls horizontally */
  .filter-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}
