:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --card: #ffffff;
  --card-soft: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #dc2626;
  --ok: #16a34a;
  --border: #e2e8f0;
  --shadow: 0 6px 20px rgba(2, 6, 23, 0.12);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body { min-height: 100vh; }

a { color: var(--primary); }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  font-size: 16px;
}

.btn {
  background: var(--primary);
  color: #fff;
  padding: 12px 18px;
  font-weight: 600;
  transition: background .15s ease, transform .05s ease;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--card-soft); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #e2e8f0; }
.btn.danger { background: var(--danger); }
.btn.small { padding: 7px 12px; font-size: 14px; }

input[type="text"], input[type="password"], input[type="number"], input[type="search"] {
  font-family: inherit;
  font-size: 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  background: #fff;
  color: var(--text);
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ---------- Tela de PIN ---------- */
.pin-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #1e293b 0%, #0f172a 100%);
  padding: 20px;
}
.pin-card {
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 30px 24px 26px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.pin-card h1 { font-size: 22px; margin: 6px 0 2px; }
.pin-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 22px; }
.pin-logo {
  width: 58px; height: 58px; border-radius: 16px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; margin: 0 auto 12px;
}
.pin-display {
  display: flex; justify-content: center; gap: 12px; margin: 6px 0 20px;
}
.pin-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--card-soft); border: 2px solid var(--border);
  transition: all .15s ease;
}
.pin-dot.filled { background: var(--primary); border-color: var(--primary); transform: scale(1.05); }
.pin-pad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
}
.pin-key {
  background: var(--card-soft);
  color: var(--text);
  font-size: 24px; font-weight: 600;
  padding: 18px 0;
  border-radius: 14px;
  border: 1px solid var(--border);
  user-select: none;
}
.pin-key:active { background: #dbe2ea; transform: translateY(1px); }
.pin-key.action { font-size: 16px; background: transparent; border-color: transparent; color: var(--muted); }
.pin-key.enter { background: var(--primary); color: #fff; border-color: var(--primary); }
.pin-msg { min-height: 20px; margin-top: 16px; font-size: 14px; font-weight: 500; }
.pin-msg.err { color: var(--danger); }
.pin-msg.ok { color: var(--ok); }
.pin-card.shake { animation: shake .35s; }
@keyframes shake {
  0%,100%{transform:translateX(0)} 20%{transform:translateX(-9px)}
  40%{transform:translateX(9px)} 60%{transform:translateX(-6px)} 80%{transform:translateX(6px)}
}

/* ---------- Layout geral ---------- */
.topbar {
  background: var(--bg);
  color: #fff;
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 20;
}
.topbar .title { font-weight: 700; font-size: 17px; display:flex; align-items:center; gap:10px;}
.topbar .title .badge {
  font-size: 11px; background: var(--primary); padding: 3px 8px; border-radius: 999px; font-weight:600;
}
.topbar button { background: rgba(255,255,255,.12); color:#fff; padding: 8px 14px; font-size: 14px; }
.topbar button:hover { background: rgba(255,255,255,.22); }
.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }
h2.section { font-size: 18px; margin: 22px 4px 12px; }
.muted { color: var(--muted); }

/* ---------- Cards de agenciados ---------- */
.ag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.ag-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 16px; box-shadow: 0 2px 8px rgba(2,6,23,.05);
  cursor: pointer; transition: transform .08s ease, box-shadow .15s ease;
}
.ag-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.ag-card .nome { font-weight: 700; font-size: 16px; margin-bottom: 6px; word-break: break-word; }
.ag-card .cnt { color: var(--muted); font-size: 14px; }
.ag-card .cnt b { color: var(--primary); }

/* ---------- Grid de fotos ---------- */
.foto-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
@media (min-width: 640px) { .foto-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }
.tile {
  position: relative; aspect-ratio: 1/1; border-radius: 12px; overflow: hidden;
  background: var(--card-soft); border: 1px solid var(--border); cursor: pointer;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .dl-hint {
  position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  background: rgba(15,23,42,.0); color:#fff; opacity:0; transition: .15s;
  font-size: 26px;
}
.tile:hover .dl-hint { background: rgba(15,23,42,.35); opacity:1; }
.tile.baixando { pointer-events: none; }
.tile.baixando::after {
  content:""; position:absolute; inset:0; background: rgba(15,23,42,.55);
}
.tile.baixando::before {
  content:""; position:absolute; z-index:2; top:50%; left:50%; width:28px; height:28px;
  margin:-14px 0 0 -14px; border:3px solid rgba(255,255,255,.35); border-top-color:#fff;
  border-radius:50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.back-link { display:inline-flex; align-items:center; gap:6px; background:none; color:var(--primary); padding:6px 0; font-weight:600; }

.empty { text-align:center; padding: 50px 20px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 8px; }

/* ---------- Admin ---------- */
.panel {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 18px; box-shadow: 0 2px 8px rgba(2,6,23,.04);
}
.panel h3 { margin: 0 0 14px; font-size: 16px; display:flex; align-items:center; gap:8px; }
.row { display:flex; gap:10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.ag-list-item {
  display:flex; align-items:center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border:1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background:#fff;
}
.ag-list-item .info b { font-size: 15px; }
.ag-list-item .info .c { color: var(--muted); font-size: 13px; }
.ag-list-item .acts { display:flex; gap:6px; }

select {
  font-family: inherit; font-size: 16px; padding: 12px 14px; border:1px solid var(--border);
  border-radius:10px; background:#fff; width:100%;
}

.dropzone {
  border: 2px dashed var(--border); border-radius: 14px; padding: 34px 20px; text-align:center;
  color: var(--muted); background: var(--card-soft); transition: .15s; cursor: pointer;
}
.dropzone.drag { border-color: var(--primary); background: #eef2ff; color: var(--primary); }
.dropzone .big { font-size: 38px; margin-bottom: 8px; }
.dropzone .hint { font-size: 13px; margin-top:6px; }

.progress-wrap { margin-top: 16px; }
.progress-bar { height: 12px; background: var(--card-soft); border-radius: 999px; overflow: hidden; border:1px solid var(--border); }
.progress-bar > span { display:block; height:100%; width:0%; background: var(--primary); transition: width .2s ease; }
.progress-label { font-size: 13px; color: var(--muted); margin-top: 6px; }

table { width:100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align:left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing:.03em; }
td { word-break: break-word; }
.table-scroll { overflow-x: auto; }

/* ---------- Toast ---------- */
#toast-container {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 999; display:flex; flex-direction: column; gap:8px; align-items:center; width: calc(100% - 32px); max-width: 420px;
}
.toast {
  background: var(--bg); color:#fff; padding: 12px 18px; border-radius: 12px;
  box-shadow: var(--shadow); font-size: 14px; text-align:center; width: fit-content; max-width:100%;
  animation: toastin .2s ease;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes toastin { from { opacity:0; transform: translateY(10px);} to {opacity:1; transform:none;} }

.spinner-center { text-align:center; padding: 40px; color: var(--muted); }
.hidden { display: none !important; }
