/* ========================================
   Nightstand PWA — Dark Theme Styles
   ======================================== */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-surface: #0f3460;
  --bg-card: #1e2746;
  --bg-input: #253050;
  --bg-hover: #2a3a5c;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a8c0;
  --text-muted: #6b7394;
  --accent: #e8a317;
  --accent-hover: #f0b430;
  --accent-dim: rgba(232, 163, 23, 0.15);
  --danger: #e74c3c;
  --danger-hover: #ff5c4d;
  --success: #2ecc71;
  --border: #2a3554;
  --shadow: rgba(0, 0, 0, 0.4);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-width: 280px;
  --header-height: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.screen {
  height: 100%;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}
.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: #1a1a2e;
}
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.btn-secondary:hover {
  background: var(--border);
}

.btn-danger-fill {
  background: var(--danger);
  color: #fff;
}
.btn-danger-fill:hover {
  background: var(--danger-hover);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.btn-icon.btn-danger:hover {
  color: var(--danger);
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
  padding: 8px;
  text-decoration: underline;
  -webkit-tap-highlight-color: transparent;
}
.btn-link:hover {
  color: var(--accent-hover);
}

/* --- Spinner --- */
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========================================
   AUTH SCREEN
   ======================================== */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  padding-top: var(--safe-top);
  background: var(--bg-primary);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: 0 8px 32px var(--shadow);
  text-align: center;
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 4px;
}
.auth-logo h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

.auth-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

.btn-google {
  width: 100%;
  background: #fff;
  color: #333;
  font-weight: 500;
}
.btn-google:hover {
  background: #f1f1f1;
}
.btn-google svg {
  flex-shrink: 0;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-muted);
  font-size: 13px;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

#email-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#email-form input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
  min-height: 44px;
}
#email-form input:focus {
  border-color: var(--accent);
}
#email-form input::placeholder {
  color: var(--text-muted);
}

#btn-toggle-signup {
  margin-top: 8px;
}

.auth-error {
  margin-top: 16px;
  padding: 10px 14px;
  background: rgba(231, 76, 60, 0.15);
  border: 1px solid rgba(231, 76, 60, 0.3);
  border-radius: var(--radius-sm);
  color: #ff6b6b;
  font-size: 14px;
}

.auth-denied {
  margin-top: 16px;
  padding: 14px;
  background: rgba(231, 76, 60, 0.12);
  border: 1px solid rgba(231, 76, 60, 0.25);
  border-radius: var(--radius-sm);
  color: #ff8a80;
  font-size: 14px;
}
.auth-denied p + p {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.auth-loading {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ========================================
   APP LAYOUT
   ======================================== */
#app-screen {
  display: grid;
  grid-template-rows: var(--header-height) 1fr;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  height: 100%;
}

/* --- Header --- */
#app-header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  padding-top: var(--safe-top);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
}

.user-name {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Hide hamburger on desktop */
#btn-menu {
  display: none;
}

/* --- Sidebar --- */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px 0;
  padding-bottom: calc(16px + var(--safe-bottom));
}

.sidebar-section {
  margin-bottom: 8px;
}

.sidebar-heading {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 8px 16px 4px;
}

.list-nav {
  list-style: none;
}

.list-nav li {
  display: flex;
  align-items: center;
}

.list-nav-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  gap: 8px;
}
.list-nav-item:hover {
  background: var(--bg-hover);
}
.list-nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 500;
}

.list-nav-item .list-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  color: var(--text-muted);
}
.list-nav-item.active .list-icon {
  color: var(--accent);
}

.list-nav-item .list-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-nav-item .list-count {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-input);
  padding: 1px 7px;
  border-radius: 10px;
  flex-shrink: 0;
}

.btn-new-list {
  margin: auto 12px 0;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px dashed rgba(232, 163, 23, 0.3);
}
.btn-new-list:hover {
  background: rgba(232, 163, 23, 0.25);
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 29;
}

