/* ============ CSS RESET & BASE ============ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #5C9CE6;
  --primary-dark: #4A8AD4;
  --danger: #E74C3C;
  --danger-dark: #C0392B;
  --success: #2ECC71;
  --bg: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #1a1a2e;
  --text: #eaeaea;
  --text-muted: #8892a0;
  --border: #2a2a4a;
  --shadow: 0 2px 4px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
  --radius: 8px;
  --radius-sm: 4px;
}

html {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

body {
  min-height: 100vh;
}

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

a:hover {
  text-decoration: underline;
}

/* ============ FORMS ============ */
input, textarea, select {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input::placeholder, textarea::placeholder {
  color: var(--text-muted);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.15);
}

input[type="color"] {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding: 0;
  width: 3rem;
  height: 2.5rem;
  cursor: pointer;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}

input[type="color"]::-webkit-color-swatch {
  border: none;
  border-radius: 2px;
}

input[type="color"]::-moz-color-swatch {
  border: none;
  border-radius: 2px;
}

input[type="checkbox"] {
  width: 1.25rem;
  height: 1.25rem;
  cursor: pointer;
  accent-color: var(--primary);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
}

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

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

.form-row input {
  flex: 1;
}

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

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1rem;
  font-size: 0.9375rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s, transform 0.1s;
  text-decoration: none;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn:hover {
  background: var(--border);
  text-decoration: none;
}

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

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

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

.btn-danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

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

.btn-small {
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
}

.btn-icon {
  padding: 0.5rem;
  background: transparent;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
}

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

/* ============ AUTH PAGES ============ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.auth-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 2rem;
  width: 100%;
  max-width: 380px;
}

.auth-card h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
  color: var(--primary);
}

.auth-card .subtitle {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

.auth-card form {
  margin-top: 1rem;
}

#password-field {
  display: none;
}

#password-field.show {
  display: block;
}

/* ============ ERROR MESSAGES ============ */
.error {
  background: rgba(231, 76, 60, 0.15);
  color: #ff6b6b;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  border: 1px solid rgba(231, 76, 60, 0.3);
}

/* ============ APP LAYOUT ============ */
.app-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  background: var(--bg-card);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header-inner {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-header h1 {
  font-size: 1.125rem;
  color: var(--primary);
}

.app-main {
  flex: 1;
  padding: 1rem;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

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

.lists-header h1 {
  font-size: 1.375rem;
}

.lists-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
}

.list-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-left: 4px solid var(--list-color, var(--primary));
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
}

.list-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.list-card.dragging {
  opacity: 0.5;
}

.list-card-header {
  padding: 0.5rem 0.5rem 0;
  display: flex;
  justify-content: flex-end;
}

.list-card-body {
  display: block;
  padding: 0 1rem 1rem;
  color: var(--text);
  text-decoration: none;
}

.list-card-body:hover {
  text-decoration: none;
}

.list-card h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  word-break: break-word;
}

.shared-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.share-icon {
  font-size: 0.875rem;
  opacity: 0.7;
  margin-right: auto;
}

.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  user-select: none;
  padding: 0.25rem;
}

.drag-handle:active {
  cursor: grabbing;
}

/* ============ TODO VIEW ============ */
.todo-view {
  max-width: 600px;
  margin: 0 auto;
}

.todo-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--list-color, var(--primary));
}

.back-btn {
  font-size: 1.5rem;
  color: var(--text);
  text-decoration: none;
  line-height: 1;
  padding: 0.25rem;
}

.back-btn:hover {
  color: var(--primary);
  text-decoration: none;
}

.todo-header-title {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.todo-header-title h1 {
  font-size: 1.25rem;
  min-width: 0;
  outline: none;
  border-bottom: 2px solid transparent;
  padding-bottom: 2px;
}

.todo-header-title h1:focus {
  border-bottom-color: var(--primary);
}

.color-picker {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  cursor: pointer;
  flex-shrink: 0;
  background: none;
  overflow: hidden;
}

.color-picker::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-picker::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}

