:root{
  --bg:#f6f8fb;
  --text:#0f172a;
  --muted:#64748b;
  --border:#e2e8f0;
  --card:#ffffff;
  --brand:#2563eb;
  --brand-600:#1d4ed8;
  --brand-50:#eff6ff;
  --success:#10b981;
  --shadow:0 1px 2px rgba(0,0,0,.06),0 4px 12px rgba(0,0,0,.06);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji", "Segoe UI Symbol", sans-serif;
  line-height:1.45;
}

.app{min-height:100%; display:flex; flex-direction:column}

.topbar{
  height:56px;
  display:flex;
  align-items:center;
  gap:16px;
  padding:0 16px;
  background:#3b82f6;
  color:#fff;
  position:sticky; top:0; z-index:50;
}
.brand{display:flex; align-items:center; gap:10px; font-weight:700}
.logo{display:inline-grid; place-items:center; width:24px; height:24px; font-size:18px; color:#93c5fd}
.brand-text{letter-spacing:.2px}

.search{flex:1; display:flex; align-items:center}
.search input{
  width:100%; border:none; height:34px; padding:0 12px;
  border-radius:6px; background:#0f172a; color:#e5e7eb; outline:none;
  box-shadow:inset 0 0 0 1px #1f2937;
}
.top-actions{display:flex; align-items:center; gap:10px}
.btn{
  border:1px solid var(--border);
  background:#fff;
  color:var(--text);
  text-decoration:none;
  padding:8px 12px; border-radius:8px;
  font-weight:600; font-size:14px; cursor:pointer;
  box-shadow:0 0 0 0 rgba(0,0,0,0);
  transition:box-shadow .15s, background .15s, border-color .15s, color .15s;
}
.btn:link,
.btn:visited,
.btn:hover,
.btn:active,
.btn:focus{
  text-decoration:none !important;
}
.btn:hover{box-shadow:var(--shadow)}
.btn.ghost{background:transparent; color:#1d4ed8; border-color:#1d4ed8}
.btn.ghost:hover{background:#1d4ed8; color:#fff}
.btn.primary{background:var(--brand); border-color:var(--brand); color:#fff}
.btn.primary:hover{background:var(--brand-600); border-color:var(--brand-600)}
.btn.small{padding:6px 10px; font-size:13px; border-radius:6px}
.btn.large{padding:12px 18px; font-size:16px; border-radius:10px}

.avatar{display:flex; align-items:center; gap:8px; margin-left:4px}
.avatar-img{width:28px; height:28px; border-radius:50%; background:#1f2937; display:grid; place-items:center; font-size:12px}
.avatar-name{font-weight:600; font-size:14px; color:#cbd5e1}

.layout{display:grid; grid-template-columns: 220px 1fr; gap:24px; padding:20px;}

.sidebar{position:sticky; top:76px; align-self:start}
.sidebar-section{display:flex; flex-direction:column; gap:4px}
.sidebar-item{
  display:flex; align-items:center; justify-content:space-between;
  padding:10px 12px; border-radius:8px; color:#0f172a; text-decoration:none; background:transparent;
}
.sidebar-item:hover{background:#e2e8f0}
.sidebar-item.active{background:#dbeafe; color:#1d4ed8; font-weight:700}
.sidebar .star{color:#f59e0b; margin-left:8px}

.content{max-width:1100px}

.page-title{margin:6px 0 4px; font-size:22px}
.page-subtitle{margin:0 0 16px; color:var(--muted); font-size:14px}

.card{
  background:var(--card); border:1px solid var(--border); border-radius:12px;
  padding:16px; margin-bottom:16px; box-shadow:var(--shadow)
}
.section-header{display:flex; align-items:center; justify-content:space-between; margin-bottom:10px}
.section-header h2{margin:0; font-size:16px}

.template-grid{
  display:grid; grid-template-columns: repeat(4, minmax(200px,1fr)); gap:12px;
}
.template-card{
  border:1px solid var(--border); border-radius:10px; padding:12px; background:#fff; display:flex; flex-direction:column; gap:8px; min-height:140px;
}
.template-card .tc-title{font-weight:700}
.template-card .tc-desc{color:var(--muted); font-size:13px; min-height:44px}
.template-card .tc-meta{color:var(--muted); font-size:12px}
.template-card .tc-actions{margin-top:auto}
.template-card.selected{outline:2px solid var(--brand); background:var(--brand-50)}

.fieldset{border-top:1px solid var(--border); padding-top:14px; margin-top:6px}
.fieldset:first-of-type{border-top:none; padding-top:0; margin-top:0}
.fieldset-title{display:flex; align-items:center; gap:10px; font-weight:700; margin-bottom:8px}
.fieldset-title .bullet{width:10px; height:10px; border-radius:50%; background:var(--brand)}

.grid.two{display:grid; grid-template-columns: 1fr 1fr; gap:12px}
.form-group{display:flex; flex-direction:column; gap:6px}
.form-group label{font-weight:600; font-size:13px}
input[type=text], select, textarea{
  width:100%; border:1px solid var(--border); border-radius:8px; padding:10px 12px; background:#fff; font-size:14px; outline:none;
}
input[type=text]:focus, select:focus, textarea:focus{border-color:#93c5fd; box-shadow:0 0 0 3px #dbeafe}

.upload{margin-top:8px}
.upload-drop{
  border:1px dashed #cbd5e1; border-radius:10px; padding:20px; display:grid; place-items:center; text-align:center; gap:6px; background:#f8fafc;
}
.upload-drop .cloud{font-size:22px; opacity:.5}
.upload .upload-meta{font-size:12px; color:var(--muted); margin-top:6px}

.panel{
  border:1px solid var(--border); background:#f8fafc; border-radius:10px; min-height:140px; padding:16px;
  display:flex; align-items:center; justify-content:space-between;
}
.panel.disabled{opacity:.65}
.panel-title{font-weight:700}
.panel-actions{}

.disabled-panels{gap:12px}

.actions{display:flex; gap:8px}
.actions.end{justify-content:flex-end; margin-top:12px}

.link.subtle{color:var(--muted); text-decoration:none; margin-left:auto}
.link.subtle:hover{text-decoration:underline}

@media (max-width: 1100px){
  .template-grid{grid-template-columns: repeat(2, 1fr)}
}
@media (max-width: 800px){
  .layout{grid-template-columns: 1fr}
  .sidebar{position:relative; top:auto}
}

/* --- Document Content Generation --- */
.pi-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 12px; margin-top: 8px; }
.pi-label { font-size: 12px; color: var(--muted); }
.pi-value { font-weight: 700; }
.pi-tabs { margin-top: 10px; display: flex; gap: 8px; }
.pi-tabs .tab { padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; color: var(--muted); }
.pi-tabs .tab.active { background: var(--brand-50); color: var(--brand-600); border-color: #93c5fd; }

.section-block { padding: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.section-title { font-weight: 800; }
.status { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); }
.status.ok { background: #ecfdf5; border-color: #10b981; color: #047857; }
.status.warn { background: #fff7ed; border-color: #f59e0b; color: #92400e; }
.status.pending { background: #eff6ff; border-color: #93c5fd; color: #1d4ed8; }

.section-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.menu { position: relative; }
.menu .menu-list { display: none; position: absolute; right: 0; top: 36px; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 6px; min-width: 160px; z-index: 20; }
.menu:hover .menu-list { display: block; }
.menu-item { display: block; width: 100%; text-align: left; padding: 6px 8px; border: none; background: transparent; }

.actions.between { display: flex; justify-content: space-between; margin-top: 12px; }


/* --- Locations Map --- */
.map-card .section-header{ align-items:flex-start; }
.map-card .muted.small{ margin-top:4px; }
.map-layout{
  display:grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap:16px;
  margin-top:12px;
}
.map-layout.single{
  grid-template-columns: 1fr;
}
.map-layout.single > div{
  width: 100%;
}
.map-canvas{
  width: 100%;
  max-width: none;
  aspect-ratio: 1 / 1;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #e2e8f0;
  overflow: hidden;
  position: relative;
}
.map-fallback{
  position:absolute;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  text-align:center;
  padding:16px;
  color:#1e293b;
  background: linear-gradient(135deg, #e2e8f0, #f8fafc);
  border-radius:12px;
  font-size:14px;
}
.map-fallback.hidden{ display:none; }
.marker-label-icon{
  background: transparent;
  border: none;
}
.marker-label{
  position: relative;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
}
.marker-label-box{
  background: #e11d48;
  color:#fff;
  font-weight:700;
  font-size:12px;
  padding:6px 12px;
  border-radius:3px;
  border: 2px solid #fff;
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.25);
  white-space: nowrap;
  display:flex;
  align-items:center;
  gap:6px;
  position: relative;
}
.marker-label-text{ line-height: 1; }
.marker-label-input{
  display:none;
  border:1px solid #fecdd3;
  background:#fff;
  color:#0f172a;
  border-radius:4px;
  padding:2px 6px;
  font-size:12px;
  min-width: 120px;
}
.marker-label-text{ display:inline-block; }
.marker-label-delete{
  display:none;
  background: rgba(255,255,255,0.25);
  color:#fff;
  border:1px solid rgba(255,255,255,0.6);
  border-radius:3px;
  width:16px;
  height:16px;
  line-height:14px;
  text-align:center;
  font-weight:700;
  cursor:pointer;
  padding:0;
}
.marker-label-actions{
  display:none;
  gap:6px;
}
.marker-label-btn{
  border:1px solid #e2e8f0;
  background:#fff;
  color:#0f172a;
  padding:2px 6px;
  border-radius:4px;
  font-size:11px;
  font-weight:600;
  cursor:pointer;
}
.marker-label-btn.delete{
  border-color:#fecdd3;
  color:#be123c;
  background:#fff1f2;
}
.marker-anchor-dot{
  display:block;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 2px solid #e11d48;
  border-radius: 2px;
  transform: rotate(45deg);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.25);
}

/* --- Document Preview --- */
.preview-layout{
  display:grid;
  grid-template-columns: 1fr 320px;
  gap:12px;
}

/* Faux A4 paper */
.paper{
  background:#fff;
  border:1px solid var(--border);
  border-radius:10px;
  padding:24px;
  box-shadow: var(--shadow);
  min-height: 600px;
}
.paper-head h1{ margin: 0 0 6px; font-size: 20px; text-align:center; }
.paper-sub{ text-align:center; color:var(--muted); font-size:13px; margin-bottom:18px; }
.paper-section{ margin: 18px 0; }
.paper-section h3{ margin:0 0 8px; font-size:15px; }
.paper-section p{ margin:8px 0; }
.paper-section ul{ margin:8px 0 0 18px; }

/* Right sidebar */
.export-panel{ display:flex; flex-direction:column; gap:12px; }
.format-tabs{ display:grid; grid-template-columns: repeat(4, 1fr); gap:6px; }
.format-tabs .tab{
  border:1px solid var(--border);
  background:#f8fafc;
  border-radius:8px;
  padding:6px 10px;
  font-size:13px;
}
.format-tabs .tab.active{ background:var(--brand-50); color:var(--brand-600); border-color:#93c5fd; }
.format-tabs .tab[disabled]{ opacity:.5; cursor:not-allowed; }

/* Range + checks */
.range-row{ display:grid; grid-template-columns: 50px 1fr 40px; align-items:center; gap:8px; }
.checks{ margin-top:8px; display:flex; flex-direction:column; gap:6px; }
.check{ display:flex; align-items:center; gap:8px; font-size:14px; }
.check.disabled{ opacity:.6; }
.toggle-row{ display:flex; align-items:center; gap:8px; border:1px solid var(--border); border-radius:8px; padding:8px; background:#f8fafc; }
.toggle-row.disabled{ opacity:.6; }

/* Document Info */
.form-stack{ display:flex; flex-direction:column; gap:10px; }
.input-row{ display:flex; gap:6px; }
.kv{ margin-top:8px; display:flex; flex-direction:column; gap:6px; font-size:14px; }
.kv-row{ display:flex; justify-content:space-between; gap:12px; }
.kv-label{ color:var(--muted); }
.kv-pill{
  display:inline-block;
  padding:2px 8px;
  background:var(--brand-50);
  color:var(--brand-600);
  border:1px solid #93c5fd;
  border-radius:999px;
  font-size:12px;
}

@media (max-width: 1100px){
  .preview-layout{ grid-template-columns: 1fr; }
}
@media (max-width: 1000px){
  .map-layout{ grid-template-columns: 1fr; }
}
