/* BorrowBox — theme + layout. Colors are driven by CSS variables so
   themes swap by flipping [data-theme] on <html>. */

:root {
    /* Brand (from the BorrowBox logo) */
    --brand-green: #3ecf8e;
    --brand-navy: #1d2b4f;
    --font-brand: "Arial Rounded MT Bold", ui-rounded, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
    --maxw: 1100px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --transition: .18s ease;
}

/* ---- Light theme ---- */
[data-theme="light"] {
    --logo-ink: #1d2b4f;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f1f3f5;
    --text: #1a1d21;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-contrast: #ffffff;
    --ok-bg: #dcfce7; --ok-fg: #166534;
    --busy-bg: #fee2e2; --busy-fg: #991b1b;
    --flash-error-bg:#fef2f2; --flash-error-fg:#991b1b; --flash-error-bd:#fecaca;
    --flash-success-bg:#f0fdf4; --flash-success-fg:#166534; --flash-success-bd:#bbf7d0;
}

/* ---- Dark theme ---- */
[data-theme="dark"] {
    --logo-ink: #ffffff;
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --text: #e7e9ee;
    --text-muted: #9aa2b1;
    --border: #2a2f3a;
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --primary-contrast: #10131a;
    --ok-bg: #10331f; --ok-fg: #86efac;
    --busy-bg: #3a1618; --busy-fg: #fca5a5;
    --flash-error-bg:#2a1416; --flash-error-fg:#fca5a5; --flash-error-bd:#7f1d1d;
    --flash-success-bg:#0f2a1a; --flash-success-fg:#86efac; --flash-success-bd:#166534;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

/* ---- Top bar ---- */
.topbar {
    display: flex; align-items: center; gap: 20px;
    padding: 12px 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
    flex-wrap: wrap;
}
.topbar-menu { display: flex; align-items: center; gap: 20px; flex: 1; min-width: 0; }
.nav-toggle { display: none; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--text); }
.brand:hover { text-decoration: none; }
.bb-logo { display: block; flex-shrink: 0; }
.brand-word { font-family: var(--font-brand); font-weight: 800; font-size: 1.22rem; letter-spacing: -.01em; }
.brand-borrow { color: var(--logo-ink); }
.brand-box { color: var(--brand-green); }
.nav { display: flex; gap: 18px; }
.nav a { color: var(--text-muted); font-weight: 500; }
.nav a:hover { color: var(--text); text-decoration: none; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.user-chip { color: var(--text-muted); font-size: .9rem; }
.theme-toggle {
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 999px; width: 34px; height: 34px; cursor: pointer; font-size: 1rem;
}

/* ---- Layout ---- */
.container { max-width: var(--maxw); margin: 0 auto; padding: 28px 22px 60px; }
.page-head { margin-bottom: 22px; }
.page-head h1 { margin: 0 0 4px; font-size: 1.7rem; }
.page-head.center { text-align: center; padding-top: 60px; }
.muted { color: var(--text-muted); }
.footer { text-align: center; color: var(--text-muted); padding: 30px; font-size: .85rem; }

/* ---- Buttons ---- */
.btn {
    display: inline-block; border: 1px solid transparent; border-radius: var(--radius-sm);
    padding: 9px 16px; font-size: .95rem; font-weight: 600; cursor: pointer;
    transition: var(--transition); font-family: inherit;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.inline { display: inline; }

/* ---- Flash ---- */
.flash { padding: 11px 15px; border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid; font-size: .92rem; }
.flash-error { background: var(--flash-error-bg); color: var(--flash-error-fg); border-color: var(--flash-error-bd); }
.flash-success { background: var(--flash-success-bg); color: var(--flash-success-fg); border-color: var(--flash-success-bd); }

/* ---- Auth ---- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 34px; width: 100%; max-width: 380px; box-shadow: var(--shadow);
}
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 26px; text-align: center; }
.auth-brand .brand-word { font-family: var(--font-brand); font-weight: 800; font-size: 1.9rem; letter-spacing: -.01em; }
.auth-tagline {
    margin: 2px 0 0; color: var(--text-muted); font-size: .78rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .13em;
}
.auth-tagline i { font-style: normal; color: var(--brand-green); }

/* ---- Forms ---- */
.stack { display: flex; flex-direction: column; gap: 14px; }
label span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 5px; color: var(--text-muted); }
input, select, textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font-family: inherit; font-size: .95rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.search-form { display: flex; gap: 8px; margin-top: 12px; }
.search-form input { max-width: 320px; }

/* ---- Stats ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 20px; display: flex; flex-direction: column; gap: 4px; color: var(--text); transition: var(--transition);
}
.stat-card:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-num { font-size: 2rem; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: .9rem; }
.stat-card-alert { border-color: var(--primary); }
.cta-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 24px; }

/* ---- Chips / categories ---- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 24px; }
.chip {
    padding: 6px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
    color: var(--text-muted); font-size: .88rem; font-weight: 500;
}
.chip:hover { text-decoration: none; color: var(--text); }
.chip-active { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }

/* ---- Cards ---- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.item-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden; color: var(--text); transition: var(--transition);
}
.item-card:hover { text-decoration: none; transform: translateY(-3px); box-shadow: var(--shadow); }
.item-thumb { position: relative; aspect-ratio: 1/1; background: var(--surface-2); display: grid; place-items: center; }
.item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-placeholder { font-size: 2.5rem; opacity: .5; }
.item-body { padding: 14px; }
.item-body h3 { margin: 0 0 4px; font-size: 1.02rem; }
.item-meta { color: var(--text-muted); font-size: .82rem; margin: 0 0 2px; }
.item-owner { color: var(--text-muted); font-size: .8rem; margin: 0; }
.badge {
    display: inline-block; padding: 3px 9px; border-radius: 999px;
    font-size: .72rem; font-weight: 700;
}
.item-thumb .badge { position: absolute; top: 10px; left: 10px; }
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-busy { background: var(--busy-bg); color: var(--busy-fg); }
.empty { color: var(--text-muted); padding: 40px 0; text-align: center; }

/* ---- Item detail ---- */
.back-link { display: inline-block; margin-bottom: 16px; color: var(--text-muted); }
.item-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 34px; align-items: start; }
.gallery-main { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: var(--radius); background: var(--surface-2); }
.gallery-empty { display: grid; place-items: center; font-size: 4rem; opacity: .4; }
.gallery-thumbs { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.gallery-thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.item-info h1 { margin: 8px 0 2px; }
.detail-list { margin: 20px 0; display: grid; gap: 0; }
.detail-list > div { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
.detail-list dt { color: var(--text-muted); margin: 0; }
.detail-list dd { margin: 0; font-weight: 500; text-align: right; }
.item-description { color: var(--text); margin: 16px 0; }

/* ---- Forms (item add/edit) ---- */
.form-narrow { max-width: 560px; }
.field-label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
textarea { resize: vertical; }

.existing-images { display: flex; flex-wrap: wrap; gap: 12px; }
.existing-image { position: relative; width: 110px; font-size: .75rem; }
.existing-image img { width: 110px; height: 110px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); display: block; }
.existing-image .remove-tag { display: block; margin-top: 4px; color: var(--text-muted); }
.existing-image .primary-tag { position: absolute; top: 6px; left: 6px; background: var(--primary); color: var(--primary-contrast); padding: 1px 7px; border-radius: 999px; font-size: .68rem; font-weight: 700; }

/* ---- Cropper ---- */
.cropper-previews { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.cropper-preview { position: relative; width: 96px; height: 96px; }
.cropper-preview img { width: 96px; height: 96px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.cropper-remove {
    position: absolute; top: -8px; right: -8px; width: 24px; height: 24px; border-radius: 999px;
    border: 0; background: var(--busy-fg); color: #fff; cursor: pointer; font-size: 1rem; line-height: 1;
}
.cropper-modal {
    position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 100; padding: 20px;
}
.cropper-dialog { background: var(--surface); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.cropper-dialog h3 { margin: 0 0 14px; }
.cropper-stage { border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2); touch-action: none; cursor: grab; }
.cropper-stage canvas { display: block; }
.cropper-stage:active { cursor: grabbing; }
.cropper-zoom { display: flex; align-items: center; gap: 10px; margin: 14px 0; }
.cropper-zoom span { font-size: .85rem; color: var(--text-muted); }
.cropper-zoom input { flex: 1; }
.cropper-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---- Row actions (cards, tables) ---- */
.row-actions { display: flex; align-items: center; gap: 14px; margin-top: 10px; font-size: .88rem; }
.row-actions form { display: inline; }
.link-danger { background: none; border: 0; color: var(--busy-fg); cursor: pointer; font: inherit; padding: 0; }
.link-danger:hover { text-decoration: underline; }

/* ---- Tables (loans, admin) ---- */
.tbl { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tbl th, .tbl td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: .92rem; vertical-align: middle; }
.tbl th { background: var(--surface-2); color: var(--text-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .74rem; font-weight: 700; }
.pill-requested { background: var(--busy-bg); color: var(--busy-fg); }
.pill-active { background: var(--ok-bg); color: var(--ok-fg); }
.pill-returned, .pill-declined, .pill-cancelled { background: var(--surface-2); color: var(--text-muted); }
.btn-sm { padding: 5px 11px; font-size: .82rem; }
.tab-row { display: flex; gap: 16px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab-row a { padding: 8px 2px; color: var(--text-muted); font-weight: 600; border-bottom: 2px solid transparent; }
.tab-row a.tab-active { color: var(--text); border-bottom-color: var(--primary); }
.tab-row a:hover { text-decoration: none; color: var(--text); }

/* ---- Category overview (home) ---- */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 18px; }
.cat-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden; color: var(--text); transition: var(--transition);
}
.cat-card:hover { text-decoration: none; transform: translateY(-3px); box-shadow: var(--shadow); }
.cat-thumb { aspect-ratio: 4/3; background: var(--surface-2); display: grid; place-items: center; }
.cat-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cat-thumb .thumb-placeholder { opacity: .45; }
.cat-body { padding: 12px 14px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.cat-body h3 { margin: 0; font-size: .98rem; }
.cat-count { color: var(--text-muted); font-size: .8rem; white-space: nowrap; }

/* ---- Nav badge (pending requests) ---- */
.nav-badge {
    display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px;
    background: var(--brand-green); color: #10131a; font-size: .72rem; font-weight: 800; vertical-align: 1px;
}

/* ---- Panels (profile, lend box) ---- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.panel h2 { margin: 0 0 6px; font-size: 1.05rem; }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; align-items: start; max-width: 860px; }
.lend-box { margin-top: 22px; }

/* ---- Either/or choice rows ---- */
.choice-fieldset { border: 0; padding: 0; margin: 0; }
.choice-fieldset legend { padding: 0; }
.choice-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.choice-row input[type="radio"] { width: auto; flex-shrink: 0; accent-color: var(--primary); }
.choice-label { flex-shrink: 0; min-width: 128px; font-size: .88rem; color: var(--text); }
.choice-row input[type="text"], .choice-row input:not([type]), .choice-row select { flex: 1; min-width: 0; }
.choice-row [data-choice-for][disabled] { opacity: .45; }
.choice-hint { font-size: .8rem; margin: 8px 0 0; }
a.user-chip:hover { color: var(--text); text-decoration: none; }

/* ---- Admin add forms ---- */
.add-panel { margin-bottom: 20px; }
.add-panel > summary { display: inline-block; list-style: none; cursor: pointer; }
.add-panel > summary::-webkit-details-marker { display: none; }
.add-form { margin-top: 16px; padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.add-inline { display: flex; gap: 8px; margin-bottom: 18px; max-width: 460px; }
.add-inline input { flex: 1; }
.inline-form { display: inline; }
.inline-form select { padding: 5px 8px; }

/* ---- Mobile ---- */
@media (max-width: 720px) {
    .container { padding: 20px 16px 48px; }
    .page-head h1 { font-size: 1.45rem; }
    .item-detail { grid-template-columns: 1fr; gap: 20px; }
    .tbl { display: block; overflow-x: auto; }
    .search-form input { max-width: none; flex: 1; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }

    /* Collapsible topbar menu behind a hamburger */
    .topbar { gap: 12px; }
    .nav-toggle {
        display: inline-flex; flex-direction: column; justify-content: center; gap: 4px;
        margin-left: auto; width: 40px; height: 36px; padding: 8px 9px;
        background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
        cursor: pointer;
    }
    .nav-toggle-bar { display: block; height: 2px; border-radius: 2px; background: var(--text); }
    .topbar-menu {
        display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 4px;
        padding: 10px 0 6px; border-top: 1px solid var(--border); margin-top: 10px;
    }
    .topbar-menu.open { display: flex; }
    .topbar-menu .nav { display: flex; flex-direction: column; gap: 0; }
    .topbar-menu .nav a { padding: 11px 4px; border-bottom: 1px solid var(--border); }
    .topbar-right { display: flex; align-items: center; gap: 10px; padding-top: 10px; }
    .user-chip { margin-right: auto; }
}

@media (max-width: 560px) {
    .card-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .item-body { padding: 10px 12px; }
    .item-body h3 { font-size: .92rem; }
    .cta-row .btn { flex: 1; text-align: center; }
    .add-inline { max-width: none; }
    .auth-card { padding: 26px 22px; }
}
