:root{
  --bg:#0b1220;
  --panel:#0f1b2d;
  --panel2:#13233a;
  --text:#e8eefb;
  --muted:#a9b7d0;
  --accent:#39d98a;
  --warn:#f7c948;
  --danger:#ff5c5c;
  --border:rgba(255,255,255,.10);
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --radius:14px;
  --radius2:18px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --pie-0: rgba(57,217,138,.85);
  --pie-1: rgba(247,201,72,.85);
  --pie-2: rgba(100,149,237,.85);
  --pie-3: rgba(255,140,0,.85);
  --pie-4: rgba(186,85,211,.85);
  --pie-5: rgba(57,217,138,.55);
  --pie-6: rgba(247,201,72,.55);
  --pie-7: rgba(100,149,237,.55);
  --pie-8: rgba(255,140,0,.55);
  --pie-9: rgba(186,85,211,.55);
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
  background: radial-gradient(1200px 600px at 15% 10%, rgba(57,217,138,.12), transparent 55%),
              radial-gradient(900px 500px at 85% 15%, rgba(247,201,72,.10), transparent 55%),
              var(--bg);
  color:var(--text);
}
a{color:inherit}
code{font-family:var(--mono); font-size:.95em}
.muted{color:var(--muted)}
.topbar{
  display:flex; justify-content:space-between; align-items:center;
  padding:14px 18px;
  border-bottom:1px solid var(--border);
  background: rgba(15,27,45,.65);
  backdrop-filter: blur(10px);
  position:sticky; top:0; z-index:10;
}
.brand{display:flex; gap:12px; align-items:center}
.brand-mark{
  font-weight:800;
  padding:8px 12px;
  border-radius:999px;
  background: linear-gradient(135deg, rgba(57,217,138,.25), rgba(57,217,138,.08));
  border:1px solid rgba(57,217,138,.25);
}
.brand-sub{font-size:.92rem; color:var(--muted)}
.topbar-right{display:flex; gap:10px; align-items:center}
.pill{
  padding:8px 10px;
  border-radius:999px;
  border:1px solid var(--border);
  background: rgba(19,35,58,.55);
  color:var(--muted);
}
.layout{display:grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 60px);}
.sidebar{
  padding:14px;
  border-right:1px solid var(--border);
  background: rgba(15,27,45,.45);
}
.nav{
  display:block;
  padding:10px 12px;
  margin:4px 0;
  text-decoration:none;
  border-radius:10px;
  border:1px solid transparent;
  color: var(--text);
}
.nav:hover{border-color: var(--border); background: rgba(19,35,58,.65);}
.sidebar-sep{height:12px}
.content{padding:18px; max-width: 1200px;}
.grid{display:grid; gap:12px}
.grid.cols-3{grid-template-columns: repeat(3, minmax(0,1fr))}
.grid.cols-4{grid-template-columns: repeat(4, minmax(0,1fr))}
.card{
  border:1px solid var(--border);
  background: rgba(15,27,45,.72);
  border-radius: var(--radius2);
  box-shadow: var(--shadow);
  padding:14px;
}
.card h2,.card h3{margin:0 0 6px 0}
.row{display:flex; gap:12px; flex-wrap:wrap; align-items:center}
.spacer{flex:1}
.btn{
  display:inline-flex; align-items:center; justify-content:center;
  padding:10px 12px;
  border-radius: 12px;
  border:1px solid rgba(57,217,138,.35);
  background: rgba(57,217,138,.14);
  color: var(--text);
  text-decoration:none;
  cursor:pointer;
  font-weight:650;
}
.btn:hover{background: rgba(57,217,138,.20);}
.btn.ghost{
  border-color: var(--border);
  background: rgba(19,35,58,.55);
  color: var(--text);
}
.btn.danger{border-color: rgba(255,92,92,.35); background: rgba(255,92,92,.12);}
.btn.warn{border-color: rgba(247,201,72,.35); background: rgba(247,201,72,.12);}
input,select,textarea{
  width:100%;
  padding:10px 10px;
  margin:6px 0 12px 0;
  border-radius: 12px;
  border:1px solid var(--border);
  background: rgba(19,35,58,.50);
  color: var(--text);
  outline:none;
}
textarea{min-height: 92px; resize: vertical;}
label{display:block; color: var(--muted); font-size:.92rem; margin-top:6px}
.table{width:100%; border-collapse: collapse; overflow:hidden; border-radius: 14px; border:1px solid var(--border)}
.table th,.table td{padding:10px 10px; border-bottom:1px solid var(--border); vertical-align: top; font-size:.95rem}
.table th{color: var(--muted); text-align:left; background: rgba(19,35,58,.35)}
.badge{display:inline-flex; padding:4px 8px; border-radius: 999px; border:1px solid var(--border); font-size:.82rem; color: var(--muted)}
.badge.green{border-color: rgba(57,217,138,.45); color: rgba(57,217,138,.95); background: rgba(57,217,138,.10)}
.badge.yellow{border-color: rgba(247,201,72,.55); color: rgba(247,201,72,.95); background: rgba(247,201,72,.10)}
.badge.red{border-color: rgba(255,92,92,.55); color: rgba(255,92,92,.95); background: rgba(255,92,92,.10)}
/* Defect severity traffic-light */
.badge.severity-critical,.severity-critical{border-color: rgba(255,92,92,.55); color: rgba(255,92,92,.95); background: rgba(255,92,92,.15)}
.badge.severity-high,.severity-high{border-color: rgba(255,140,0,.6); color: #ffb347; background: rgba(255,140,0,.15)}
.badge.severity-medium,.severity-medium{border-color: rgba(247,201,72,.55); color: rgba(247,201,72,.95); background: rgba(247,201,72,.15)}
.badge.severity-low,.severity-low{border-color: rgba(57,217,138,.45); color: rgba(57,217,138,.95); background: rgba(57,217,138,.15)}
.kpi{font-size:1.35rem; font-weight:800}
.auth-wrap{min-height:100vh; display:flex; align-items:center; justify-content:center; padding:18px}
.auth{max-width:460px; width:100%}
.auth h1{margin:0 0 6px 0}
.form{margin-top:10px}
.form-grid{display:grid;grid-template-columns:1fr 1fr;gap:10px 16px;margin-top:8px;max-width:600px;}
.form-grid label{display:flex;flex-direction:column;gap:4px;}
.form-grid .span-2{grid-column:1 / -1;}
.alert{
  padding:10px 12px;
  border-radius: 12px;
  border:1px solid rgba(255,92,92,.45);
  background: rgba(255,92,92,.12);
  margin:10px 0;
}
.demo ul{margin:10px 0 0 18px; color: var(--muted)}
.tiles{display:grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap:12px}
.tile{
  border-radius: var(--radius);
  border:1px solid var(--border);
  padding:12px;
  background: rgba(19,35,58,.45);
  text-decoration:none;
}
.tile:hover{background: rgba(19,35,58,.65);}
.tile .title{display:flex; justify-content:space-between; align-items:center; gap:10px}
.progress{
  height:8px; border-radius: 999px; background: rgba(255,255,255,.08); overflow:hidden; margin-top:10px
}
.progress > div{height:100%; background: linear-gradient(90deg, rgba(57,217,138,.9), rgba(57,217,138,.35));}
.hint{font-size:.9rem; color: var(--muted)}
.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}
.defects-by-wbs-row summary::-webkit-details-marker{display:none}
.defects-by-wbs-row summary::before{content:"▶ ";margin-right:4px;color:var(--muted)}
.defects-by-wbs-row[open] summary::before{content:"▼ "}
.boq-group-0{border-left:4px solid rgba(57,217,138,.6)}
.boq-group-1{border-left:4px solid rgba(247,201,72,.6)}
.boq-group-2{border-left:4px solid rgba(100,149,237,.6)}
.boq-group-3{border-left:4px solid rgba(255,140,0,.6)}
.boq-group-4{border-left:4px solid rgba(186,85,211,.6)}

