/* ============================================================================
   CALORIE TRACKER PWA - MAIN CSS
   iPhone-only layout with chat, navigation, forms, and cards
   ============================================================================ */

/* 1. RESET & BASE ========================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* 2. CSS CUSTOM PROPERTIES ================================================= */
:root {
  /* Colors */
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --text-primary: #ffffff;
  --text-secondary: #b0b0b0;
  --danger: #ff6b6b;
  --success: #51cf66;
  --warning: #ffd43b;
  --subtle: #2d3561;
  --chat-assistant: #0f3460;

  /* Border Radius */
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 50px;

  /* Layout Heights */
  --nav-height: 72px;
  --input-bar-height: 56px;

  /* Safe Area Insets */
  --safe-top: max(12px, env(safe-area-inset-top));
  --safe-bottom: max(12px, env(safe-area-inset-bottom));
  --safe-left: max(12px, env(safe-area-inset-left));
  --safe-right: max(12px, env(safe-area-inset-right));

  /* Typography */
  --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* 3. HTML & BODY ========================================================== */
html,
body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-main);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

/* 4. #app CONTAINER ======================================================= */
#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* 5. #main-app =========================================================== */
#main-app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* 6. #tab-content ======================================================== */
#tab-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* 7. .tab-view ========================================================== */
.tab-view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Chat tab needs flex layout to pin input bar at bottom */
#view-chat {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 8. .hidden ============================================================ */
.hidden {
  display: none !important;
}

/* 9. #bottom-nav ======================================================== */
#bottom-nav {
  display: flex;
  justify-content: space-around;
  height: var(--nav-height);
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--subtle);
  padding-bottom: var(--safe-bottom);
}

/* 10. .nav-btn ========================================================= */
.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 10px;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
}

.nav-btn.active {
  color: var(--accent-light);
}

/* 11. .summary-card ==================================================== */
.summary-card {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin: 12px 16px;
  cursor: pointer;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.summary-card:active {
  transform: scale(0.98);
}

.summary-card .balance-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-primary);
  opacity: 0.9;
  margin-bottom: 4px;
}

.summary-card .balance-value {
  font-size: 28px;
  font-weight: bold;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.summary-card .balance-details {
  display: flex;
  justify-content: space-around;
}

.summary-card .balance-item {
  font-size: 12px;
  color: var(--text-primary);
  opacity: 0.85;
  text-align: center;
}

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

/* 13. .chat-bubble ===================================================== */
.chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  animation: fadeIn 0.3s ease;
}

.chat-bubble.user {
  background: var(--accent);
  color: var(--text-primary);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-bubble.assistant {
  background: var(--chat-assistant);
  color: var(--text-primary);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

/* 14. @keyframes fadeIn ================================================ */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 15. .input-bar ======================================================= */
.input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--subtle);
  min-height: var(--input-bar-height);
  flex-shrink: 0;
}

.input-bar input {
  flex: 1;
  background-color: var(--bg-primary);
  border: 1px solid var(--subtle);
  border-radius: var(--radius-full);
  font-size: 15px;
  padding: 12px 16px;
  color: var(--text-primary);
  min-height: 44px;
}

.input-bar input::placeholder {
  color: var(--text-secondary);
}

.input-bar button {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background-color: var(--accent);
  border: none;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}

/* 16. .card ============================================================ */
.card {
  background-color: var(--bg-secondary);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 8px 16px;
}

.card-title {
  font-size: 13px;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* 17. .entry-item ====================================================== */
.entry-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--subtle);
}

.entry-item:last-child {
  border-bottom: none;
}

.entry-name {
  font-size: 15px;
  color: var(--text-primary);
}

.entry-detail {
  font-size: 12px;
  color: var(--text-secondary);
}

.entry-calories {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent-light);
}

/* 18. .btn ============================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border-radius: var(--radius-full);
  font-size: 16px;
  font-weight: 600;
  min-height: 44px;
  border: none;
  cursor: pointer;
  transition: transform 0.2s ease;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
  color: var(--text-primary);
}

.btn-secondary {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--subtle);
}

.btn-block {
  width: 100%;
}

/* 19. .form-group ====================================================== */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-input {
  width: 100%;
  padding: 12px 16px;
  background-color: var(--bg-primary);
  border: 1px solid var(--subtle);
  border-radius: var(--radius-sm);
  font-size: 16px;
  color: var(--text-primary);
  min-height: 44px;
}

