/* CondeWitt — Personal time management */

:root {
  --font: 'Instrument Sans', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --bg: #0f0f14;
  --bg-elevated: #18181f;
  --bg-hover: #1f1f28;
  --border: #2a2a36;
  --text: #e8e8ed;
  --text-muted: #8b8b9a;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --cyan: #22d3ee;
  --danger: #f43f5e;
  --success: #34d399;
  --warning: #fbbf24;

  --priority-low: #64748b;
  --priority-medium: #6366f1;
  --priority-high: #f43f5e;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --header-h: 56px;
  --sidebar-w: 240px;
  --transition: 0.2s ease;
}

[data-theme="light"] {
  --bg: #f4f4f8;
  --bg-elevated: #ffffff;
  --bg-hover: #ececf2;
  --border: #d8d8e4;
  --text: #1a1a24;
  --text-muted: #6b6b7b;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --accent-glow: rgba(99, 102, 241, 0.15);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  overflow-x: hidden;
}

#app { min-height: 100dvh; position: relative; }

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen[hidden] { display: none !important; }

/* ── Auth (3D login room) ── */
#auth-screen {
  position: relative;
  overflow: hidden;
  background: #000;
  padding: 0;
}

#auth-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#auth-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 70% 55% at 50% 42%, rgba(210, 230, 255, 0.95), rgba(140, 170, 220, 0.4) 45%, transparent 70%);
  opacity: 0;
  z-index: 2;
  mix-blend-mode: screen;
}

#auth-tv-overlay {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s ease;
}

#auth-tv-overlay.auth-tv-overlay--visible {
  opacity: 1;
}

#auth-tv-overlay.auth-tv-overlay--fallback .auth-tv-panel {
  position: relative;
  inset: auto;
  padding: 24px;
  min-height: 280px;
}

#auth-tv-overlay.auth-tv-overlay--burst .auth-static-noise {
  opacity: 0.85;
  animation: auth-static-burst 0.12s steps(3) infinite;
}

.auth-tv-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  padding: 8% 10%;
  pointer-events: auto;
  color: #c8d4e8;
  font-family: var(--font);
}

.auth-tv-panel .auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 6%;
  flex-shrink: 0;
}

.auth-tv-panel .auth-logo h1 {
  font-size: clamp(0.65rem, 4.5vw, 1rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-shadow: 0 0 8px rgba(160, 190, 255, 0.35);
}

.auth-tv-panel .logo-mark {
  font-size: clamp(0.7rem, 5vw, 1.1rem);
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 5%;
  flex: 1;
  justify-content: center;
  min-height: 0;
}

#auth-form input[type="password"] {
  width: 100%;
  padding: 6% 5%;
  border: 1px solid rgba(140, 170, 210, 0.35);
  border-radius: 3px;
  background: rgba(8, 12, 20, 0.72);
  color: #d8e4f4;
  font-family: var(--font-mono);
  font-size: clamp(0.55rem, 3.2vw, 0.8rem);
  margin: 0;
  transition: border-color var(--transition), box-shadow var(--transition);
}

#auth-form input::placeholder {
  color: rgba(140, 170, 210, 0.45);
}

#auth-form input:focus {
  outline: none;
  border-color: rgba(160, 200, 255, 0.7);
  box-shadow: 0 0 0 2px rgba(100, 150, 255, 0.2);
}

.auth-submit-icon {
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(28px, 12%, 40px);
  height: clamp(28px, 12%, 40px);
  margin-top: 2%;
  padding: 0;
  border: 1px solid rgba(140, 170, 210, 0.4);
  border-radius: 50%;
  background: rgba(20, 30, 50, 0.8);
  color: #a8c8f0;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform 0.1s;
  touch-action: manipulation;
}

.auth-submit-icon svg {
  width: 55%;
  height: 55%;
}

.auth-submit-icon:hover:not(:disabled) {
  background: rgba(40, 60, 100, 0.9);
  border-color: rgba(160, 200, 255, 0.6);
}

.auth-submit-icon:active:not(:disabled) { transform: scale(0.94); }

.auth-submit-icon:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.auth-submit-icon.is-loading svg {
  animation: auth-spin 0.8s linear infinite;
}

@keyframes auth-spin {
  to { transform: rotate(360deg); }
}

.auth-static-noise {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.08;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
  mix-blend-mode: overlay;
  animation: auth-static-drift 0.15s steps(4) infinite;
}

@keyframes auth-static-drift {
  0% { background-position: 0 0; }
  100% { background-position: 180px 90px; }
}

@keyframes auth-static-burst {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 0.35; }
}

.auth-tv-panel .auth-message {
  margin-top: 4%;
  padding: 4%;
  border-radius: 3px;
  font-size: clamp(0.5rem, 2.8vw, 0.72rem);
  text-align: center;
  flex-shrink: 0;
}

