:root,
[data-theme="dark"] {
  color-scheme: dark;
}

[data-theme="light"] {
  color-scheme: light;
}

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

html {
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100dvh;
  line-height: 1.5;
  overflow-x: hidden;
}

/* Inset the app card from the viewport on mobile (shared theme zeroes app-page padding) */
body.app-page:has(#app.app-shell--full) {
  padding:
    max(0.75rem, var(--safe-top))
    max(0.75rem, var(--safe-right))
    max(0.75rem, var(--safe-bottom))
    max(0.75rem, var(--safe-left));
}

#app.app-shell--full {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding:
    max(1rem, calc(0.75rem + var(--safe-top)))
    max(1.25rem, var(--gutter-inline-end))
    max(1rem, calc(0.75rem + var(--safe-bottom)))
    max(1.25rem, var(--gutter-inline-start));
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border-left: 1px solid var(--color-border);
  border-right: 1px solid var(--color-border);
  box-shadow: var(--shadow);
  min-height: auto;
}

@media (min-width: 600px) {
  #app.app-shell--full {
    margin-top: var(--shell-padding-y);
    margin-bottom: var(--shell-padding-y);
    min-height: calc(100dvh - (var(--shell-padding-y) * 2));
  }
}

/* Override shared theme.css zeroing horizontal padding on shell children */
#app.app-shell--full > .header {
  width: 100%;
  min-width: 0;
  padding: 1.15rem;
  margin: 0;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

#app.app-shell--full > .tabs {
  width: 100%;
  min-width: 0;
  display: flex;
  margin: 0;
  padding: 0.5rem;
  gap: 0.45rem;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

#app.app-shell--full > .main,
#app.app-shell--full > main {
  width: 100%;
  min-width: 0;
  flex: 1;
  padding: 0.25rem 0 1rem;
  position: relative;
}

#app.app-shell--full > .app-footer {
  width: 100%;
  min-width: 0;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.header-actions .theme-toggle,
.header-actions .help-btn {
  position: static;
}

.help-btn {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-muted);
  width: var(--min-touch);
  height: var(--min-touch);
  border: 2px solid var(--color-border);
  background: var(--color-surface);
  border-radius: var(--radius-sm);
}

.help-btn:active {
  color: var(--color-primary);
  background: var(--color-primary-light);
  border-color: var(--color-primary);
}

.help-content {
  max-height: 85dvh;
}

.help-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.help-section h3 {
  font-size: 0.9375rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.help-section p {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.help-section p + p {
  margin-top: 8px;
}

.help-section ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help-section li {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.5;
  padding-left: 14px;
  position: relative;
}

.help-section li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
}

.help-section li strong {
  color: var(--text);
  font-weight: 600;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--color-primary);
  margin: 0;
  line-height: 1.2;
}

.date-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.date-nav .icon-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
}

.date-display {
  flex: 1;
  min-width: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 1rem;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: background 0.15s;
}

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

#date-label {
  font-size: 1rem;
  font-weight: 600;
}

