/* =========================================================
   CSS Custom Properties
   ========================================================= */
:root {
  --primary: #4f6ef7;
  --primary-dark: #3a57d4;
  --danger: #e53e3e;
  --danger-dark: #c53030;
  --success: #38a169;
  --bg: #f7f8fc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-muted: #718096;
  --sidebar-width: 280px;
  --radius: 6px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
}

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

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

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

/* =========================================================
   Forms & Inputs
   ========================================================= */
input, textarea, select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,110,247,0.15);
}

label {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group { margin-bottom: 14px; }

/* =========================================================
   Buttons
   ========================================================= */
button, .btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn-primary, button[type="submit"] {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover, button[type="submit"]:hover {
  background: var(--primary-dark);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); }

.btn-sm { padding: 4px 10px; font-size: 12px; }

button:disabled { opacity: 0.55; cursor: not-allowed; }

/* =========================================================
   Error / notice
   ========================================================= */
.error-msg {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  color: var(--danger);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}
.error-msg.visible { display: block; }

/* =========================================================
   Auth Section
   ========================================================= */
#auth-section {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.10);
  padding: 36px 40px;
  width: 100%;
  max-width: 420px;
}

.auth-card h1 {
  font-size: 22px;
  margin-bottom: 6px;
}

.auth-card .subtitle {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 24px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  text-align: center;
  padding: 8px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}
.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.auth-form { display: none; }
.auth-form.active { display: block; }

/* =========================================================
   App Layout (two-column)
   ========================================================= */
#app-section {
  display: none;
  height: 100vh;
  overflow: hidden;
}
#app-section.visible {
  display: flex;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

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

#sidebar-header h2 { font-size: 16px; }

#user-info {
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#list-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.list-item {
  padding: 10px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.1s;
}
.list-item:hover { background: var(--bg); }
.list-item.active {
  background: #eef1ff;
  border-left-color: var(--primary);
}
.list-item .list-title { font-weight: 500; font-size: 14px; }
.list-item .list-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.list-item .list-badge {
  font-size: 10px;
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  padding: 2px 7px;
  flex-shrink: 0;
}

/* New list form inside sidebar */
#new-list-form {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
#new-list-form input { margin-bottom: 6px; }

/* Main pane */
#main-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#main-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#main-header h2 { font-size: 18px; flex: 1; }

#main-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

/* =========================================================
   Todo Items
   ========================================================= */
.item-list { list-style: none; }

.todo-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.1s;
}
.todo-item:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.1); }

.todo-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex-shrink: 0;
  cursor: pointer;
}

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

.todo-item .item-title {
  font-weight: 500;
  font-size: 15px;
  word-break: break-word;
}

/* Completed state */
.todo-item.completed .item-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

.todo-item .item-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}
.todo-item .item-due {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}
.todo-item .item-due.overdue { color: var(--danger); font-weight: 600; }

.todo-item .item-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Inline edit */
.todo-item .item-body .edit-title,
.todo-item .item-body .edit-desc,
.todo-item .item-body .edit-due {
  margin-bottom: 6px;
  font-size: 14px;
}
.todo-item .item-body .edit-actions { display: flex; gap: 6px; margin-top: 4px; }

/* Add item form */
#add-item-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
#add-item-form h3 { font-size: 14px; margin-bottom: 12px; }

/* =========================================================
   Members Panel
   ========================================================= */
#members-panel {
  margin-top: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
#members-panel h3 { font-size: 14px; margin-bottom: 12px; }

.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.member-row:last-child { border-bottom: none; }
.member-role {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
}
.member-role.owner { color: var(--primary); background: #eef1ff; }

#invite-form { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
#invite-form input { flex: 1; min-width: 140px; }

/* =========================================================
   Empty state
   ========================================================= */
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 48px 24px;
  font-size: 14px;
}

/* =========================================================
   Optional item fields (Feature 2)
   ========================================================= */
#item-optional-fields { display: none; }
#item-optional-fields.expanded { display: block; }
a.more-toggle { font-size: 0.8rem; color: #666; text-decoration: none; display: block; margin: 4px 0 8px; }
a.more-toggle:hover { text-decoration: underline; }

/* =========================================================
   Sort bar (Feature 3)
   ========================================================= */
#sort-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.sort-label { font-size: 0.85rem; color: #666; }
.sort-btn { font-size: 0.8rem; padding: 2px 8px; cursor: pointer; border: 1px solid #ccc; border-radius: 4px; background: #f5f5f5; }
.sort-btn:hover { background: #e8e8e8; }

/* =========================================================
   Mobile top bar (hidden on desktop)
   ========================================================= */
#mobile-header {
  display: none;
}

/* Sidebar overlay backdrop (hidden by default) */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 99;
}
#sidebar-overlay.visible { display: block; }

/* =========================================================
   Responsive — drawer layout below 640px
   ========================================================= */
@media (max-width: 640px) {
  /* Fixed top bar */
  #mobile-header {
    display: flex;
    align-items: center;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    z-index: 98;
    gap: 12px;
  }
  #mobile-header #sidebar-toggle-btn {
    font-size: 20px;
    background: none;
    border: none;
    padding: 6px;
    color: var(--text);
    cursor: pointer;
  }
  #mobile-header #mobile-list-title {
    flex: 1;
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #mobile-header #hub-link {
    font-size: 22px;
    text-decoration: none;
    padding: 4px;
  }

  /* Push app content below the fixed header */
  #app-section.visible {
    padding-top: 52px;
    flex-direction: row; /* keep row so sidebar overlays on top */
  }

  /* Sidebar becomes a fixed slide-in drawer */
  #sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    width: 82%;
    max-width: 300px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    border-right: 1px solid var(--border);
    overflow-y: auto;
  }
  #sidebar.open {
    transform: translateX(0);
  }

  /* Main pane fills the full width */
  #main-pane {
    flex: 1;
    min-height: 0;
    width: 100%;
  }

  .auth-card {
    padding: 24px 20px;
  }

  /* Prevent iOS Safari auto-zoom on input focus (requires font-size >= 16px) */
  input, textarea, select {
    font-size: 16px;
  }

  /* New list form hidden by default inside drawer; shown via "+ New" button */
  #new-list-form-wrapper { display: none; }
  #new-list-form-wrapper.drawer-open { display: block; }
}

mark {
  background: #fef08a;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

.add-item-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.add-item-row input {
  flex: 1;
  width: auto;
  min-width: 0;
  margin: 0;
}
.add-item-row .btn {
  flex-shrink: 0;
  white-space: nowrap;
}
.more-options-toggle {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 2px 6px;
}
#more-options-panel {
  margin-top: 8px;
}
