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

:root {
  --primary: #4a90d9;
  --primary-dark: #357abd;
  --success: #4caf50;
  --warning: #ff9800;
  --danger: #e53935;
  --bg: #f0f4f8;
  --card: #ffffff;
  --text: #2d3748;
  --text-light: #718096;
  --border: #e2e8f0;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
}

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

/* ===== LOGIN SCREEN ===== */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  background: #1a1a2e;
  overflow: hidden;
}

.login-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 20%, rgba(26,26,46,0.4) 50%, rgba(26,26,46,0.95) 75%, #1a1a2e 100%);
  z-index: 1;
}

.login-photo {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.login-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.login-content {
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 380px;
  padding: 0 24px 40px;
  text-align: center;
}

.login-title {
  font-size: 36px;
  font-weight: 800;
  color: white;
  margin-bottom: 4px;
  text-shadow: 0 2px 20px rgba(0,0,0,0.5);
  letter-spacing: -0.5px;
}

.login-subtitle {
  font-size: 15px;
  color: rgba(255,255,255,0.7);
  margin-bottom: 28px;
}

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

.login-input {
  width: 100%;
  padding: 14px 18px;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  background: rgba(255,255,255,0.1);
  backdrop-filter: blur(10px);
  color: white;
  font-size: 16px;
  outline: none;
  transition: border-color 0.3s;
}

.login-input::placeholder { color: rgba(255,255,255,0.4); }
.login-input:focus { border-color: rgba(255,255,255,0.5); }

.login-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #6c5ce7);
  color: white;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s;
}

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

.login-hint {
  font-size: 13px;
  color: rgba(255,255,255,0.6);
  margin-bottom: 4px;
}

.login-error {
  color: #ff6b6b;
  font-size: 13px;
  margin-top: -4px;
}

.login-lang {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 3;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  padding: 4px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* ===== APP CONTAINER ===== */
.app-container {
  padding-bottom: 80px;
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--primary), #6c5ce7);
  color: white;
  padding: 16px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(74,144,217,0.3);
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header h1 { font-size: 20px; font-weight: 700; }
.header-sub { font-size: 13px; opacity: 0.85; margin-top: 2px; }

.lang-toggle {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.4);
  color: white;
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.lang-toggle:hover { background: rgba(255,255,255,0.3); }

/* Navigation */
.nav {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
  z-index: 100;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
}

.nav button {
  flex: 1;
  padding: 8px 2px;
  border: none;
  background: none;
  font-size: 10px;
  color: var(--text-light);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: color 0.2s;
}

.nav button.active { color: var(--primary); font-weight: 600; }
.nav button svg { width: 22px; height: 22px; }

/* Date picker bar */
.date-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.date-bar button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 18px;
  color: var(--primary);
}

.date-bar .date-display {
  font-size: 16px;
  font-weight: 600;
  min-width: 180px;
  text-align: center;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: background 0.2s;
}

.date-bar .date-display:hover { background: var(--bg); }

/* Pages */
.page {
  display: none;
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
}

.page.active { display: block; }

/* Cards */
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--primary-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title .icon { font-size: 18px; }

/* Toggle items */
.toggle-group { display: flex; flex-direction: column; gap: 10px; }

.toggle-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.toggle-item:last-child { border-bottom: none; }
.toggle-label { font-size: 14px; flex: 1; }
.toggle-sublabel { font-size: 11px; color: var(--text-light); display: block; }

/* Flex tags (for day type, parent home - single select) */
.flex-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}

.flex-tag {
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
  background: var(--bg);
  color: var(--text-light);
  border: 1px solid var(--border);
  transition: all 0.2s;
}

.flex-tag.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Scale selector */
.scale-selector {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.scale-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-light);
}