.date-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Tabs (base styles; padding lives on #app selector above) */
.tab {
  flex: 1;
  padding: 0.7rem 0.5rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  min-height: var(--min-touch);
  font-family: inherit;
}

.tab.active {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* Main — layout handled on #app selector above */
.view {
  display: none;
}

.view.active {
  display: block;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.btn-primary:active {
  opacity: 0.85;
  transform: scale(0.98);
}

.btn-ghost {
  background: transparent;
  color: var(--danger);
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.8125rem;
}

.btn-block {
  width: 100%;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.icon-btn:active {
  background: var(--bg-hover);
  color: var(--text);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.empty-state p {
  color: var(--text-muted);
  margin-bottom: 20px;
}

.hidden {
  display: none !important;
}

/* Entry cards */
.entry-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tracker-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}

.tracker-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}

.tracker-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

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

.tracker-name {
  font-weight: 600;
  font-size: 0.9375rem;
}

.tracker-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.tracker-actions {
  display: flex;
  gap: 4px;
}

.tracker-value-display {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Goal progress */
.goal-bar-wrap {
  padding: 0 16px 14px;
}

.goal-bar {
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
}

.goal-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
  min-width: 0;
}

.goal-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.goal-label .hit {
  color: var(--accent);
  font-weight: 600;
}

/* Entry rows inside card */
.entry-rows {
  border-top: 1px solid var(--border);
}

.entry-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 0.875rem;
}

.entry-row + .entry-row {
  border-top: 1px solid var(--border);
}

.entry-value {
  font-weight: 600;
  min-width: 48px;
}

.entry-note {
  flex: 1;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.entry-row-with-photo {
  flex-wrap: wrap;
}

.entry-row-with-photo .entry-value,
.entry-row-with-photo .entry-note {
  flex: 1 1 auto;
}

.entry-thumb {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  cursor: pointer;
}

.entry-photo-group .hint {
  margin-top: 8px;
}

.photo-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.photo-picker-btn:active {
  border-color: var(--accent);
  color: var(--accent);
}

.photo-preview {
  margin-top: 10px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.photo-preview img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
}

#entry-photo-clear {
  margin-top: 8px;
}

.lightbox-modal::backdrop {
  background: rgba(0, 0, 0, 0.92);
}

.lightbox-modal .modal-content {
  display: none;
}

.lightbox-modal[open] {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.lightbox-close {
  position: fixed;
  top: calc(12px + var(--safe-top));
  right: 16px;
  z-index: 2;
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}

.lightbox-image {
  max-width: 100%;
  max-height: 90dvh;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.day-log-photo {
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  cursor: pointer;
}

.entry-delete {
  opacity: 0.4;
  padding: 4px;
}

.entry-delete:active {
  opacity: 1;
  color: var(--danger);
}

/* Counter quick tap */
.counter-tap {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 16px 14px;
}

.counter-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-hover);
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.counter-btn.plus {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.counter-btn:active {
  transform: scale(0.92);
}

/* Boolean toggle */
.bool-toggle {
  display: flex;
  gap: 8px;
  padding: 8px 16px 14px;
}

.bool-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
}

.bool-btn.active-yes {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

.bool-btn.active-no {
  border-color: var(--danger);
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
}

/* Rating stars */
.rating-row {
  display: flex;
  gap: 6px;
  padding: 8px 16px 14px;
  justify-content: center;
}

.star-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  cursor: pointer;
  opacity: 0.3;
  transition: opacity 0.15s, transform 0.15s;
}

.star-btn.filled {
  opacity: 1;
}

.star-btn:active {
  transform: scale(1.15);
}

/* FAB */
.fab {
  position: fixed;
  bottom: calc(24px + var(--safe-bottom));
  right: max(24px, calc(50% - 240px + 24px));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.fab svg {
  width: 24px;
  height: 24px;
}

.fab:active {
  transform: scale(0.92);
}

/* Tracker list (settings view) */
.tracker-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.tracker-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.tracker-list-item:active {
  background: var(--bg-hover);
}

.tracker-list-item .type-badge {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 3px 8px;
  border-radius: 4px;
}

/* Summary */
.summary-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.select {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238896a8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 12px;
  text-align: center;
}

.stat-value {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 4px;
}

.chart-wrap {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.chart-title {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.bar-chart {
  display: flex;
  align-items: stretch;
  gap: 3px;
  height: 120px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  min-width: 0;
  height: 100%;
}

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

.bar-label {
  font-size: 0.5625rem;
  color: var(--text-muted);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  max-height: 32px;
  overflow: hidden;
}

.goal-line-info {
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 8px;
}

.day-log-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.day-log-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.day-log-date {
  color: var(--text-muted);
}

.day-log-value {
  font-weight: 600;
}

.day-log-value.goal-hit {
  color: var(--accent);
}

/* Modal */
.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
}

.modal::backdrop {
  background: var(--color-overlay);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  border-top: 1px solid var(--border);
}

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

.modal-header h2 {
  font-size: 1.125rem;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-actions .btn-primary {
  flex: 1;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.optional {
  font-weight: 400;
  opacity: 0.7;
}

.form-group input[type="text"],
.form-group input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

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

.hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.color-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.15s;
}

.color-swatch.selected {
  border-color: var(--text);
  transform: scale(1.1);
}

.color-swatch:active {
  transform: scale(0.95);
}

/* Entry input in modal */
.entry-number-input {
  width: 100%;
  padding: 16px;
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
}

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

.entry-text-input {
  width: 100%;
  padding: 14px;
  min-height: 100px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
}

/* Quiet footer install link (no banners / alerts) */
.app-footer {
  margin-top: auto;
  padding: 0.85rem 0 0.25rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.app-footer p {
  margin: 0 0 0.35rem;
}

.btn-link {
  background: none;
  border: none;
  color: var(--color-primary);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  padding: 0.35rem;
  font-family: inherit;
}

.btn-link:hover {
  color: var(--color-primary-hover);
}

@media (min-width: 481px) {
  body {
    background: var(--color-bg);
  }
}
