/* ─── ZenPro Pets CRM — Brand Theme: Orange / White / Charcoal ─────────────── */

:root {
    --sidebar-width: 230px;
    --topbar-height: 64px;

    /* Brand colors */
    --orange:        #f07030;
    --orange-dk:     #c85a18;
    --orange-lt:     #fff3ec;
    --orange-mid:    #ff9050;
    --charcoal:      #333333;
    --charcoal-lt:   #555555;

    /* Semantic aliases */
    --primary:       var(--orange);
    --primary-dk:    var(--orange-dk);
    --primary-lt:    var(--orange-lt);
    --accent:        var(--orange-mid);
    --danger:        #d94040;
    --warning:       #e9a319;
    --success:       #2d8a4e;

    /* Grays */
    --gray-50:   #fafafa;
    --gray-100:  #f5f5f5;
    --gray-200:  #ebebeb;
    --gray-300:  #d9d9d9;
    --gray-400:  #bbbbbb;
    --gray-600:  #777777;
    --gray-700:  #555555;
    --gray-800:  #333333;

    --radius:    8px;
    --shadow:    0 1px 6px rgba(0,0,0,.07), 0 2px 12px rgba(0,0,0,.04);
    --shadow-lg: 0 4px 24px rgba(0,0,0,.13);
}

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

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    color: var(--charcoal);
    background: var(--gray-100);
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Auth screen ─────────────────────────────────────────────────────────── */
#auth-screen {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: #fff;
    z-index: 1000;
}
#auth-screen.hidden { display: none; }

.auth-card {
    background: #fff;
    border-radius: 16px;
    padding: 52px 44px 44px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-lg);
}
.auth-logo {
    margin: 0 auto 24px;
    display: block;
    max-width: 220px;
    height: auto;
}
.auth-logo-fallback {
    font-size: 52px;
    display: block;
    margin-bottom: 16px;
}
.auth-card h1 {
    font-size: 22px; font-weight: 800;
    color: var(--charcoal);
    margin-bottom: 6px;
    letter-spacing: -.02em;
}
.auth-card .auth-subtitle {
    color: var(--gray-600);
    font-size: 14px;
    margin-bottom: 32px;
    line-height: 1.5;
}
.auth-divider {
    border: none;
    border-top: 1px solid var(--gray-200);
    margin: 0 0 24px;
}
.btn-signin {
    background: var(--orange);
    color: #fff;
    border: none;
    padding: 13px 28px;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    transition: background .18s, box-shadow .18s;
    letter-spacing: -.01em;
}
.btn-signin:hover {
    background: var(--orange-dk);
    box-shadow: 0 4px 16px rgba(240,112,48,.3);
}
.btn-signin svg { flex-shrink: 0; }
.auth-note {
    margin-top: 16px;
    font-size: 12px;
    color: var(--gray-400);
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app { display: flex; width: 100%; height: 100vh; }
#app.hidden { display: none; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
    width: var(--sidebar-width);
    background: var(--charcoal);
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
}
.sidebar-brand {
    padding: 18px 16px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-logo {
    max-width: 140px;
    height: auto;
    display: block;
    filter: brightness(0) invert(1);   /* white logo on dark sidebar */
    margin-bottom: 2px;
}
.sidebar-logo-fallback {
    font-size: 13px; font-weight: 800;
    color: var(--orange);
    letter-spacing: -.01em;
    display: block;
}
.sidebar-sub { font-size: 10px; color: rgba(255,255,255,.4); margin-top: 3px; letter-spacing: .04em; text-transform: uppercase; }

nav { padding: 10px 0; flex: 1; }
.nav-section {
    padding: 10px 16px 4px;
    font-size: 9px; font-weight: 800;
    letter-spacing: .12em;
    color: rgba(255,255,255,.28);
    text-transform: uppercase;
}
nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 16px;
    color: rgba(255,255,255,.65);
    text-decoration: none;
    font-size: 13px; font-weight: 500;
    border-left: 3px solid transparent;
    transition: all .14s;
}
nav a:hover  { background: rgba(255,255,255,.05); color: rgba(255,255,255,.9); }
nav a.active {
    background: rgba(240,112,48,.15);
    color: #fff;
    border-left-color: var(--orange);
    font-weight: 700;
}
nav a .icon { width: 18px; text-align: center; font-size: 15px; }
.nav-badge {
    margin-left: auto;
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 9px; background: var(--orange);
    color: #fff; font-size: 11px; font-weight: 800; line-height: 1;
    display: inline-flex; align-items: center; justify-content: center;
}
/* Generic visibility utility (used by the nav badge, the applications queue toggle, etc.) */
.hidden { display: none !important; }

