:root{
  --charcoal:#211D1B;
  --charcoal-2:#2B241F;
  --walnut:#5C4030;
  --walnut-l:#8A6448;
  --sawdust:#EDE4D3;
  --paper:#FBF8F2;
  --iron:#6B7280;
  --iron-l:#9AA0A6;
  --orange:#E8622C;
  --orange-l:#F3835A;
  --moss:#5F8767;
  --danger:#C1443A;
  --line:rgba(92,64,48,.16);
  --shadow:0 1px 2px rgba(33,29,27,.06), 0 1px 8px rgba(33,29,27,.04);
}
*{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
  font-family:'Inter',sans-serif;
  background:
    linear-gradient(0deg, rgba(92,64,48,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(92,64,48,.035) 1px, transparent 1px),
    var(--sawdust);
  background-size:28px 28px, 28px 28px, auto;
  color:var(--charcoal);
  min-height:100vh;
  -webkit-font-smoothing:antialiased;
}
h1,h2,h3,h4{font-family:'Space Grotesk',sans-serif; margin:0; letter-spacing:-.01em;}
.mono{font-family:'IBM Plex Mono',monospace;}
button{font-family:inherit; cursor:pointer;}
input,select,textarea{font-family:'Inter',sans-serif;}
a{color:inherit;}
::selection{background:rgba(232,98,44,.25);}

#app{display:flex; min-height:100vh; align-items:flex-start;}

/* ---------- Sidebar ---------- */
.sidebar{
  width:234px; flex:0 0 234px; min-height:100vh; position:sticky; top:0;
  background:linear-gradient(175deg,var(--charcoal),var(--charcoal-2));
  color:#EDE4D3; display:flex; flex-direction:column; padding:22px 0 16px;
  z-index:20;
}
.brand{display:flex; align-items:center; gap:10px; padding:0 20px 22px; border-bottom:1px solid rgba(237,228,211,.12); margin-bottom:14px;}
.brand-mark{width:34px; height:34px; border-radius:8px; background:var(--orange); display:flex; align-items:center; justify-content:center; flex:0 0 34px;}
.brand-mark svg{width:19px; height:19px; stroke:#211D1B; stroke-width:2;}
.brand-name{font-family:'Space Grotesk'; font-weight:700; font-size:16.5px; line-height:1.15;}
.brand-sub{font-family:'IBM Plex Mono'; font-size:10px; color:#B9AC97; text-transform:uppercase; letter-spacing:.08em; margin-top:2px;}

nav.nav{padding:0 10px; flex:1;}
.nav-item{
  display:flex; align-items:center; gap:11px; width:100%; text-align:left;
  padding:10px 12px; border-radius:8px; background:transparent; border:none; color:#D8CFC0;
  font-size:13.5px; font-weight:500; margin-bottom:2px; border-left:3px solid transparent;
}
.nav-item svg{width:17px; height:17px; stroke:currentColor; fill:none; stroke-width:1.7; stroke-linecap:round; stroke-linejoin:round; flex:0 0 17px; opacity:.85;}
.nav-item:hover{background:rgba(237,228,211,.07); color:#fff;}
.nav-item.active{background:rgba(232,98,44,.14); color:#fff; border-left-color:var(--orange);}
.nav-item .badge{margin-left:auto; font-family:'IBM Plex Mono'; font-size:10px; background:rgba(237,228,211,.14); padding:1px 6px; border-radius:20px; color:#EDE4D3;}
.nav-item.active .badge{background:var(--orange); color:#211D1B; font-weight:600;}

.shop-status{margin:14px 12px 0; padding:12px 12px; border-radius:9px; background:rgba(237,228,211,.05); border:1px solid rgba(237,228,211,.1);}
.shop-status-title{font-family:'IBM Plex Mono'; font-size:9.5px; text-transform:uppercase; letter-spacing:.09em; color:#A99C86; margin-bottom:8px;}
.status-row{display:flex; align-items:center; gap:7px; font-size:12px; color:#D8CFC0; margin-bottom:6px;}
.status-row:last-child{margin-bottom:0;}
.dot{width:7px; height:7px; border-radius:50%; flex:0 0 7px;}
.dot.on{background:#7EC988; box-shadow:0 0 0 3px rgba(126,201,136,.18);}
.dot.idle{background:#C9BCA4;}
.dot.warn{background:var(--orange); box-shadow:0 0 0 3px rgba(232,98,44,.18);}

.sidebar-footer{padding:14px 20px 0; margin-top:10px; border-top:1px solid rgba(237,228,211,.1);}
.sync-note{font-family:'IBM Plex Mono'; font-size:10px; color:#9C8F79; display:flex; align-items:center; gap:6px;}
.sync-note .dot{width:6px; height:6px;}

/* ---------- Main ---------- */
#main{flex:1; min-width:0; padding:26px 32px 60px;}
.wrap{max-width:1320px; margin:0 auto;}

.topbar{display:flex; align-items:flex-start; justify-content:space-between; margin-bottom:22px; gap:16px; flex-wrap:wrap;}
.topbar h1{font-size:23px; font-weight:700;}
.topbar .date{font-family:'IBM Plex Mono'; font-size:12px; color:var(--iron); margin-top:4px;}
.topbar-actions{display:flex; align-items:center; gap:10px;}
.icon-btn{width:36px; height:36px; border-radius:8px; background:var(--paper); border:1px solid var(--line); display:flex; align-items:center; justify-content:center; color:var(--walnut);}
.icon-btn svg{width:16px; height:16px; stroke:currentColor; fill:none; stroke-width:1.8;}
.icon-btn:hover{border-color:var(--walnut-l); background:#fff;}

.view{display:none;}
.view.active{display:block; animation:fadein .25s ease;}
@keyframes fadein{from{opacity:0; transform:translateY(4px);} to{opacity:1; transform:none;}}

/* ---------- Cards / grid ---------- */
.card{background:var(--paper); border:1px solid var(--line); border-radius:12px; padding:19px 20px; box-shadow:var(--shadow);}
.card + .card{margin-top:16px;}
.grid-2{display:grid; grid-template-columns:1.3fr 1fr; gap:16px;}
.card-head{display:flex; align-items:center; justify-content:space-between; margin-bottom:14px; gap:10px; flex-wrap:wrap;}
.card-head h3{font-size:15px;}
.card-head .eyebrow{font-family:'IBM Plex Mono'; font-size:10.5px; text-transform:uppercase; letter-spacing:.08em; color:var(--iron); display:block; margin-bottom:3px;}

.kpi-grid{display:grid; grid-template-columns:repeat(6,1fr); gap:12px; margin-bottom:16px;}
.kpi{background:var(--paper); border:1px solid var(--line); border-radius:12px; padding:15px 16px; box-shadow:var(--shadow); position:relative; overflow:hidden;}
.kpi::before{content:''; position:absolute; left:0; top:0; bottom:0; width:3px; background:var(--kc,var(--orange));}
.kpi-label{font-family:'IBM Plex Mono'; font-size:10px; text-transform:uppercase; letter-spacing:.07em; color:var(--iron); margin-bottom:8px;}
.kpi-value{font-family:'Space Grotesk'; font-size:24px; font-weight:700; line-height:1;}
.kpi-sub{font-size:11.5px; color:var(--iron-l); margin-top:6px;}

/* ---------- Buttons ---------- */
.btn{border-radius:7px; padding:8px 14px; font-size:13px; font-weight:600; border:1px solid transparent; display:inline-flex; align-items:center; gap:6px;}
.btn svg{width:14px; height:14px; stroke:currentColor; fill:none; stroke-width:2.2;}
.btn-primary{background:var(--orange); color:#fff;}
.btn-primary:hover{background:var(--orange-l);}
.btn-ghost{background:transparent; border-color:var(--line); color:var(--walnut);}
.btn-ghost:hover{border-color:var(--walnut-l); background:#fff;}
.btn-sm{padding:5px 10px; font-size:12px; border-radius:6px;}
.btn-danger-ghost{background:transparent; border:1px solid rgba(193,68,58,.35); color:var(--danger);}
.btn-danger-ghost.armed{background:var(--danger); color:#fff; border-color:var(--danger);}
.btn-icon-sm{width:26px; height:26px; border-radius:6px; border:1px solid var(--line); background:#fff; display:inline-flex; align-items:center; justify-content:center; color:var(--walnut); font-size:13px; line-height:1;}
.btn-icon-sm:hover{border-color:var(--walnut-l);}
.btn-icon-sm:disabled{opacity:.3; cursor:default;}

/* ---------- Tabs ---------- */
.subtabs{display:flex; gap:6px; margin-bottom:16px; flex-wrap:wrap;}
.subtab{padding:7px 14px; border-radius:20px; font-size:12.5px; font-weight:600; background:transparent; border:1px solid var(--line); color:var(--iron);}
.subtab.active{background:var(--charcoal); color:#EDE4D3; border-color:var(--charcoal);}

/* ---------- Kanban ---------- */
.kanban{display:flex; gap:13px; overflow-x:auto; padding:4px 2px 12px;}
.kanban-col{min-width:252px; flex:0 0 252px; background:rgba(92,64,48,.045); border:1px solid var(--line); border-radius:11px; padding:11px;}
.kanban-col-head{display:flex; align-items:center; justify-content:space-between; padding:2px 4px 10px; border-bottom:1px dashed rgba(92,64,48,.25); margin-bottom:10px;}
.kanban-col-title{font-family:'Space Grotesk'; font-weight:600; font-size:12.5px;}
.kanban-col-clause{font-family:'IBM Plex Mono'; font-size:9px; color:var(--walnut-l); text-transform:uppercase; letter-spacing:.04em; display:block; margin-top:2px;}
.kanban-col-count{font-family:'IBM Plex Mono'; font-size:11px; background:#fff; border:1px solid var(--line); padding:1px 7px; border-radius:20px; color:var(--walnut);}

.job-tag{background:#fff; border:1px solid var(--line); border-radius:8px; padding:12px 12px 10px 18px; margin-bottom:10px; position:relative; box-shadow:0 1px 3px rgba(33,29,27,.05);}
.job-tag::before{content:''; position:absolute; left:7px; top:14px; width:7px; height:7px; border-radius:50%; background:var(--sawdust); box-shadow:inset 0 0 0 1px rgba(92,64,48,.3);}
.job-code{font-family:'IBM Plex Mono'; font-size:11px; font-weight:600; color:var(--walnut); display:flex; align-items:center; gap:6px;}
.prio-dot{width:6px; height:6px; border-radius:50%; display:inline-block;}
.prio-high{background:var(--danger);} .prio-normal{background:var(--orange);} .prio-low{background:var(--iron-l);}
.job-customer{font-size:13.5px; font-weight:600; margin-top:4px;}
.job-product{font-size:12px; color:var(--iron); margin-top:2px;}
.job-meta{display:flex; align-items:center; justify-content:space-between; margin-top:9px; font-size:11.5px; color:var(--iron);}
.job-value{font-family:'IBM Plex Mono'; color:var(--charcoal); font-weight:600;}
.job-controls{display:flex; align-items:center; justify-content:space-between; margin-top:9px; gap:6px;}
.job-arrows{display:flex; gap:4px;}
.empty-col{font-size:11.5px; color:var(--iron-l); font-style:italic; padding:6px 4px;}

/* ---------- Tables ---------- */
.table-wrap{overflow-x:auto;}
table.t{width:100%; border-collapse:collapse; font-size:13px;}
table.t th{text-align:left; font-family:'IBM Plex Mono'; text-transform:uppercase; font-size:10.5px; letter-spacing:.05em; color:var(--iron); border-bottom:1px solid var(--line); padding:8px 10px; white-space:nowrap;}
table.t td{padding:10px; border-bottom:1px solid rgba(92,64,48,.09); vertical-align:middle;}
table.t tr:last-child td{border-bottom:none;}
table.t td.num{font-family:'IBM Plex Mono';}
.row-muted{color:var(--iron);}

.pill{padding:3px 10px; border-radius:20px; font-size:10.5px; font-weight:600; text-transform:uppercase; letter-spacing:.03em; display:inline-block;}
.pill-green{background:rgba(95,135,103,.15); color:var(--moss);}
.pill-orange{background:rgba(232,98,44,.15); color:#B84E22;}
.pill-red{background:rgba(193,68,58,.15); color:var(--danger);}
.pill-grey{background:rgba(107,114,128,.15); color:var(--iron);}
select.inline-select{border:1px solid var(--line); border-radius:6px; padding:4px 6px; font-size:11.5px; background:#fff; color:var(--charcoal); font-weight:600;}
input.inline-input{border:1px solid var(--line); border-radius:6px; padding:5px 7px; font-size:12px; background:#fff; width:100%;}

/* ---------- Forms ---------- */
form.form-grid{display:grid; grid-template-columns:1fr 1fr; gap:12px 14px;}
form.form-grid .full{grid-column:1 / -1;}
.field label{display:block; font-size:11.5px; font-weight:600; color:var(--walnut); margin-bottom:5px;}
.field input, .field select, .field textarea{
  width:100%; border:1px solid var(--line); border-radius:7px; padding:9px 10px; font-size:13.5px; background:#fff; color:var(--charcoal);
}
.field textarea{resize:vertical; min-height:56px;}
.field input:focus, .field select:focus, .field textarea:focus{outline:2px solid rgba(232,98,44,.35); outline-offset:1px; border-color:var(--orange);}
.form-actions{grid-column:1/-1; display:flex; justify-content:flex-end; gap:8px; margin-top:4px;}

/* ---------- Modal ---------- */
.modal-overlay{position:fixed; inset:0; background:rgba(33,29,27,.55); display:flex; align-items:center; justify-content:center; z-index:200; padding:20px;}
.modal{background:var(--paper); border-radius:13px; padding:22px 22px 20px; width:min(520px,94vw); max-height:88vh; overflow-y:auto; box-shadow:0 20px 50px rgba(0,0,0,.3);}
.modal-head{display:flex; align-items:center; justify-content:space-between; margin-bottom:16px;}
.modal-head h3{font-size:16px;}
.modal-close{width:28px; height:28px; border-radius:7px; border:1px solid var(--line); background:#fff; color:var(--walnut); font-size:14px;}

/* ---------- ISO ---------- */
.std-grid{display:grid; grid-template-columns:repeat(auto-fill,minmax(260px,1fr)); gap:12px; margin-bottom:16px;}
.std-card{border:1px solid var(--line); border-radius:10px; padding:13px 14px; background:var(--paper);}
.std-code{font-family:'IBM Plex Mono'; font-size:11.5px; font-weight:600; color:var(--orange);}
.std-title{font-size:13px; font-weight:700; margin:4px 0 5px;}
.std-scope{font-size:12px; color:var(--iron); line-height:1.45;}
.compliance-bar{height:9px; background:rgba(92,64,48,.1); border-radius:20px; overflow:hidden; margin-top:8px;}
.compliance-fill{height:100%; background:linear-gradient(90deg,var(--moss),#7EC988); border-radius:20px;}

/* ---------- Charts (css bars) ---------- */
.vbars{display:flex; align-items:flex-end; gap:14px; height:172px; padding-top:22px;}
.vbar-col{flex:1; display:flex; flex-direction:column; align-items:center; justify-content:flex-end; height:100%;}
.vbar-value{font-family:'IBM Plex Mono'; font-size:10.5px; color:var(--walnut); margin-bottom:4px; white-space:nowrap;}
.vbar-track{width:100%; max-width:36px; flex:1; display:flex; align-items:flex-end; background:rgba(92,64,48,.08); border-radius:5px 5px 0 0; overflow:hidden;}
.vbar-fill{width:100%; background:linear-gradient(180deg,var(--orange),var(--walnut)); border-radius:5px 5px 0 0; transition:height .5s ease;}
.vbar-label{margin-top:6px; font-size:10.5px; color:var(--iron); font-family:'IBM Plex Mono'; text-align:center;}

.hbar-row{display:grid; grid-template-columns:135px 1fr 76px; align-items:center; gap:10px; margin-bottom:10px; font-size:12.5px;}
.hbar-label{color:var(--charcoal); overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
.hbar-track{background:rgba(92,64,48,.08); border-radius:5px; height:11px; overflow:hidden;}
.hbar-fill{height:100%; border-radius:5px; background:var(--orange);}
.hbar-fill.alt{background:var(--iron);}
.hbar-value{font-family:'IBM Plex Mono'; text-align:right; color:var(--iron);}

.empty-note{color:var(--iron-l); font-size:13px; font-style:italic; padding:6px 2px;}
.help-text{font-size:12px; color:var(--iron); line-height:1.5; margin-top:4px;}
.section-intro{font-size:13px; color:var(--iron); line-height:1.55; margin-bottom:16px; max-width:760px;}

@media(max-width:920px){
  .kpi-grid{grid-template-columns:repeat(2,1fr);}
  .grid-2{grid-template-columns:1fr;}
  form.form-grid{grid-template-columns:1fr;}
  .std-grid{grid-template-columns:1fr;}
}
@media(max-width:760px){
  #app{flex-direction:column;}
  .sidebar{position:relative; width:100%; height:auto; flex-direction:row; align-items:center; padding:12px;}
  .brand{border-bottom:none; padding:0 10px 0 0; margin-bottom:0;}
  nav.nav{display:flex; overflow-x:auto; padding:0 6px;}
  .nav-item{flex:0 0 auto; white-space:nowrap; border-left:none; border-bottom:3px solid transparent;}
  .nav-item.active{border-left:none; border-bottom-color:var(--orange);}
  .shop-status, .sidebar-footer{display:none;}
  #main{padding:18px 14px 40px;}
  .hbar-row{grid-template-columns:88px 1fr 60px;}
}

/* ---------- Added for the database-backed app ---------- */
.form-error{
  background:rgba(193,68,58,.1); color:var(--danger); border:1px solid rgba(193,68,58,.3);
  border-radius:7px; padding:8px 10px; font-size:12.5px; margin-bottom:12px;
}
.toast{
  position:fixed; bottom:18px; right:18px; z-index:400; color:#fff; padding:10px 16px;
  border-radius:8px; font-size:13px; box-shadow:0 6px 20px rgba(0,0,0,.25); max-width:340px;
  animation:toastin .18s ease;
}
.toast.err{background:var(--danger);}
.toast.ok{background:var(--charcoal);}
@keyframes toastin{from{opacity:0; transform:translateY(6px);} to{opacity:1; transform:none;}}
.fatal-card{max-width:640px;}
.fatal-card h3{color:var(--danger); margin-bottom:8px;}
.fatal-card pre{
  background:#fff; border:1px solid var(--line); padding:10px 12px; border-radius:7px;
  font-family:'IBM Plex Mono',monospace; font-size:12px; white-space:pre-wrap; word-break:break-word;
  color:var(--charcoal); margin:10px 0;
}
.loading-note{color:var(--iron); font-size:13px; padding:40px 0; text-align:center;}

/* ---------- Branding / logo ---------- */
.brand-mark{ background:#fff; padding:4px; }
.brand-logo-img{ width:100%; height:100%; object-fit:contain; display:block; }
.logout-btn{ width:100%; justify-content:center; margin-top:10px; }

/* ---------- Login screen ---------- */
.login-screen{
  min-height:100vh; display:flex; align-items:center; justify-content:center; padding:20px;
}
.login-card{
  background:var(--paper); border:1px solid var(--line); border-radius:16px;
  padding:38px 34px 32px; width:min(380px,100%); box-shadow:0 20px 50px rgba(33,29,27,.14);
  text-align:center;
}
.login-logo{ width:104px; height:104px; object-fit:contain; margin:0 auto 16px; display:block; }
.login-title{ font-size:20px; font-weight:700; margin-bottom:3px; }
.login-sub{
  font-size:11px; color:var(--iron); font-family:'IBM Plex Mono',monospace; text-transform:uppercase;
  letter-spacing:.08em; margin:0 0 26px;
}
.login-form{ text-align:left; display:flex; flex-direction:column; gap:14px; }
.login-submit{ width:100%; justify-content:center; padding:11px; font-size:14px; margin-top:6px; }
