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

:root {
  --bg: #1a1a2e;
  --card: #16213e;
  --accent: #0f3460;
  --accent-hover: #1a5276;
  --text: #e0e0e0;
  --text-muted: #888;
  --border: #2a2a4a;
  --danger: #c0392b;
  --danger-hover: #e74c3c;
  --success: #27ae60;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

/* Login Screen */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20px;
}

#login-screen[hidden] { display: none; }

.login-container {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-title {
  font-size: 42px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 32px;
  font-size: 16px;
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#login-form input {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: #fff;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

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

/* Buttons */
.btn-primary {
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.btn-small {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

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

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  padding: 6px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.error { color: var(--danger-hover); font-size: 14px; text-align: center; }

/* App Shell */
#app-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
}

#app-shell[hidden] { display: none; }

/* Top Bar */
#top-bar {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
}

.top-title {
  flex: 1;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
}

.dropdown {
  position: absolute;
  right: 16px;
  top: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.dropdown[hidden] { display: none; }

.dropdown button {
  display: block;
  width: 100%;
  padding: 12px 20px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}

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

/* Screens */
#screens {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.screen {
  display: none;
  padding: 16px;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.screen.active { display: block; }

.empty-msg {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 15px;
}

.empty-msg[hidden] { display: none; }

/* Bottom Nav */
#bottom-nav {
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  flex-shrink: 0;
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  transition: color 0.2s;
  min-height: 52px;
}

.nav-tab.active { color: #fff; }
.nav-icon { font-size: 22px; }
.nav-label { font-weight: 500; }

/* Grocery Screen */
.grocery-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: flex-start;
}

.add-form {
  display: flex;
  gap: 8px;
  flex: 1;
}

.add-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: #fff;
  font-size: 15px;
  outline: none;
}

.add-form input:first-child { flex: 1; min-width: 0; }
.qty-input { width: 60px; }

.btn-add {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.2s;
}

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

.grocery-menu { position: relative; }

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

.grocery-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--card);
  border-radius: 10px;
  margin-bottom: 6px;
  transition: opacity 0.2s;
}

.grocery-item.checked { opacity: 0.5; }
.grocery-item.checked .grocery-item-name { text-decoration: line-through; }

.grocery-item input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

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

.grocery-item-name {
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grocery-item-qty {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.btn-delete-item {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

/* Board Screen */
.board-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.board-header h2 {
  font-size: 18px;
  color: #fff;
}

.post-form {
  background: var(--card);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 16px;
}

.post-form[hidden] { display: none; }

.post-form textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: #fff;
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.post-card {
  background: var(--card);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.post-card:active { background: var(--accent); }

.post-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.avatar-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
}

.post-meta { flex: 1; min-width: 0; }

.post-author {
  font-weight: 600;
  font-size: 14px;
  color: #fff;
}

.post-time {
  font-size: 12px;
  color: var(--text-muted);
}

.post-content {
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
}

.post-content.preview {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.post-footer {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

/* Expanded post / replies */
.post-card.expanded { cursor: default; }
.post-card.expanded:active { background: var(--card); }

.replies-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.reply-item {
  display: flex;
  gap: 8px;
  padding: 8px 0;
}

.reply-item .avatar-dot {
  width: 24px;
  height: 24px;
  font-size: 11px;
}

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

.reply-author {
  font-weight: 600;
  font-size: 13px;
  color: #fff;
}

.reply-author span {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 11px;
  margin-left: 6px;
}

.reply-text { font-size: 13px; color: var(--text); margin-top: 2px; line-height: 1.3; }

.reply-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.reply-form input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: #fff;
  font-size: 14px;
  outline: none;
}

.reply-form button {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

/* Chat Screen */
#screen-chat {
  display: none;
  padding: 0;
  flex-direction: column;
  height: 100%;
}

#screen-chat.active {
  display: flex;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-msg {
  display: flex;
  gap: 8px;
  max-width: 85%;
  align-items: flex-end;
}

.chat-msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg.theirs { align-self: flex-start; }

.chat-msg .avatar-dot {
  width: 28px;
  height: 28px;
  font-size: 12px;
  flex-shrink: 0;
}

.chat-msg.mine .avatar-dot { display: none; }

.chat-bubble {
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
}

.chat-msg.mine .chat-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg.theirs .chat-bubble {
  background: var(--card);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-bubble-name {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 2px;
  opacity: 0.8;
}

.chat-bubble-time {
  font-size: 10px;
  opacity: 0.5;
  margin-top: 2px;
  text-align: right;
}

.chat-bubble img {
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  display: block;
  margin: 4px 0;
  cursor: pointer;
}

.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: var(--card);
  border-top: 1px solid var(--border);
  align-items: center;
  flex-shrink: 0;
}

.chat-input-bar input[type="text"] {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: #fff;
  font-size: 15px;
  outline: none;
}

.chat-date-divider {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 8px 0 4px;
}

.chat-load-more {
  text-align: center;
  padding: 8px;
}

.chat-load-more button {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 16px;
  padding: 6px 16px;
  font-size: 12px;
  cursor: pointer;
}

/* Check In Screen */
.checkin-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.checkin-form input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: #fff;
  font-size: 15px;
  outline: none;
}

.btn-checkin {
  padding: 16px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-checkin:hover { background: var(--accent-hover); }
.btn-checkin:active { transform: scale(0.98); }
.btn-checkin:disabled { opacity: 0.5; cursor: not-allowed; }

.section-title {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-weight: 600;
}

.checkin-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--card);
  border-radius: 10px;
  margin-bottom: 6px;
}

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

.checkin-name {
  font-weight: 600;
  font-size: 14px;
  color: #fff;
}

.checkin-label {
  font-size: 13px;
  color: var(--text);
  margin-top: 2px;
}

.checkin-time {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.checkin-map {
  font-size: 12px;
  color: var(--accent-hover);
  text-decoration: none;
  flex-shrink: 0;
}

/* Loading spinner */
.loading {
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
}

/* Notification badge */
.nav-tab { position: relative; }

.badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 20px);
  background: var(--danger-hover);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

.badge[hidden] { display: none; }
