:root{
  --bg:#0b1220;
  --surface:#0f1b2e;
  --surface2:#101f33;
  --text:#e7eefc;
  --muted:#a8b3c7;
  --line:rgba(255,255,255,.10);
  --accent:#3b82f6;
  --danger:#ef4444;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
}

*{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial;
  background: var(--bg);
  color: var(--text);
}

.topbar{
  position: sticky;
  top:0;
  z-index: 10;
  display:flex;
  align-items:center;
  padding:14px 16px;
  border-bottom:1px solid var(--line);
  background: rgba(11,18,32,.92);
  backdrop-filter: blur(8px);
}
.topbar__brand{ display:flex; gap:12px; align-items:center; }
.logo{
  width:38px; height:38px;
  display:grid; place-items:center;
  border-radius:10px;
  background: rgba(59,130,246,.16);
  border:1px solid rgba(59,130,246,.28);
  font-weight:900;
}
.title{ font-weight:900; letter-spacing:.2px; }
.subtitle{ font-size:12px; color:var(--muted); margin-top:2px; }

.container{
  width: min(96vw, 1880px);
  max-width: 1880px;
  margin: 0 auto;
  padding: 16px;
  display:flex;
  flex-direction: column;
  gap: 14px;
}

.card{
  background: rgba(15,27,46,.70);
  border:1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow:hidden;
}
.card__header{
  padding: 14px 16px;
  border-bottom:1px solid var(--line);
  background: rgba(16,31,51,.35);
}
.card__title{ margin:0; font-size:16px; }
.card__sub{ margin-top:4px; font-size:12px; color:var(--muted); }

.toolbar{ display:flex; justify-content: space-between; align-items: center; gap: 12px; }
.toolbar__actions{ display:flex; gap:10px; flex-wrap:wrap; }

