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

:root {
  --amber:    #f59e0b;
  --amber-d:  #d97706;
  --bg:       #0f172a;
  --surface:  #1e293b;
  --surface2: #334155;
  --text:     #f1f5f9;
  --muted:    #94a3b8;
  --radius:   14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ── Update banner ───────────────────────────────────────────────────────── */
.update-banner {
  position: fixed;
  top: calc(var(--safe-top) + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--amber);
  color: #000;
  border-radius: 999px;
  padding: 8px 14px 8px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  z-index: 999;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  animation: slideDown .25s ease;
}
@keyframes slideDown {
  from { opacity: 0; transform: translateX(-50%) translateY(-12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.update-reload-btn {
  background: rgba(0,0,0,.15);
  border: none;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  color: #000;
}

/* ── Screens ─────────────────────────────────────────────────────────────── */
.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }

/* ── Auth ────────────────────────────────────────────────────────────────── */
#screen-auth {
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(var(--safe-top) + 24px);
}
.auth-box {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.logo { font-size: 56px; text-align: center; }
h1 { font-size: 28px; font-weight: 700; text-align: center; }

.tabs {
  display: flex;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px;
  gap: 4px;
}
.tab {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
  transition: all .15s;
}
.tab.active {
  background: var(--amber);
  color: #000;
  font-weight: 600;
}

.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input {
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--surface2);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color .15s;
}
.auth-form input:focus { border-color: var(--amber); }
.auth-error { color: #f87171; font-size: 14px; text-align: center; min-height: 18px; }
.passkey-hint {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  padding: 14px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  -webkit-appearance: none;
}
.btn:active { opacity: .8; transform: scale(.97); }
.btn-primary { background: var(--amber); color: #000; }
.btn-ghost {
  background: var(--surface2);
  color: var(--text);
}
.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--text);
  line-height: 1;
}
.icon-btn:active { opacity: .6; }

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(var(--safe-top) + 12px);
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-left { display: flex; align-items: center; gap: 8px; }
.header-right { display: flex; align-items: center; gap: 4px; }
#header-username { font-weight: 700; font-size: 17px; }
.today-badge {
  background: var(--amber);
  color: #000;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
}

/* Offline/sync indicator */
.sync-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f87171;
  margin-right: 4px;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}

/* ── Beverage Grid ───────────────────────────────────────────────────────── */
main { padding: 16px; }
.beverage-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
@media (min-width: 480px) {
  .beverage-grid { grid-template-columns: repeat(3, 1fr); }
}

.beverage-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px 12px;
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all .15s;
  -webkit-appearance: none;
}
.beverage-btn:active {
  background: var(--surface2);
  transform: scale(.96);
}
.beverage-emoji { font-size: 36px; line-height: 1; }
.beverage-name { font-size: 13px; font-weight: 600; color: var(--text); text-align: center; }
.beverage-vol { font-size: 11px; color: var(--muted); }

/* ── Recent Log ──────────────────────────────────────────────────────────── */
.recent {
  padding: 0 16px 16px;
  padding-bottom: calc(var(--safe-bot) + 16px);
}
.recent h2 { font-size: 14px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 10px; }

.log-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.log-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.log-emoji { font-size: 22px; flex-shrink: 0; margin-top: 1px; }
.log-info { flex: 1; min-width: 0; }
.log-name { font-size: 14px; font-weight: 600; }
.log-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.log-comment { font-size: 13px; color: var(--text); margin-top: 4px; font-style: italic; }
.log-pending { font-size: 11px; color: #fbbf24; margin-top: 3px; }
.edit-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  opacity: 0.4;
  transition: opacity .15s;
  flex-shrink: 0;
  align-self: center;
}
.log-item:hover .edit-btn,
.log-item:active .edit-btn { opacity: 1; }

/* ── History Screen ──────────────────────────────────────────────────────── */
#screen-history header { gap: 16px; }
#screen-history header span { font-weight: 600; }
.padded { padding: 16px; }
#btn-load-more {
  display: block;
  margin: 8px 16px 24px;
  width: calc(100% - 32px);
}

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding-bottom: var(--safe-bot);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: slideUp .2s ease;
}
@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.modal-title { font-size: 20px; font-weight: 700; text-align: center; }

.modal textarea {
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  padding: 12px;
  resize: none;
  outline: none;
  width: 100%;
  transition: border-color .15s;
}
.modal textarea:focus { border-color: var(--amber); }