/* Dashboard at-a-glance */
.dashboard-glance{
  display:grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap:12px;
  margin-top:14px;
}
.card-metric{
  display:flex;
  flex-direction:column;
  gap:4px;
  text-decoration:none;
  color:inherit;
  transition: background .15s, border-color .15s;
}
.card-metric:hover{ background: rgba(19,35,58,.85); border-color: rgba(57,217,138,.25); }
.card-metric-label{ font-size:.85rem; color: var(--muted); }
.card-metric-value{ font-size:1.6rem; font-weight:800; }
.card-metric-hint{ font-size:.8rem; color: var(--muted); margin-top:2px; }
.card-metric-urgent .card-metric-value{ color: rgba(255,140,0,.95); }
.card-chart-title{ margin:0 0 2px 0; font-size:1rem; }
.card-chart-sub{ margin:0 0 12px 0; font-size:.88rem; }
.dashboard-charts{
  display:grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap:12px;
  margin-top:14px;
  align-items:start;
}
.dashboard-charts-col1{
  display:flex;
  flex-direction:column;
  gap:12px;
  min-width:0;
}
.card-defects-in-gap{
  display:block;
  text-decoration:none;
  color:inherit;
  padding:12px 14px;
  margin:0;
}
.card-defects-in-gap:hover{
  background: rgba(19,35,58,.85);
  border-color: rgba(57,217,138,.25);
}
.card-chart{ min-width:0; padding:12px; }
.card-chart .card-chart-sub{ margin-bottom:8px; }
.donut-wrap{ display:flex; align-items:flex-start; gap:12px; flex-wrap:wrap; }
.donut{
  width:120px; height:120px;
  border-radius:50%;
  background: conic-gradient(
    rgba(57,217,138,.85) 0 calc(var(--pct-completed, 0) * 1%),
    rgba(57,217,138,.35) calc(var(--pct-completed, 0) * 1%) calc((var(--pct-completed, 0) + var(--pct-in-progress, 0)) * 1%),
    rgba(247,201,72,.4) calc((var(--pct-completed, 0) + var(--pct-in-progress, 0)) * 1%) calc((var(--pct-completed, 0) + var(--pct-in-progress, 0) + var(--pct-pending, 0)) * 1%),
    rgba(247,201,72,.2) calc((var(--pct-completed, 0) + var(--pct-in-progress, 0) + var(--pct-pending, 0)) * 1%) calc((var(--pct-completed, 0) + var(--pct-in-progress, 0) + var(--pct-pending, 0) + var(--pct-pending-appr, 0)) * 1%),
    rgba(255,92,92,.25) calc((var(--pct-completed, 0) + var(--pct-in-progress, 0) + var(--pct-pending, 0) + var(--pct-pending-appr, 0)) * 1%) 100%
  );
  flex-shrink:0;
  position:relative;
}
.donut::before{
  content:"";
  position:absolute;
  inset:10px;
  border-radius:50%;
  background: var(--panel);
  z-index:0;
}
.donut-center{
  position:absolute;
  top:50%; left:50%;
  transform:translate(-50%, -50%);
  font-size:1.1rem;
  font-weight:700;
  z-index:2;
}
.donut-legend-counts{ display:flex; flex-direction:column; gap:6px; flex:1; min-width:0; }
.wbs-legend-vertical{ display:flex; flex-direction:column; gap:4px; }
.wbs-legend-row{ display:flex; align-items:center; justify-content:space-between; gap:12px; }
.wbs-legend-num{ font-size:.9rem; font-weight:700; color: var(--text); min-width:2em; text-align:right; }
.donut-legend-item{ font-size:.82rem; color: var(--muted); }
.donut-legend-item.completed{ color: rgba(57,217,138,.95); }
.donut-legend-item.in-progress{ color: rgba(57,217,138,.7); }
.donut-legend-item.pending-appr{ color: rgba(247,201,72,.9); }
.donut-legend-item.rejected{ color: rgba(255,92,92,.8); }
.card-chart-footer{ margin-top:8px; padding-top:8px; border-top:1px solid var(--border); }
.defect-card-by-status{
  margin-top:12px; padding-top:10px; border-top:1px solid var(--border);
  display:flex; flex-direction:column; gap:4px;
  font-size:.85rem;
}
.defect-card-by-status .muted{ font-size:.8rem; }
.defect-card-urgent{ color: rgba(255,140,0,.95); font-weight:600; }
.pie-wrap{ display:flex; align-items:flex-start; gap:10px; flex-wrap:wrap; }
.pie-donut{ width:100px; height:100px; border-radius:50%; flex-shrink:0; position:relative; }
.pie-donut::before{ content:""; position:absolute; inset:8px; border-radius:50%; background: var(--panel); z-index:0; }
.pie-center{ position:absolute; top:50%; left:50%; transform:translate(-50%, -50%); font-size:.75rem; font-weight:600; color: var(--muted); z-index:2; white-space:nowrap; }
.pie-legend{ flex:1; min-width:0; font-size:.8rem; }
.pie-legend-row{ display:flex; align-items:center; gap:6px; margin-bottom:3px; }
.pie-dot{ width:8px; height:8px; border-radius:50%; flex-shrink:0; }
.pie-0{ background: rgba(57,217,138,.85); }
.pie-1{ background: rgba(247,201,72,.85); }
.pie-2{ background: rgba(100,149,237,.85); }
.pie-3{ background: rgba(255,140,0,.85); }
.pie-4{ background: rgba(186,85,211,.85); }
.pie-5{ background: rgba(57,217,138,.5); }
.pie-6{ background: rgba(247,201,72,.5); }
.pie-7{ background: rgba(100,149,237,.5); }
.pie-8{ background: rgba(255,140,0,.5); }
.pie-9{ background: rgba(186,85,211,.5); }
.pie-name{ flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color: var(--text); }
.pie-pct{ color: var(--muted); flex-shrink:0; }
.card-spend-by-project{ margin-top:12px; padding:12px 14px; }
.card-spend-by-project .card-chart-title{ margin:0 0 2px 0; }
.card-spend-by-project .card-chart-sub{ margin:0 0 10px 0; font-size:.88rem; }
.spend-bars{ display:flex; flex-direction:column; gap:6px; }
.spend-row{ display:flex; align-items:center; gap:8px; text-decoration:none; color:inherit; padding:4px 0; border-radius:8px; }
.spend-row:hover{ background: rgba(255,255,255,.04); }
.spend-label{ font-size:.82rem; min-width:120px; max-width:180px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.spend-track{ flex:1; height:8px; border-radius:999px; background: rgba(255,255,255,.08); overflow:hidden; min-width:0; }
.spend-fill{ height:100%; border-radius:999px; background: linear-gradient(90deg, rgba(57,217,138,.6), rgba(57,217,138,.25)); transition: width .3s ease; }
.spend-pct{ font-size:.8rem; color: var(--muted); min-width:2.5em; text-align:right; }
.bar-stack{ display:flex; flex-direction:column; gap:10px; flex:1; min-width:0; }
.bar-row{ display:flex; align-items:center; gap:10px; }
.bar-label{ min-width:72px; font-size:.85rem; color: var(--muted); flex-shrink:0; }
.bar-track{ flex:1; min-width:0; height:10px; border-radius:999px; background: rgba(255,255,255,.08); overflow:hidden; }
.bar-fill{ height:100%; border-radius:999px; transition: width .3s ease; }
.bar-fill.severity-critical{ background: rgba(255,92,92,.7); }
.bar-fill.severity-high{ background: rgba(255,140,0,.7); }
.bar-fill.severity-medium{ background: rgba(247,201,72,.6); }
.bar-fill.severity-low{ background: rgba(57,217,138,.6); }
.bar-value{ min-width:28px; font-size:.9rem; font-weight:600; color: var(--muted); text-align:right; flex-shrink:0; }
.defect-summary-row{ display:flex; align-items:stretch; gap:0; }
.defect-summary-block{ flex:1; padding:4px 0; display:flex; flex-direction:column; gap:2px; min-width:0; }
.defect-summary-block .card-metric-hint{ font-size:.8rem; }
.defect-summary-divider{ width:1px; background: var(--border); flex-shrink:0; margin:0 8px; }
.defect-summary-urgent .card-metric-value{ color: rgba(255,140,0,.95); }

/* Mobile & touch-friendly */
.mobile-menu-btn { display: none; }
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .dashboard-glance { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-charts { grid-template-columns: 1fr; }
  .defect-summary-row { flex-direction: column; }
  .defect-summary-divider { width: 100%; height: 1px; margin: 8px 0; }
  .spend-label { min-width: 100px; max-width: 140px; }
  .mobile-menu-btn {
    display: inline-flex; min-width: 44px; min-height: 44px; align-items: center; justify-content: center;
    font-size: 1.25rem; padding: 0;
  }
  .sidebar {
    position: fixed; top: 56px; left: 0; right: 0; bottom: auto;
    max-height: 0; overflow: hidden; opacity: 0; transition: max-height .25s ease, opacity .2s ease;
    z-index: 20; border-right: none; border-bottom: 1px solid var(--border);
    padding: 0 10px 10px; background: rgba(15,27,45,.97); backdrop-filter: blur(10px);
    display: block; flex-wrap: unset; gap: 0;
    box-shadow: 0 8px 24px rgba(0,0,0,.3);
  }
  .sidebar.sidebar-open { max-height: 80vh; overflow-y: auto; opacity: 1; }
  .sidebar .nav { display: block; padding: 12px 14px; font-size: 1rem; min-height: 44px; box-sizing: border-box; }
  .content { padding: 12px; max-width: 100%; }
  .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .row { gap: 8px; }
  .topbar { flex-wrap: wrap; padding: 10px 12px; }
  .brand-sub { font-size: .8rem; }
  .btn, .btn.ghost { min-height: 44px; padding: 10px 14px; }
  input, select, textarea { min-height: 44px; font-size: 16px; }
  .table { font-size: .9rem; }
  .table th, .table td { padding: 8px 6px; }
  .file-input { min-height: 44px; }
}
@media (max-width: 480px) {
  .topbar-right { width: 100%; justify-content: flex-end; }
  .card { padding: 12px; }
  .wbs-actions form { flex-wrap: wrap; }
}

