/* Buildflow — clean, friendly styling for non-technical users */

:root {
  --primary: #1c4435;
  --primary-container: #345c4b;
  --primary-fixed: #c0ecd6;
  --bg: #f5fbf7;
  --surface: #f5fbf7;
  --surface-low: #eff5f1;
  --surface-container: #e9efec;
  --surface-high: #e4e9e6;
  --surface-highest: #dee4e0;
  --white: #ffffff;
  --on-surface: #171d1b;
  --secondary: #56615a;
  --outline: #717974;
  --outline-variant: #c1c8c2;
  --error: #ba1a1a;
  --error-container: #ffdad6;
  --amber: #b26a00;
  --amber-bg: #f9e2ae;
  --green: #1e5c36;
  --green-bg: #cfe9d6;
  --red: #b32d2d;
  --red-bg: #f7cdc4;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(37, 43, 41, 0.06), 0 4px 14px rgba(37, 43, 41, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--on-surface);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }
code { background: var(--surface-container); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }

.icon { width: 20px; height: 20px; flex: 0 0 auto; }

/* ------------------------------------------------------------------ */
/* App shell                                                           */
/* ------------------------------------------------------------------ */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 264px;
  display: flex;
  flex-direction: column;
  background: var(--surface-low);
  border-right: 1px solid var(--outline-variant);
  padding: 16px;
  z-index: 40;
  transition: transform 0.2s ease;
}

.main-wrap {
  flex: 1;
  margin-left: 264px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 64px;
  padding: 0 24px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--outline-variant);
}

.topbar-title { min-width: 0; }
.topbar-title h1 { font-size: 18px; font-weight: 700; color: var(--primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.breadcrumb { font-size: 12px; color: var(--secondary); margin-top: 2px; }

.content { padding: 24px; max-width: 1720px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 20px; }

/* ------------------------------------------------------------------ */
/* Brand & nav                                                         */
/* ------------------------------------------------------------------ */

.brand { display: flex; align-items: center; gap: 10px; padding: 10px 8px 18px; }
.brand-mark {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary);
  color: var(--white);
  border-radius: 9px;
  flex: 0 0 auto;
}
.brand-mark .icon { width: 20px; height: 20px; }
.brand-text { font-size: 19px; font-weight: 800; color: var(--primary); letter-spacing: -0.02em; }

.nav { flex: 1; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 12px;
  border-radius: 8px;
  color: var(--secondary);
  font-weight: 550;
  font-size: 14px;
}
.nav-item:hover { background: var(--surface-container); color: var(--on-surface); text-decoration: none; }
.nav-item.active { background: var(--surface-highest); color: var(--primary); font-weight: 700; }
.nav-item .icon { width: 20px; height: 20px; }

.sidebar-footer { border-top: 1px solid var(--outline-variant); padding-top: 12px; margin-top: 8px; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--white); border: 1px solid var(--outline-variant); border-radius: 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary-container); color: var(--white);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; flex: 0 0 auto;
}
.user-meta { flex: 1; min-width: 0; }
.user-name { font-weight: 650; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--secondary); }

/* ------------------------------------------------------------------ */
/* Buttons                                                             */
/* ------------------------------------------------------------------ */

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--surface-container);
  color: var(--on-surface);
  font-family: inherit;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(0.97); }
.btn .icon { width: 18px; height: 18px; }

.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-container); filter: none; }
.btn-quiet { background: var(--white); border-color: var(--outline-variant); color: var(--on-surface); }
.btn-quiet:hover { background: var(--surface-low); filter: none; }
.btn-danger { background: var(--error-container); color: var(--error); }
.btn-danger:hover { background: #ffc4bc; filter: none; }
.btn-small { padding: 7px 12px; font-size: 13px; border-radius: 7px; }
.btn-block { width: 100%; justify-content: center; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border: none; border-radius: 8px;
  background: transparent; color: var(--secondary);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-container); color: var(--on-surface); }
.icon-btn .icon { width: 19px; height: 19px; }

.sidebar-backdrop { display: none; }