.location-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
}
.location-row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--amber); cursor: pointer; }
.location-hint { font-size: 12px; color: var(--muted); margin-left: auto; }

.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; }
.modal-map {
  height: 180px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--surface2);
}
.btn-danger { background: #ef4444; color: #fff; }

/* ── More drinks button (below home grid) ────────────────────────────────── */
.more-drinks-btn {
  width: 100%;
  margin-top: 10px;
  background: var(--surface);
  border: 1.5px dashed var(--surface2);
  border-radius: var(--radius);
  padding: 12px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .15s, color .15s;
  -webkit-appearance: none;
}
.more-drinks-btn:hover { border-color: var(--amber); color: var(--text); }

/* ── More drinks overlay ─────────────────────────────────────────────────── */
.more-drinks-modal {
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 80vh;
  overflow-y: auto;
}
.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.link-btn {
  background: none;
  border: none;
  color: var(--amber);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 0;
}
.more-drinks-grid { margin-top: 8px; }

/* ── Drinks management screen ────────────────────────────────────────────── */
.drinks-wrap {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  flex: 1;
}
.drinks-section {}
.section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 8px;
}
.drink-manage-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.dm-empty { font-size: 13px; color: var(--muted); text-align: center; padding: 16px 0; }

.drink-manage-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.dm-emoji { font-size: 22px; flex-shrink: 0; }
.dm-info  { flex: 1; min-width: 0; }
.dm-name  { display: block; font-size: 14px; font-weight: 600; }
.dm-vol   { font-size: 12px; color: var(--muted); }
.dm-actions { display: flex; gap: 4px; flex-shrink: 0; }
.dm-btn {
  background: var(--surface2);
  border: none;
  border-radius: 8px;
  padding: 6px 9px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  transition: opacity .15s;
  line-height: 1;
}
.dm-btn[disabled]    { opacity: 0.25; cursor: default; }
.dm-btn:not([disabled]):active { opacity: 0.7; }
.dm-star   { color: var(--amber); }
.dm-remove { color: #f87171; }

/* ── Catalog screen ──────────────────────────────────────────────────────── */
.catalog-list { display: flex; flex-direction: column; gap: 8px; }
.catalog-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.catalog-info  { flex: 1; min-width: 0; }
.catalog-name  { font-size: 14px; font-weight: 600; }
.catalog-meta  { font-size: 12px; color: var(--muted); margin-top: 2px; }
.catalog-add {
  background: var(--amber);
  color: #000;
  border: none;
  border-radius: 10px;
  padding: 7px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity .15s;
}
.catalog-add:disabled { opacity: 0.5; cursor: default; }

/* ── Add custom drink modal ──────────────────────────────────────────────── */
.add-drink-form { display: flex; flex-direction: column; gap: 10px; }
.add-drink-row  { display: flex; gap: 10px; }
.add-drink-row input {
  padding: 13px 14px;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s;
  min-width: 0;
}
.add-drink-row input:focus { border-color: var(--amber); }
.emoji-input { width: 62px; flex-shrink: 0; text-align: center; font-size: 22px; padding: 8px; }
.add-drink-name-input { flex: 1; }

/* ── Admin panel ─────────────────────────────────────────────────────────── */
.admin-wrap {
  overflow-x: auto;
  padding: 16px;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.admin-table th {
  text-align: left;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 6px 10px;
  border-bottom: 1px solid var(--surface2);
}
.admin-table td {
  padding: 10px;
  border-bottom: 1px solid var(--surface2);
  vertical-align: middle;
}
.admin-username { font-weight: 600; }
.admin-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--amber);
  color: #000;
  margin-left: 6px;
  vertical-align: middle;
}
.admin-badge.warn {
  background: #f87171;
  color: #fff;
}
.admin-date { color: var(--muted); white-space: nowrap; }
.admin-actions { display: flex; gap: 6px; }
.admin-actions button {
  background: var(--surface2);
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 16px;
  cursor: pointer;
  transition: opacity .15s;
}
.admin-actions button:hover { opacity: .8; }

/* ── Re-register link input ──────────────────────────────────────────────── */
.rereglink-input {
  width: 100%;
  padding: 12px;
  background: var(--surface2);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: monospace;
  outline: none;
  cursor: text;
}