.auth-tv-panel .auth-message.success { background: rgba(52, 211, 153, 0.15); color: #6ee7b7; }
.auth-tv-panel .auth-message.error { background: rgba(244, 63, 94, 0.15); color: #fb7185; }

@media (prefers-reduced-motion: reduce) {
  #auth-flash { display: none; }
  #auth-tv-overlay { transition: none; opacity: 1; }
  .auth-static-noise { animation: none; opacity: 0.04; }
}

.logo-mark {
  font-size: 2rem;
  background: linear-gradient(135deg, var(--accent), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-mark.small { font-size: 1.25rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform 0.1s;
  touch-action: manipulation;
  min-height: 44px;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}

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

.btn-small {
  padding: 6px 12px;
  min-height: 36px;
  font-size: 0.85rem;
  background: var(--accent);
  color: #fff;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-danger:hover { background: rgba(244, 63, 94, 0.1); }

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.btn-icon:hover { background: var(--bg-hover); color: var(--text); }
.btn-icon svg { width: 20px; height: 20px; }

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 100;
  padding-top: env(safe-area-inset-top);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-actions { display: flex; gap: 4px; }

/* ── Layout ── */
.app-body {
  display: flex;
  flex: 1;
  min-height: calc(100dvh - var(--header-h));
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  overflow-y: auto;
  background: var(--bg-elevated);
}

.sidebar-section { margin-bottom: 28px; }

.sidebar-section h2 {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.main-content {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  min-width: 0;
}

/* ── Categories ── */
.category-list { list-style: none; }

.category-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  transition: background var(--transition);
  touch-action: manipulation;
}

.category-item:hover, .category-item.active { background: var(--bg-hover); }

.category-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.category-item .cat-delete {
  margin-left: auto;
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 2px 6px;
  border-radius: 4px;
}

.category-item:hover .cat-delete { opacity: 1; }
.category-item .cat-delete:hover { color: var(--danger); }

.category-form {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.category-form input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
}

.category-form input[type="color"] {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  cursor: pointer;
  background: var(--bg);
}

/* ── Filters ── */
.filters { display: flex; flex-wrap: wrap; gap: 6px; }

.filter-chip {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 32px;
}

.filter-chip:hover { border-color: var(--accent); color: var(--text); }
.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Task form ── */
.task-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
  padding: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.task-form input[type="text"] {
  flex: 1 1 200px;
  min-width: 0;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
}

.task-form select,
.task-form input[type="date"] {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.85rem;
  min-height: 44px;
}

.task-form .btn-primary { width: auto; flex-shrink: 0; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Task list ── */
.task-list-view { display: flex; flex-direction: column; gap: 8px; }

.task-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
  touch-action: manipulation;
}

.task-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow);
}

.task-card.done { opacity: 0.55; }
.task-card.done .task-card-title { text-decoration: line-through; }

.task-check {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 6px;
  flex-shrink: 0;
  margin-top: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  background: transparent;
  color: transparent;
  font-size: 0.75rem;
}

.task-check:hover { border-color: var(--accent); }
.task-check.checked {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.task-card-body { flex: 1; min-width: 0; }

.task-card-title {
  font-weight: 500;
  font-size: 0.95rem;
  word-break: break-word;
}

.task-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.task-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-priority-low { background: rgba(100, 116, 139, 0.2); color: var(--priority-low); }
.badge-priority-medium { background: rgba(99, 102, 241, 0.2); color: var(--priority-medium); }
.badge-priority-high { background: rgba(244, 63, 94, 0.2); color: var(--priority-high); }

.badge-due { font-family: var(--font-mono); }
.badge-due.overdue { color: var(--danger); }

.task-reorder {
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
}

.task-card:hover .task-reorder { opacity: 1; }

.task-reorder button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  font-size: 0.7rem;
  line-height: 1;
}

.task-reorder button:hover { color: var(--text); }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state p { font-size: 0.95rem; }

/* ── Board view ── */
.task-board-view {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  min-height: 300px;
}

.board-column {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  min-height: 200px;
}

.board-column h3 {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.board-tasks { display: flex; flex-direction: column; gap: 8px; }

.board-tasks .task-card { cursor: grab; }
.board-tasks .task-card:active { cursor: grabbing; }

.task-card.dragging { opacity: 0.4; }
.board-tasks.drag-over { background: var(--accent-glow); border-radius: var(--radius-sm); }

/* ── Modals ── */
.modal {
  border: none;
  border-radius: calc(var(--radius) * 1.5);
  padding: 0;
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
  max-width: 480px;
  width: calc(100% - 32px);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-header h2 { font-size: 1.2rem; font-weight: 700; }

.modal-body {
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.modal-body input,
.modal-body select,
.modal-body textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 0.95rem;
  color: var(--text);
}

.setting-row select { width: auto; min-width: 140px; }

/* ── Loading ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.3s;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(24px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  z-index: 2000;
  max-width: 90vw;
}

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

/* ── Mobile ── */
@media (max-width: 768px) {
  .app-body { flex-direction: column; }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 16px;
    display: flex;
    gap: 16px;
    overflow-x: auto;
  }

  .sidebar-section { margin-bottom: 0; flex-shrink: 0; }
  .sidebar-section.filters { display: flex; flex-wrap: nowrap; align-items: center; gap: 6px; }
  .sidebar-section.filters h2 { display: none; }

  .category-form { display: none; }

  .task-form {
    flex-direction: column;
  }

  .task-form .btn-primary { width: 100%; }

  .task-board-view {
    grid-template-columns: 1fr;
  }

  .task-reorder { opacity: 1; }
}

@media (max-width: 480px) {
  .main-content { padding: 12px; }
  .task-form { padding: 12px; }
}
