/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --brand:        #CC0000;
    --brand-dark:   #a00000;
    --brand-light:  #fff0f0;
    --sidebar-bg:   #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-active-bg: rgba(255,255,255,0.08);
    --sidebar-active-text: #ffffff;
    --bg:           #f1f5f9;
    --surface:      #ffffff;
    --border:       #e2e8f0;
    --text:         #0f172a;
    --text-muted:   #64748b;
    --danger:       #dc2626;
    --success:      #16a34a;
    --warning:      #d97706;
    --radius:       8px;
    --shadow:       0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:    0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.04);
}

html { font-size: 16px; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 50;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 24px 20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-brand img {
    height: 36px;
    width: auto;
    object-fit: contain;
    flex-shrink: 0;
}

.sidebar-brand-name {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    line-height: 1.3;
}

.sidebar-brand-sub {
    font-size: 11px;
    color: var(--sidebar-text);
    margin-top: 2px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
}

.sidebar-section {
    padding: 16px 16px 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #475569;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    font-size: 13.5px;
    color: var(--sidebar-text);
    transition: background 0.15s, color 0.15s;
    border-radius: 0;
    text-decoration: none;
    margin: 1px 8px;
    border-radius: 6px;
}

.sidebar-link:hover {
    background: var(--sidebar-active-bg);
    color: #fff;
    text-decoration: none;
}

.sidebar-link.active {
    background: var(--brand);
    color: #fff;
}

.sidebar-link svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.sidebar-link.active svg,
.sidebar-link:hover svg {
    opacity: 1;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255,255,255,0.06);
    font-size: 12px;
    color: #475569;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.sidebar-avatar {
    width: 32px;
    height: 32px;
    background: var(--brand);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 500;
    color: #cbd5e1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 11px;
    color: #475569;
}

/* ── Main content ────────────────────────────────────────────────────────── */
.main {
    flex: 1;
    margin-left: 240px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 32px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 40;
}

.topbar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.content {
    flex: 1;
    padding: 32px;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.card-body {
    padding: 24px;
}

/* ── Stat cards ──────────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    box-shadow: var(--shadow);
}

.stat-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.stat-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

.stat-card.accent { border-left: 3px solid var(--brand); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13.5px;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    text-decoration: none;
    white-space: nowrap;
    font-family: inherit;
    line-height: 1.4;
}

.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
}
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg); }

.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; color: #fff; }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border-color: transparent;
}
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-sm {
    padding: 5px 10px;
    font-size: 12.5px;
}

.btn-lg {
    padding: 11px 24px;
    font-size: 15px;
}

.btn[disabled], .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 6px;
}

.form-label .optional {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 12px;
    margin-left: 4px;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.15s, box-shadow 0.15s;
    line-height: 1.5;
}

.form-control:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(204,0,0,0.1);
}

.form-control::placeholder { color: #94a3b8; }

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 5px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-top: 8px;
}

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead th {
    text-align: left;
    padding: 10px 16px;
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

tbody td {
    padding: 13px 16px;
    vertical-align: middle;
    color: var(--text);
}

.td-muted { color: var(--text-muted); font-size: 13px; }

.table-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
}

.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-green  { background: #dcfce7; color: #166534; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-grey   { background: #f1f5f9; color: #475569; }
.badge-orange { background: #ffedd5; color: #9a3412; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 20px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.alert-danger  { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.alert-info    { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}

.page-sub {
    font-size: 13.5px;
    color: var(--text-muted);
    margin-top: 3px;
}

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 24px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 40px;
    margin-bottom: 16px;
    opacity: 0.4;
}

.empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.empty-state p {
    font-size: 14px;
    margin-bottom: 20px;
}

/* ── Items inline form ───────────────────────────────────────────────────── */
.items-table .part-code { font-family: monospace; font-size: 13.5px; font-weight: 600; }
.items-table .qty-cell  { width: 80px; text-align: center; }

.inline-add-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    padding: 16px;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

.inline-add-form .form-group { margin-bottom: 0; }
.inline-add-form .form-control { min-width: 0; }

/* ── Colour preview ──────────────────────────────────────────────────────── */
.colour-preview {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: inline-block;
    vertical-align: middle;
    margin-left: 8px;
}

/* ── Logo upload ─────────────────────────────────────────────────────────── */
.logo-preview {
    max-height: 60px;
    max-width: 200px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    background: var(--bg);
}

/* ── Login page ──────────────────────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--sidebar-bg);
    padding: 24px;
}

.login-box {
    background: var(--surface);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-logo img {
    max-height: 56px;
    max-width: 180px;
    object-fit: contain;
}

.login-logo-name {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
    margin-top: 10px;
}

.login-logo-sub {
    font-size: 13px;
    color: var(--text-muted);
}

/* ── Scan log ────────────────────────────────────────────────────────────── */
.scan-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

/* ── Utilities ───────────────────────────────────────────────────────────── */
.text-muted   { color: var(--text-muted); }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.font-mono    { font-family: monospace; }
.font-bold    { font-weight: 700; }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.d-flex { display: flex; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.align-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: 24px 0;
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .main    { margin-left: 0; }
    .form-row { grid-template-columns: 1fr; }
    .content  { padding: 16px; }
}
