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

:root {
  --background: hsl(240 10% 3.9%);
  --foreground: hsl(0 0% 98%);
  --card: hsl(240 10% 3.9%);
  --muted: hsl(240 3.7% 15.9%);
  --muted-foreground: hsl(240 5% 64.9%);
  --accent: hsl(240 3.7% 15.9%);
  --border: hsl(240 3.7% 15.9%);
  --ring: hsl(240 4.9% 83.9%);
  --destructive: hsl(0 62.8% 30.6%);
  --radius-sm: 0.375rem;
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --blue: hsl(217 91% 60%);
  --blue-muted: hsla(217 91% 60% / 0.12);
  --green: hsl(142 71% 45%);
  --yellow: hsl(48 96% 53%);
  --orange: hsl(25 95% 53%);
  --red: hsl(0 84% 60%);
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--background);
  color: var(--foreground);
  line-height: 1.5;
  min-height: 100vh;
}

/* --- Utilities --- */
.container { max-width: 960px; margin: 0 auto; padding: 0 1rem; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-size: 0.875rem;
}

input, textarea, select {
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--foreground);
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--ring);
}

textarea { resize: vertical; min-height: 100px; }
select { appearance: none; cursor: pointer; }

label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted-foreground);
  margin-bottom: 0.25rem;
}

/* --- Login Screen --- */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}

.login-card h1 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.login-card p {
  font-size: 0.8125rem;
  color: var(--muted-foreground);
  margin-bottom: 1.5rem;
}

.login-card .form-group { margin-bottom: 1rem; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--foreground);
  color: var(--background);
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  width: 100%;
  transition: opacity 0.15s;
}

.btn-primary:hover { opacity: 0.9; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.login-error {
  color: var(--red);
  font-size: 0.8125rem;
  margin-top: 0.75rem;
  display: none;
}

/* --- App Screen --- */
#app-screen { display: none; padding: 1.5rem 0; }

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.header h1 { font-size: 1.25rem; font-weight: 600; }

.header-actions { display: flex; gap: 0.5rem; align-items: center; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--muted-foreground);
  transition: background 0.15s, color 0.15s;
}

.btn-ghost:hover { background: var(--accent); color: var(--foreground); }

.btn-new {
  background: var(--foreground);
  color: var(--background);
  font-weight: 500;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
}

.btn-new:hover { opacity: 0.9; }

/* --- Filter Bar --- */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.filter-tab {
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  color: var(--muted-foreground);
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.filter-tab:hover { color: var(--foreground); }

.filter-tab.active {
  color: var(--foreground);
  border-bottom-color: var(--foreground);
}

.filter-tab .count {
  font-size: 0.6875rem;
  background: var(--accent);
  padding: 0.0625rem 0.375rem;
  border-radius: 9999px;
  margin-left: 0.25rem;
}

.search-wrap {
  margin-left: auto;
  position: relative;
}

.search-wrap input {
  width: 200px;
  padding: 0.375rem 0.625rem 0.375rem 1.75rem;
  font-size: 0.8125rem;
  border: 1px solid transparent;
  background: var(--accent);
  border-radius: var(--radius-sm);
}

.search-wrap input:focus { border-color: var(--ring); }

.search-wrap svg {
  position: absolute;
  left: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--muted-foreground);
}

/* --- Task Table --- */
.task-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.task-table th {
  text-align: left;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-foreground);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.5rem 0.625rem;
  border-bottom: 1px solid var(--border);
}

.task-table td {
  padding: 0.5rem 0.625rem;
  font-size: 0.8125rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.task-table tbody tr {
  position: relative;
  transition: background 0.1s;
}

.task-table tbody tr:hover { background: var(--accent); }
.task-table tbody tr.selected { background: var(--blue-muted); }
.task-table tbody tr.selected:hover { background: hsla(217 91% 60% / 0.18); }

.task-table tbody tr.focused {
  box-shadow: inset 3px 0 0 var(--blue);
}

.col-check { width: 36px; }
.col-priority { width: 48px; }
.col-status { width: 90px; }
.col-actions { width: 72px; text-align: right; }

/* Checkbox */
.task-table input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--blue);
  cursor: pointer;
}

/* Priority badges */
.badge-priority {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  font-weight: 600;
  width: 1.625rem;
  height: 1.375rem;
  border-radius: var(--radius-sm);
}

.badge-p1 { background: hsla(0 84% 60% / 0.15); color: var(--red); }
.badge-p2 { background: hsla(25 95% 53% / 0.15); color: var(--orange); }
.badge-p3 { background: hsla(48 96% 53% / 0.15); color: var(--yellow); }
.badge-p4 { background: hsla(217 91% 60% / 0.15); color: var(--blue); }
.badge-p5 { background: hsla(240 5% 64.9% / 0.15); color: var(--muted-foreground); }

