/* ============================================================
   ShelfPro — Core App Stylesheet
   Mobile-first. Tenant brand color is injected as --brand via
   an inline <style> tag in layout.php (from tenants.theme_color).
   ============================================================ */

:root {
    --brand: #16a34a;
    --brand-dark: #0f7a37;
    --brand-light: #e8f8ee;
    --ink: #16181d;
    --ink-soft: #5b6270;
    --bg: #f4f5f7;
    --card: #ffffff;
    --border: #e6e8ec;
    --danger: #dc2626;
    --warn: #d97706;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
    --tabbar-h: 62px;
    --topbar-h: 56px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: contain;
    padding-bottom: calc(var(--tabbar-h) + var(--safe-b));
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; } /* 16px prevents iOS zoom-on-focus */

/* ---------------- Top bar ---------------- */
.topbar {
    position: sticky; top: 0; z-index: 40;
    height: calc(var(--topbar-h) + var(--safe-t));
    padding-top: var(--safe-t);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
    padding-left: 14px; padding-right: 14px;
}
.topbar__logo { width: 30px; height: 30px; border-radius: 8px; object-fit: cover; background: var(--brand-light); }
.topbar__title { font-weight: 700; font-size: 16px; flex: 1; }
.topbar__action { width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
    border-radius: 10px; background: var(--bg); border: none; font-size: 18px; }

/* ---------------- Bottom tab bar (mobile app feel) ---------------- */
.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    height: calc(var(--tabbar-h) + var(--safe-b));
    padding-bottom: var(--safe-b);
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    box-shadow: 0 -2px 12px rgba(16,24,40,.05);
}
.tabbar__item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; font-size: 11px; color: var(--ink-soft); font-weight: 600;
}
.tabbar__item svg { width: 22px; height: 22px; }
.tabbar__item.active { color: var(--brand); }

/* ---------------- Layout shell ---------------- */
.app-shell { min-height: 100%; }
.page { padding: 14px; max-width: 640px; margin: 0 auto; }

/* Desktop / tablet landscape: sidebar instead of bottom tabs */
@media (min-width: 900px) {
    body { padding-bottom: 0; }
    .app-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
    .sidebar {
        background: var(--card); border-right: 1px solid var(--border);
        padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
    }
    .sidebar__brand { display: flex; align-items: center; gap: 10px; padding: 8px 10px 20px; }
    .sidebar__brand img { width: 32px; height: 32px; border-radius: 9px; }
    .sidebar__brand b { font-size: 16px; }
    .sidebar__link {
        display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
        color: var(--ink-soft); font-weight: 600; font-size: 14px; margin-bottom: 2px;
    }
    .sidebar__link.active, .sidebar__link:hover { background: var(--brand-light); color: var(--brand-dark); }
    .tabbar { display: none; }
    .main { min-width: 0; }
    .page { max-width: 1080px; padding: 24px; }
    .topbar { display: none; }
}

/* ---------------- Cards / common UI ---------------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 520px) { .grid-3 { grid-template-columns: 1fr 1fr; } }

.stat {
    background: var(--card); border-radius: var(--radius); padding: 14px; border: 1px solid var(--border);
}
.stat b { font-size: 20px; display: block; }
.stat span { font-size: 12px; color: var(--ink-soft); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    background: var(--brand); color: #fff; border: none; border-radius: var(--radius-sm);
    padding: 12px 16px; font-weight: 700; font-size: 14px; cursor: pointer; min-height: 44px;
}
.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--bg); color: var(--ink); }
.btn.outline { background: transparent; color: var(--brand); border: 1.5px solid var(--brand); }
.btn.danger { background: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 12px; font-size: 13px; min-height: 36px; }

.input, select.input, textarea.input {
    width: 100%; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
    background: var(--card); min-height: 46px;
}
.input:focus, select.input:focus { outline: none; border-color: var(--brand); }
label.lbl { font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; display: block; }
.field { margin-bottom: 14px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge.green { background: #dcfce7; color: #15803d; }
.badge.amber { background: #fef3c7; color: #b45309; }
.badge.red   { background: #fee2e2; color: #b91c1c; }
.badge.gray  { background: #eef0f3; color: #4b5563; }

.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: none; }
.list-row__thumb { width: 44px; height: 44px; border-radius: 10px; background: var(--brand-light); flex-shrink: 0; object-fit: cover; }
.list-row__title { font-weight: 700; font-size: 14px; }
.list-row__sub { font-size: 12px; color: var(--ink-soft); }

.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
    color: var(--ink-soft); margin: 20px 4px 8px; }

.empty { text-align: center; padding: 40px 16px; color: var(--ink-soft); }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); transform: translateX(-50%);
    background: #16181d; color: #fff; padding: 10px 18px; border-radius: 30px; font-size: 13px; font-weight: 600;
    z-index: 90; box-shadow: var(--shadow); }

/* Skeleton loading */
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.5} }
.skel { background: var(--border); border-radius: 8px; animation: pulse 1.2s ease-in-out infinite; }
