/* Karibu Store — minimal, mobile-first design. Earthy palette, big touch targets. */

:root {
  --bg:           #FAF7F2;
  --surface:      #FFFFFF;
  --surface-2:    #F2EDE3;
  --accent:       #6B4423;
  --accent-dark:  #4A2E18;
  --accent-soft:  #EFE4D4;
  --ink:          #1F1F1F;
  --ink-soft:     #6B6B6B;
  --ink-faint:    #A09A8E;
  --border:       #E5DFD2;
  --border-strong:#C8C0AE;
  --good:         #2E7D4F;
  --warn:         #8A5A1E;
  --bad:          #B23A2E;
  --shadow-sm:    0 1px 2px rgba(31,31,31,.04);
  --shadow:       0 1px 2px rgba(31,31,31,.04), 0 8px 24px rgba(31,31,31,.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; line-height: 1.5;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
.muted  { color: var(--ink-soft); }
.small  { font-size: 0.85rem; }
.center { text-align: center; }
.mt-2   { margin-top: 8px; }
.mt-3   { margin-top: 12px; }
.mt-4   { margin-top: 18px; }
.hint   { color: var(--ink-faint); font-size: 0.78rem; margin-top: 6px; }
.err    { color: var(--bad); font-size: 0.85rem; min-height: 18px; margin-top: 8px; text-align: center; }
.msg    { font-size: 0.85rem; min-height: 18px; margin-top: 8px; text-align: center; color: var(--good); }
.banner { background: #FEF3C7; border: 1px solid #FCD34D; color: #92400E; padding: 10px 14px;
          border-radius: 10px; font-size: 0.9rem; margin-bottom: 14px; }

/* App bar */
.appbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.appbar-inner {
  max-width: 880px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; gap: 12px;
}
.appbar-right { display: flex; align-items: center; gap: 10px; }
.user-pill {
  font-size: 0.8rem; color: var(--ink-soft); padding: 4px 10px;
  background: var(--surface-2); border-radius: 999px;
  max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand-dot { width: 28px; height: 28px; border-radius: 6px; background: var(--accent); color: white;
             display: grid; place-items: center; font-size: 14px; font-weight: 700; }
.brand-name { font-weight: 600; letter-spacing: -0.01em; }
.brand-light { color: var(--ink-soft); font-weight: 400; font-style: italic; }
.back-arrow { font-size: 1.6rem; line-height: 1; color: var(--ink-soft); padding-right: 4px; }

/* Container */
.container { max-width: 880px; margin: 0 auto; padding: 16px; padding-bottom: 100px; }

/* Camp filters */
.filters {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px;
  scrollbar-width: none; margin-bottom: 16px;
  -webkit-overflow-scrolling: touch;
}
.filters::-webkit-scrollbar { display: none; }
.chip {
  padding: 7px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  font-size: 0.85rem; color: var(--ink-soft); cursor: pointer; white-space: nowrap;
  font-family: inherit;
}
.chip:hover { border-color: var(--border-strong); }
.chip-active { background: var(--accent); color: white; border-color: var(--accent); }

.chip-row {
  display: flex; flex-wrap: wrap; gap: 6px; max-height: 180px; overflow-y: auto;
  padding: 4px 0;
}
.chip-pick {
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 0.82rem; color: var(--ink); cursor: pointer;
  font-family: inherit;
}
.chip-pick:hover { background: var(--accent-soft); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 500; font-size: 0.95rem; padding: 11px 18px; border-radius: 12px;
  border: 1px solid transparent; cursor: pointer; line-height: 1;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--ink); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; border-radius: 10px; }
.btn-lg { padding: 16px 24px; font-size: 1.02rem; border-radius: 14px; }
.btn-icon { background: transparent; border: 0; font-size: 22px; cursor: pointer;
            width: 36px; height: 36px; color: var(--ink-soft); }

/* Inputs */
.input {
  width: 100%; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 13px; font: inherit; color: var(--ink);
  font-family: inherit;
}
.input:focus { outline: none; border-color: var(--accent);
               box-shadow: 0 0 0 3px rgba(107,68,35,0.12); }
textarea.input { resize: vertical; min-height: 60px; }
.label { display: block; font-size: 0.78rem; font-weight: 600;
         color: var(--ink-soft); margin-bottom: 5px; }
.otp-input { font-family: 'SF Mono', Menlo, monospace; letter-spacing: 6px;
             font-size: 1.3rem; text-align: center; }

/* Camp + room layout */
.camp-block { margin-bottom: 28px; }
.camp-h { font-size: 1.2rem; font-weight: 600; margin: 14px 4px 14px;
          display: flex; align-items: baseline; gap: 10px; }
.section-h { font-size: 0.78rem; font-weight: 600; color: var(--ink-soft);
             text-transform: uppercase; letter-spacing: 0.05em;
             margin: 18px 4px 8px; }

.room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  gap: 10px;
}
.room-tile {
  position: relative;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 10px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  text-align: center;
  transition: border .12s, transform .06s;
}
.room-tile:hover { border-color: var(--accent); }
.room-tile:active { transform: scale(0.97); }
.tile-code { font-family: 'Fraunces', Georgia, serif; font-size: 1.7rem; font-weight: 600;
             line-height: 1; color: var(--ink); }
.tile-sub { font-size: 0.7rem; color: var(--ink-soft); line-height: 1.2; min-height: 1.2em; }
.tile-badge {
  position: absolute; top: 6px; right: 6px;
  background: var(--accent); color: white;
  font-size: 0.7rem; font-weight: 600;
  padding: 2px 7px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.tile-badge-pending { background: #92400E; }

.room-list { display: flex; flex-direction: column; gap: 6px; }
.room-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border);
  font-weight: 500;
}
.room-row:hover { border-color: var(--accent); }

/* Room detail page */
.room-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin: 6px 4px 16px; gap: 16px;
}
.room-title { font-size: 1.45rem; margin: 2px 0 0; font-weight: 600; line-height: 1.2; }
.photo-counter {
  font-size: 0.8rem; color: var(--ink-soft);
  background: var(--surface-2); padding: 4px 10px; border-radius: 999px; white-space: nowrap;
}
.add-btn { margin-bottom: 18px; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}
.photo {
  position: relative;
  margin: 0; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; cursor: zoom-in;
}
.photo img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; display: block; }
.photo figcaption { font-size: 0.78rem; color: var(--ink); padding: 6px 8px;
                    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-pending { border-color: #FCD34D; background: #FEF3C7; }
.photo-pending img { opacity: 0.78; }
.pending-badge {
  position: absolute; top: 6px; left: 6px;
  background: rgba(146, 64, 14, 0.92); color: white;
  font-size: 0.62rem; font-weight: 700; letter-spacing: 0.06em;
  padding: 2px 7px; border-radius: 4px;
}

/* Drawer */
.drawer-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none; transition: opacity .18s;
  z-index: 30;
}
.drawer-bg.show { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-top-left-radius: 18px; border-top-right-radius: 18px;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto;
  transform: translateY(100%); transition: transform .22s ease-out;
  z-index: 31; box-shadow: 0 -8px 30px rgba(0,0,0,0.18);
}
.drawer.show { transform: translateY(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.drawer-head h2 { font-size: 1.1rem; margin: 0; }

/* Drawer with sticky footer for Save/Cancel — keeps action buttons visible
   even with on-screen keyboard or long chip rows. */
.drawer-flex {
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;       /* footer doesn't scroll */
}
.drawer-flex .drawer-body {
  flex: 1; overflow-y: auto;
  padding: 0 18px 12px;
  margin: 0 -18px;        /* counter outer padding so scrollbar reaches edges */
  -webkit-overflow-scrolling: touch;
}
.drawer-flex .drawer-head { padding: 0 18px; margin: 0 -18px 8px; }
.drawer-footer {
  display: flex; gap: 10px;
  padding: 12px 0 calc(env(safe-area-inset-bottom) + 4px);
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.drawer-footer .btn { flex: 1; }
.drawer-footer .btn-primary { flex: 1.6; }   /* bigger primary action */

.preview-img {
  width: 100%; max-height: 220px; object-fit: cover; border-radius: 10px;
  margin-bottom: 12px; background: var(--surface-2);
}

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,0.94);
  display: none; flex-direction: column; align-items: center; justify-content: center;
  padding: 20px; z-index: 40; cursor: zoom-out;
}
.lightbox.show { display: flex; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 200px); object-fit: contain; border-radius: 8px; }
.lb-meta {
  color: white; font-size: 0.9rem; text-align: center; max-width: 600px;
  margin-top: 16px; line-height: 1.4;
}
.lb-meta .muted { color: rgba(255,255,255,0.7); }
.lb-close {
  position: absolute; top: 14px; right: 14px;
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,0.95); color: #111; font-size: 22px; cursor: pointer;
  font-family: inherit;
}
.lb-delete {
  position: absolute; bottom: 24px;
  padding: 10px 18px; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--bad); color: white; font-weight: 500;
  font-family: inherit;
}

