@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800&family=Inter:wght@400;500;600;700&family=Roboto:wght@400;500;700;800&family=Montserrat:wght@400;500;600;700;800&family=Playfair+Display:wght@500;600;700;800&family=Merriweather:wght@400;700;900&family=Oswald:wght@400;500;600;700&family=Lato:wght@400;700;900&family=Nunito:wght@400;600;700;800&family=Raleway:wght@400;600;700;800&display=swap');

:root {
  --bg: #f1f4f9;
  --bg-dark: #0b1220;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-dim: #64748b;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --radius: 14px;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.16);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { min-height: 100vh; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3, h4 { font-family: 'Poppins', 'Inter', sans-serif; margin: 0 0 6px; }
button, input, select, textarea { font-family: inherit; }

/* ---------- Top App Bar ---------- */
.topbar {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  background: linear-gradient(120deg, #0b1220, #14213d);
  color: #fff;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 200;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.topbar .brand .dot { width: 10px; height: 10px; border-radius: 50%; background: linear-gradient(135deg, #38bdf8, #6366f1); box-shadow: 0 0 0 4px rgba(99,102,241,.25); }
.topbar nav { display: flex; gap: 6px; }
.topbar nav a { color: #cbd5e1; padding: 8px 14px; border-radius: 8px; font-size: 14px; font-weight: 500; }
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,.08); color: #fff; }
.topbar .user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #cbd5e1; }
.topbar .user .avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg,#38bdf8,#6366f1); display:flex; align-items:center; justify-content:center; font-weight:700; color:#fff; font-size:13px; }

/* ---------- Layout ---------- */
.page-wrap { max-width: 1400px; margin: 0 auto; padding: 26px 22px 60px; }
.grid { display: grid; gap: 18px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) { .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; } }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card h3 { font-size: 15px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 9px 16px; border-radius: 10px; font-weight: 600; font-size: 13.5px;
  cursor: pointer; transition: all .15s ease;
}
.btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff; border: none; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn.success { background: #f0fdf4; color: var(--success); border-color: #bbf7d0; }
.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; justify-content: center; }
.btn.icon { padding: 8px; }

input[type=text], input[type=number], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; font-size: 13.5px; background: #fff; color: var(--text);
}
input[type=color] { width: 40px; height: 34px; padding: 2px; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: pointer; }
label { font-size: 12.5px; font-weight: 600; color: var(--text-dim); display: block; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--text-dim); font-size: 13px; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; background: #eef2ff; color: #4338ca; text-transform: uppercase; letter-spacing: .04em; }
.badge.role-admin { background:#fef2f2; color:#b91c1c; }
.badge.role-editor { background:#eff6ff; color:#1d4ed8; }
.badge.role-viewer { background:#f1f5f9; color:#475569; }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow-lg); animation: toast-in .2s ease; }
.toast.error { background: #7f1d1d; }
.toast.success { background: #14532d; }
@keyframes toast-in { from { opacity:0; transform: translateY(8px);} to {opacity:1; transform:none;} }

/* ---------- Gallery (public index) ---------- */
.hero { text-align:center; padding: 46px 10px 30px; }
.hero h1 { font-size: 32px; background: linear-gradient(135deg,#1d4ed8,#6d28d9); -webkit-background-clip:text; background-clip:text; color:transparent; }
.hero p { color: var(--text-dim); max-width: 640px; margin: 8px auto 0; }
.project-card { cursor: pointer; transition: transform .15s ease, box-shadow .15s ease; }
.project-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.project-card .thumb { height: 140px; border-radius: 10px; background: linear-gradient(135deg,#e0ecff,#eef2ff); display:flex; align-items:center; justify-content:center; margin-bottom: 12px; color:#94a3b8; font-size:13px; overflow:hidden; }
.page-pill-row { display:flex; flex-wrap:wrap; gap:6px; margin-top:10px; }
.page-pill { padding: 5px 10px; border-radius: 999px; background:#f1f5f9; font-size:12px; font-weight:600; color:#334155; }

/* ---------- Login ---------- */
.login-shell { min-height: 100vh; display:flex; align-items:center; justify-content:center; background: radial-gradient(circle at 20% 20%, #1e293b, #0b1220 60%); }
.login-card { width: 380px; background:#fff; border-radius: 18px; padding: 34px; box-shadow: var(--shadow-lg); }
.login-card h1 { font-size: 22px; text-align:center; }
.login-card p.sub { text-align:center; color:var(--text-dim); font-size:13px; margin-bottom:22px; }

/* ---------- Editor Shell ---------- */
.editor-shell { display: flex; height: calc(100vh - 60px); }
.editor-sidebar { width: 340px; min-width: 340px; background: var(--panel); border-right: 1px solid var(--border); overflow-y: auto; padding: 16px; }
.editor-canvas-wrap { flex: 1; overflow: auto; background: #dde3ec repeating-linear-gradient(45deg,#dde3ec,#dde3ec 12px,#d5dbe5 12px,#d5dbe5 24px); display:flex; align-items:flex-start; justify-content:center; padding: 36px; }
.poster-frame { background:#fff; box-shadow: var(--shadow-lg); position: relative; width: min(820px, 90%); flex: none; }
.poster-frame svg { display: block; width: 100%; height: auto; }
.editor-tabs { display:flex; gap:4px; border-bottom:1px solid var(--border); margin-bottom:14px; flex-wrap:wrap; }
.editor-tabs button { flex:1; min-width: 70px; padding:9px 6px; border:none; background:none; font-size:12px; font-weight:700; color:var(--text-dim); cursor:pointer; border-bottom:2px solid transparent; }
.editor-tabs button.active { color: var(--brand); border-color: var(--brand); }
.tab-panel { display:none; }
.tab-panel.active { display:block; }
.el-row { display:flex; align-items:center; justify-content:space-between; padding:8px 10px; border:1px solid var(--border); border-radius:9px; margin-bottom:6px; background:#fff; }
.el-row .name { font-size:13px; font-weight:600; }
.el-row.dim { opacity: .55; }
.switch { position: relative; width:38px; height:22px; }
.switch input { opacity:0; width:0; height:0; }
.switch .slider { position:absolute; inset:0; background:#cbd5e1; border-radius:999px; cursor:pointer; transition:.15s; }
.switch .slider:before { content:''; position:absolute; width:16px; height:16px; left:3px; top:3px; background:#fff; border-radius:50%; transition:.15s; }
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider:before { transform: translateX(16px); }
.color-stops { display:flex; gap:6px; flex-wrap:wrap; }
.state-table { width:100%; border-collapse: collapse; font-size:12.5px; }
.state-table th, .state-table td { padding:6px 7px; border-bottom:1px solid var(--border); text-align:left; }
.state-table input { padding:5px 7px; font-size:12.5px; }
.state-table tr.unmatched td { background:#fff7ed; }
.data-scroll { max-height: 360px; overflow-y:auto; border:1px solid var(--border); border-radius:9px; }
.drag-hint { position:absolute; inset:0; border:2px dashed transparent; border-radius:6px; pointer-events:none; }
.el-selected .drag-hint { border-color:#2563eb; background: rgba(37,99,235,.06); }
.el-group { cursor: grab; }
.el-group:active { cursor: grabbing; }
.dropzone { border:2px dashed var(--border); border-radius:10px; padding:20px; text-align:center; color:var(--text-dim); font-size:13px; cursor:pointer; }
.dropzone:hover { border-color: var(--brand); color: var(--brand); }
.import-preview-table { width:100%; border-collapse:collapse; font-size:12.5px; }
.import-preview-table th, .import-preview-table td { padding:6px 8px; border-bottom:1px solid var(--border); }
.import-preview-table tr.bad { background:#fef2f2; }
.modal-backdrop { position:fixed; inset:0; background:rgba(15,23,42,.55); display:flex; align-items:center; justify-content:center; z-index:500; }
.modal { background:#fff; border-radius:16px; width: 640px; max-width: 92vw; max-height: 88vh; overflow-y:auto; padding:24px; box-shadow: var(--shadow-lg); }
.modal.wide { width: 900px; }
.modal-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:14px; }
table.simple { width:100%; border-collapse:collapse; font-size:13px; }
table.simple th { text-align:left; color:var(--text-dim); font-size:11.5px; text-transform:uppercase; padding:8px; border-bottom:1px solid var(--border); }
table.simple td { padding:9px 8px; border-bottom:1px solid var(--border); }

/* ---------- Poster / Map SVG ---------- */
svg.poster-svg { display:block; }
.poster-svg text { font-family: 'Poppins','Inter',sans-serif; }
.state-path { stroke-linejoin: round; cursor: pointer; transition: filter .12s ease; }
.state-path:hover { filter: brightness(0.9); }
.state-path.no-data { fill: #e5e7eb; }
.leader-line { fill:none; stroke:#475569; stroke-width:1.1; opacity:.75; }
.leader-dot { fill:#334155; }
.legend-row-hover { fill: rgba(37,99,235,.08); }

.no-print {}
@media print {
  .no-print { display: none !important; }
  body { background: #fff; margin: 0; }
  .poster-frame { box-shadow: none !important; margin: 0 !important; }
  .view-shell { padding: 0 !important; min-height: auto !important; }
}

/* ---------- Viewer ---------- */
.view-shell { min-height: 100vh; background:#dde3ec; padding: 30px; display:flex; flex-direction:column; align-items:center; gap:16px; }
.view-toolbar { display:flex; gap:10px; align-items:center; background:#fff; padding:10px 14px; border-radius:12px; box-shadow: var(--shadow); }
.view-toolbar .sep-v { width:1px; height:22px; background:var(--border); }

/* ---------- Map zoom controls (view + editor) ---------- */
.map-zoom-controls {
  position: absolute;
  transform: translateY(-100%);
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid var(--border);
  z-index: 20;
}
.map-zoom-controls button {
  width: 34px;
  height: 34px;
  border: none;
  background: #fff;
  font-size: 16px;
  font-weight: 700;
  color: #334155;
  cursor: pointer;
  line-height: 1;
}
.map-zoom-controls button:hover { background: #f1f5f9; }
.map-zoom-controls button + button { border-top: 1px solid var(--border); }
.map-zoom-controls button#zoomResetBtn { font-size: 14px; }
.map-zoom-controls button#zoomLockBtn { font-size: 14px; }
.map-zoom-controls button.locked { background: #eff6ff; color: var(--brand); }