.scale-btn.active { border-color: var(--primary); background: var(--primary); color: white; }
.scale-btn.s1.active { background: #4caf50; border-color: #4caf50; }
.scale-btn.s2.active { background: #8bc34a; border-color: #8bc34a; }
.scale-btn.s3.active { background: #ff9800; border-color: #ff9800; }
.scale-btn.s4.active { background: #ff5722; border-color: #ff5722; }
.scale-btn.s5.active { background: #e53935; border-color: #e53935; }

/* Tag inputs */
.tag-container { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #e8f0fe;
  color: var(--primary-dark);
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.tag.active { background: var(--primary); color: white; }

.tag-input-row { display: flex; gap: 8px; margin-top: 8px; }

.tag-input-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}

.tag-input-row input:focus { border-color: var(--primary); }

.tag-input-row button {
  padding: 8px 16px;
  border: none;
  background: var(--primary);
  color: white;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

/* Textarea */
.notes-area {
  width: 100%;
  min-height: 80px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}

.notes-area:focus { border-color: var(--primary); }

/* Save button */
.save-btn {
  width: 100%;
  padding: 14px;
  border: none;
  background: linear-gradient(135deg, var(--primary), #6c5ce7);
  color: white;
  font-size: 16px;
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
  margin-top: 8px;
  transition: transform 0.2s;
}

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

.save-toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #2d3748;
  color: white;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s;
  pointer-events: none;
  z-index: 200;
}

.save-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Calendar */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 8px; }
.cal-header { text-align: center; font-size: 12px; font-weight: 600; color: var(--text-light); padding: 4px; }

.cal-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.cal-day:hover { background: var(--bg); }
.cal-day.today { font-weight: 700; border: 2px solid var(--primary); }
.cal-day.has-data { background: #e8f0fe; color: var(--primary-dark); font-weight: 600; }
.cal-day.other-month { color: #cbd5e0; }

.cal-nav { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }

.cal-nav button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 16px;
  cursor: pointer;
  color: var(--primary);
}

.cal-nav .month-label { font-size: 16px; font-weight: 700; }

/* Report */
.stat-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.stat-row:last-child { border-bottom: none; }
.stat-bar-wrap { flex: 1; margin: 0 12px; height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.stat-bar { height: 100%; border-radius: 4px; transition: width 0.5s ease; }
.stat-bar.good { background: #4caf50; }
.stat-bar.neutral { background: #ff9800; }
.stat-bar.bad { background: #e53935; }
.stat-value { font-weight: 700; min-width: 40px; text-align: right; }

.ai-report-content {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.7;
}

.generate-report-btn {
  width: 100%;
  padding: 14px;
  border: none;
  background: linear-gradient(135deg, #6c5ce7, #a855f7);
  color: white;
  font-size: 15px;
  font-weight: 700;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.generate-report-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.report-loading { text-align: center; padding: 30px; color: var(--text-light); }

.report-loading .spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 8px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Settings */
.settings-group { margin-bottom: 8px; }

.settings-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.btn-outline {
  padding: 8px 16px;
  border: 1px solid var(--primary);
  background: none;
  color: var(--primary);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}

.btn-danger {
  padding: 8px 16px;
  border: 1px solid var(--danger);
  background: none;
  color: var(--danger);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}

/* Chat */
#pageChat { padding: 0; display: none; height: calc(100vh - 120px); max-width: 600px; margin: 0 auto; }
#pageChat.active { display: flex; }

.chat-container { display: flex; flex-direction: column; height: 100%; width: 100%; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.chat-welcome { text-align: center; padding: 40px 20px; color: var(--text-light); }
.chat-welcome-icon { font-size: 48px; margin-bottom: 12px; }
.chat-welcome p { font-size: 14px; line-height: 1.6; margin-bottom: 16px; }
.chat-suggestions { display: flex; flex-direction: column; gap: 8px; }

.chat-suggestion {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  color: var(--text);
}

.chat-suggestion:hover { border-color: var(--primary); background: #e8f0fe; }

.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

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

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

.chat-bubble.ai .typing-dots { display: inline-flex; gap: 4px; }

.chat-bubble.ai .typing-dots span {
  width: 6px; height: 6px; background: var(--text-light); border-radius: 50%; animation: typing 1.2s infinite;
}

.chat-bubble.ai .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-bubble.ai .typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing { 0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); } 30% { opacity: 1; transform: scale(1); } }

.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--card);
  border-top: 1px solid var(--border);
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
}

.chat-input:focus { border-color: var(--primary); }

.chat-send {
  width: 40px; height: 40px; border: none;
  background: linear-gradient(135deg, var(--primary), #6c5ce7);
  color: white; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

.chat-send svg { width: 18px; height: 18px; }

/* Month selector */
.month-selector { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 16px; }

.month-selector button {
  background: none; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 14px; font-size: 16px; cursor: pointer; color: var(--primary);
}

.month-selector .month-label { font-size: 16px; font-weight: 700; min-width: 160px; text-align: center; }

.hidden-date { position: absolute; opacity: 0; width: 0; height: 0; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-light); }
.empty-state .emoji { font-size: 48px; margin-bottom: 12px; }

.api-key-banner {
  background: linear-gradient(135deg, #fff3e0, #ffe0b2);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.5;
  display: flex;
  align-items: center;
  gap: 10px;
}

@media (min-width: 768px) {
  .page { padding: 24px; }
  #pageChat { padding: 0; }
  .card { padding: 20px; }
}