:focus-visible { outline: 3px solid #56846d; outline-offset: 2px; }

/* ------------------------------------------------------------------ */
/* Notices, banners, badges                                            */
/* ------------------------------------------------------------------ */

.notice {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-radius: 9px;
  font-size: 14px; font-weight: 550;
}
.notice .icon { width: 20px; height: 20px; }
.notice-success { background: #e3f3e8; color: #1e5c36; }
.notice-error { background: var(--error-container); color: var(--error); }
.notice-info { background: #e7f0fa; color: #245a8a; }

.demo-banner {
  display: flex; align-items: center; gap: 10px;
  background: #fdf3df;
  color: #8a5a00;
  border-bottom: 1px solid #f0d9a8;
  padding: 10px 24px;
  font-size: 14px; font-weight: 550;
}

.demo-badge {
  display: inline-block;
  background: #f0a928;
  color: #3d2a00;
  font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 999px;
  vertical-align: middle;
  margin-left: 6px;
}

.role-pill {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
  background: var(--primary-fixed); color: var(--primary);
  margin-left: 6px;
}
.role-pill.quiet { background: var(--surface-container); color: var(--secondary); }

/* ------------------------------------------------------------------ */
/* Page heads, panels                                                  */
/* ------------------------------------------------------------------ */

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.kicker { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--secondary); }
.page-title { font-size: 26px; font-weight: 750; letter-spacing: -0.02em; }
.page-sub { color: var(--secondary); margin-top: 4px; }

.panel {
  background: var(--white);
  border: 1px solid var(--outline-variant);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 18px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-head h2 { font-size: 16px; font-weight: 700; }
.subhead { font-size: 14px; font-weight: 700; margin: 16px 0 8px; }

.count-pill { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--surface-container); color: var(--secondary); }
.count-pill.danger { background: var(--error-container); color: var(--error); }

.hint { color: var(--secondary); font-size: 13px; }
.muted { color: var(--secondary); }

/* ------------------------------------------------------------------ */
/* KPI cards                                                           */
/* ------------------------------------------------------------------ */

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.kpi {
  background: var(--white);
  border: 1px solid var(--outline-variant);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex; flex-direction: column; gap: 6px;
  color: var(--on-surface);
}
.kpi:hover { text-decoration: none; border-color: var(--outline); }
.kpi-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--secondary); }
.kpi-value { font-size: 34px; font-weight: 800; letter-spacing: -0.03em; }
.kpi-note { font-size: 13px; color: var(--secondary); }
.kpi-danger { border-left: 5px solid var(--red); }
.kpi-danger .kpi-value { color: var(--red); }
.kpi-warn { border-left: 5px solid var(--amber); }
.kpi-warn .kpi-value { color: var(--amber); }
.kpi-ok { border-left: 5px solid var(--green); }
.kpi-ok .kpi-value { color: var(--green); }

/* ------------------------------------------------------------------ */
/* Lists                                                               */
/* ------------------------------------------------------------------ */

.list-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--surface-container);
}
.list-item:last-child { border-bottom: none; }
.list-icon {
  width: 38px; height: 38px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
.list-icon .icon { width: 20px; height: 20px; }
.list-icon.danger { background: var(--error-container); color: var(--error); }
.list-icon.ok { background: #e3f3e8; color: var(--green); }
.list-body { flex: 1; min-width: 0; }
.list-title { font-weight: 650; font-size: 14px; }
.list-title a { color: inherit; text-decoration: none; }
.list-title a:hover { text-decoration: underline; }
.list-sub { font-size: 12.5px; color: var(--secondary); margin-top: 2px; }
.muted-panel {
  display: flex; align-items: center; gap: 10px;
  padding: 14px;
  color: var(--secondary); font-size: 14px;
  background: var(--surface-low);
  border-radius: 9px;
}

/* ------------------------------------------------------------------ */
/* Project cards & rows                                                */
/* ------------------------------------------------------------------ */

.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.project-card { border: 1px solid var(--outline-variant); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 12px; background: var(--white); }
.project-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.project-card-title { font-size: 16px; font-weight: 700; }
.project-card-title a { color: inherit; text-decoration: none; }
.project-card-title a:hover { text-decoration: underline; }
.project-card-sub { font-size: 12.5px; color: var(--secondary); margin-top: 3px; }
.pct { font-size: 18px; font-weight: 800; color: var(--primary); }
.progress { height: 8px; border-radius: 999px; background: var(--surface-container); overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 999px; }
.project-card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; }

.project-row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 14px 4px;
  border-bottom: 1px solid var(--surface-container);
}
.project-row:last-child { border-bottom: none; }
.project-row-main { flex: 1; min-width: 220px; }
.project-row-title { font-size: 15px; font-weight: 700; }
.project-row-sub { font-size: 12.5px; color: var(--secondary); margin-top: 2px; }
.project-row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.order-block { border-bottom: 1px solid var(--surface-container); padding: 6px 0; }
.order-block:last-child { border-bottom: none; }
.order-comments { padding: 4px 0 10px; display: flex; flex-direction: column; gap: 8px; }
.comment-row { padding: 8px 10px; background: var(--surface-low); border-radius: 8px; }
.comment-body { font-size: 13.5px; white-space: pre-wrap; }
.comment-sub { font-size: 12px; color: var(--secondary); margin-top: 3px; }
.comment-form { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.comment-form .field { flex: 1; min-width: 220px; }
.comment-form textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 9px 11px;
  border: 1px solid var(--outline-variant);
  border-radius: 8px;
  background: var(--white);
  color: var(--on-surface);
  resize: vertical;
  min-height: 60px;
}
.comment-form textarea:focus { outline: 2px solid var(--primary-container); border-color: var(--primary); }
.dialog-order-fields { display: flex; flex-direction: column; gap: 12px; padding: 10px; border: 1px dashed var(--outline-variant); border-radius: 8px; }