/* --- Main Content --- */
.main-content {
  grid-area: main;
  overflow-y: auto;
  padding: 20px 24px;
  padding-bottom: calc(20px + var(--safe-bottom));
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 16px;
  color: var(--text-muted);
  font-size: 15px;
}

/* --- List View --- */
.list-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.list-title {
  font-size: 22px;
  font-weight: 700;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.shared-info {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.shared-info .shared-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
}
.shared-info .shared-name {
  background: var(--bg-input);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
}

/* --- Task Form --- */
.task-form {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}

.task-form input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
  min-height: 44px;
}
.task-form input:focus {
  border-color: var(--accent);
}
.task-form input::placeholder {
  color: var(--text-muted);
}

.btn-add-task {
  width: 44px;
  padding: 0;
  font-size: 22px;
  font-weight: 700;
  flex-shrink: 0;
}

.tasks-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 15px;
}

/* --- Task List --- */
.task-list {
  list-style: none;
}

.task-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.task-item .task-checkbox {
  width: 22px;
  height: 22px;
  margin-top: 2px;
  flex-shrink: 0;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid var(--text-muted);
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.task-item .task-checkbox:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.task-item .task-checkbox:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 6px;
  height: 11px;
  border: solid var(--bg-primary);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.task-body {
  flex: 1;
  min-width: 0;
}

.task-text {
  font-size: 15px;
  word-break: break-word;
  transition: opacity 0.2s, text-decoration-color 0.2s;
}
.task-item.completed .task-text {
  text-decoration: line-through;
  text-decoration-color: var(--text-muted);
  opacity: 0.5;
}

.task-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.task-delete {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.task-item:hover .task-delete,
.task-delete:focus {
  opacity: 1;
}
.task-delete:hover {
  color: var(--danger);
}
/* Always visible on touch devices */
@media (hover: none) {
  .task-delete {
    opacity: 0.6;
  }
}

/* ========================================
   MODALS
   ======================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
  animation: fadeOverlay 0.15s ease;
}
@keyframes fadeOverlay {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 440px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px var(--shadow);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-small {
  max-width: 360px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-hint {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* Share user list */
.share-user-list {
  list-style: none;
}
.share-user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}
.share-user-item label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  flex: 1;
  min-height: 36px;
}
.share-user-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
}
.share-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-surface);
  flex-shrink: 0;
}
.share-user-name {
  font-size: 14px;
}
.share-user-email {
  font-size: 12px;
  color: var(--text-muted);
}
.share-no-users {
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 20px;
}

/* Admin */
.admin-add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.admin-add-form input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  min-height: 44px;
}
.admin-add-form input:focus {
  border-color: var(--accent);
}
.admin-add-form input::placeholder {
  color: var(--text-muted);
}

.admin-list-heading {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.admin-email-list {
  list-style: none;
}
.admin-email-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.admin-email-item .admin-badge {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 1px 6px;
  border-radius: 8px;
  margin-left: 6px;
}
.admin-email-item .btn-remove-email {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
  flex-shrink: 0;
}
.admin-email-item .btn-remove-email:hover {
  color: var(--danger);
}

/* New list modal form */
#newlist-form input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  min-height: 44px;
}
#newlist-form input:focus {
  border-color: var(--accent);
}
#newlist-form input::placeholder {
  color: var(--text-muted);
}

/* ========================================
   RESPONSIVE — Mobile (<768px)
   ======================================== */
@media (max-width: 767px) {
  #app-screen {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "main";
  }

  #btn-menu {
    display: flex;
  }

  .user-name {
    display: none;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    padding-top: calc(var(--safe-top) + 16px);
  }
  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-bottom));
  }

  .list-title {
    font-size: 20px;
  }
}

/* ========================================
   Larger screens
   ======================================== */
@media (min-width: 1200px) {
  .main-content {
    padding: 24px 40px;
  }
}