.sidebar-user {
    padding: 14px 16px;
    border-top: 1px solid rgba(255,255,255,.08);
    display: flex; align-items: center; gap: 10px;
}
.user-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--orange);
    color: #fff;
    font-weight: 700; font-size: 13px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.user-name  { font-size: 12px; font-weight: 600; color: #fff; }
.user-email { font-size: 10px; color: rgba(255,255,255,.4); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.btn-signout {
    margin-left: auto; flex-shrink: 0;
    background: none; border: none;
    color: rgba(255,255,255,.3); cursor: pointer; font-size: 16px;
    padding: 4px; border-radius: 4px;
    transition: color .14s;
}
.btn-signout:hover { color: #fff; }

/* ── Main area ───────────────────────────────────────────────────────────── */
#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--gray-100);
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */
#topbar {
    height: var(--topbar-height);
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    display: flex; align-items: center;
    padding: 0 24px; gap: 16px;
    flex-shrink: 0;
}
#topbar h2 {
    font-size: 19px; font-weight: 800;
    color: var(--charcoal);
    flex: 1;
    letter-spacing: -.02em;
}
.brand-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.brand-chip {
    padding: 5px 13px;
    border-radius: 20px;
    border: 2px solid var(--gray-300);
    font-size: 12px; font-weight: 700;
    cursor: pointer;
    transition: all .14s;
    background: #fff;
    color: var(--gray-600);
    letter-spacing: .01em;
}
.brand-chip:hover { border-color: var(--orange); color: var(--orange); }
.brand-chip.active[data-code=""]   { background: var(--charcoal); color: #fff; border-color: var(--charcoal); }
.brand-chip.active[data-code="ZH"] { background: #1a5c3a; color: #fff; border-color: #1a5c3a; }
.brand-chip.active[data-code="BRD"]{ background: #1a5580; color: #fff; border-color: #1a5580; }
.brand-chip.active[data-code="PR"] { background: #6a2077; color: #fff; border-color: #6a2077; }
.brand-chip.active[data-code="WP"] { background: var(--orange-dk); color: #fff; border-color: var(--orange-dk); }

/* ── Page container ──────────────────────────────────────────────────────── */
#page-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    border: 1px solid var(--gray-200);
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px;
}
.card-header h3 { font-size: 15px; font-weight: 700; color: var(--charcoal); }

/* ── Dashboard stats ─────────────────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 22px 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
    border-top: 4px solid var(--orange);
    position: relative;
    overflow: hidden;
}
.stat-card::after {
    content: "";
    position: absolute;
    right: -10px; top: -10px;
    width: 60px; height: 60px;
    border-radius: 50%;
    background: var(--orange-lt);
    opacity: .6;
}
.stat-card.warning { border-top-color: var(--warning); }
.stat-card.warning::after { background: #fff8e8; }
.stat-card.success { border-top-color: var(--success); }
.stat-card.success::after { background: #edf7f0; }
.stat-value { font-size: 34px; font-weight: 900; color: var(--charcoal); line-height: 1; letter-spacing: -.03em; }
.stat-label { font-size: 12px; color: var(--gray-600); margin-top: 5px; font-weight: 500; }

/* ── Toolbar ─────────────────────────────────────────────────────────────── */
.toolbar {
    display: flex; align-items: center; gap: 10px;
    margin-bottom: 16px; flex-wrap: wrap;
}
.search-box {
    flex: 1; min-width: 200px;
    padding: 8px 14px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    color: var(--charcoal);
    transition: border-color .14s, box-shadow .14s;
}
.search-box:focus {
    border-color: var(--orange);
    box-shadow: 0 0 0 3px rgba(240,112,48,.12);
}
select.filter-select {
    padding: 8px 10px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 13px;
    background: #fff;
    color: var(--charcoal);
    cursor: pointer;
    outline: none;
    transition: border-color .14s;
}
select.filter-select:focus { border-color: var(--orange); }

/* Multi-select checkbox dropdown filter */
.ms { position: relative; display: inline-block; }
.ms-btn {
    padding: 8px 10px; border: 1px solid var(--gray-300); border-radius: var(--radius);
    font-size: 13px; background: #fff; color: var(--charcoal); cursor: pointer; outline: none;
    display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; transition: border-color .14s;
}
.ms-btn:hover { border-color: var(--gray-400, #b6bcc4); }
.ms.open .ms-btn { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(240,112,48,.12); }
.ms.active .ms-btn { border-color: var(--orange); font-weight: 600; }
.ms-caret { font-size: 10px; color: var(--gray-600, #6c757d); }
.ms-panel {
    display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 50;
    min-width: 100%; max-width: 280px; max-height: 280px; overflow-y: auto;
    background: #fff; border: 1px solid var(--gray-300); border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 4px;
}
.ms.open .ms-panel { display: block; }
.ms-opt {
    display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 5px;
    font-size: 13px; color: var(--charcoal); cursor: pointer; white-space: nowrap;
}
.ms-opt:hover { background: var(--gray-100, #f1f3f5); }
.ms-opt input { width: 15px; height: 15px; cursor: pointer; accent-color: var(--orange); flex: none; }
.ms-empty { padding: 8px; font-size: 13px; color: var(--gray-600, #6c757d); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
    padding: 8px 16px;
    border-radius: var(--radius);
    border: none; cursor: pointer;
    font-size: 13px; font-weight: 700;
    display: inline-flex; align-items: center; gap: 6px;
    transition: all .14s;
    text-decoration: none;
    letter-spacing: -.01em;
}
.btn-primary { background: var(--orange); color: #fff; }
.btn-primary:hover { background: var(--orange-dk); box-shadow: 0 3px 12px rgba(240,112,48,.3); }
.btn-secondary { background: var(--gray-200); color: var(--charcoal); border: 1px solid var(--gray-300); }
.btn-secondary:hover { background: var(--gray-300); }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.9); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon {
    padding: 6px; background: none; color: var(--gray-600);
    border: none; cursor: pointer; border-radius: 4px;
    transition: all .12s;
}
.btn-icon:hover { background: var(--gray-200); color: var(--charcoal); }

/* ── Product grid ────────────────────────────────────────────────────────── */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 16px;
}
.product-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--gray-200);
    overflow: hidden;
    cursor: pointer;
    transition: box-shadow .15s, transform .15s, border-color .15s;
    display: flex; flex-direction: column;
}
.product-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
    border-color: var(--orange);
}
.product-card-img {
    width: 100%; aspect-ratio: 1;
    object-fit: contain;
    background: var(--gray-50);
    padding: 12px;
    border-bottom: 1px solid var(--gray-200);
}
.product-card-img.placeholder {
    display: flex; align-items: center; justify-content: center;
    font-size: 40px; color: var(--gray-300);
}
.product-card-body { padding: 12px; flex: 1; display: flex; flex-direction: column; gap: 5px; }
.product-card-name { font-weight: 700; font-size: 13px; line-height: 1.3; color: var(--charcoal); }
.product-card-sku  { font-size: 11px; color: var(--gray-600); font-family: 'Consolas', monospace; }
.product-card-foot {
    padding: 8px 12px;
    border-top: 1px solid var(--gray-200);
    display: flex; align-items: center; justify-content: space-between;
    background: var(--gray-50);
}

/* ── Table ───────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
    text-align: left; padding: 10px 12px;
    background: var(--gray-100);
    border-bottom: 2px solid var(--gray-200);
    font-size: 10.5px; font-weight: 800;
    text-transform: uppercase; letter-spacing: .06em;
    color: var(--gray-600); white-space: nowrap;
    cursor: pointer; user-select: none;
}
.data-table th:hover { color: var(--orange); }
.data-table td { padding: 11px 12px; border-bottom: 1px solid var(--gray-200); vertical-align: middle; }
.data-table tr:hover td { background: var(--orange-lt); }
.data-table tr:last-child td { border-bottom: none; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 12px;
    font-size: 11px; font-weight: 700;
    line-height: 1.4;
    letter-spacing: .01em;
}
.badge-brand { color: #fff; }
.badge-status-active       { background: #e2f4e8; color: #1a5c38; }
.badge-status-inactive     { background: var(--gray-200); color: var(--gray-600); }
.badge-status-discontinued { background: #fce8e8; color: #8b2020; }
.badge-status-comingsoon   { background: #fff0e0; color: #b85500; }
.badge-kit { background: #fff3e0; color: #b85500; }
.badge-low-stock { background: #fce8e8; color: #8b2020; }

/* ── Detail panel ────────────────────────────────────────────────────────── */
.detail-panel {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: 540px;
    background: #fff;
    box-shadow: -4px 0 24px rgba(0,0,0,.11);
    border-left: 1px solid var(--gray-200);
    z-index: 200;
    display: flex; flex-direction: column;
    transform: translateX(100%);
    transition: transform .25s ease;
}
.detail-panel.open { transform: translateX(0); }
.detail-panel-header {
    padding: 20px 24px 16px;
    border-bottom: 3px solid var(--orange);
    display: flex; align-items: flex-start; gap: 12px;
    background: var(--orange-lt);
}
.detail-panel-header .close-btn {
    margin-left: auto; margin-top: 2px;
    background: none; border: none; cursor: pointer;
    color: var(--gray-600); font-size: 20px;
    padding: 2px 6px; border-radius: 4px;
    transition: background .12s;
}
.detail-panel-header .close-btn:hover { background: rgba(0,0,0,.08); }
.detail-panel-body { flex: 1; overflow-y: auto; padding: 20px 24px; }
.detail-section { margin-bottom: 24px; }
.detail-section h4 {
    font-size: 10px; font-weight: 800;
    text-transform: uppercase; letter-spacing: .1em;
    color: var(--orange-dk);
    margin-bottom: 10px; padding-bottom: 6px;
    border-bottom: 2px solid var(--orange-lt);
}
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-field label { font-size: 10px; font-weight: 700; color: var(--gray-600); margin-bottom: 2px; display: block; text-transform: uppercase; letter-spacing: .05em; }
.detail-field value { font-size: 13px; font-weight: 600; color: var(--charcoal); display: block; }
.detail-field.full { grid-column: 1 / -1; }
.detail-img {
    width: 100%; max-height: 240px;
    object-fit: contain; background: var(--gray-50);
    border-radius: var(--radius); padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--gray-200);
}
.detail-panel-foot {
    padding: 16px 24px;
    border-top: 1px solid var(--gray-200);
    display: flex; gap: 8px;
    background: var(--gray-50);
}

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.35);
    backdrop-filter: blur(2px);
    z-index: 300;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal {
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 100%; max-width: 680px;
    max-height: 90vh;
    display: flex; flex-direction: column;
    border: 1px solid var(--gray-200);
}
.modal-header {
    padding: 20px 24px 16px;
    border-bottom: 3px solid var(--orange);
    display: flex; align-items: center; justify-content: space-between;
    background: var(--orange-lt);
}
.modal-header h3 { font-size: 16px; font-weight: 800; color: var(--charcoal); }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer {
    padding: 14px 24px;
    border-top: 1px solid var(--gray-200);
    display: flex; justify-content: flex-end; gap: 8px;
    background: var(--gray-50);
}

/* ── Form fields ─────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
label.form-label {
    display: block; font-size: 11px; font-weight: 700;
    color: var(--gray-700); margin-bottom: 4px;
    text-transform: uppercase; letter-spacing: .04em;
}
input[type=text], input[type=number], input[type=url],
textarea, select.form-control {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    background: #fff;
    color: var(--charcoal);
    transition: border-color .14s, box-shadow .14s;
}
input:focus, textarea:focus, select.form-control:focus {
    border-color: var(--orange);
    box-shadow: 0 0 0 3px rgba(240,112,48,.12);
}
textarea { min-height: 80px; resize: vertical; }
.form-check { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.form-check input { width: auto; accent-color: var(--orange); }

/* ── Inventory bar ───────────────────────────────────────────────────────── */
.inv-bar { height: 6px; border-radius: 3px; background: var(--gray-200); overflow: hidden; margin-top: 6px; }
.inv-bar-fill { height: 100%; border-radius: 3px; background: var(--orange); transition: width .3s; }
.inv-bar-fill.low      { background: var(--warning); }
.inv-bar-fill.critical { background: var(--danger); }

/* ── Toasts ──────────────────────────────────────────────────────────────── */
#toast-container {
    position: fixed; bottom: 24px; right: 24px;
    display: flex; flex-direction: column; gap: 8px;
    z-index: 999;
}
.toast {
    padding: 12px 18px; border-radius: 8px;
    background: var(--charcoal); color: #fff;
    font-size: 13px; font-weight: 600;
    box-shadow: var(--shadow-lg);
    animation: slideIn .2s ease;
    max-width: 320px;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--gray-600); }
.empty-state .icon { font-size: 48px; margin-bottom: 14px; }
.empty-state h3 { font-size: 16px; font-weight: 700; margin-bottom: 6px; color: var(--charcoal); }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--orange);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    margin: 60px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Panel overlay ───────────────────────────────────────────────────────── */
.panel-overlay {
    position: fixed; inset: 0; z-index: 199;
    background: transparent;
}
.panel-overlay.hidden { display: none; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    #sidebar { width: 56px; }
    .sidebar-brand .sidebar-sub,
    nav a span, .sidebar-user .user-name, .sidebar-user .user-email { display: none; }
    .sidebar-logo { display: none; }
    .sidebar-logo-fallback { font-size: 20px; }
    nav a { justify-content: center; padding: 12px; }
    .detail-panel { width: 100%; }
    .form-row, .form-row.cols-3 { grid-template-columns: 1fr; }
}
