/* ============================================================
   ShopList — mobile-first plain CSS
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --primary:       #3d8b5e;
  --primary-dark:  #2d6b47;
  --primary-light: #e8f5ee;
  --accent:        #f0a500;
  --text:          #1a1a1a;
  --text-muted:    #6b7280;
  --bg:            #f2f4f6;
  --surface:       #ffffff;
  --border:        #e0e4e8;
  --danger:        #dc3545;
  --danger-light:  #fff0f0;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.08);
  --shadow:        0 2px 10px rgba(0,0,0,.1);
  --radius:        14px;
  --radius-sm:     9px;
  --header-h:      56px;
  --nav-h:         62px;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  touch-action: manipulation;
  overscroll-behavior-y: none;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
  touch-action: manipulation;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font: inherit; }
img { display: block; max-width: 100%; }

/* ── App shell ─────────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.app-logo { font-size: 1.5rem; padding: 0 4px; }

.header-title {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.header-btn {
  min-width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 0 8px;
  transition: background .15s;
}
.header-btn:active { background: rgba(255,255,255,.2); }

.lang-btn { font-size: .8rem; letter-spacing: .05em; }

.app-main {
  padding-top: var(--header-h);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

/* ── Sync bar ───────────────────────────────────────────────── */
.sync-bar {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .3s;
  z-index: 99;
}
.sync-bar.active {
  transform: scaleX(1);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:.4 } }

/* ── Live badge ─────────────────────────────────────────────── */
.live-badge {
  position: fixed;
  top: calc(var(--header-h) + 8px);
  right: 12px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: .7rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 5px;
  z-index: 98;
  box-shadow: var(--shadow-sm);
}
.live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--primary);
  animation: blink 2s ease-in-out infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.2} }

