:root{
  --bg:#f6f7fb;
  --panel:#ffffff;
  --text:#111827;
  --muted:#6b7280;
  --border:#e5e7eb;
  --shadow:0 8px 24px rgba(17,24,39,0.06);
  --accent:#2563eb;
  --accent2:#1d4ed8;
  --danger:#dc2626;
  --cell:#ffffff;
  --cellAlt:#fafafa;
  --cellReadonly:#f3f4f6;
  --cellSelected:#dbeafe;
  --inputHighlight:#fff7ed;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
}

*{ box-sizing:border-box; }

html,body{ height:100%; }
body{
  margin:0;
  font-family:var(--sans);
  font-size:9pt;
  line-height:1.25;
  color:var(--text);
  background:var(--bg);
}

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

.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:12px 14px;
  background:rgba(255,255,255,0.8);
  border-bottom:1px solid var(--border);
  backdrop-filter: blur(8px);
  position:sticky;
  top:0;
  z-index:10;
}

.brand{ display:flex; gap:10px; align-items:center; }
.brandIcon{
  width:28px; height:28px;
  border-radius:9px;
  background:var(--panel);
  border:1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:center;
  box-shadow:var(--shadow);
  font-weight:700;
}
.brandTitle{ font-weight:700; font-size:10.5pt; }
.brandSub{ color:var(--muted); margin-top:2px; }

