:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --secondary: #64748b;
    --success: #16a34a;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Navigation ── */
.navbar {
    background: var(--primary);
    color: #fff;
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-md);
}
.navbar-brand {
    font-size: 1.2rem;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: .4rem;
}
.navbar-brand span { opacity: .7; font-size: .85rem; font-weight: 400; }
.nav-links {
    display: flex;
    align-items: center;
    gap: .25rem;
    list-style: none;
}
.nav-links a {
    color: rgba(255,255,255,.85);
    text-decoration: none;
    padding: .35rem .7rem;
    border-radius: var(--radius);
    font-size: .9rem;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.nav-links a:hover,
.nav-links a.active { background: rgba(255,255,255,.15); color: #fff; }
.nav-user {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: rgba(255,255,255,.75);
    font-size: .85rem;
}
.nav-user a { color: rgba(255,255,255,.85); text-decoration: none; }
.nav-user a:hover { color: #fff; text-decoration: underline; }
.hamburger {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: .25rem;
}

/* ── Main layout ── */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: .75rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; }

/* ── Cards ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: .875rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-body { padding: 1.25rem; }

/* ── Stats row ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow);
}
.stat-card .stat-label { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; color: var(--primary); margin-top: .15rem; }
.stat-card .stat-sub { font-size: .8rem; color: var(--text-muted); margin-top: .1rem; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
thead th {
    background: #f1f5f9;
    padding: .6rem .875rem;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
thead th a { color: var(--text); text-decoration: none; }
thead th a:hover { color: var(--primary); }
tbody td { padding: .6rem .875rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
.td-actions { white-space: nowrap; text-align: right; }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .45rem .9rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s, border-color .15s, box-shadow .15s;
    white-space: nowrap;
    line-height: 1.4;
}
.btn:focus { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f1f5f9; }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { opacity: .9; }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-sm { padding: .25rem .6rem; font-size: .8rem; }
.btn-icon { padding: .3rem .5rem; }

/* ── Forms ── */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}
.form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: .3rem; }
.form-group label { font-size: .875rem; font-weight: 500; color: var(--text); }
.form-group label .required { color: var(--danger); margin-left: .2rem; }
.form-control {
    padding: .45rem .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: .9rem;
    background: var(--surface);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
    width: 100%;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: .8rem; color: var(--text-muted); }
.form-actions {
    display: flex;
    gap: .75rem;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

/* ── Alerts / Flash messages ── */
.alert {
    padding: .75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    border: 1px solid transparent;
    font-size: .9rem;
}
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-error   { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }

/* ── Badges ── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
    white-space: nowrap;
}
.badge-fdm     { background: #dbeafe; color: #1e40af; }
.badge-plotter { background: #d1fae5; color: #065f46; }
.badge-laser   { background: #fce7f3; color: #9d174d; }
.badge-sla     { background: #ede9fe; color: #5b21b6; }
.badge-ok      { background: #d1fae5; color: #065f46; }
.badge-retired { background: #fee2e2; color: #991b1b; }
.badge-admin   { background: #fef3c7; color: #92400e; }
.badge-demo    { background: #ff7a00; color: #fff; }

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: .25rem;
    border-radius: var(--radius);
}
.modal-close:hover { background: #f1f5f9; color: var(--text); }
.modal-body { padding: 1.25rem; }

/* ── Warning button variant ── */
.btn-warn-red { color: #dc2626 !important; border-color: #dc2626 !important; }
.btn-warn-red:hover { background: #fee2e2 !important; }

/* ── Log material rows ── */
.material-row {
    display: grid;
    grid-template-columns: 2fr 1fr auto;
    gap: .5rem;
    align-items: end;
    margin-bottom: .5rem;
}
.material-row-header {
    display: grid;
    grid-template-columns: 2fr 1fr auto;
    gap: .5rem;
    margin-bottom: .25rem;
}
.material-row-header span { font-size: .8rem; font-weight: 600; color: var(--text-muted); }

/* ── Sortable header arrows ── */
.sort-icon { font-size: .75rem; vertical-align: middle; }

/* ── Pagination / filters ── */
.filters { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; align-items: flex-end; }
.filters .form-group { min-width: 150px; }

/* ── Login page ── */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2rem;
    width: 100%;
    max-width: 380px;
}
.login-logo {
    text-align: center;
    margin-bottom: 1.5rem;
}
.login-logo h1 { font-size: 1.6rem; font-weight: 800; color: var(--primary); }
.login-logo p { color: var(--text-muted); font-size: .9rem; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .hamburger { display: block; }
    .nav-links {
        display: none;
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        background: var(--primary);
        flex-direction: column;
        padding: .75rem;
        gap: .25rem;
        z-index: 99;
    }
    .nav-links.open { display: flex; }
    .nav-links a { width: 100%; padding: .6rem .9rem; }
    .nav-user { display: none; }
    .form-grid.cols-2,
    .form-grid.cols-3 { grid-template-columns: 1fr; }
    .material-row { grid-template-columns: 1fr 1fr auto; }
    .page-header h1 { font-size: 1.2rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .container { padding: 1rem; }
    table { font-size: .8rem; }
    thead th, tbody td { padding: .5rem .6rem; }
}

/* ── Misc ── */
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mt-1 { margin-top: .5rem; }
.gap-1 { gap: .5rem; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
hr.divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
