:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --nav: #1e293b;
  --nav-text: #94a3b8;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #3b82f6;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --ok-bg: #dcfce7;
  --warn-bg: #fef9c3;
  --danger-bg: #fee2e2;
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── Nav ── */
nav {
  background: var(--nav);
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
}
nav a { color: var(--nav-text); text-decoration: none; font-size: 14px; }
nav a:hover, nav a.active { color: #fff; }
nav .brand { color: #fff; font-weight: 600; font-size: 16px; margin-right: 1rem; }
nav .logout { margin-left: auto; }

/* ── Layout ── */
main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.page-header h2 { font-size: 1.25rem; font-weight: 600; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 2rem 0 1rem;
}
.section-header h2 { font-size: 1.1rem; font-weight: 600; }
.section-header a { font-size: 13px; color: var(--primary); text-decoration: none; }

/* ── Cards ── */
.cards {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.material-card {
  min-width: 160px;
  flex: 1 1 160px;
  max-width: 220px;
}
.mat-name { font-weight: 600; font-size: 1rem; margin-bottom: 0.25rem; }
.mat-weight { font-size: 1.75rem; font-weight: 700; line-height: 1.1; }
.mat-spools { color: var(--muted); font-size: 12px; margin-bottom: 0.75rem; }

/* ── Progress bar ── */
.progress {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 4px;
}
.bar { height: 100%; border-radius: 3px; transition: width 0.3s; }
.bar-ok { background: var(--ok); }
.bar-warn { background: var(--warn); }
.bar-danger { background: var(--danger); }
.pct-label { font-size: 12px; color: var(--muted); }
.text-warn { color: var(--warn); }
.text-danger { color: var(--danger); }

/* ── Table ── */
.table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
}
table { width: 100%; border-collapse: collapse; }
th {
  background: var(--bg);
  text-align: left;
  padding: 0.6rem 1rem;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr.row-unassigned { background: #fffbeb; }
.job-name { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  background: #e2e8f0;
  color: var(--text);
}
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }

/* ── Buttons ── */
.btn {
  display: inline-block;
  padding: 0.4rem 0.9rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { opacity: 0.88; }
.btn-secondary {
  background: var(--border);
  color: var(--text);
}
.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-sm:hover { opacity: 0.88; }
.btn-danger { background: var(--danger); color: #fff; }

/* ── Forms ── */
.form-card { margin-bottom: 1.25rem; }
.form-card h3 { margin-bottom: 1rem; font-size: 1rem; }
.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}
.grid-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
.grid-form input {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
}
.grid-form input:focus { outline: 2px solid var(--primary); border-color: transparent; }
.form-actions { display: flex; align-items: flex-end; gap: 0.5rem; grid-column: 1 / -1; }
.hidden { display: none; }

.filter-bar { margin-bottom: 1rem; }
.filter-bar select {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
}

.weight-form { display: flex; align-items: center; gap: 4px; }
.weight-input { width: 80px; padding: 0.25rem 0.4rem; border: 1px solid var(--border); border-radius: 5px; font-size: 13px; }

.assign-form { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.assign-form select {
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 12px;
  max-width: 200px;
}
.weight-input-sm { width: 60px; padding: 0.25rem 0.4rem; border: 1px solid var(--border); border-radius: 5px; font-size: 12px; }

.inline-form { display: inline-flex; gap: 0.5rem; }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 6px !important; }

.play-link { color: var(--primary); text-decoration: none; font-size: 13px; white-space: nowrap; }
.play-link:hover { text-decoration: underline; }

.spool-cell { min-width: 260px; }
.assignment-row { display: flex; align-items: center; gap: 4px; margin-bottom: 4px; flex-wrap: wrap; }
.tool-hint { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; }
.label-input { width: 70px; padding: 0.25rem 0.4rem; border: 1px solid var(--border); border-radius: 5px; font-size: 12px; }
.btn-xs { padding: 1px 5px; font-size: 11px; background: var(--danger); color: #fff; border: none; border-radius: 4px; cursor: pointer; line-height: 1.4; }
.btn-xs:hover { opacity: 0.85; }

/* ── Video modal ── */
.vid-modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  background: #000;
  max-width: 90vw;
  max-height: 90vh;
  box-shadow: 0 25px 60px rgba(0,0,0,0.5);
}
.vid-modal::backdrop { background: rgba(0,0,0,0.75); }
.vid-modal video { display: block; max-width: 90vw; max-height: 80vh; }
.close-btn {
  display: block;
  width: 100%;
  padding: 0.5rem;
  background: #111;
  color: #ccc;
  border: none;
  cursor: pointer;
  font-size: 13px;
}
.close-btn:hover { background: #222; color: #fff; }

/* ── Login ── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--nav);
}
.login-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 320px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
.login-card h1 { font-size: 1.25rem; margin-bottom: 1.5rem; }
.login-card input[type=password] {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 0.75rem;
}
.login-card button {
  width: 100%;
  padding: 0.5rem;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.error { color: var(--danger); font-size: 13px; margin-bottom: 0.75rem; }
