/* ===================================================================
   Global app navigation — icon+text sidebar / bottom bar, customizable
   =================================================================== */

:root{
  --nav-width: 224px;
  --nav-width-collapsed: 68px;
  --nav-bar-height: 64px;
  --nav-ink: var(--ink, #1A1A1A);
  --nav-card: var(--card-bg, #FFFFFF);
  --nav-bg: var(--bg, #FBF3DD);
  --nav-border: var(--border, #E5DCC3);
  --nav-accent: var(--accent, #1B5FBF);
  --nav-yellow: var(--yellow, #FFC72C);
  --nav-muted: var(--muted, #6B5B3E);
  --nav-font: 'Baloo 2', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Hide the old inline top navs once the new nav is in control */
.app-nav-ready .nav-row,
.app-nav-ready .header-nav{
  display: none !important;
}

/* Content wrapper: everything the page originally had in <body> */
.app-main{
  min-height: 100vh;
  box-sizing: border-box;
}

body.nav-sidebar .app-main{
  margin-left: var(--nav-width);
  transition: margin-left .16s ease;
}
body.nav-sidebar.nav-collapsed .app-main{
  margin-left: var(--nav-width-collapsed);
}
body.nav-bottom .app-main{
  margin-left: 0;
  padding-bottom: calc(var(--nav-bar-height) + 10px);
}

@media (max-width: 640px){
  body.nav-sidebar .app-main{ margin-left: var(--nav-width-collapsed); }
}

/* -------------------- Sidebar -------------------- */
.app-sidebar{
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--nav-width);
  display: flex;
  flex-direction: column;
  background: var(--nav-card);
  border-right: 3px solid var(--nav-ink);
  font-family: var(--nav-font);
  z-index: 500;
  transition: width .16s ease;
  overflow: visible;
}
body.nav-bottom .app-sidebar{ display: none; }
body.nav-collapsed .app-sidebar{ width: var(--nav-width-collapsed); }
@media (max-width: 640px){
  .app-sidebar{ width: var(--nav-width-collapsed); }
  .app-sidebar .nav-label{ display: none; }
}

.app-sidebar-brand{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 14px;
  border-bottom: 2px solid var(--nav-border);
  white-space: nowrap;
  overflow: hidden;
}
.app-sidebar-brand-mark{
  flex: 0 0 32px;
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.app-sidebar-brand-icon{
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}
.app-sidebar-brand-wordmark{
  height: 28px;
  width: auto;
  max-width: 100%;
  display: block;
  object-fit: contain;
}

.app-sidebar-brand-text{
  font-weight: 700;
  font-size: 0.98em;
  color: var(--nav-ink);
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-sidebar-items{
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item{
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 999px;
  border: 2px solid transparent;
  color: var(--nav-ink);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92em;
  white-space: nowrap;
  overflow: hidden;
}
.nav-item:hover{
  background: var(--nav-bg);
}
.nav-item.current{
  background: var(--nav-yellow);
  border-color: var(--nav-ink);
  box-shadow: 0 2px 0 var(--nav-ink);
}
.nav-item .nav-icon{
  flex: 0 0 20px;
  width: 20px; height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav-item .nav-label{
  overflow: hidden;
  text-overflow: ellipsis;
}
body.nav-collapsed .app-sidebar .nav-item{
  justify-content: center;
  padding: 9px 0;
}
body.nav-collapsed .app-sidebar .nav-item .nav-label{ display: none; }
@media (max-width: 640px){
  .app-sidebar .nav-item{ justify-content: center; padding: 9px 0; }
}

.app-sidebar-foot{
  border-top: 2px solid var(--nav-border);
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
body.nav-collapsed .app-sidebar-foot{ flex-direction: column; }

/* Small circular icon buttons used in sidebar foot + floating cluster */
.nav-btn{
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 999px;
  border: 2px solid var(--nav-ink);
  background: var(--nav-card);
  box-shadow: 0 2px 0 var(--nav-ink);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--nav-ink);
  padding: 0;
}
.nav-btn:hover{ background: var(--nav-bg); }
.nav-btn:active{ transform: translateY(2px); box-shadow: 0 0 0 var(--nav-ink); }
.nav-btn svg{
  width: 18px; height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* -------------------- Bottom bar -------------------- */
.app-bottombar{
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--nav-bar-height);
  background: var(--nav-card);
  border-top: 3px solid var(--nav-ink);
  z-index: 500;
  font-family: var(--nav-font);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
body.nav-bottom .app-bottombar{ display: flex; align-items: stretch; }
.app-bottombar-items{
  display: flex;
  flex: 1 1 auto;
}
.app-bottombar .nav-item{
  flex: 0 0 auto;
  min-width: 68px;
  flex-direction: column;
  gap: 3px;
  border-radius: 14px;
  justify-content: center;
  padding: 6px 10px;
  font-size: 0.72em;
  margin: 6px 3px;
}
.app-bottombar .nav-item .nav-icon{ width: 20px; height: 20px; }

/* -------------------- Floating nav tools cluster -------------------- */
.app-navtools{
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 600;
}
body.nav-bottom .app-navtools{
  bottom: calc(var(--nav-bar-height) + 12px);
}

/* -------------------- Edit-mode overlay -------------------- */
.navedit-overlay{
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26,26,26,0.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.navedit-overlay.open{ display: flex; }
.navedit-panel{
  width: 100%;
  max-width: 380px;
  max-height: 84vh;
  background: var(--nav-card);
  border: 3px solid var(--nav-ink);
  border-radius: 18px;
  box-shadow: 0 6px 0 var(--nav-ink);
  font-family: var(--nav-font);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.navedit-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 2px solid var(--nav-border);
}
.navedit-header h3{
  margin: 0;
  font-size: 1.05em;
  color: var(--nav-ink);
}
.navedit-hint{
  margin: 10px 16px 4px;
  font-size: 0.78em;
  color: var(--nav-muted);
}
.navedit-list{
  list-style: none;
  margin: 0;
  padding: 6px 10px;
  overflow-y: auto;
  flex: 1 1 auto;
}
.navedit-item{
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px;
  border-radius: 12px;
  margin-bottom: 4px;
  background: var(--nav-card);
}
.navedit-item.dragging{ opacity: 0.35; }
.navedit-item.drag-over{ outline: 2px dashed var(--nav-accent); outline-offset: 2px; }
.navedit-grip{
  flex: 0 0 18px;
  width: 18px; height: 18px;
  color: var(--nav-muted);
  cursor: grab;
  stroke: currentColor;
  fill: currentColor;
}
.navedit-icon{
  flex: 0 0 20px;
  width: 20px; height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--nav-ink);
}
.navedit-label{
  flex: 1 1 auto;
  font-weight: 600;
  font-size: 0.92em;
  color: var(--nav-ink);
}
.navedit-item.is-hidden .navedit-label,
.navedit-item.is-hidden .navedit-icon{
  opacity: 0.4;
}

/* toggle switch */
.navedit-switch{
  position: relative;
  flex: 0 0 auto;
  width: 40px; height: 22px;
  display: inline-block;
}
.navedit-switch input{
  opacity: 0; width: 0; height: 0; position: absolute;
}
.navedit-switch .navedit-slider{
  position: absolute; inset: 0;
  background: var(--nav-card);
  border: 2px solid var(--nav-ink);
  border-radius: 999px;
  cursor: pointer;
  transition: background .12s ease;
}
.navedit-switch .navedit-slider::before{
  content: "";
  position: absolute;
  top: 1px; left: 1px;
  width: 14px; height: 14px;
  border-radius: 999px;
  background: var(--nav-ink);
  transition: transform .12s ease;
}
.navedit-switch input:checked + .navedit-slider{
  background: var(--nav-yellow);
}
.navedit-switch input:checked + .navedit-slider::before{
  transform: translateX(17px);
}

.navedit-footer{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px 16px;
  border-top: 2px solid var(--nav-border);
}
.navedit-footer button{
  font-family: var(--nav-font);
  font-weight: 700;
  font-size: 0.85em;
  border-radius: 999px;
  cursor: pointer;
  padding: 8px 16px;
}
.navedit-reset{
  background: var(--nav-card);
  border: 2px solid var(--nav-border);
  color: var(--nav-muted);
}
.navedit-reset:hover{ border-color: var(--nav-ink); color: var(--nav-ink); }
.navedit-done{
  background: var(--nav-yellow);
  border: 2px solid var(--nav-ink);
  color: var(--nav-ink);
  box-shadow: 0 2px 0 var(--nav-ink);
}
.navedit-done:active{ transform: translateY(2px); box-shadow: 0 0 0 var(--nav-ink); }

.navedit-layout-row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 2px 16px 10px;
  padding: 10px 12px;
  border: 2px solid var(--nav-border);
  border-radius: 14px;
}
.navedit-layout-row span{
  font-size: 0.85em;
  font-weight: 600;
  color: var(--nav-ink);
}
.navedit-layout-buttons{
  display: flex;
  gap: 6px;
}
.navedit-layout-buttons button{
  width: 34px; height: 34px;
  border-radius: 10px;
  border: 2px solid var(--nav-ink);
  background: var(--nav-card);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--nav-ink);
}
.navedit-layout-buttons button svg{
  width: 18px; height: 18px;
  stroke: currentColor; fill: none; stroke-width: 1.8;
}
.navedit-layout-buttons button.active{
  background: var(--nav-yellow);
  box-shadow: 0 2px 0 var(--nav-ink);
}

/* ---------------- Line item editor (quotes + jobs) ---------------- */
.line-items-container { margin-top: 10px; }
.li-loading, .li-error, .li-empty { padding: 10px 2px; font-size: 13px; color: var(--nav-muted); }
.li-error { color: #b3261e; }
.li-editor {
  border: 2px solid var(--nav-border); border-radius: 10px; padding: 12px 14px;
  background: #FCFAF3;
}
.li-head-row, .li-row {
  display: grid;
  grid-template-columns: 52px minmax(120px, 2fr) 64px 72px 96px 96px 32px;
  gap: 8px;
  align-items: center;
}
.li-editor.li-has-optional .li-head-row,
.li-editor.li-has-optional .li-row {
  grid-template-columns: 52px minmax(120px, 2fr) 64px 72px 96px 96px 70px 32px;
}
.li-editor.li-has-cost .li-head-row,
.li-editor.li-has-cost .li-row {
  grid-template-columns: 52px minmax(120px, 2fr) 64px 72px 96px 96px 96px 96px 32px;
}
.li-editor.li-has-cost.li-has-optional .li-head-row,
.li-editor.li-has-cost.li-has-optional .li-row {
  grid-template-columns: 52px minmax(120px, 2fr) 64px 72px 96px 96px 96px 96px 70px 32px;
}
.li-line-cost { font-weight: 700; text-align: right; padding-right: 4px; color: var(--nav-muted); }
.li-head-row {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--nav-muted);
  font-weight: 700; padding: 4px 2px 8px;
}
.li-row { padding: 7px 2px; border-top: 1px solid var(--nav-border); }
.li-row:first-of-type { border-top: none; }
.li-move { display: flex; flex-direction: column; gap: 1px; }
.li-move-btn {
  width: 20px; height: 16px; padding: 0; border: 1px solid var(--nav-border); background: #fff;
  border-radius: 4px; font-size: 9px; line-height: 1; cursor: pointer; color: var(--nav-ink);
}
.li-move-btn:disabled { opacity: .3; cursor: default; }
.li-input {
  width: 100%; padding: 6px 8px; border: 1.5px solid var(--nav-border); border-radius: 7px;
  font-size: 13px; font-family: inherit; background: #fff;
}
.li-input:focus { outline: none; border-color: var(--nav-accent); }
.li-desc { font-weight: 600; }
.li-total { font-weight: 700; text-align: right; padding-right: 4px; }
.li-optional-cb { width: 18px; height: 18px; accent-color: var(--nav-accent); cursor: pointer; justify-self: center; }
.li-delete-btn {
  width: 26px; height: 26px; border: 1.5px solid var(--nav-border); background: #fff; border-radius: 7px;
  cursor: pointer; font-size: 13px; color: #b3261e;
}
.li-delete-btn:hover { background: #fee2e2; border-color: #b3261e; }
.li-foot-row { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--nav-border); }
.li-add-btn {
  border: 1.5px solid var(--nav-accent); color: var(--nav-accent); background: #fff;
  border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 700; cursor: pointer; width: auto;
}
.li-add-btn:hover { background: #E7F1F8; }
.li-running-total { font-size: 13px; font-weight: 700; color: var(--nav-ink); }
.li-row-thumb { width: 32px; height: 32px; object-fit: cover; border-radius: 6px; border: 1.5px solid var(--nav-border); margin-bottom: 2px; }
.li-catalog-btn { border: 1.5px solid var(--nav-accent); color: var(--nav-accent); background: #fff; border-radius: 999px; padding: 6px 14px; font-size: 13px; font-weight: 700; cursor: pointer; width: auto; margin-left: 8px; }
.li-catalog-btn:hover { background: #E7F1F8; }
.li-catalog-picker { margin-top: 10px; border: 1.5px solid var(--nav-border); border-radius: 10px; padding: 10px; background: #fff; }
.li-catalog-search { width: 100%; padding: 6px 8px; border: 1.5px solid var(--nav-border); border-radius: 7px; font-size: 13px; margin-bottom: 8px; box-sizing: border-box; }
.li-catalog-list { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.li-catalog-item { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 7px; cursor: pointer; }
.li-catalog-item:hover { background: #FCFAF3; }
.li-catalog-thumb { width: 32px; height: 32px; object-fit: cover; border-radius: 6px; border: 1.5px solid var(--nav-border); flex-shrink: 0; }
.li-catalog-thumb.placeholder { background: #f1f1f1; }
.li-catalog-name { flex: 1; font-size: 13px; font-weight: 600; }
.li-catalog-price { font-size: 13px; color: var(--nav-muted); }
.li-catalog-empty { font-size: 13px; color: var(--nav-muted); padding: 8px 2px; }

.client-link { color: inherit; text-decoration: none; }
.client-link:hover { text-decoration: underline; }
.address-link { color: var(--accent, #1B5FBF); text-decoration: none; }
.address-link:hover { text-decoration: underline; }