/* ── Settings screen ─────────────────────────────────────────────────────── */
.settings-wrap {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.settings-section {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 14px;
}
.settings-copy {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 12px;
}
.settings-field-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  margin: 10px 0 6px;
}
.settings-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  padding: 11px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.settings-input:focus {
  border-color: var(--amber);
}
.settings-input[type=file] {
  padding: 9px 10px;
}
.settings-preview {
  margin-top: 12px;
  background: rgba(148, 163, 184, 0.1);
  border: 1px solid var(--surface2);
  border-radius: 10px;
  padding: 10px;
  font-size: 13px;
  color: var(--text);
}
.settings-error {
  text-align: left;
  min-height: 18px;
  margin-top: 8px;
}
.settings-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

/* ── Analytics Screen ─────────────────────────────────────────────────────── */
.analytics-wrap {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding-bottom: calc(var(--safe-bot) + 24px);
}

.analytics-loading {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
  font-size: 15px;
}

/* Year navigator */
.analytics-year-nav {
  display: flex;
  align-items: center;
  gap: 2px;
}
.analytics-year-text {
  font-size: 17px;
  font-weight: 700;
  min-width: 52px;
  text-align: center;
}
.analytics-year-btn {
  font-size: 24px;
  line-height: 1;
  padding: 4px 6px;
}

/* Stat cards */
.analytics-stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 480px) {
  .analytics-stats-grid { grid-template-columns: repeat(4, 1fr); }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--amber);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
  line-height: 1.3;
}

/* Analytics sections */
.analytics-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.analytics-map {
  height: 320px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--surface2);
}
/* Override markercluster default green with blue */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large { background-color: rgba(59, 130, 246, .4); }
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div { background-color: rgba(59, 130, 246, .8); color: #fff; font-weight: 700; }

/* Chart containers */
.chart-wrap {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 12px;
  position: relative;
  height: 220px;
}
.chart-wrap-donut {
  height: 220px;
  flex-shrink: 0;
  width: 220px;
}

/* Drink breakdown side-by-side layout */
.analytics-drink-layout {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.analytics-drinks-list {
  flex: 1;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.analytics-drink-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: 10px;
  padding: 7px 10px;
}
.analytics-drink-name {
  font-size: 12px;
  color: var(--text);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.analytics-drink-bar-wrap {
  width: 50px;
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
  flex-shrink: 0;
}
.analytics-drink-bar {
  height: 100%;
  border-radius: 2px;
}
.analytics-drink-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  min-width: 26px;
  text-align: right;
  flex-shrink: 0;
}

/* Heatmap */
.analytics-heatmap-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.analytics-heatmap-labels {
  display: flex;
  gap: 0;
  margin-bottom: 3px;
  width: max-content;
  height: 14px;
  position: relative;
}
.heatmap-month-lbl {
  position: absolute;
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}
.analytics-heatmap-grid {
  display: grid;
  grid-template-rows: repeat(7, 12px);
  grid-auto-flow: column;
  grid-auto-columns: 12px;
  gap: 3px;
  width: max-content;
}
.hm-cell {
  width: 12px;
  height: 12px;
  border-radius: 2px;
}
.heatmap-lv0 { background: var(--surface2); }
.heatmap-lv1 { background: #78350f; }
.heatmap-lv2 { background: #b45309; }
.heatmap-lv3 { background: #d97706; }
.heatmap-lv4 { background: #f59e0b; }
.heatmap-lv5 { background: #fde68a; }
.hm-empty    { background: transparent; }

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  justify-content: flex-end;
}
.heatmap-legend-label {
  font-size: 11px;
  color: var(--muted);
}
.heatmap-swatch {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  display: inline-block;
}

/* Top days */
.analytics-top-days-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.analytics-top-day {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 14px;
}
.analytics-top-day-rank {
  font-size: 12px;
  color: var(--muted);
  min-width: 20px;
}
.analytics-top-day-date {
  font-size: 13px;
  font-weight: 600;
  flex: 1;
}
.analytics-top-day-bar-wrap {
  width: 70px;
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
}
.analytics-top-day-bar {
  height: 100%;
  background: var(--amber);
  border-radius: 2px;
}
.analytics-top-day-count {
  font-size: 14px;
  font-weight: 700;
  color: var(--amber);
  min-width: 24px;
  text-align: right;
}