.form-input::placeholder {
  color: var(--text-secondary);
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.2);
}

.form-select {
  width: 100%;
  padding: 12px 16px;
  background-color: var(--bg-primary);
  border: 1px solid var(--subtle);
  border-radius: var(--radius-sm);
  font-size: 16px;
  color: var(--text-primary);
  min-height: 44px;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b0b0b0' stroke-width='2'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 20px;
  padding-right: 36px;
}

.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.2);
}

/* 20. .progress-bar ==================================================== */
.progress-bar {
  width: 100%;
  height: 12px;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent) 0%, var(--accent-light) 100%);
  border-radius: 6px;
  transition: width 0.3s ease;
}

/* 21. #onboarding ====================================================== */
#onboarding {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 24px;
  padding-top: calc(24px + var(--safe-top));
}

.onboarding-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.onboarding-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  margin-bottom: 16px;
}

.onboarding-subtitle {
  font-size: 16px;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.5;
}

.onboarding-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  gap: 12px;
}

.onboarding-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex: 1;
}

.onboarding-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--subtle);
  transition: background-color 0.3s ease;
}

.onboarding-dot.active {
  background-color: var(--accent);
}

/* 22. .daily-log-overlay =============================================== */
.daily-log-overlay {
  position: fixed;
  inset: 0;
  background-color: var(--bg-primary);
  z-index: 100;
  transform: translateY(100%);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}

.daily-log-overlay.open {
  transform: translateY(0);
}

.daily-log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  padding: 16px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--subtle);
  z-index: 101;
}

/* 23. .bar-chart ======================================================= */
.bar-chart {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  height: 120px;
  gap: 8px;
}

.bar-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}

.bar {
  max-width: 32px;
  width: 100%;
  border-radius: 4px 4px 0 0;
  transition: height 0.3s ease;
}

.bar.deficit {
  background-color: var(--success);
}

.bar.surplus {
  background-color: var(--danger);
}

.bar-label {
  font-size: 10px;
  color: var(--text-secondary);
  margin-top: 8px;
}

/* 24. .weight-chart ==================================================== */
.weight-chart {
  width: 100%;
  height: 160px;
}

.weight-chart canvas {
  width: 100%;
  height: 100%;
}

/* 25. .swipeable ======================================================= */
.swipeable {
  position: relative;
  overflow: hidden;
}

.swipe-delete {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 80px;
  background-color: var(--danger);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  cursor: pointer;
}

/* 26. UTILITIES ========================================================= */
.text-center {
  text-align: center;
}

.mt-8 {
  margin-top: 8px;
}

.mt-16 {
  margin-top: 16px;
}

.mt-24 {
  margin-top: 24px;
}

.mb-8 {
  margin-bottom: 8px;
}

.mb-16 {
  margin-bottom: 16px;
}

.p-16 {
  padding: 16px;
}

/* 27. .typing-indicator ================================================ */
.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent);
  animation: bounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
  animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-10px);
  }
}

/* 28. .offline-banner ================================================== */
.offline-banner {
  background-color: var(--warning);
  color: #000;
  padding: 12px 16px;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  display: none;
}

.offline-banner.visible {
  display: block;
}

/* 29. .manual-entry-form =============================================== */
.manual-entry-form {
  padding: 16px;
}

.form-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.form-row > input,
.form-row > select {
  flex: 1;
}

/* 30. .summary-grid (for weekly summary) ================================== */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.summary-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background-color: var(--bg-primary);
  border-radius: var(--radius-sm);
  text-align: center;
}

.summary-icon {
  font-size: 24px;
  margin-bottom: 4px;
}

.summary-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 4px;
}

.summary-value {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

/* 31. .date-nav (for week navigation) ==================================== */
.date-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  margin: 8px 0;
  gap: 12px;
}

.date-nav-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background-color: var(--bg-secondary);
  border: 1px solid var(--subtle);
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

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

.date-nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.date-label {
  flex: 1;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