.color-picker::-moz-color-swatch {
  border: none;
  border-radius: 50%;
}

.color-picker:hover {
  border-color: rgba(0, 0, 0, 0.25);
  transform: scale(1.1);
}

.color-picker:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.3);
}

/* ============ DROPDOWN ============ */
.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  min-width: 150px;
  z-index: 200;
  display: none;
  overflow: hidden;
}

.dropdown.open .dropdown-menu {
  display: block;
}

.dropdown-menu button {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  text-align: left;
  background: none;
  border: none;
  font-size: 0.9375rem;
  cursor: pointer;
  color: var(--text);
}

.dropdown-menu button:hover {
  background: var(--bg);
}

.dropdown-menu button.danger {
  color: var(--danger);
}

/* ============ ADD TODO FORM ============ */
.add-todo-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.add-todo-form input {
  flex: 1;
}

/* ============ TODO LIST ============ */
.todo-list {
  list-style: none;
}

.todo-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  box-shadow: var(--shadow);
  transition: opacity 0.2s;
}

.todo-item.dragging {
  opacity: 0.5;
}

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

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

.todo-checkbox {
  margin-top: 0.125rem;
  flex-shrink: 0;
}

.todo-content {
  flex: 1;
  cursor: pointer;
  min-width: 0;
}

.todo-title {
  display: block;
  font-weight: 500;
  word-break: break-word;
}

.todo-desc {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  word-break: break-word;
}

.completed-divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8125rem;
  margin: 1.25rem 0 0.75rem;
  position: relative;
}

.completed-divider span {
  background: var(--bg);
  padding: 0 0.75rem;
  position: relative;
  z-index: 1;
}

/* ============ DESCRIPTION TRUNCATION ============ */
.todo-desc {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: 100%;
}

.completed-divider::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--border);
}

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

/* ============ MODALS ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal h2 {
  font-size: 1.125rem;
  margin-bottom: 1rem;
}

.modal h3 {
  font-size: 0.9375rem;
  margin: 1.25rem 0 0.75rem;
  color: var(--text-muted);
}

/* ============ COLLABORATORS ============ */
.collaborators-list {
  list-style: none;
}

.collaborators-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--border);
}

.collaborators-list li:last-child {
  border-bottom: none;
}

.badge {
  font-size: 0.6875rem;
  background: var(--primary);
  color: white;
  padding: 0.125rem 0.5rem;
  border-radius: 1rem;
  text-transform: uppercase;
  font-weight: 600;
}

/* ============ TOKEN DISPLAY ============ */
.token-display {
  display: flex;
  gap: 0.5rem;
}

.token-display input {
  flex: 1;
  font-family: monospace;
  font-size: 0.75rem;
}

/* ============ ADMIN PAGE ============ */
.admin-page {
  max-width: 600px;
  margin: 0 auto;
  padding: 1rem;
}

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

.admin-header h1 {
  font-size: 1.375rem;
}

.admin-section {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.admin-section h2 {
  font-size: 1rem;
  margin-bottom: 1rem;
}

.user-list {
  list-style: none;
}

.user-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.user-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.user-info {
  flex: 1;
  min-width: 150px;
}

.user-info strong {
  display: block;
}

.user-info small {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.user-actions {
  display: flex;
  gap: 0.5rem;
}

/* ============ PROFILE ============ */
.profile-info p {
  margin-bottom: 1rem;
}

/* ============ HTMX INDICATORS ============ */
.htmx-request {
  opacity: 0.7;
  pointer-events: none;
}

.htmx-request.htmx-indicator {
  opacity: 1;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 480px) {
  .lists-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-actions {
    flex-wrap: wrap;
  }

  .form-actions .btn {
    flex: 1;
  }

  .user-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .user-actions {
    width: 100%;
  }

  .user-actions .btn {
    flex: 1;
  }
}
