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

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --bg: #f8fafc;
  --sidebar-bg: #1e293b;
  --sidebar-text: #e2e8f0;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
header {
  background: var(--primary);
  color: white;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header h1 {
  font-size: 1.5rem;
}

.user-section input {
  padding: 0.5rem;
  border: none;
  border-radius: 4px;
  width: 200px;
}

/* Main Layout */
main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.project-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.project-list li {
  padding: 1rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  transition: background 0.2s;
}

.project-list li:hover {
  background: rgba(255,255,255,0.1);
}

.project-list li.active {
  background: var(--primary);
}

.project-list li .project-name {
  font-weight: 500;
}

.project-list li .project-stats {
  font-size: 0.8rem;
  color: rgba(255,255,255,0.6);
  margin-top: 0.25rem;
}

/* Content */
.content {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
}

.project-view.hidden,
.hidden {
  display: none !important;
}

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

.project-header h2 {
  font-size: 1.75rem;
}

/* Add Todo */
.add-todo {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.add-todo input {
  flex: 1;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}

.add-todo input:focus {
  outline: none;
  border-color: var(--primary);
}

/* Filters */
.todo-filters {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.filter-btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  background: white;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-btn:hover {
  border-color: var(--primary);
}

.filter-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Todo List */
.todo-list {
  list-style: none;
}

.todo-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.todo-item:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.todo-item.complete {
  opacity: 0.6;
}

.todo-item.complete .todo-title {
  text-decoration: line-through;
}

.todo-checkbox {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.todo-checkbox:hover {
  border-color: var(--primary);
}

.todo-item.complete .todo-checkbox {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

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

.todo-title {
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.todo-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.comment-count {
  margin-left: 0.5rem;
}

/* Detail Panel */
.detail-panel {
  width: 350px;
  background: var(--card-bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.detail-content {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}

.detail-field {
  margin-bottom: 1rem;
}

.detail-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.detail-field input,
.detail-field textarea,
.detail-field select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9rem;
}

.detail-field textarea {
  resize: vertical;
}

/* Comments */
.comments-section {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.comments-section h4 {
  margin-bottom: 1rem;
}

.comments-list {
  list-style: none;
  margin-bottom: 1rem;
}

.comment-item {
  background: var(--bg);
  border-radius: 6px;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
}

.comment-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.comment-author {
  font-weight: 500;
  color: var(--text);
}

.comment-content {
  font-size: 0.9rem;
}

.add-comment textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  margin-bottom: 0.5rem;
  resize: vertical;
}

/* Buttons */
.btn-icon {
  width: 32px;
  height: 32px;
  border: none;
  background: rgba(255,255,255,0.1);
  color: inherit;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: rgba(255,255,255,0.2);
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s;
}

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

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

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

.btn-danger {
  background: var(--danger);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

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

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: white;
  padding: 2rem;
  border-radius: 12px;
  min-width: 400px;
}

.modal-content h3 {
  margin-bottom: 1rem;
}

.modal-content input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Responsive */
@media (max-width: 900px) {
  .sidebar {
    width: 220px;
  }
  .detail-panel {
    width: 300px;
  }
}

@media (max-width: 700px) {
  main {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    max-height: 200px;
  }
  .detail-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    z-index: 50;
  }
}

/* === Auth screen === */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1f5f9;
}
.auth-card {
  background: #fff;
  padding: 2.5rem;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  width: 100%;
  max-width: 380px;
}
.auth-card h1 { margin: 0 0 0.25rem; }
.auth-subtitle { color: #64748b; margin: 0 0 1.5rem; }
.auth-tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.auth-tab {
  flex: 1;
  padding: 0.5rem;
  border: 1px solid #e2e8f0;
  background: #fff;
  border-radius: 6px;
  cursor: pointer;
}
.auth-tab.active { background: #2563eb; color: #fff; border-color: #2563eb; }
#auth-form { display: flex; flex-direction: column; gap: 0.75rem; }
#auth-form input {
  padding: 0.6rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 1rem;
}
.auth-hint { color: #64748b; font-size: 0.85rem; margin: 0; }
.auth-error { color: #dc2626; font-size: 0.9rem; margin: 0; }

/* === Header user controls === */
.current-user { font-weight: 600; margin-right: 0.75rem; }

/* === Sidebar join box and badges === */
.join-box { display: flex; gap: 0.5rem; padding: 0.75rem; border-top: 1px solid #e2e8f0; }
.join-box input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  text-transform: uppercase;
}
.badge-shared {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  color: #7c3aed;
  background: #ede9fe;
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  margin-left: 0.4rem;
  vertical-align: middle;
}

/* === Project actions / invite panel === */
.project-actions { display: flex; gap: 0.5rem; }
.invite-panel {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}
.invite-panel label { font-size: 0.85rem; color: #64748b; }
.invite-row { display: flex; gap: 0.5rem; margin: 0.4rem 0; }
.invite-row input {
  flex: 1;
  padding: 0.4rem 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-family: monospace;
}
.btn-danger-link {
  background: none;
  border: none;
  color: #dc2626;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* === Identity lines === */
.todo-added-by { color: #94a3b8; font-size: 0.78rem; }
.detail-created-by { color: #64748b; font-size: 0.85rem; }

/* === Comment delete === */
.comment-delete {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 1rem;
  padding: 0 0.2rem;
  margin-left: 0.3rem;
  vertical-align: middle;
}
.comment-delete:hover { color: #dc2626; }

/* === Mobile === */
@media (max-width: 768px) {
  main { flex-direction: column; }
  .sidebar {
    width: 100%;
    max-height: 220px;
    overflow-y: auto;
    border-right: none;
    border-bottom: 1px solid #e2e8f0;
  }
  .detail-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    z-index: 50;
    overflow-y: auto;
  }
  .add-todo { flex-wrap: wrap; }
  .project-header { flex-wrap: wrap; gap: 0.5rem; }
}