/* ── Bottom nav ─────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--nav-h);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 100;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  font-size: .7rem;
  font-weight: 500;
  padding: 8px 4px;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.nav-item.active { color: var(--primary); }
.nav-item:active { color: var(--primary); }
.nav-icon { font-size: 1.35rem; }
.nav-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; }

/* ── Flash messages ─────────────────────────────────────────── */
.flash {
  padding: 12px 16px;
  margin: 12px 16px 0;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
}
.flash-success { background: var(--primary-light); color: var(--primary-dark); }
.flash-error   { background: var(--danger-light);  color: var(--danger); }
.flash-warning { background: #fff8e1; color: #7c5e00; }

/* ── Sections / Cards ───────────────────────────────────────── */
.section {
  padding: 16px;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

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

.list-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  gap: 12px;
  transition: background .1s;
  -webkit-tap-highlight-color: transparent;
}
.list-card:active { background: var(--primary-light); }
.list-card-body { flex: 1; min-width: 0; }
.list-card-name {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-card-meta {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.list-card-badge {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.badge-done { color: var(--primary); }

.tpl-actions {
  display: flex;
  gap: 8px;
  padding: 4px 16px 12px;
}

/* ── Empty states ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 24px 16px;
  color: var(--text-muted);
  font-size: 1rem;
}
.empty-sub {
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
  padding-bottom: 24px;
}

/* ── Category groups ────────────────────────────────────────── */
.category-group { margin-bottom: 4px; }

.category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: var(--primary-light);
  font-size: .78rem;
  font-weight: 700;
  color: var(--primary-dark);
  letter-spacing: .05em;
  text-transform: uppercase;
  position: sticky;
  top: var(--header-h);
  z-index: 10;
}

/* ── Item rows ──────────────────────────────────────────────── */
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  transition: background .15s;
}
.item:last-child { border-bottom: none; }

.item.checked {
  background: #fafafa;
}
.item.checked .item-name {
  text-decoration: line-through;
  color: #aaa;
}

.item-check {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  color: transparent;
  transition: all .2s;
  -webkit-tap-highlight-color: transparent;
}
.item-check.checked {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.item-body {
  flex: 1;
  min-width: 0;
}
.item-name {
  display: block;
  font-size: .98rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-meta {
  display: block;
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.item-photo-thumb {
  display: inline-block;
  margin-top: 4px;
}
.item-photo-thumb img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: 6px;
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.item-action {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--text-muted);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.item-action:active, .item-action:hover { background: var(--bg); }
.item-action.danger { color: var(--danger); }

/* ── Checked section ────────────────────────────────────────── */
.checked-section {
  margin-top: 8px;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.checked-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #f0f0f0;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.checked-toggle { font-size: .8rem; }

/* ── Add item bar ───────────────────────────────────────────── */
.add-item-bar {
  position: fixed;
  bottom: var(--nav-h);
  left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  z-index: 90;
  box-shadow: 0 -2px 10px rgba(0,0,0,.06);
}

.add-item-inner {
  display: flex;
  gap: 8px;
  align-items: center;
}

.add-name-input { flex: 1; }
.add-item-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  font-size: 1.5rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.add-item-extras {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.add-item-extras::-webkit-scrollbar { display: none; }

/* Extra bottom padding so items aren't hidden behind the add bar */
#items-container { padding-bottom: 130px; }

/* ── Autocomplete ───────────────────────────────────────────── */
.add-item-main { position: relative; flex: 1; }
.autocomplete-results {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 200;
  overflow: hidden;
  max-height: 200px;
  overflow-y: auto;
}
.autocomplete-results.hidden { display: none; }
.ac-item {
  padding: 12px 14px;
  font-size: .92rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:active { background: var(--primary-light); }
.ac-cat { font-size: .75rem; color: var(--text-muted); margin-left: auto; }

/* ── Forms ──────────────────────────────────────────────────── */
.field-label {
  display: block;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
  margin-top: 14px;
}
.field-label:first-child { margin-top: 0; }

.field-input {
  display: block;
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: .95rem;
  transition: border-color .15s;
  -webkit-appearance: none;
  appearance: none;
}
.field-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(61,139,94,.15);
}

/* Password show/hide toggle */
.password-wrapper { position: relative; }
.password-wrapper .field-input { padding-right: 46px; }
.password-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.password-toggle:active { background: var(--bg); }

.field-sm {
  padding: 8px 10px;
  font-size: .85rem;
  min-width: 80px;
  width: auto;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.field-group { display: flex; flex-direction: column; }

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

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: .95rem;
  font-weight: 600;
  transition: filter .15s;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
.btn:active { filter: brightness(.92); }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline.danger { color: var(--danger); border-color: var(--danger); }
.btn-full { width: 100%; }
.btn-sm { padding: 7px 14px; font-size: .82rem; }

.btn-link {
  color: var(--primary);
  font-size: .85rem;
  font-weight: 500;
  padding: 4px 6px;
  border-radius: 6px;
}
.btn-link:active { background: var(--primary-light); }
.btn-link.danger { color: var(--danger); }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-active   { background: var(--primary-light); color: var(--primary-dark); }
.badge-inactive { background: #f0f0f0; color: var(--text-muted); }

/* ── Toast notifications ────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: calc(var(--nav-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 340px);
  pointer-events: none;
}

.toast {
  background: #1a1a1a;
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: toastIn .25s ease;
  pointer-events: auto;
}
.toast.success { background: var(--primary); }
.toast.error   { background: var(--danger); }

@keyframes toastIn {
  from { opacity:0; transform:translateY(12px); }
  to   { opacity:1; transform:translateY(0); }
}

/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: flex-end;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-height: 88dvh;
  overflow-y: auto;
  padding: 8px 20px calc(28px + env(safe-area-inset-bottom));
  animation: slideUp .28s ease;
}
@keyframes slideUp {
  from { transform: translateY(60px); opacity:0; }
  to   { transform: translateY(0);    opacity:1; }
}

.modal-handle {
  width: 38px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 20px;
}
.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 16px;
}

/* ── Share / menu modal rows ────────────────────────────────── */
.share-list { margin-top: 16px; }
.share-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.share-row:last-child { border-bottom: none; }
.share-perm { flex: 1; color: var(--text-muted); font-size: .8rem; }

.menu-list { display: flex; flex-direction: column; }
.menu-item {
  padding: 16px 4px;
  font-size: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.menu-item:last-child { border-bottom: none; }
.menu-item.danger { color: var(--danger); }
.menu-item:active { background: var(--bg); }

/* ── Admin table ────────────────────────────────────────────── */
.admin-table-wrap { overflow-x: auto; }
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}
.admin-table th, .admin-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.admin-table th {
  font-size: .75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--bg);
}
.table-sub { font-size: .75rem; color: var(--text-muted); }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Login page ─────────────────────────────────────────────── */
.login-body {
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 20px;
}
.login-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 40px 28px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.login-logo {
  font-size: 3rem;
  text-align: center;
  margin-bottom: 8px;
}
.login-title {
  text-align: center;
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 28px;
}
.login-form { display: flex; flex-direction: column; gap: 4px; }
.login-form .btn { margin-top: 12px; }
.login-error {
  background: var(--danger-light);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  margin-bottom: 14px;
}
.login-lang { text-align: center; margin-top: 20px; }

/* ── Profile ────────────────────────────────────────────────── */
.profile-avatar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding-top: 24px;
}
.avatar-wrap {
  position: relative;
  cursor: pointer;
  display: block;
  -webkit-tap-highlight-color: transparent;
}
.avatar-img, .avatar-placeholder {
  width: 80px; height: 80px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  border: 3px solid var(--primary);
}
.avatar-edit-badge {
  position: absolute;
  bottom: 0; right: 0;
  background: var(--primary);
  color: #fff;
  width: 26px; height: 26px;
  border-radius: 50%;
  font-size: .85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.profile-name { font-size: 1.1rem; font-weight: 700; }

/* ── Utilities ──────────────────────────────────────────────── */
.hidden { display: none !important; }

@media (min-width: 540px) {
  .hide-xs { display: table-cell; }
  .app-main { max-width: 600px; margin: 0 auto; }
  .add-item-bar { max-width: 600px; left: 50%; transform: translateX(-50%); }
  .bottom-nav { max-width: 600px; left: 50%; transform: translateX(-50%); }
}
@media (max-width: 539px) {
  .hide-xs { display: none; }
}