/* ------------------------------------------------------------------ */
/* Forms                                                               */
/* ------------------------------------------------------------------ */

.stack-form { display: flex; flex-direction: column; gap: 14px; max-width: 640px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; font-weight: 600; }
.field input, .field select, .row-editor input, .row-editor select, .stage-name, .mini-label input, .mini-label select, .inline-form input, .inline-form select {
  font-family: inherit;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--outline-variant);
  border-radius: 8px;
  background: var(--white);
  color: var(--on-surface);
}
.field input:focus, .field select:focus, .row-editor input:focus, .row-editor select:focus, .stage-name:focus, .inline-form input:focus {
  outline: 2px solid var(--primary-container);
  outline-offset: 0;
  border-color: var(--primary);
}
.field input, .field select { width: 100%; }

.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 6px; }

.row-editor { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 6px 0; }
.row-editor .w-small { width: 120px; }
.w-small { width: 120px; }
.mini-label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 650; color: var(--secondary); }
.mini-label.inline { flex-direction: row; align-items: center; gap: 8px; }
.check-label { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; padding-top: 16px; }
.check-label input { width: 18px; height: 18px; }

/* ------------------------------------------------------------------ */
/* Wizard                                                              */
/* ------------------------------------------------------------------ */

.wizard { display: flex; flex-direction: column; gap: 18px; }
.wiz-track { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wiz-step {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface-container);
  color: var(--secondary);
  font-size: 13px; font-weight: 650;
}
.wiz-step.active { background: var(--primary); color: var(--white); }
.wiz-num {
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(255,255,255,0.25);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800;
}

.stage-editor { border: 1px solid var(--outline-variant); border-radius: 11px; padding: 14px; background: var(--surface-low); }
.stage-editor-head { margin-bottom: 8px; }
.stage-name { width: 100%; font-weight: 700; }
.stage-materials { display: flex; flex-direction: column; }
.material-row { border-bottom: 1px dashed var(--outline-variant); }
.material-row:last-child { border-bottom: none; }

/* ------------------------------------------------------------------ */
/* Chart                                                               */
/* ------------------------------------------------------------------ */

.page-tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--outline-variant); overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-gutter: stable; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px;
  font-weight: 650; font-size: 14px;
  color: var(--secondary);
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  flex: 0 0 auto;
}
.tab:hover { color: var(--on-surface); text-decoration: none; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab .icon { width: 18px; height: 18px; }

.chart-panel { padding: 0; overflow: hidden; }
.chart-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--outline-variant); }
.filter-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--white); border: 1px solid var(--outline-variant); border-radius: 8px; padding: 0 10px; }
.search-box .icon { width: 17px; height: 17px; color: var(--secondary); }
.search-box input { border: none; outline: none; padding: 10px 0; font-family: inherit; font-size: 14px; min-width: 150px; background: transparent; }

