:root {
  --gold: #b08d57;
  --gold-dark: #8f7040;
  --bg: #faf7f2;
  --card: #ffffff;
  --text: #2c2620;
  --muted: #8a8178;
  --border: #e7e0d5;
  --danger: #c0483a;
  --ok: #4a7a4a;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

/* Atrybut hidden musi wygrywac z regulami display: flex/grid (np. .lightbox). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: env(safe-area-inset-bottom); }

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px calc(14px + env(safe-area-inset-top));
  padding-top: max(14px, env(safe-area-inset-top));
  text-align: center;
}

.title {
  margin: 0 0 10px;
  font-size: 22px;
  font-weight: 600;
  color: var(--gold-dark);
  letter-spacing: 0.5px;
}

.tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.tab {
  flex: 1;
  max-width: 160px;
  padding: 10px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg);
  transition: all 0.15s;
}

.tab.active {
  color: #fff;
  background: var(--gold);
  border-color: var(--gold);
}

/* ===== Layout ===== */
main { max-width: 900px; margin: 0 auto; padding: 16px; }
.view { animation: fade 0.2s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.lead { text-align: center; color: var(--muted); margin: 8px 0 20px; }

/* ===== Form ===== */
.field { display: block; margin-bottom: 16px; }
.field span { display: block; font-weight: 600; margin-bottom: 6px; font-size: 15px; }
.field input {
  width: 100%;
  padding: 14px;
  font-size: 16px; /* >=16px zapobiega zoomowi na iOS */
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
}
.field input:focus { outline: 2px solid var(--gold); border-color: var(--gold); }

.picker { text-align: center; margin-bottom: 16px; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

/* ===== Buttons ===== */
.btn {
  display: inline-block;
  min-height: 48px;
  padding: 14px 22px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  line-height: 1.2;
}
.btn-primary { background: var(--gold); color: #fff; }
.btn-primary:active { background: var(--gold-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }
.btn-block { display: block; width: 100%; margin-top: 8px; }
/* Przycisk wysylki przyklejony pod naglowkiem — widoczny przy dlugiej liscie. */
#sendBtn { position: sticky; top: calc(var(--topbarH, 100px) + 6px); z-index: 5; box-shadow: var(--shadow); }
.btn-small { min-height: 36px; padding: 8px 14px; font-size: 14px; }
.btn-ghost { background: var(--bg); color: var(--gold-dark); border: 1px solid var(--border); }

/* ===== File list ===== */
.file-list { list-style: none; padding: 0; margin: 0 0 16px; }
.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.file-item .fi-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.file-item .fi-size { color: var(--muted); font-size: 12px; white-space: nowrap; }
.file-item .fi-status { font-size: 12px; white-space: nowrap; }
.file-item .fi-status.ok { color: var(--ok); }
.file-item .fi-status.err { color: var(--danger); }
.progress { height: 5px; background: var(--border); border-radius: 999px; overflow: hidden; margin-top: 8px; position: relative; }
.progress-bar { height: 100%; width: 0; background: var(--gold); transition: width 0.15s; }
/* Stan "wysyłanie na Dysk" — pasek nieokreslony (bajty juz w serwerze, leca na Drive). */
.progress.indeterminate .progress-bar {
  width: 40%;
  position: absolute;
  transition: none;
  animation: indet 1.1s ease-in-out infinite;
}
@keyframes indet {
  0% { left: -40%; }
  100% { left: 100%; }
}
.file-item .fi-main { flex: 1; min-width: 0; }

/* ===== Messages ===== */
.msg { padding: 12px 14px; border-radius: var(--radius); margin: 8px 0; font-size: 14px; }
.msg.ok { background: #eaf3ea; color: var(--ok); }
.msg.err { background: #f7e9e7; color: var(--danger); }

/* ===== Grid / Gallery ===== */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.grid-small { grid-template-columns: repeat(4, 1fr); }
@media (min-width: 640px) {
  .grid { grid-template-columns: repeat(5, 1fr); gap: 8px; }
  .grid-small { grid-template-columns: repeat(6, 1fr); }
}
@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(6, 1fr); }
}

.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #eee6d9;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
}
.tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity 0.3s;
}
.tile img.loaded { opacity: 1; }
.tile .tile-name {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 10px 6px 4px;
  font-size: 11px;
  color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,0.55));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Placeholder "przetwarzanie" */
.tile.processing, .tile.failed {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.ph {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
  padding: 6px;
}
.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.ph-icon { font-size: 20px; }

.sentinel { height: 1px; }
.loader, .empty { text-align: center; color: var(--muted); padding: 24px; }

/* ===== Lightbox ===== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.lightbox img { max-width: 100%; max-height: 82vh; object-fit: contain; border-radius: 8px; }
.lightbox-name { color: #fff; margin-top: 14px; font-size: 15px; }
.lightbox-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 14px;
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
}
