/* TaskPilot PWA – Mobile-first, dark theme */

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

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface-hover: #242424;
  --border: #2a2a2a;
  --text: #e4e4e7;
  --text-muted: #71717a;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  font-family: var(--font);
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(60px + var(--safe-bottom));
}

/* --- Login screen --- */

#login-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 2rem;
  gap: 1.5rem;
  text-align: center;
}

#login-screen h1 {
  font-size: 1.75rem;
  font-weight: 700;
}

#login-screen p {
  color: var(--text-muted);
  max-width: 320px;
  line-height: 1.5;
}

#login-screen input {
  width: 100%;
  max-width: 320px;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}

#login-screen input:focus {
  border-color: var(--accent);
}

#login-screen button {
  width: 100%;
  max-width: 320px;
}

#login-error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.25rem;
}

/* --- Header --- */

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

#btn-logout {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
}

/* --- Nav tabs --- */

nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
}

nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0.5rem 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.65rem;
  cursor: pointer;
  transition: color 0.15s;
}

nav button .icon {
  font-size: 1.25rem;
}

nav button.active {
  color: var(--accent);
}

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

main {
  flex: 1;
  padding: 1rem 1rem 1.5rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.view-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

/* --- Filter bar --- */

.filter-bar {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.2rem;
}

.filter-btn {
  flex: 1;
  padding: 0.4rem 0;
  background: none;
  border: none;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-btn.active {
  background: var(--accent);
  color: #fff;
}

/* --- Task card --- */

.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  margin-bottom: 0.625rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  transition: background 0.15s;
}

.task-card:active {
  background: var(--surface-hover);
}

.task-check {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  margin-top: 1px;
  background: none;
  padding: 0;
  color: transparent;
}

.task-check:hover {
  border-color: var(--accent);
}

.task-card.done .task-check {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.task-card.done .task-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

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

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

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

.task-meta .overdue {
  color: var(--danger);
}

.task-meta .high {
  color: var(--warning);
}

.task-meta .recurrence {
  color: var(--accent);
}

.task-delete {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 1rem;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.task-card:hover .task-delete,
.task-card:focus-within .task-delete {
  opacity: 1;
}

.task-delete:hover {
  color: var(--danger);
}

/* --- List cards --- */

.list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  margin-bottom: 0.625rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
}

.list-card:active {
  background: var(--surface-hover);
}

.list-card .icon {
  font-size: 1.35rem;
}

.list-card .name {
  flex: 1;
  font-weight: 500;
}

.list-card .count {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.list-edit,
.list-delete {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.list-card:hover .list-edit,
.list-card:hover .list-delete,
.list-card:focus-within .list-edit,
.list-card:focus-within .list-delete {
  opacity: 1;
}

.list-edit:hover {
  color: var(--accent);
}

.list-delete:hover {
  color: var(--danger);
}

.list-rename-input {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  outline: none;
}

/* --- Sharing panel --- */

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

.share-panel-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.share-panel-inner h4 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.share-member {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  font-size: 0.9rem;
}

.share-member .role-badge {
  font-size: 0.75rem;
  background: var(--accent);
  color: #fff;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.share-member .role-badge.member {
  background: var(--text-muted);
}

.share-member .btn-remove-member {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
}

.share-member .btn-remove-member:hover {
  color: var(--danger);
}

.share-invite-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.share-invite-form input {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
}

.share-hint {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 0.5rem;
  margin-bottom: 0;
}

/* --- Stats --- */

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.stat-card .number {
  font-size: 1.75rem;
  font-weight: 700;
}

.stat-card .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* --- Empty state --- */

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state .icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

/* --- Add task input --- */

.add-bar {
  position: sticky;
  bottom: calc(60px + var(--safe-bottom));
  background: var(--bg);
  padding: 0.75rem 0;
  display: flex;
  gap: 0.5rem;
}

.add-bar input {
  flex: 1;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

.add-bar input:focus {
  border-color: var(--accent);
}

.add-bar button {
  padding: 0 1rem;
}

/* --- Buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

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

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

/* --- Loading spinner --- */

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.loading-center {
  display: flex;
  justify-content: center;
  padding: 3rem;
}

/* --- Modal overlay --- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 85dvh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
}

.modal-body {
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.modal-body label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 0.25rem;
}

.modal-body input,
.modal-body select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.modal-body input:focus,
.modal-body select:focus {
  border-color: var(--accent);
}

/* Fix date input color scheme for dark mode */
.modal-body input[type="date"] {
  color-scheme: dark;
}

.date-time-row {
  display: flex;
  gap: 0.5rem;
}

.date-time-row input[type="date"] {
  flex: 1;
}

.date-time-row input#modal-task-time {
  width: 5rem;
  flex-shrink: 0;
  text-align: center;
  letter-spacing: 0.05em;
}

.modal-footer {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  padding: 0.75rem 1.25rem 1.25rem;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

/* --- Inline form (new list) --- */

.inline-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: center;
}

.inline-form input {
  padding: 0.55rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

.inline-form input:focus {
  border-color: var(--accent);
}

.inline-form input.icon-input {
  width: 3rem;
  text-align: center;
  flex-shrink: 0;
}

.inline-form input:not(.icon-input) {
  flex: 1;
}

/* --- Weekday picker --- */

#weekday-picker {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
}

.weekday-chip {
  cursor: pointer;
}

.weekday-chip input {
  display: none;
}

.weekday-chip span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  transition: all 0.15s;
  user-select: none;
}

.weekday-chip input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* --- Attachment preview in modal --- */

#attachment-area {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#attachment-preview {
  position: relative;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

#attachment-preview img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  display: block;
}

#attachment-preview .btn-close {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.6);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
}

.task-meta .has-attachment {
  color: var(--accent);
  cursor: pointer;
}

/* --- Task card attachment thumbnail --- */

.task-thumb {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--border);
  cursor: pointer;
}

/* --- Responsive tweaks --- */

@media (min-width: 640px) {
  main {
    max-width: 600px;
    margin: 0 auto;
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}