.legend { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--secondary); font-weight: 550; }
.swatch { width: 18px; height: 18px; border-radius: 5px; display: inline-block; border: 1px solid var(--outline-variant); }
.sw-blank { background: #ffffff; border: 1px dashed var(--outline); }
.sw-ordered { background: var(--amber-bg); }
.sw-delivered { background: var(--green-bg); }
.sw-overdue { background: var(--red-bg); border-color: var(--red); }
.sw-na { background: repeating-linear-gradient(45deg, #f5fbf7, #f5fbf7 3px, #d9dfdb 3px, #d9dfdb 5px); }
.sw-calloff { background: #dce8f5; }

.matrix-scroll { overflow: auto; max-height: 70vh; scrollbar-gutter: stable both-edges; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y; }
.matrix-scrollbar {
  overflow-x: auto;
  overflow-y: hidden;
  border-top: 1px solid var(--outline-variant);
  border-bottom: 1px solid var(--outline-variant);
  background: var(--surface-low);
  height: 20px;
  -webkit-overflow-scrolling: touch;
}
.matrix-scrollbar[hidden] { display: none; }
.matrix-scrollbar-inner { height: 1px; }
table.matrix { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 12px; }
table.matrix th, table.matrix td { padding: 0; }
table.matrix thead th { position: sticky; top: 0; z-index: 20; background: var(--surface-low); }

.stage-row th { padding: 10px 8px; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; border-right: 2px solid var(--outline-variant); border-bottom: 1px solid var(--outline-variant); text-align: center; }
.stage-group-0 { background: #e4efe8; color: var(--primary); }
.stage-group-1 { background: #fcf3e6; color: #a16817; }
.stage-group-2 { background: #eff3f8; color: #305777; }
.stage-group-3 { background: #f5eef7; color: #6e3778; }
.stage-row .corner { text-align: left; background: var(--surface-low); border-right: 2px solid var(--outline-variant); }

.material-row th { padding: 10px 6px; font-size: 11px; font-weight: 700; border-right: 1px solid var(--outline-variant); border-bottom: 2px solid var(--outline); text-align: center; }
.m-name { display: block; white-space: nowrap; }
.m-lead-btn {
  display: inline-block;
  margin-top: 3px;
  padding: 2px 8px;
  border: 1px solid var(--outline-variant);
  border-radius: 999px;
  background: var(--white);
  color: var(--secondary);
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.35;
  cursor: pointer;
}
.m-lead-btn:hover { border-color: var(--primary); color: var(--primary); background: #eef5f1; }

.sticky { position: sticky; z-index: 10; }
.sticky-1 { left: 0; min-width: 56px; width: 56px; }
.sticky-2 { left: 56px; min-width: 136px; width: 136px; }
.sticky-3 { left: 192px; min-width: 96px; width: 96px; border-right: 2px solid var(--outline-variant) !important; }

/* Pinned first columns and the "Plot" corner must sit above the stage groups
   that slide underneath them when the sheet is scrolled sideways. */
.stage-row .sticky-corner { position: sticky; left: 0; z-index: 30; background: var(--surface-low); border-right: 2px solid var(--outline-variant) !important; }
.material-row .sticky { z-index: 30; }

.plot-row td { border-bottom: 1px solid var(--surface-container); }
.plot-row .sticky { background: var(--white); }
.plot-row:nth-child(even) .sticky { background: #fbfdfb; }
.plot-row:hover .sticky { background: var(--surface-low); }

.plot-num { text-align: center; font-weight: 800; font-size: 13px; }
.plot-type { text-align: left; padding: 0 10px !important; font-weight: 600; font-size: 12.5px; }
.plot-type-col { text-align: center; padding: 0 6px !important; font-weight: 600; font-size: 12.5px; color: var(--secondary); }

.cell-td { text-align: center; vertical-align: middle; padding: 3px; }
.cell {
  position: relative;
  display: block;
  width: 100%;
  min-width: 88px;
  height: 58px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  overflow: hidden;
}
.cell:hover { outline: 2px solid var(--primary-container); outline-offset: 0; }
.half-top { position: absolute; top: 6px; left: 7px; font-size: 11px; font-weight: 800; line-height: 1; }
.half-bottom { position: absolute; bottom: 6px; right: 7px; font-size: 11px; font-weight: 800; line-height: 1; text-align: right; }

.cell-blank { background: linear-gradient(135deg, #ffffff 50%, #eff5f1 50%); border: 1px dashed var(--outline); color: var(--secondary); }
.cell-ordered { background: linear-gradient(135deg, var(--amber-bg) 50%, #eff5f1 50%); border: 1px solid #e8cf92; color: #6b4a00; }
.cell-delivered { background: linear-gradient(135deg, var(--amber-bg) 50%, var(--green-bg) 50%); border: 1px solid #a9d3b8; color: #1e5c36; }
.cell-overdue { background: linear-gradient(135deg, var(--amber-bg) 50%, var(--red-bg) 50%); border: 2px solid var(--red); color: #7a1c1c; }
.cell-na { background: repeating-linear-gradient(45deg, #f5fbf7, #f5fbf7 4px, #dce2de 4px, #dce2de 8px); border: 1px solid var(--outline-variant); color: var(--secondary); font-weight: 800; }
.chart-empty td { padding: 18px; color: var(--secondary); text-align: center; }

.chart-statusbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--outline-variant); font-size: 13px; color: var(--secondary); }
.chart-statusbar .spacer { flex: 1; }
.chart-statusbar .dot { color: var(--outline-variant); }

/* Cell dialog */
dialog#cell-dialog { border: none; border-radius: 14px; padding: 0; width: min(460px, 94vw); max-height: calc(100vh - 48px); overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.25); }
dialog#cell-dialog::backdrop { background: rgba(23, 29, 27, 0.45); }
dialog#expected-dialog { border: none; border-radius: 14px; padding: 0; width: min(440px, 94vw); max-height: calc(100vh - 48px); overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.25); }
dialog#expected-dialog::backdrop { background: rgba(23, 29, 27, 0.45); }
.dialog-form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head h3 { font-size: 17px; font-weight: 750; }
.dialog-sub { color: var(--secondary); font-size: 13.5px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.dialog-fields { display: flex; flex-direction: column; gap: 12px; padding: 12px; background: var(--surface-low); border-radius: 10px; }
.dialog-order-summary { display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 1px solid var(--outline-variant); border-radius: 10px; background: var(--surface-low); }
.dialog-order-summary[hidden] { display: none; }
.dos-title { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 750; color: var(--primary); }
.dos-title .icon { width: 16px; height: 16px; }
.dos-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }
.dos-cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dos-cell span { color: var(--secondary); font-size: 12px; }
.dos-cell strong { font-size: 13.5px; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ */
/* Calendar                                                            */
/* ------------------------------------------------------------------ */

.cal-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.cal-label { font-size: 17px; font-weight: 750; color: var(--primary); }
table.calendar { width: 100%; border-collapse: collapse; table-layout: fixed; }
table.calendar th { padding: 8px; font-size: 12px; font-weight: 750; color: var(--secondary); text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--outline-variant); }
.cal-day { height: 92px; vertical-align: top; padding: 6px; border: 1px solid var(--surface-container); font-size: 12px; }
.cal-day.out { background: #fbfcfb; color: var(--outline-variant); }
.cal-day.weekend { background: var(--surface-low); }
.cal-day.today { background: #e6f2eb; box-shadow: inset 0 0 0 2px var(--primary); border-radius: 8px; }
.cal-num { font-weight: 750; }
.cal-events { display: flex; flex-direction: column; gap: 3px; margin-top: 5px; overflow: hidden; }
.cal-event { font-size: 10px; font-weight: 650; padding: 2px 5px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev-due { background: var(--amber-bg); color: #6b4a00; }
.ev-delivered { background: var(--green-bg); color: #1e5c36; }
.ev-overdue { background: var(--red-bg); color: #7a1c1c; }
.ev-calloff { background: #dce8f5; color: #245a8a; }
.cal-more { font-size: 10px; color: var(--secondary); font-weight: 650; }
.calendar-mobile { display: none; }
.calendar-agenda-day { padding: 12px 0; border-bottom: 1px solid var(--surface-container); }
.calendar-agenda-day:last-child { border-bottom: 0; }
.calendar-agenda-day h3 { margin-bottom: 8px; font-size: 14px; }
.calendar-agenda-events { display: flex; flex-direction: column; gap: 6px; }
.calendar-agenda-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 44px; padding: 9px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 650;
}
.calendar-agenda-item:hover { text-decoration: none; filter: brightness(0.96); }
.calendar-agenda-item.ev-due { background: var(--amber-bg); color: #6b4a00; }
.calendar-agenda-item.ev-delivered { background: var(--green-bg); color: #1e5c36; }
.calendar-agenda-item.ev-overdue { background: var(--red-bg); color: #7a1c1c; }
.calendar-agenda-item.ev-calloff { background: #dce8f5; color: #245a8a; }
.calendar-agenda-plot { flex: 0 0 auto; font-size: 12px; }
.calendar-mobile-title { margin-bottom: 8px !important; }

.backup-list { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.backup-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 10px; background: var(--surface-low); border-radius: 8px; font-size: 13px; }
.inline-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline-details summary { cursor: pointer; list-style: none; }
.inline-details[open] .inline-form { margin-top: 8px; }
.inline-details .field { flex: 1; min-width: 210px; }
.team-user-form { max-width: 760px; }
.file-location { margin: 10px 0; }
.file-location summary { color: var(--primary); cursor: pointer; font-size: 13px; font-weight: 650; }
.file-location code { display: block; margin-top: 8px; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ */
/* Help & misc                                                         */
/* ------------------------------------------------------------------ */

.help-list { margin: 8px 0 16px; padding-left: 22px; display: flex; flex-direction: column; gap: 6px; }
.help-list li { line-height: 1.5; }
.panel h2 { margin: 14px 0 6px; font-size: 16px; }
.panel h2:first-child { margin-top: 0; }

.empty-state { text-align: center; padding: 40px 20px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-icon { width: 56px; height: 56px; border-radius: 14px; background: var(--surface-low); color: var(--primary); display: flex; align-items: center; justify-content: center; }
.empty-icon .icon { width: 28px; height: 28px; }
.empty-state h2 { font-size: 18px; }
.empty-state p { color: var(--secondary); max-width: 420px; }

/* ------------------------------------------------------------------ */
/* Auth pages                                                          */
/* ------------------------------------------------------------------ */

.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.auth-card-wrap { width: 100%; max-width: 420px; }
.auth-card { background: var(--white); border: 1px solid var(--outline-variant); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-brand .brand-text { font-size: 21px; }
.auth-title { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.auth-sub { color: var(--secondary); margin: 6px 0 20px; font-size: 14px; }

/* ------------------------------------------------------------------ */
/* New detail / orders / switcher styles                               */
/* ------------------------------------------------------------------ */

.project-switcher { padding: 4px 8px 14px; }
.project-switcher .ps-label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--secondary); margin-bottom: 6px; }
.project-switcher select { width: 100%; font-family: inherit; font-size: 14px; font-weight: 650; padding: 10px 12px; border: 1px solid var(--outline-variant); border-radius: 8px; background: var(--white); color: var(--on-surface); }

.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 650; color: var(--secondary); margin-bottom: 6px; }
.back-link:hover { color: var(--primary); text-decoration: none; }
.back-link .icon { width: 16px; height: 16px; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.detail-fact { background: var(--surface-low); border: 1px solid var(--outline-variant); border-radius: 9px; padding: 12px 14px; display: flex; flex-direction: column; gap: 3px; }
.df-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--secondary); }
.df-value { font-size: 16px; font-weight: 750; }

.audit-row { display: flex; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--surface-container); }
.audit-row:last-child { border-bottom: none; }
.audit-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary-container); margin-top: 6px; flex: 0 0 auto; }
.audit-main { flex: 1; min-width: 0; }
.audit-title { font-size: 13.5px; font-weight: 600; }
.audit-sub { font-size: 12px; color: var(--secondary); margin-top: 2px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.two-col > .field { min-width: 0; }
@media (max-width: 560px) { .two-col { grid-template-columns: 1fr; } }

.dialog-details { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 650; }
.dialog-details .icon { width: 16px; height: 16px; }

.cal-event { text-decoration: none; display: block; }
.cal-event:hover { filter: brightness(0.94); }

/* ------------------------------------------------------------------ */
/* Stats page                                                          */
/* ------------------------------------------------------------------ */

.stats-tabs .tab {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  font-family: inherit;
}

.stats-panel { display: flex; flex-direction: column; gap: 16px; }
.stats-panel[hidden] { display: none; }
.stats-search-form { margin-top: 6px; margin-bottom: 12px; }
.stats-search-box { min-width: 320px; }
.stats-collapse { border: 1px solid var(--outline-variant); border-radius: 10px; background: var(--surface-low); margin-bottom: 14px; }
.stats-collapse summary { cursor: pointer; padding: 10px 12px; font-size: 13px; font-weight: 700; color: var(--primary); }
.stats-collapse[open] summary { border-bottom: 1px solid var(--outline-variant); }
.materials-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; padding: 10px; }
.material-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 1px solid var(--outline-variant);
  border-radius: 8px;
  background: var(--white);
  padding: 9px 10px;
  font-size: 13.5px;
  color: var(--on-surface);
}
.material-link.active { border-color: var(--primary); background: #eef5f1; }
.material-link:hover { text-decoration: none; border-color: var(--primary); }
.compact-kpi-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 10px; }
.link-chip {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--outline-variant);
  border-radius: 999px;
  padding: 3px 10px;
  color: var(--primary);
  background: var(--white);
  font-size: 12.5px;
}
.link-chip:hover { text-decoration: none; border-color: var(--primary); background: #eef5f1; }
.stats-summary {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-low);
  border: 1px solid var(--outline-variant);
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--secondary);
  font-size: 14px;
}
.stats-summary .icon { width: 20px; height: 20px; color: var(--green); }
.stats-summary strong { color: var(--on-surface); }
.stats-panel-inner {
  background: var(--white);
  border: 1px solid var(--outline-variant);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 18px;
}
.stats-scroll { overflow-x: auto; }
.stats-table { border-collapse: collapse; width: 100%; font-size: 13px; min-width: 620px; }
.stats-table th, .stats-table td { padding: 10px 12px; border-bottom: 1px solid var(--surface-container); text-align: right; }
.stats-table th:first-child, .stats-table td:first-child { text-align: left; }
.stats-table th { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--secondary); background: var(--surface-low); white-space: nowrap; }
.stats-table tbody tr:last-child td { border-bottom: none; }
.strong-cell { font-weight: 700; color: var(--on-surface); }
.row-sub { display: block; font-size: 11.5px; font-weight: 500; color: var(--secondary); margin-top: 2px; }
.cell-good { color: var(--green); font-weight: 700; }
.cell-bad { color: var(--red); font-weight: 700; }
.empty-cell { text-align: center !important; color: var(--secondary); padding: 22px 12px; }
.pct-badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--surface-container); color: var(--secondary); }
.pct-badge.pct-good { background: #e3f3e8; color: #1e5c36; }
.pct-badge.pct-warn { background: var(--amber-bg); color: #6b4a00; }
.pct-badge.pct-bad { background: var(--error-container); color: var(--error); }
.stats-hint { margin-top: 12px; }
.price-group { border: 1px solid var(--outline-variant); border-radius: 10px; padding: 12px; background: var(--surface-low); margin-bottom: 12px; }
.price-group:last-child { margin-bottom: 0; }
.price-group-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.price-group-head h3 { font-size: 15px; font-weight: 700; }
.price-group .stats-table { min-width: 480px; background: var(--white); border-radius: 8px; overflow: hidden; }
.price-group .stats-table th { background: var(--surface-container); }
.price-group .stats-table td, .price-group .stats-table th { border-bottom-color: var(--surface-container); }
.price-group .row-cheapest td { background: #f3faf5; }

/* Wizard centering */
.wizard { align-items: center; }
.wizard > .stack-form { width: 100%; max-width: 760px; }
.wiz-track { justify-content: center; }

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */

.menu-toggle { display: none; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,0.2); }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 35; padding: 0; border: 0; background: rgba(23, 29, 27, 0.45); }
  .sidebar.open + .sidebar-backdrop { display: block; }
  .main-wrap { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 0 14px; }
  .topbar { height: 58px; }
  .topbar-title h1 { font-size: 16px; }
  .breadcrumb { font-size: 11px; }
  .page-title { font-size: 22px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .panel { padding: 14px; }
  .panel-head { align-items: flex-start; }
  .project-card { padding: 12px; }
  .project-grid { grid-template-columns: 1fr; }
  .filter-form { width: 100%; align-items: stretch; }
  .filter-form .mini-label { flex: 1 1 180px; }
  .filter-form .search-box { flex: 1 1 240px; }
  .search-box input { min-width: 0; width: 100%; }
  body.nav-open { overflow: hidden; }
}

@media (max-width: 700px) {
  .content { gap: 14px; padding: 12px; }
  .page-head { align-items: flex-start; gap: 10px; }
  .page-title { font-size: 20px; line-height: 1.2; }
  .page-sub { font-size: 13px; }
  .btn { width: 100%; justify-content: center; }
  .btn.btn-small { width: auto; }
  .btn.btn-small.btn-primary,
  .btn.btn-small.btn-danger { width: 100%; }
  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .btn { width: 100%; }
  .project-row { gap: 10px; }
  .project-row-main { min-width: 0; width: 100%; }
  .project-row-actions { width: 100%; display: grid; grid-template-columns: 1fr; }
  .project-row-actions .btn { width: 100%; }
  .list-item { align-items: flex-start; flex-wrap: wrap; gap: 10px; }
  .list-item > .btn,
  .list-item > a.btn { width: 100%; justify-content: center; }
  .comment-form { align-items: stretch; }
  .comment-form .field { min-width: 0; width: 100%; }
  .comment-form .btn { width: 100%; }
  .dialog-form { padding: 16px; gap: 12px; }
  .dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .dialog-actions .btn { width: 100%; justify-content: center; padding: 9px 10px; font-size: 12.5px; }
  .dos-grid { grid-template-columns: 1fr; }
  dialog#cell-dialog,
  dialog#expected-dialog,
  dialog#lead-dialog { width: calc(100vw - 12px); max-height: calc(100vh - 12px); border-radius: 12px; }
  .filter-form { gap: 8px; }
  .filter-form .mini-label { width: 100%; flex: 1 1 100%; }
  .filter-form .search-box { width: 100%; flex: 1 1 100%; }
  .filter-form > .btn { width: 100%; }
  .field input,
  .field select,
  .mini-label input,
  .mini-label select,
  .inline-form input,
  .inline-form select,
  .comment-form textarea { font-size: 16px; }
  .chart-toolbar { padding: 12px; gap: 10px; }
  .legend { gap: 8px; }
  .legend-item { font-size: 12px; }
  .matrix-scroll { max-height: 58vh; }
  .matrix-scrollbar { height: 24px; }
  .sticky-1 { left: 0; min-width: 52px; width: 52px; }
  .sticky-2 { left: 52px; min-width: 112px; width: 112px; }
  .sticky-3 { left: 164px; min-width: 84px; width: 84px; }
  .plot-type, .plot-type-col { font-size: 11px; padding-left: 6px !important; padding-right: 6px !important; }
  .material-row th { font-size: 10px; padding: 8px 4px; }
  .m-lead-btn { font-size: 9px; padding: 2px 6px; }
  .cell { min-width: 74px; height: 54px; }
  .half-top, .half-bottom { font-size: 10px; }
  .stats-panel-inner { padding: 12px; }
  .stats-table { min-width: 540px; font-size: 12px; }
  .stats-table th, .stats-table td { padding: 8px 9px; }
  .stats-tabs .tab { padding: 9px 12px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 30px; }
  .back-link { margin-bottom: 2px; }
  .calendar-desktop { display: none; }
  .calendar-mobile { display: block; }
  .calendar-agenda-plot { white-space: nowrap; }
  .project-row-actions { width: 100%; }
  .invoice-upload { width: 100%; }
  .stats-search-box { min-width: 0; width: 100%; }
  .stats-search-form { align-items: stretch; }
  .invoice-upload summary { justify-content: center; }
  .invoice-upload form { display: flex; flex-direction: column; align-items: stretch; gap: 10px; margin-top: 10px; }
  .invoice-upload .field input { width: 100%; }
  .btn, .icon-btn { min-height: 44px; }
}

@media (max-width: 520px) {
  .topbar { height: 54px; }
  .content { padding: 10px; }
  .panel { padding: 12px; border-radius: 10px; }
  .page-tabs { gap: 4px; }
  .tab { padding: 9px 10px; font-size: 13px; }
  .tab .icon { width: 16px; height: 16px; }
  .chart-statusbar { padding: 10px 12px; font-size: 12px; flex-wrap: wrap; }
  .chart-statusbar .dot { display: none; }
  .chart-statusbar .spacer { display: none; }
  .material-row th { padding: 7px 3px; }
  .m-name { font-size: 9px; }
  .m-lead-btn { margin-top: 2px; font-size: 8px; padding: 1px 5px; }
  .sticky-1 { left: 0; min-width: 46px; width: 46px; }
  .sticky-2 { left: 46px; min-width: 94px; width: 94px; }
  .sticky-3 { left: 140px; min-width: 72px; width: 72px; }
  .plot-type, .plot-type-col { font-size: 10px; }
  .cell { min-width: 66px; height: 50px; }
  .half-top, .half-bottom { font-size: 9px; }
  .stats-table { min-width: 500px; }
  .kpi-value { font-size: 26px; }
  .stats-summary { padding: 10px 12px; font-size: 13px; }
}

@media (max-width: 420px) {
  .topbar-title h1 { font-size: 15px; }
  .breadcrumb { display: none; }
  .page-title { font-size: 18px; }
  .dialog-actions { grid-template-columns: 1fr; }
  .dialog-actions .btn { font-size: 13px; }
  .project-row-title { font-size: 14px; }
  .project-row-sub { font-size: 12px; line-height: 1.35; }
  .detail-grid { grid-template-columns: 1fr; }
  .stats-tabs .tab { padding: 8px 10px; }
}

@media (max-width: 360px) {
  .content { padding: 8px; }
  .page-tabs { gap: 2px; }
  .tab { padding: 8px 9px; font-size: 12px; }
  .panel { padding: 10px; }
  .btn { font-size: 13px; padding: 9px 12px; }
  .sticky-1 { min-width: 42px; width: 42px; }
  .sticky-2 { left: 42px; min-width: 86px; width: 86px; }
  .sticky-3 { left: 128px; min-width: 68px; width: 68px; }
  .cell { min-width: 62px; height: 48px; }
}

/* ------------------------------------------------------------------ */
/* Print                                                               */
/* ------------------------------------------------------------------ */

@media print {
  @page { size: A4 landscape; margin: 10mm; }
  .sidebar, .topbar, .demo-banner, .chart-toolbar, .page-tabs, .page-head, .chart-statusbar, #cell-dialog, .menu-toggle, .notice { display: none !important; }
  body { background: #fff; }
  .main-wrap { margin: 0; }
  .content { padding: 0; max-width: none; }
  .panel { border: none; box-shadow: none; }
  .matrix-scroll { max-height: none; overflow: visible; }
  table.matrix { font-size: 9px; }
  .cell { height: 34px; min-width: 44px; }
  .m-name, .m-lead-btn { font-size: 8px; }
}