.actions{ display:flex; gap:8px; align-items:center; }
.btn{
  border:1px solid var(--border);
  background:var(--panel);
  border-radius:10px;
  padding:7px 10px;
  font-size:9pt;
  cursor:pointer;
}
.btn:hover{ border-color:#d1d5db; }
.btn:active{ transform: translateY(0.5px); }
.btnPrimary{
  background:var(--accent);
  border-color:var(--accent);
  color:white;
}
.btnPrimary:hover{ background:var(--accent2); border-color:var(--accent2); }

.menuBtn{
  display:none;
  padding:7px 9px;
  line-height:1;
}

.sidebarOverlay{ display:none; }

.layout{ flex:1; display:flex; min-height:0; }

.sidebar{
  width:270px;
  background:var(--panel);
  border-right:1px solid var(--border);
  display:flex;
  flex-direction:column;
  min-height:0;
  /* Keep the sidebar visible while the page scrolls */
  position:sticky;
  top:60px;
  height: calc(100vh - 60px);
  align-self:flex-start;
}

/* Mobile: make sidebar an off-canvas drawer */
@media (max-width: 820px){
  .topbar{ flex-wrap:wrap; gap:10px; }
  .brandSub{ display:none; }
  .menuBtn{ display:inline-flex; align-items:center; justify-content:center; }
  .actions{ flex-wrap:wrap; }
  .actions .btn{ padding:6px 9px; }
  .sidebar{
    position:fixed;
    top:0;
    left:0;
    height:100vh;
    width:min(82vw, 320px);
    transform:translateX(-105%);
    transition:transform 180ms ease;
    z-index:40;
    box-shadow:var(--shadow);
    border-right:1px solid var(--border);
  }
  .sidebar.open{ transform:translateX(0); }
  .sidebarOverlay{
    position:fixed;
    inset:0;
    background:rgba(17,24,39,0.35);
    z-index:35;
  }
  .sidebarOverlay.show{ display:block; }
}

.sidebarHeader{ padding:12px; border-bottom:1px solid var(--border); }
.sidebarTitle{ font-weight:700; margin-bottom:8px; }
.search{
  width:100%;
  border:1px solid var(--border);
  border-radius:12px;
  padding:8px 10px;
  font-size:9pt;
  outline:none;
  background:#fbfbfe;
}
.search:focus{ border-color:#c7d2fe; box-shadow: 0 0 0 3px rgba(37,99,235,0.10); }

.nav{ padding:10px; overflow:auto; flex:1; }
.navGroup{
  margin:10px 0 6px;
  color:var(--muted);
  font-size:8pt;
  letter-spacing:0.06em;
  text-transform:uppercase;
}
.navItem{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:8px 10px;
  border-radius:12px;
  cursor:pointer;
}
.navItem:hover{ background:#f3f4f6; }
.navItem.active{ background:#e8edff; outline:1px solid #c7d2fe; }
.navItem .name{ font-weight:400; }
.navItem .meta{ color:var(--muted); font-size:8pt; }

.sidebarFooter{
  border-top:1px solid var(--border);
  padding:10px 12px;
  color:var(--muted);
}

.main{ flex:1; min-width:0; }
.content{ padding:14px; max-width:1200px; margin:0 auto; }

@media (max-width: 560px){
  .content{ padding:10px; }
}

.card{
  background:var(--panel);
  border:1px solid var(--border);
  border-radius:16px;
  box-shadow:var(--shadow);
}
.cardHeader{ padding:14px 14px 10px; border-bottom:1px solid var(--border); }
.cardTitle{ font-weight:800; font-size:12pt; }
.cardDesc{ color:var(--muted); margin-top:4px; }
.cardBody{ padding:14px; }

.breadcrumb{ color:var(--muted); margin-bottom:8px; font-size:8.5pt; }

.gridLayout{
  display:grid;
  grid-template-columns: 1.6fr 1fr;
  gap:12px;
  margin-top:12px;
  align-items:start;
}

@media (max-width: 980px){
  .sidebar{ width:240px; }
  .gridLayout{ grid-template-columns: 1fr; }
}

.sheetTop{
  display:flex;
  gap:8px;
  align-items:center;
  flex-wrap:wrap;
}
.sheetSelect{
  border:1px solid var(--border);
  border-radius:12px;
  padding:8px 10px;
  background:#fbfbfe;
  font-size:9pt;
}

.sheetWrap{
  border:1px solid var(--border);
  border-radius:14px;
  overflow:hidden;
  background:var(--panel);
}

.sheetHeaderRow{
  display:flex;
  position:sticky;
  top:0;
  z-index:2;
  background:linear-gradient(#fff,#fafafa);
  border-bottom:1px solid var(--border);
}

.cornerCell{
  width:52px;
  flex:0 0 52px;
  background:#f3f4f6;
  border-right:1px solid var(--border);
  height:28px;
}

.colHeader{
  height:28px;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:700;
  color:#374151;
  border-right:1px solid var(--border);
  background:#f9fafb;
  user-select:none;
}

.sheetViewport{
  position:relative;
  overflow:auto;
  height:68vh;
}

.spacer{ position:relative; width:100%; }

.row{
  display:flex;
  position:absolute;
  left:0;
  right:0;
}

.rowHeader{
  width:52px;
  flex:0 0 52px;
  height:28px;
  display:flex;
  align-items:center;
  justify-content:center;
  color:#4b5563;
  background:#f9fafb;
  border-right:1px solid var(--border);
  border-bottom:1px solid var(--border);
  user-select:none;
}

.cell{
  height:28px;
  display:flex;
  align-items:center;
  padding:0 6px;
  border-bottom:1px solid var(--border);
  border-right:1px solid var(--border);
  background:var(--cell);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  user-select:none;
}
.cell.readonly{ background:var(--cellReadonly); color:#111827; }
.cell.input{ background:var(--inputHighlight); }
.cell.selected{ outline:2px solid #93c5fd; outline-offset:-2px; background:var(--cellSelected); }
.cell .mono{ font-family:var(--mono); }

.cellInput{
  width:100%;
  height:24px;
  border:1px solid #c7d2fe;
  border-radius:8px;
  padding:3px 6px;
  font-size:9pt;
  outline:none;
}

.noteBox{
  border:1px dashed #d1d5db;
  background:#fbfbfe;
  border-radius:14px;
  padding:12px;
  color:#374151;
}
.noteTitle{ font-weight:800; margin-bottom:6px; }
.noteList{ margin:0; padding-left:16px; color:#4b5563; }

.kv{
  display:grid;
  grid-template-columns: 1fr auto;
  gap:6px 10px;
  margin-top:10px;
}
.kv .k{ color:var(--muted); }
.kv .v{ font-family:var(--mono); }

.toast{
  position:fixed;
  bottom:16px;
  left:50%;
  transform:translateX(-50%);
  background:#111827;
  color:white;
  padding:10px 12px;
  border-radius:12px;
  font-size:9pt;
  box-shadow:0 10px 30px rgba(0,0,0,0.18);
  opacity:0;
  pointer-events:none;
  transition: opacity 160ms ease;
}
.toast.show{ opacity:1; }

.footer{
  padding:10px 14px;
  color:var(--muted);
  border-top:1px solid var(--border);
  background:rgba(255,255,255,0.7);
}

/* ===== Form UI additions ===== */

.headerFlex{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
}

.headerRight{ display:flex; align-items:center; gap:8px; }

.btnSmall{
  padding:6px 10px;
  border-radius:12px;
  font-size:9pt;
}

.formLayout{
  display:grid;
  grid-template-columns: 1.25fr 1fr;
  gap:12px;
  margin-top:12px;
  align-items:start;
}

@media (max-width: 980px){
  .formLayout{ grid-template-columns: 1fr; }
}

.cardTitleSm{
  font-weight:800;
  font-size:10.5pt;
}

.cardDescSm{
  color:var(--muted);
  margin-top:3px;
  font-size:8.5pt;
}

.specialStack{
  display:flex;
  flex-direction:column;
  gap:10px;
  margin-bottom:12px;
}

.fieldList{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.fieldSection{
  margin-top:10px;
  padding:6px 4px;
  font-weight:800;
  font-size:9.5pt;
  color:#111827;
}

.fieldSection:first-child{
  margin-top:0;
}

.fieldRow{
  display:grid;
  grid-template-columns: 1.35fr 1fr 0.45fr;
  gap:10px;
  align-items:center;
  padding:8px 10px;
  border:1px solid var(--border);
  border-radius:14px;
  background:#fbfbfe;
}

/* Phone-friendly input layout */
@media (max-width: 560px){
  .fieldRow{
    grid-template-columns: 1fr;
    gap:8px;
    align-items:stretch;
  }
  .fieldControl{ justify-content:flex-start; }
  .fieldUnit{ text-align:left; }
  .fieldInput, .fieldSelect, .fieldValue{ max-width: none; }
  .fieldValue{ text-align:left; }
}

.fieldRow.isTotal{
  background:#f3f4f6;
  border-color:#d1d5db;
}

.fieldRow.isTotal .fieldLabel,
.fieldRow.isTotal .fieldValue{
  font-weight:800;
}

.fieldLabel{
  font-weight:600;
  color:#111827;
}

.fieldControl{
  display:flex;
  justify-content:flex-end;
}

.fieldUnit{
  color:var(--muted);
  text-align:right;
  font-size:8.5pt;
}

.fieldInput, .fieldSelect{
  width:100%;
  max-width: 220px;
  border:1px solid var(--border);
  border-radius:12px;
  padding:8px 10px;
  font-size:9pt;
  background:white;
}

.fieldInput:focus, .fieldSelect:focus{
  outline:none;
  border-color:#c7d2fe;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.10);
}

.fieldValue{
  width:100%;
  max-width: 220px;
  padding:8px 10px;
  border-radius:12px;
  background:#f3f4f6;
  border:1px solid var(--border);
  text-align:right;
  font-family:var(--mono);
  font-size:9pt;
}


/* Compound ft + in input (single row) */
.ftinWrap{
  display:flex;
  flex-wrap:nowrap;
  gap:8px;
  justify-content:flex-end;
  align-items:center;
  width:100%;
  max-width:220px;
}

.ftinPart{
  display:flex;
  align-items:center;
  gap:6px;
}

.ftinInput{
  width:78px;
  border:1px solid var(--border);
  border-radius:12px;
  padding:8px 10px;
  font-size:9pt;
  background:white;
}

.ftinInput:focus{
  outline:none;
  border-color:#c7d2fe;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.10);
}

.ftinUnit{
  color:var(--muted);
  font-size:8.5pt;
}

@media (max-width: 560px){
  .ftinWrap{
    justify-content:flex-start;
    max-width:none;
  }
  .ftinInput{
    width:72px;
    min-width: 0;
  }
}


.diagramSvg{
  width:100%;
  height:auto;
  display:block;
}

.diagramImgStack{
  display:flex;
  flex-direction:column;
  gap:12px;
}

.diagramImg{
  width:100%;
  height:auto;
  display:block;
  border:1px solid #e5e7eb;
  border-radius:14px;
  background:#ffffff;
}

.diagramPlaceholder{
  border:1px dashed #d1d5db;
  border-radius:14px;
  padding:14px;
  background:#fbfbfe;
  color:var(--muted);
}

.diagramTitle{
  font-weight:800;
  color:#111827;
  margin-bottom:6px;
}

.diagramText{
  font-size:9pt;
  line-height:1.35;
}

.advancedSheet{
  margin-top:14px;
}

.advancedTitle{
  font-weight:800;
  margin:10px 0 8px;
  color:#111827;
}

/* ===== Password gate ===== */

.authOverlay{
  position:fixed;
  inset:0;
  background: rgba(17,24,39,0.55);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
  z-index:50;
}

.authCard{
  width: min(440px, 100%);
}

.authInput{
  max-width:none;
}

.authError{
  color: var(--danger);
  margin-top:8px;
  min-height: 18px;
}

.authActions{
  margin-top:10px;
  display:flex;
  justify-content:flex-end;
}

.authHint{
  margin-top:12px;
  font-size:8.5pt;
  color: var(--muted);
}

.authShake{
  animation: authShake 220ms ease;
}

@keyframes authShake{
  0%{ transform: translateX(0); }
  25%{ transform: translateX(-4px); }
  50%{ transform: translateX(4px); }
  75%{ transform: translateX(-3px); }
  100%{ transform: translateX(0); }
}


/* ===== Basic / Advanced Inputs Toggle ===== */

.toggleRow{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding:8px 10px;
  border:1px dashed #d1d5db;
  border-radius:14px;
  background:#ffffff;
}

.toggleLabel{
  display:flex;
  align-items:center;
  gap:8px;
  color:var(--muted);
  font-size:9pt;
}

.toggleHint{
  color:var(--muted);
  font-size:8.5pt;
}

/* ===== Tool Automation Panels ===== */

.autoGrid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
  margin-top:10px;
}

@media (max-width: 540px){
  .autoGrid{ grid-template-columns: 1fr; }
}

.autoBlock{
  display:flex;
  flex-direction:column;
  gap:6px;
}

.autoLabel{
  font-size:8.5pt;
  color:var(--muted);
}

.autoBtns{
  display:flex;
  gap:8px;
  margin-top:10px;
  flex-wrap:wrap;
}

.autoCheck{
  display:flex;
  align-items:center;
  gap:8px;
  color:var(--muted);
  font-size:9pt;
}


/* ===== Print / Export PDF ===== */

@media print{
  body{ background:#ffffff; }
  .topbar, .sidebar, .sidebarOverlay, .footer, .toast, .authOverlay{ display:none !important; }

  .content{ max-width:none; margin:0; padding:0; }
  .card{ box-shadow:none; }
  .formLayout{ grid-template-columns: 1fr; }
  .fieldRow{ break-inside: avoid; }
}

.btn:disabled{
  opacity:0.58;
  cursor:not-allowed;
}

.navSection{
  display:flex;
  flex-direction:column;
  gap:6px;
  margin-bottom:10px;
}

.navGroup{
  margin:10px 4px 2px;
}

.navItems{
  display:flex;
  flex-direction:column;
  gap:4px;
}

.navItem{
  width:100%;
  border:1px solid transparent;
  background:transparent;
  text-align:left;
  font:inherit;
  color:inherit;
  appearance:none;
  align-items:flex-start;
}

.navItem .name{
  font-weight:600;
}

.navCopy{
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:3px;
}

.navSub{
  color:var(--muted);
  font-size:8.2pt;
  line-height:1.2;
  white-space:normal;
  display:-webkit-box;
  -webkit-line-clamp:2;
  -webkit-box-orient:vertical;
  overflow:hidden;
}

.navItem .meta{
  flex:0 0 auto;
  min-width:42px;
  padding:2px 8px;
  border-radius:999px;
  border:1px solid var(--border);
  background:#fff;
  color:var(--muted);
  font-size:7.8pt;
  text-align:center;
}

.navItem .meta[aria-hidden="true"]{
  display:none;
}

.navItem:hover{
  background:#f3f4f6;
  border-color:#eceff3;
}

.navItem.active{
  background:#e8edff;
  border-color:#c7d2fe;
  outline:none;
}

.navItem:focus-visible{
  outline:2px solid rgba(37,99,235,0.22);
  outline-offset:1px;
}

.standaloneCard,
.standaloneCardPlain,
.standaloneCardCompact{
  overflow:hidden;
}

.standaloneBody,
.standaloneBodyFlush{
  padding:0;
}

.standaloneFrameWrap{
  border-radius:16px;
  overflow:hidden;
  background:#fff;
}

.standaloneFrame{
  width:100%;
  min-height:720px;
  border:0;
  display:block;
  background:#fff;
}

@media (max-width: 820px){
  .standaloneFrame{
    min-height:72vh;
  }
}