/* Auth pages */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 28px 22px; box-shadow: var(--shadow);
}
.auth-card .brand { justify-content: center; margin-bottom: 18px; }
.auth-title { font-size: 1.4rem; margin: 0 0 4px; font-weight: 600; }
.auth-sub { font-size: 0.9rem; margin: 0 0 18px; }

@media (min-width: 720px) {
  .room-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* Admin page */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
}
.stat-num {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.8rem; font-weight: 600; line-height: 1;
  color: var(--accent-dark);
}
.stat-lbl {
  font-size: 0.75rem; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: 0.05em; margin-top: 6px;
}

.admin-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.admin-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden;
  font-size: 0.88rem;
}
.admin-table th, .admin-table td {
  padding: 10px 14px; text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table th {
  background: var(--surface-2); color: var(--ink-soft);
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--surface-2); }

.admin-toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  flex-wrap: wrap; margin: 24px 0 12px;
}
.admin-toolbar .input { padding: 7px 12px; font-size: 0.85rem; }
.admin-photo figcaption { padding: 6px 8px; }
.admin-photo figcaption strong { font-size: 0.82rem; display: block; }

/* Pending-upload banner */
.q-banner {
  display: none;
  position: sticky; top: 53px; z-index: 19;
  align-items: center; gap: 10px;
  background: #FEF3C7; border-bottom: 1px solid #FCD34D; color: #92400E;
  padding: 10px 16px; font-size: 0.88rem;
}
.q-banner.q-show { display: flex; }
.q-banner.q-busy   { background: #DBEAFE; border-bottom-color: #93C5FD; color: #1E40AF; }
.q-banner.q-offline{ background: #FEE2E2; border-bottom-color: #FCA5A5; color: #991B1B; }
.q-icon { font-size: 1.05rem; line-height: 1; }
.q-text { flex: 1; }
.q-upload {
  background: rgba(255,255,255,0.85); border: 1px solid currentColor; color: inherit;
  font-size: 0.82rem; padding: 5px 12px; border-radius: 999px; cursor: pointer;
  font-family: inherit; font-weight: 500;
}

/* Queue drawer rows */
.q-status { margin-bottom: 6px; }
.q-items  { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.q-row {
  display: flex; gap: 10px; align-items: center;
  padding: 8px; background: var(--surface-2); border-radius: 10px;
}
.q-row img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.q-meta { flex: 1; min-width: 0; }
.q-label { font-weight: 500; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Toast */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: rgba(31,31,31,0.94); color: white; padding: 10px 18px;
  border-radius: 999px; font-size: 0.88rem; z-index: 50;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }
