:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #dfe3e8;
  --dark: #18212b;
  --dark-2: #24313e;
  --accent: #2f6fed;
  --danger: #c23b3b;
  --warn: #b7791f;
  --ok: #2f855a;
  --radius: 12px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
a { color: inherit; text-decoration: none; }
.topbar {
  background: var(--dark);
  color: #fff;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 20px;
}
.brand { font-weight: 750; letter-spacing: .2px; }
.brand small { display: block; color: #aeb8c4; font-weight: 400; margin-top: 2px; }
.nav { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.nav a { color: #e8edf2; }
.nav .admin-link { color: #aeb8c4; }
.container { max-width: 1280px; margin: 0 auto; padding: 28px 20px 48px; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}
.page-head h1 { margin: 0; font-size: 27px; }
.page-head p { margin: 7px 0 0; color: var(--muted); }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 650;
  font-size: 14px;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
}
.btn.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.danger { background: var(--danger); }
.grid { display: grid; gap: 16px; }
.metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 20px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 3px 14px rgba(27, 39, 51, .04);
}
.metric-label { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.metric-value { font-size: 30px; line-height: 1; font-weight: 760; }
.metric-note { color: var(--muted); font-size: 12px; margin-top: 8px; }
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 26px 0 12px;
}
.section-title h2 { margin: 0; font-size: 19px; }
.project-list { display: grid; gap: 12px; }
.project-row {
  display: grid;
  grid-template-columns: minmax(220px, 1.5fr) 1fr .7fr .7fr;
  align-items: center;
  gap: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
}
.project-row:hover { border-color: #bcc6d1; }
.project-name { font-weight: 720; }
.subtle { color: var(--muted); font-size: 13px; }
.progress { height: 8px; background: #edf0f3; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }
.badge { display: inline-flex; padding: 5px 8px; border-radius: 999px; font-size: 12px; font-weight: 650; }
.badge.active, .badge.in_progress { background: #e8f0ff; color: #285fca; }
.badge.completed, .badge.accepted { background: #e6f5ed; color: var(--ok); }
.badge.blocked { background: #fdeaea; color: var(--danger); }
.badge.paused, .badge.not_started { background: #f0f2f4; color: #5f6872; }
.badge.preparation { background: #fff3d8; color: #8b6115; }
.badge.archive { background: #eceff2; color: #626b75; }
.danger-text { color: var(--danger); font-weight: 700; }
.filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr)) auto;
  gap: 10px;
  margin-bottom: 14px;
}
input, select, textarea {
  width: 100%;
  border: 1px solid #cfd5dc;
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
label { display: block; font-size: 13px; font-weight: 650; margin-bottom: 6px; }
.form-row { margin-bottom: 14px; }
.form-card { max-width: 820px; }
.helptext { color: var(--muted); font-size: 12px; }
.errorlist { color: var(--danger); margin: 6px 0; padding-left: 18px; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; min-width: 900px; }
th, td { padding: 12px 13px; border-bottom: 1px solid #edf0f2; text-align: left; vertical-align: top; }
th { background: var(--dark-2); color: #fff; font-size: 12px; font-weight: 650; }
td { font-size: 13px; }
tr:last-child td { border-bottom: 0; }
.empty { padding: 28px; color: var(--muted); text-align: center; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(420px, 100%); background: #fff; padding: 28px; border-radius: 14px; border: 1px solid var(--line); }
.login-card h1 { margin: 0 0 6px; }
.login-card p { color: var(--muted); margin: 0 0 22px; }
@media (max-width: 900px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .project-row { grid-template-columns: 1fr 1fr; }
  .filters { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
  .topbar { padding: 0 16px; }
  .nav .admin-link { display: none; }
  .container { padding: 20px 12px 36px; }
  .page-head { flex-direction: column; }
  .metrics, .project-row, .filters { grid-template-columns: 1fr; }
  .metric-value { font-size: 26px; }
}

.login-shell {
  min-height: calc(100vh - 120px);
  display: grid;
  place-items: center;
  padding: 32px 0;
}
.login-card { width: min(440px, 100%); padding: 32px; }
.login-card h1 { margin: 12px 0 8px; font-size: 28px; }
.login-mark {
  width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center; font-weight: 800;
  background: #171b21; color: #fff; letter-spacing: .04em;
}
.alert { padding: 12px 14px; border-radius: 10px; margin: 16px 0; }
.alert.danger { background: #fff0f0; color: #9b1c1c; border: 1px solid #ffd0d0; }
.full { width: 100%; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.date-bar {
  display: grid;
  grid-template-columns: minmax(180px, 260px) auto;
  gap: 10px;
  margin-bottom: 14px;
}
.save-bar { display: flex; justify-content: flex-end; margin-top: 14px; }
.attendance-table select { min-width: 130px; }
.attendance-table input { min-width: 180px; }
.form-row ul { list-style: none; padding: 0; margin: 6px 0 0; }
.form-row ul li { margin: 4px 0; }
.form-row ul input[type="checkbox"] { width: auto; margin-right: 8px; }
@media (max-width: 600px) {
  .date-bar { grid-template-columns: 1fr; }
  .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; }
}

.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.badge.priority-normal { background: #f0f2f4; color: #5f6872; }
.badge.priority-high { background: #fff3d8; color: #8b6115; }
.badge.priority-urgent { background: #fdeaea; color: var(--danger); }
.badge.request-new { background: #e8f0ff; color: #285fca; }
.badge.request-approved { background: #e8f0ff; color: #285fca; }
.badge.request-ordered { background: #fff3d8; color: #8b6115; }
.badge.request-partial { background: #fff3d8; color: #8b6115; }
.badge.request-received { background: #e6f5ed; color: var(--ok); }
.badge.request-cancelled { background: #eceff2; color: #626b75; }

.badge.new { background: #fff3d8; color: #8b6115; }
.badge.fixed { background: #e8f0ff; color: #285fca; }
.badge.review { background: #f3e8ff; color: #6b3fa0; }
.badge.signed { background: #e6f5ed; color: var(--ok); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 600px) {
  .actions { width: 100%; }
  .actions .btn { flex: 1 1 auto; }
  .table-wrap { margin-left: -2px; margin-right: -2px; }
}

.location-box { margin: 18px 0; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: #fafbfc; }
.location-box h3 { margin: 0 0 14px; font-size: 16px; }
.toggle-line { display: flex; align-items: center; gap: 8px; margin: 12px 0; }
.toggle-line input[type="checkbox"] { width: auto; margin: 0; }
.toggle-line label { margin: 0; }
.checklist ul { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 7px; }
.checklist li label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.checklist input[type="checkbox"] { width: auto; margin: 0; }

.matrix-legend{display:flex;gap:16px;flex-wrap:wrap;margin:12px 0 16px;color:#667085;font-size:13px}
.matrix-legend span{display:inline-flex;align-items:center;gap:6px}
.matrix-dot{width:10px;height:10px;border-radius:50%;display:inline-block;background:#d0d5dd}
.matrix-dot.done,.matrix-cell.done{background:#ecfdf3}
.matrix-dot.active,.matrix-cell.active{background:#eff8ff}
.matrix-dot.start,.matrix-cell.start{background:#fffaeb}
.matrix-dot.danger,.matrix-cell.danger{background:#fef3f2}
.matrix-dot.empty,.matrix-cell.empty{background:#f9fafb}
.matrix-wrap{overflow:auto;border:1px solid #eaecf0;border-radius:14px;background:#fff}
.progress-matrix{min-width:1120px;margin:0}
.progress-matrix th{position:sticky;top:0;z-index:2;background:#f8fafc;text-align:center;white-space:nowrap}
.progress-matrix th.matrix-zone{text-align:left}
.progress-matrix td{vertical-align:middle}
.matrix-row.section td{border-top:2px solid #d0d5dd;background:#f8fafc;font-weight:600}
.matrix-row.floor td:first-child,.matrix-row.floor td:nth-child(2),.matrix-row.floor td:nth-child(3){background:#fcfcfd}
.room-indent{padding-left:14px}
.matrix-cell{text-align:center;min-width:118px;border-left:1px solid #f2f4f7}
.matrix-cell strong{display:block;font-size:16px}
.matrix-cell small{display:block;margin-top:3px;color:#667085;font-size:11px;white-space:nowrap}
.matrix-cell.danger strong{color:#b42318}
.matrix-cell.done strong{color:#067647}
.matrix-empty-mark{color:#98a2b3}
.matrix-note{margin-top:14px;font-size:13px;color:#475467}

.matrix-cell{padding:0!important}
.matrix-cell-link{
  display:block;
  min-height:64px;
  padding:12px 10px;
  border-radius:6px;
  transition:box-shadow .15s ease, transform .15s ease;
}
.matrix-cell-link:hover{
  box-shadow:inset 0 0 0 2px rgba(47,111,237,.32);
  transform:translateY(-1px);
}
.matrix-cell-link:focus-visible{
  outline:2px solid var(--accent);
  outline-offset:-2px;
}
.matrix-detail{margin-top:28px;scroll-margin-top:18px}
.matrix-detail-metrics{margin-bottom:14px}
.matrix-detail .table-wrap table{min-width:920px}

/* Matrix contrast fix */
.progress-matrix thead th {
  background: #dfe7f1;
  color: #172033;
  font-weight: 750;
  border-bottom: 2px solid #c4ceda;
}
.progress-matrix tbody td {
  color: #172033;
  border-bottom: 1px solid #e2e8f0;
}
.progress-matrix tbody tr:hover td {
  background-color: #f7f9fc;
}
.matrix-cell small,
.matrix-cell .subtle,
.matrix-cell a {
  color: #526078;
}
.matrix-empty-mark {
  color: #7b879a;
}

/* Matrix header high-contrast override */
.progress-matrix thead th {
  background: #24313e !important;
  color: #ffffff !important;
  border-bottom: 2px solid #17212b !important;
}
.progress-matrix thead th.matrix-zone {
  color: #ffffff !important;
}
.progress-matrix tbody td {
  border-right: 1px solid #e3e8ef;
}
.progress-matrix tbody tr:nth-child(even) td {
  background-color: #fbfcfe;
}

/* Warehouse journal and nomenclature card */
.movement-filters{grid-template-columns:2fr 1fr 1fr 1.5fr 1fr 1fr auto auto}
.movement-metrics{grid-template-columns:repeat(4,minmax(0,1fr))}
.movement-table{min-width:1380px}
.badge.movement-receipt{background:#e6f5ed;color:var(--ok)}
.badge.movement-issue{background:#e8f0ff;color:#285fca}
.badge.movement-return{background:#f3e8ff;color:#6b3fa0}
.badge.movement-writeoff{background:#fdeaea;color:var(--danger)}
.badge.movement-transfer{background:#fff3d8;color:#8b6115}
.material-price{font-size:22px}
.material-card-info{margin-bottom:20px}
.material-info-grid{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:16px}
.material-info-grid span{display:block;color:var(--muted);font-size:12px;margin-bottom:5px}
.material-info-grid strong{font-size:14px}
.material-notes{border-top:1px solid var(--line);margin-top:16px;padding-top:14px;color:#475467}
@media(max-width:1000px){.movement-filters{grid-template-columns:repeat(2,minmax(0,1fr))}.material-info-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
@media(max-width:600px){.movement-filters,.movement-metrics,.material-info-grid{grid-template-columns:1fr}}
.journal-pagination{display:flex;align-items:center;justify-content:center;gap:12px;margin-top:16px}
.journal-pagination span{color:var(--muted);font-size:13px}
@media(max-width:600px){.journal-pagination{justify-content:space-between}.journal-pagination .btn{flex:0 0 auto}}

/* Stock documents */
.form-grid.two-col{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:14px 18px}
.stock-document-form .section-title{margin-top:22px}
.stock-document-form table select{min-width:260px}
.stock-document-form table input[type=number]{min-width:110px}
.document-total{text-align:right;font-size:18px;margin:14px 4px 18px}
.document-total strong{font-size:22px}
.quick-doc-actions{display:flex;gap:10px;flex-wrap:wrap;margin:12px 0 18px}
.quick-doc-actions a{padding:7px 11px;border:1px solid #d7dee8;border-radius:8px;background:#fff}
.document-meta{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:12px;margin:16px 0}
.link-button{border:0;background:none;color:var(--accent);cursor:pointer;padding:4px}
@media(max-width:760px){.form-grid.two-col,.document-meta{grid-template-columns:1fr}.stock-document-form table{min-width:760px}}
