:root {
    --bg: #07162d;
    --bg-soft: #0d1d38;
    --panel: rgba(11, 24, 45, 0.9);
    --panel-alt: #102545;
    --card: #ffffff;
    --card-soft: #f3f8ff;
    --line: rgba(148, 163, 184, 0.2);
    --text: #e2ecff;
    --muted: #96a7c1;
    --primary: #3b82f6;
    --primary-strong: #1d4ed8;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --shadow: 0 30px 60px rgba(7, 20, 38, 0.25);
    --radius: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; font-family: 'Inter', sans-serif; background: linear-gradient(135deg, #4b4c4d 0%, #84227f 100%); color: var(--text); }
body { min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.auth-page {
    min-height: 100vh; display: grid; place-items: center; padding: 32px 20px; background: radial-gradient(circle at top, rgba(59,130,246,.25), transparent 30%), linear-gradient(135deg, #07162d 0%, #0b1b34 100%);
}
.auth-shell {
    width: min(1100px, 100%); display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 24px; background: rgba(11,22,39,.7); border: 1px solid var(--line); border-radius: 30px; overflow: hidden; box-shadow: var(--shadow);
}
.auth-visual { padding: 30px; background: linear-gradient(160deg, rgba(59,130,246,.25), rgba(15,23,42,.7)); border-right: 1px solid var(--line); }
.auth-card { padding: 32px 28px; background: rgba(15, 23, 42, 0.72); }
.auth-badge { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 999px; background: rgba(59,130,246,.18); color: #dfeeff; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.hero-title { font-size: clamp(2.2rem, 4vw, 4rem); line-height: 1.1; margin: 18px 0 14px; }
.hero-copy { color: var(--muted); line-height: 1.7; max-width: 470px; }
.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 32px; }
.metric { background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08); border-radius: 16px; padding: 16px; }
.metric strong { display: block; font-size: 1.5rem; margin-top: 8px; }
.form-title { font-size: 2rem; margin: 0 0 8px; }
.form-subtitle { color: var(--muted); margin-bottom: 24px; }
.form-grid { display: grid; gap: 16px; }
.input-group { display: grid; gap: 8px; }
.input-group label { color: #dfeeff; font-weight: 600; font-size: .92rem; }
.input-group input, .input-group select, .input-group textarea {
    width: 100%; background: rgba(255,255,255,.03); border: 1px solid rgba(148,163,184,.2); border-radius: 12px; padding: 14px 16px; color: var(--text); outline: none;
}
.input-group input:focus, .input-group select:focus, .input-group textarea:focus { border-color: rgba(59,130,246,.8); box-shadow: 0 0 0 3px rgba(59,130,246,.16); }
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 12px 18px; border: 0; border-radius: 12px; cursor: pointer; font-weight: 700; transition: .2s ease; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-strong)); color: white; box-shadow: 0 10px 25px rgba(59,130,246,.4); }
.btn-secondary { background: rgba(255,255,255,.06); color: var(--text); border: 1px solid rgba(148,163,184,.2); }
.btn-danger { background: rgba(239,68,68,.12); color: #fecaca; border: 1px solid rgba(239,68,68,.3); }
.btn:hover { transform: translateY(-1px); }
.inline-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 10px; }
.link-muted { color: var(--muted); }
.alert { border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; font-weight: 500; }
.alert-success { background: rgba(34,197,94,.12); color: #dcfce7; border: 1px solid rgba(34,197,94,.2); }
.alert-error { background: rgba(239,68,68,.12); color: #fecaca; border: 1px solid rgba(239,68,68,.3); }

.app-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: rgba(8,17,29,.9); border-right: 1px solid var(--line); padding: 26px 18px; display: flex; flex-direction: column; }
.brand-block { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.brand-mark { width: 42px; height: 42px; background: linear-gradient(135deg, var(--primary), #7dd3fc); display: grid; place-items: center; border-radius: 14px; font-weight: 800; color: white; }
.brand-name { font-weight: 800; }
.brand-tag { font-size: .75rem; color: var(--muted); }
.nav-links { display: grid; gap: 10px; }
.nav-link { padding: 12px 14px; border-radius: 12px; color: var(--muted); font-weight: 600; }
.nav-link.active, .nav-link:hover { background: rgba(59,130,246,.12); color: white; }
.user-card { margin-top: auto; background: rgba(255,255,255,.03); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; }
.user-avatar { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(135deg, var(--primary), #22d3ee); display: grid; place-items: center; font-weight: 700; }
.user-name { font-weight: 700; }
.user-role { font-size: .75rem; color: var(--muted); }
.logout-button { grid-column: 1 / -1; display: inline-flex; justify-content: center; margin-top: 8px; padding: 10px 12px; border-radius: 10px; background: rgba(239,68,68,.08); color: #fecaca; }
.main-panel { padding: 32px; }
.page-head { display: flex; justify-content: space-between; gap: 18px; align-items: center; margin-bottom: 24px; }
.page-title { font-size: clamp(1.8rem, 3vw, 2.8rem); margin: 0; }
.page-subtitle { color: var(--muted); margin-top: 8px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; margin-bottom: 22px; }
.stat-card, .panel, .table-wrap { background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-card { padding: 18px; }
.stat-label { color: var(--muted); font-size: .85rem; display: flex; justify-content: space-between; align-items: center; }
.stat-value { font-size: clamp(1.6rem, 3vw, 2.4rem); font-weight: 800; margin-top: 14px; }
.stat-value.green { color: #86efac; }
.stat-value.blue { color: #93c5fd; }
.stat-value.gold { color: #fcd34d; }
.stat-value.red { color: #fca5a5; }
.panel { padding: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.table-wrap { overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 6px 10px; font-size: .72rem; font-weight: 700; }
.badge-success { background: rgba(34,197,94,.12); color: #dcfce7; }
.badge-warning { background: rgba(245,158,11,.12); color: #fef3c7; }
.badge-danger { background: rgba(239,68,68,.12); color: #fecaca; }
.badge-info { background: rgba(59,130,246,.12); color: #dbeafe; }
.kpi-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.details-box { padding: 18px; border-radius: 18px; background: rgba(255,255,255,.03); border: 1px solid var(--line); }
.momo-box { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; }
.momo-card { background: rgba(255,255,255,.03); border: 1px solid var(--line); border-radius: 18px; padding: 18px; }
.progress-bar { width: 100%; height: 12px; background: rgba(255,255,255,.06); border-radius: 999px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; background: linear-gradient(90deg, #3b82f6, #22d3ee); border-radius: inherit; }
.mobile-nav, .mobile-menu-toggle, .mobile-menu-backdrop { display: none; }
.pagination { display: flex; justify-content: center; gap: 8px; padding: 18px 10px 4px; }
.pagination-link { min-width: 36px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; text-align: center; color: var(--muted); }
.pagination-link.current, .pagination-link:hover { background: rgba(59,130,246,.16); border-color: rgba(59,130,246,.45); color: white; }
@media (max-width: 980px) {
    .auth-shell { grid-template-columns: 1fr; }
    .app-shell { grid-template-columns: 1fr; }
    .mobile-menu-backdrop:not([hidden]) { position: fixed; z-index: 39; inset: 0; display: block; width: 100%; height: 100%; background: rgba(1,7,18,.72); border: 0; }
    .sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; display: flex; width: min(320px, 88vw); max-height: 100vh; padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain; transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow); }
    .sidebar.is-open { transform: translateX(0); }
    .nav-links { gap: 6px; }
    .nav-link { min-height: 44px; display: flex; align-items: center; }
    .mobile-nav { position: fixed; z-index: 38; inset: auto 12px max(10px, env(safe-area-inset-bottom)); display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); align-items: stretch; gap: 2px; padding: 6px; background: rgba(8,17,29,.92); border: 1px solid rgba(148,163,184,.24); border-radius: 24px; box-shadow: 0 16px 36px rgba(1,7,18,.48); backdrop-filter: blur(18px); }
    .mobile-nav-link { min-width: 0; min-height: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 5px 2px; border: 0; border-radius: 17px; background: transparent; color: var(--muted); font-size: .68rem; font-weight: 600; line-height: 1.1; cursor: pointer; touch-action: manipulation; transition: transform .18s ease, background-color .18s ease, color .18s ease, box-shadow .18s ease; }
    .mobile-nav-link svg { width: 20px; height: 20px; flex: 0 0 auto; }
    .mobile-nav-link span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .mobile-nav-link.active { transform: translateY(-4px); background: rgba(59,130,246,.2); color: #fff; box-shadow: 0 6px 16px rgba(59,130,246,.18); }
    .mobile-nav-link:active { transform: translateY(-8px) scale(1.04); background: rgba(59,130,246,.28); color: #fff; }
    @media (hover: hover) {
        .mobile-nav-link:hover { transform: translateY(-5px); background: rgba(59,130,246,.16); color: #fff; }
    }
    .mobile-nav .mobile-menu-toggle { display: flex; }
    .main-panel { min-width: 0; padding: 32px 20px calc(88px + env(safe-area-inset-bottom)); }
    .main-panel-wrap, .panel, .stat-card { min-width: 0; }
    .page-head { align-items: flex-start; flex-wrap: wrap; }
    .kpi-row { grid-template-columns: minmax(0, 1fr); }
    .table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { display: block; width: 100%; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    th, td { white-space: nowrap; }
    .inline-actions { flex-wrap: wrap; }
    .btn { min-height: 44px; }
}

@media (max-width: 600px) {
    html, body { max-width: 100%; overflow-x: hidden; }
    .auth-page { min-height: 100vh; align-items: start; padding: 14px 12px; }
    .auth-shell { gap: 0; border-radius: 22px; }
    .auth-visual { padding: 22px 20px; border-right: 0; border-bottom: 1px solid var(--line); }
    .auth-card { padding: 24px 20px; }
    .hero-title { font-size: clamp(1.9rem, 9vw, 2.6rem); }
    .hero-copy { line-height: 1.55; }
    .metric-grid { gap: 8px; margin-top: 20px; }
    .metric { padding: 10px; }
    .metric strong { font-size: 1rem; overflow-wrap: anywhere; }
    .form-title { font-size: 1.7rem; }
    .main-panel { padding: 24px 12px calc(84px + env(safe-area-inset-bottom)); }
    .page-head { gap: 12px; margin-bottom: 18px; }
    .page-title { font-size: clamp(1.55rem, 7vw, 2rem); line-height: 1.15; }
    .page-subtitle { line-height: 1.45; }
    .card-grid, .momo-box { grid-template-columns: minmax(0, 1fr); gap: 12px; }
    .kpi-row { gap: 12px; }
    .panel, .stat-card { padding: 15px; border-radius: 16px; }
    .panel-head { align-items: flex-start; flex-wrap: wrap; margin-bottom: 14px; }
    .stat-value { overflow-wrap: anywhere; }
    .form-grid { gap: 14px; }
    .input-group input, .input-group select, .input-group textarea { min-width: 0; padding: 13px 14px; font-size: 16px; }
    .btn { width: 100%; padding: 12px 14px; }
    .inline-actions { align-items: stretch; gap: 8px; }
    .inline-actions > * { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar { transition: none; }
}

/* Product photos */
.product-card { display: flex; flex-direction: column; gap: 10px; }
.product-photo {
    width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block;
    border-radius: 14px; border: 1px solid var(--line); background: var(--bg-soft);
}
.product-photo-empty {
    display: flex; align-items: center; justify-content: center;
    color: var(--muted); font-size: .78rem; font-weight: 600;
    letter-spacing: .06em; text-transform: uppercase;
}
.product-description { margin: 0; color: var(--muted); font-size: .92rem; line-height: 1.5; }

/* Editing an existing record opens its form as an on-screen dialog instead of burying it
   below the rest of the page. */
.edit-dialog-backdrop {
    position: fixed; z-index: 55; inset: 0; display: block;
    background: rgba(1, 7, 18, .74); backdrop-filter: blur(4px);
}
.edit-dialog {
    position: fixed; z-index: 56; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: min(760px, calc(100% - 32px)); max-height: calc(100vh - 48px);
    overflow-y: auto; overscroll-behavior: contain;
    background: rgba(11, 24, 45, .97);
}

