:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #64748b;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --green: #16a34a;
    --blue: #2563eb;
    --orange: #ea580c;
    --red: #dc2626;
    --gray: #64748b;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0 0 8px; }
p { margin: 4px 0; }

/* === Topbar === */
.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    flex-wrap: wrap;
}
.brand { font-size: 18px; font-weight: 700; color: var(--text); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a {
    color: var(--secondary);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 14px;
    white-space: nowrap;
}
.nav a:hover { background: var(--bg); color: var(--text); }
.user-area { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.user-name { font-size: 14px; color: var(--secondary); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* === Container === */
.container { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* === Page head === */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
    text-align: center;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: #fff; color: var(--red); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-small { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* Microsoft button */
.btn-ms { background: #fff; color: #1b1b1b; border: 1px solid #d1d5db; font-weight: 600; }
.btn-ms:hover { background: #f9fafb; }
.ms-logo { display: inline-block; width: 18px; height: 18px; flex-shrink: 0; }

/* === QR-Scanner === */
.scanner-box { margin-bottom: 12px; }
.scanner-video-wrap {
    position: relative;
    width: 100%;
    max-width: 420px;
    margin: 12px auto;
    aspect-ratio: 4/3;
    background: #000;
    border-radius: 10px;
    overflow: hidden;
}
.scanner-video-wrap video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.scanner-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}
.scanner-frame {
    width: 60%;
    aspect-ratio: 1;
    border: 3px solid #4ade80;
    border-radius: 12px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.25);
}
#scannerStatus { text-align: center; margin: 8px 0; }

/* === Forms === */
.form { display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-full { grid-column: 1 / -1; }
.label { font-size: 13px; font-weight: 600; color: var(--secondary); }
.label.small { font-weight: 500; }
.input {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    width: 100%;
    background: #fff;
    color: var(--text);
}
.input:focus { outline: 2px solid var(--primary); border-color: transparent; }
.input-inv { font-size: 20px; text-transform: uppercase; letter-spacing: 1px; text-align: center; }
.input-inline { width: auto; padding: 5px 8px; font-size: 13px; }
textarea.input { resize: vertical; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.date-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* === Card / box === */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.box { border-radius: 8px; padding: 12px; font-size: 14px; }
.box-ok { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.box-warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }

/* === Alerts === */
.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }

/* === Badges === */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-green { background: #dcfce7; color: #166534; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* === Item grid === */
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.item-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    color: var(--text);
    transition: box-shadow .15s;
    display: block;
}
.item-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.item-img { width: 100%; aspect-ratio: 4/3; background: #f8fafc; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.item-img img { width: 100%; height: 100%; object-fit: cover; }
.item-img-placeholder { font-size: 48px; opacity: .4; }
.item-img-placeholder.large { font-size: 96px; }
.item-body { padding: 12px; }
.item-invnr { font-size: 12px; color: var(--muted); font-weight: 700; letter-spacing: .5px; }
.item-title { font-weight: 600; font-size: 15px; margin-top: 2px; }
.item-meta { display: flex; align-items: center; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.item-status { margin-top: 8px; font-size: 13px; font-weight: 600; }
.item-status.available { color: var(--green); }
.item-status.unavailable { color: var(--orange); }

/* === Detail === */
.detail-card { display: grid; grid-template-columns: 280px 1fr; gap: 20px; }
.detail-img img { width: 100%; border-radius: 8px; }
.detail-invnr { font-size: 13px; color: var(--muted); font-weight: 700; letter-spacing: 1px; }
.detail-meta { display: flex; gap: 10px; margin: 8px 0; flex-wrap: wrap; }

/* === Filters === */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters .input { width: auto; flex: 1; min-width: 140px; }

/* === Tables === */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 12px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: none; }
.actions { white-space: nowrap; }

/* === Lists === */
.list { list-style: none; padding: 0; margin: 0; }
.list-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }

/* === Tabs === */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab {
    padding: 10px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 14px;
    font-weight: 600;
    color: var(--secondary);
    cursor: pointer;
    white-space: nowrap;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.filter-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.filter-tab { padding: 6px 14px; border-radius: 999px; background: #fff; border: 1px solid var(--border); font-size: 13px; color: var(--secondary); }
.filter-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* === Login === */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 14px; padding: 28px; box-shadow: 0 8px 30px rgba(0,0,0,.08); }
.login-logo { text-align: center; font-size: 24px; margin-bottom: 4px; }
.login-sub { text-align: center; color: var(--muted); margin-bottom: 20px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 16px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* === Misc === */
.footer { text-align: center; padding: 20px; color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 24px; }
.section-title { font-size: 18px; margin: 20px 0 12px; }
.thumb-preview { margin-bottom: 8px; }
.thumb-preview img { width: 120px; height: 90px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }

.loan-card { margin-bottom: 14px; }
.loan-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.loan-body { font-size: 14px; }
.loan-actions { display: flex; gap: 8px; margin-top: 12px; }

/* === Responsive === */
@media (max-width: 640px) {
    .detail-card { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .date-row { grid-template-columns: 1fr; }
    .user-name { display: none; }
    .nav { order: 3; width: 100%; }
    .filters .input { min-width: 100%; }
    .item-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .page-head h1 { font-size: 19px; }
}
