:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-alt: #22262f;
  --text: #f2f3f5;
  --text-dim: #9aa0ab;
  --accent: #4fd1a5;
  --danger: #e5636b;
  --border: #2b2f38;
}

* {
  box-sizing: border-box;
}

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

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px 80px;
}

.app-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-top: 32px;
}

.app-footer p {
  margin: 0 0 6px;
}

.app-footer a {
  color: var(--text-dim);
  text-decoration: underline;
}

.app-footer a:hover {
  color: var(--accent);
}

header {
  text-align: center;
  margin-bottom: 20px;
}

header h1 {
  margin: 0 0 4px;
  font-size: 1.5rem;
}

.date {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
}

.tab-button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.tab-button.active {
  background: var(--surface-alt);
  color: var(--text);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-day {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.history-day-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px;
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  color: var(--text);
  font: inherit;
}

.history-day-date {
  font-size: 0.95rem;
}

.history-day-summary {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-shrink: 0;
}

.history-day-cals {
  font-weight: 700;
  color: var(--accent);
  font-size: 1.05rem;
}

.history-day-macros {
  font-size: 0.75rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.history-entries {
  list-style: none;
  margin: 0;
  padding: 0 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.history-entries[hidden] {
  display: none;
}

.history-entry {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.85rem;
}

.history-entry-desc {
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-entry-cals {
  flex-shrink: 0;
  font-weight: 600;
}

.export-btn {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.export-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.swap-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-top: 4px;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.swap-result[hidden] {
  display: none;
}

.totals {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  margin-bottom: 20px;
}

.total-card {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}

.total-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--accent);
}

.total-label {
  font-size: 1rem;
  color: var(--text-dim);
}

.goal-section {
  margin-bottom: 16px;
}

.goal-bar-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
  margin-bottom: 8px;
}

.goal-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.goal-bar-fill.over {
  background: var(--danger);
}

.goal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.goal-status {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.goal-edit-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
}

.goal-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

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

.goal-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.goal-field-full {
  grid-column: 1 / -1;
}

.goal-form input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.9rem;
}

.goal-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.goal-form-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
}

.goal-form-actions button {
  flex: 1;
  padding: 10px 14px;
  border-radius: 10px;
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

#goal-save-btn {
  background: var(--accent);
  color: #0f1115;
}

#goal-cancel-btn {
  background: var(--surface-alt);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.macro-row {
  display: flex;
  justify-content: space-around;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.macro {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.macro-value {
  font-size: 1.1rem;
  font-weight: 600;
}

.macro-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.macro-bar-track {
  width: 100%;
  height: 4px;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
  margin-top: 4px;
}

.macro-bar-track[hidden] {
  display: none;
}

.macro-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.macro-bar-fill.over {
  background: var(--danger);
}

.macro-goal-label {
  display: block;
  font-size: 0.65rem;
  color: var(--text-dim);
  margin-top: 3px;
}

.macro-goal-label[hidden] {
  display: none;
}

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

#food-input,
#swap-input {
  flex: 1;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

#food-input:focus,
#swap-input:focus {
  outline: none;
  border-color: var(--accent);
}

#add-button,
#swap-button {
  padding: 12px 18px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: #0f1115;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}

#add-button:disabled,
#swap-button:disabled {
  opacity: 0.6;
  cursor: default;
}

.clarify-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.clarify-panel[hidden] {
  display: none;
}

#clarify-submit-btn,
#clarify-skip-btn {
  background: var(--accent);
  color: #0f1115;
}

#clarify-submit-btn {
  padding: 12px 18px;
  border-radius: 12px;
  border: none;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}

#clarify-cancel-btn {
  background: var(--surface-alt);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.status {
  min-height: 1.2em;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 4px 2px 16px;
}

.status.error {
  color: var(--danger);
}

.log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.log-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.entry-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.entry-desc {
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-macros {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.entry-cals {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  white-space: nowrap;
}

.remove-btn {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.remove-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 0;
  font-size: 0.9rem;
}

.alt-entry-methods {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.alt-method-btn {
  flex: 1;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.alt-method-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-panel {
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 20px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-close-btn {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

#barcode-reader {
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  min-height: 200px;
}

.modal-status {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 12px 0;
  text-align: center;
}

.modal-hint {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: 0 0 12px;
}

.modal-result-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 0 0 4px;
}

#photo-start .goal-form-actions,
#photo-camera .goal-form-actions,
#photo-preview .goal-form-actions,
#barcode-confirm .goal-form-actions {
  margin-top: 4px;
}

#photo-take-btn,
#photo-capture-btn,
#photo-analyze-btn,
#barcode-add-btn,
#photo-add-btn {
  background: var(--accent);
  color: #0f1115;
}

#photo-upload-btn,
#photo-camera-cancel-btn,
#photo-retake-btn,
#barcode-cancel-confirm-btn,
#photo-retry-btn {
  background: var(--surface-alt);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

#photo-video {
  width: 100%;
  border-radius: 12px;
  background: #000;
  max-height: 50vh;
}

#photo-preview-img {
  width: 100%;
  max-height: 40vh;
  object-fit: contain;
  border-radius: 12px;
  background: #000;
}

#photo-start,
#photo-camera,
#photo-preview,
#photo-confirm,
#barcode-confirm,
#barcode-fallback {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#photo-start[hidden],
#photo-camera[hidden],
#photo-preview[hidden],
#photo-confirm[hidden],
#barcode-confirm[hidden],
#barcode-fallback[hidden] {
  display: none;
}