.formGrid{
  padding: 14px 16px 10px;
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.formGrid .field.inline{ grid-column: 1 / -1; }

@media (max-width: 860px){
  .formGrid{ grid-template-columns: 1fr; }
  .toolbar{ flex-direction: column; align-items: flex-start; }
}

.field{ margin:0; }
.label{ display:block; font-size:12px; color:var(--muted); margin-bottom:6px; }
.input{
  width:100%;
  padding:10px 11px;
  border-radius:12px;
  border:1px solid var(--line);
  background: rgba(16,31,51,.55);
  color: var(--text);
  outline:none;
}
.input:disabled{ opacity:.55; cursor:not-allowed; }

.checkbox{ display:flex; gap:10px; align-items:center; user-select:none; }
.checkbox input{ transform: scale(1.05); }

.hint{
  margin: 0 16px 14px;
  font-size:12px;
  color:var(--muted);
  padding:10px 12px;
  border-radius:12px;
  border:1px dashed var(--line);
  background: rgba(16,31,51,.25);
}

.dropzone{
  margin:14px 16px 16px;
  border-radius:14px;
  border:1px dashed rgba(255,255,255,.16);
  background: rgba(16,31,51,.22);
  padding:16px;
  display:flex;
  align-items:center;
  gap:14px;
}
.dropzone.dragover{ border-color: rgba(59,130,246,.65); background: rgba(59,130,246,.10); }
.dropzone__icon{ font-size: 22px; opacity: .9; }
.dropzone__text{ flex:1; }
.dropzone__note{ font-size: 12px; margin-left:auto; }

.btn{
  border: 1px solid var(--line);
  background: rgba(16,31,51,.55);
  color: var(--text);
  padding:10px 12px;
  border-radius: 12px;
  cursor:pointer;
  font-weight: 700;
  transition: transform .08s ease, filter .15s ease;
}
.btn:hover{ filter: brightness(1.05); }
.btn:active{ transform: translateY(1px); }
.btn:disabled{ opacity:.5; cursor:not-allowed; }
.btn--primary{
  border-color: rgba(59,130,246,.55);
  background: rgba(59,130,246,.20);
}
.btn--secondary{
  background: rgba(16,31,51,.35);
}
.btn--danger{
  border-color: rgba(239,68,68,.50);
  background: rgba(239,68,68,.14);
}

.smallBtn{ padding:8px 10px; font-size: 12px; border-radius: 10px; }

.tableWrap{ padding: 14px 16px 6px; overflow:auto; }
.table{
  width:100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 900px;
}
.table th{
  text-align:left;
  font-size:12px;
  color: var(--muted);
  padding: 10px 10px;
  border-bottom:1px solid var(--line);
}
.table td{
  padding: 10px 10px;
  border-bottom:1px solid rgba(255,255,255,.06);
  vertical-align: top;
}
.th-actions{ width: 320px; }

.muted{ color: var(--muted); }
.pill{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:6px 10px;
  border-radius: 999px;
  font-size: 12px;
  border:1px solid var(--line);
  background: rgba(11,18,32,.35);
}
.pill--ok{ border-color: rgba(34,197,94,.35); background: rgba(34,197,94,.12); }
.pill--warn{ border-color: rgba(245,158,11,.35); background: rgba(245,158,11,.12); }
.pill--bad{ border-color: rgba(239,68,68,.35); background: rgba(239,68,68,.12); }

.cellInput{
  width:100%;
  padding:10px 11px;
  border-radius: 12px;
  border:1px solid var(--line);
  background: rgba(11,18,32,.35);
  color: var(--text);
  outline: none;
}

.actionRow{ display:flex; gap:8px; flex-wrap: wrap; }
.footerNote{ padding: 0 16px 14px; }

/* Modal */
.hidden{ display:none !important; }
.modalBackdrop{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 50;
}
.modal{
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(900px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
  background: rgba(15,27,46,.97);
  border:1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  z-index: 60;
  overflow:hidden;
}
.modal__header{
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display:flex;
  justify-content: space-between;
  align-items:center;
  gap:12px;
  background: rgba(16,31,51,.45);
}
.modal__title{ font-weight: 900; }
.modal__sub{ font-size: 12px; margin-top: 2px; }
.modal__body{
  padding: 14px 16px;
  overflow: auto;
}
.modalGrid{ padding: 0; }

/* Fält som bara gäller textdokument / ritningar */
.onlyCad{ display:none; }
.onlyText{ display:block; }
.modal__footer{
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  display:flex;
  gap: 10px;
  align-items:center;
  background: rgba(16,31,51,.35);
}
.spacer{ flex: 1; }

.confBtn{
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.confBtn:hover .pill{ filter: brightness(1.06); }

.pillIcon{ opacity: .9; }

.codeBox{
  margin: 0;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(16,31,51,.35);
  color: var(--text);
  font-size: 12px;
  line-height: 1.4;
  max-height: 45vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Friendly confidence summary */
.confSummary{
  display:flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.confCard{
  border:1px solid var(--line);
  background: rgba(16,31,51,.25);
  border-radius: 12px;
  padding: 10px 12px;
}

.confCardTitle{
  font-weight: 900;
  margin-bottom: 6px;
}
.confRow{
  display:flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  font-size: 13px;
}
.confKey{ color: var(--muted); }
.confVal{ font-weight: 800; }
.confWhy{
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.confTag{
  display:inline-flex;
  align-items:center;
  gap:6px;
  padding:4px 8px;
  border-radius:999px;
  border:1px solid var(--line);
  background: rgba(11,18,32,.25);
  font-size: 12px;
}

.confDetails summary{
  cursor: pointer;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 8px;
}

.busyOverlay{
  position:fixed;
  inset:0;
  z-index:70;
  background:rgba(11,18,32,.42);
  display:grid;
  place-items:center;
  backdrop-filter: blur(2px);
}
.busyCard{
  display:flex;
  align-items:center;
  gap:12px;
  padding:14px 18px;
  border-radius:14px;
  border:1px solid var(--line);
  background:rgba(15,27,46,.95);
  box-shadow: var(--shadow);
}
.busyText{ font-weight:800; }
.spinner{
  width:20px; height:20px;
  border-radius:999px;
  border:3px solid rgba(255,255,255,.18);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }


.modal--preview{ width:min(1200px, calc(100vw - 24px)); height:min(92vh, 980px); }
.modal__body--preview{ padding:12px; height:100%; }
.previewFrame{ width:100%; height:100%; min-height:70vh; border:0; border-radius:12px; background:#0a1730; }
.previewFallback{ height:100%; min-height:70vh; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:14px; border:1px solid var(--line); border-radius:12px; background:rgba(16,31,51,.35); }