/* Status badges */
.badge-status {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
}

.badge-queued { background: hsla(217 91% 60% / 0.15); color: var(--blue); }
.badge-running { background: hsla(48 96% 53% / 0.15); color: var(--yellow); }
.badge-done { background: hsla(142 71% 45% / 0.15); color: var(--green); }
.badge-failed { background: hsla(0 84% 60% / 0.15); color: var(--red); }

.badge-running::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--yellow);
  animation: pulse-dot 1.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Prompt cell */
.prompt-cell {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
}

/* Action buttons */
.btn-action {
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--muted-foreground);
  transition: background 0.15s, color 0.15s;
}

.btn-action:hover { background: var(--accent); color: var(--foreground); }

.btn-action.delete:hover { color: var(--red); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted-foreground);
  font-size: 0.875rem;
}

/* Loading skeleton */
.loading-row td {
  padding: 0.75rem 0.625rem;
}

.skeleton {
  height: 1rem;
  background: var(--accent);
  border-radius: var(--radius-sm);
  animation: pulse-bg 1.5s ease-in-out infinite;
}

@keyframes pulse-bg {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* --- Bulk Action Bar --- */
.bulk-bar {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--foreground);
  color: var(--background);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-lg);
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8125rem;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 50;
}

.bulk-bar.visible { display: flex; }

.bulk-bar .bulk-count { margin-right: 0.25rem; }

.bulk-bar button {
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--background);
  transition: opacity 0.15s;
}

.bulk-bar button:hover { opacity: 0.7; }

.bulk-bar .bulk-delete { color: var(--red); }

.bulk-bar .bulk-sep {
  width: 1px;
  height: 1rem;
  background: hsla(240 10% 3.9% / 0.3);
}

/* --- Overlay --- */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: hsla(240 10% 3.9% / 0.8);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.overlay.visible { display: flex; }

.overlay-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}

.overlay-card h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.overlay-card .form-group { margin-bottom: 0.75rem; }

.overlay-card .form-row {
  display: flex;
  gap: 0.75rem;
}

.overlay-card .form-row > * { flex: 1; }

.overlay-card details {
  margin-top: 0.5rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
}

.overlay-card details summary {
  font-size: 0.8125rem;
  color: var(--muted-foreground);
  cursor: pointer;
  margin-bottom: 0.75rem;
}

.overlay-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.btn-cancel {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--foreground);
  transition: background 0.15s;
}

.btn-cancel:hover { background: var(--accent); }

.btn-save {
  padding: 0.5rem 1rem;
  background: var(--foreground);
  color: var(--background);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: opacity 0.15s;
}

.btn-save:hover { opacity: 0.9; }
.btn-save:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Shortcuts Overlay --- */
.shortcuts-overlay {
  display: none;
}

.shortcuts-overlay.visible { display: flex; }

.shortcuts-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem 2rem;
  max-width: 480px;
  width: 100%;
}

.shortcuts-card h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.shortcuts-section {
  margin-bottom: 1rem;
}

.shortcuts-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-foreground);
  margin-bottom: 0.5rem;
}

.shortcut-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0;
  font-size: 0.8125rem;
}

.shortcut-row span:first-child { color: var(--muted-foreground); }

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.375rem;
  padding: 0 0.375rem;
  font-family: inherit;
  font-size: 0.6875rem;
  font-weight: 500;
  background: var(--accent);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  color: var(--foreground);
}

/* --- Toast --- */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
}

.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 280px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: slide-in 0.2s ease-out;
  border-left: 3px solid var(--green);
}

.toast.error { border-left-color: var(--red); }

.toast .toast-undo {
  margin-left: auto;
  font-weight: 600;
  color: var(--blue);
  cursor: pointer;
  padding: 0.125rem 0.375rem;
  border-radius: var(--radius-sm);
}

.toast .toast-undo:hover { background: var(--accent); }

@keyframes slide-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .container { padding: 0 0.5rem; }
  .header { flex-wrap: wrap; gap: 0.5rem; }
  .header h1 { font-size: 1rem; }
  .overlay-card { margin: 0.5rem; max-width: 100%; }
  .overlay-card .form-row { flex-direction: column; gap: 0.75rem; }
  .search-wrap input { width: 120px; }
  .col-actions { display: none; }
  .filter-bar { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { font-size: 0.8rem; }
}

@media (max-width: 480px) {
  .col-priority { display: none; }
  .col-cb { display: none; }
  th.col-cb { display: none; }
  .filter-tab { padding: 0.4rem 0.4rem; font-size: 0.7rem; }
  .filter-tab .count { display: none; }
  .search-wrap { display: none; }
  .bulk-bar { font-size: 0.75rem; padding: 0.375rem 0.5rem; }
  .header-actions .btn-ghost span { display: none; }
  .overlay-body { padding: 0.75rem; }
}
