:root {
  --bg: #f6f8fc;
  --bg-2: #eef3fb;
  --card: rgba(255,255,255,0.88);
  --card-strong: #ffffff;
  --text: #132238;
  --muted: #5f728c;
  --line: rgba(19,34,56,0.10);
  --brand: #f59e0b;
  --brand-2: #2563eb;
  --green: #16a34a;
  --red: #e11d48;
  --radius: 22px;
  --shadow: 0 14px 40px rgba(15, 23, 42, 0.10);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: Inter, system-ui, sans-serif; background: linear-gradient(180deg, #f8fbff 0%, #eef4fb 100%); color: var(--text); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
body { overflow-x: hidden; }
.bg-orb { position: fixed; border-radius: 50%; filter: blur(90px); opacity: .22; pointer-events: none; z-index: 0; }
.orb-1 { width: 340px; height: 340px; background: #fde68a; top: -70px; right: -70px; opacity:.35; }
.orb-2 { width: 320px; height: 320px; background: #bfdbfe; bottom: -100px; left: -90px; opacity:.35; }
.app-shell { position: relative; z-index: 1; display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; gap: 18px; padding: 18px; }
.glass { background: var(--card); backdrop-filter: blur(16px); border: 1px solid var(--line); box-shadow: var(--shadow); }
.topbar { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-radius: 22px; position: sticky; top: 12px; z-index: 10; }
.brand-wrap { display: flex; align-items: center; gap: 12px; }
.brand-mark { display: flex; align-items: center; gap: 12px; }
.brand-k { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-weight: 800; color: #111827; background: linear-gradient(135deg, #f59e0b, #fde68a); }
.brand-mark strong { display: block; font-size: 1rem; }
.brand-mark small { color: var(--muted); font-size: .82rem; }
.nav-toggle { display: none; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 12px; width: 42px; height: 42px; }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sidebar { border-radius: 24px; padding: 16px; display: flex; flex-direction: column; gap: 8px; min-height: calc(100vh - 98px); position: sticky; top: 88px; }
.sidebar a { padding: 14px 16px; border-radius: 16px; color: var(--text); }
.sidebar a:hover, .sidebar a.active { background: rgba(37,99,235,.08); }
.content-area { display: flex; flex-direction: column; gap: 18px; }
.hero { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; border-radius: 28px; }
.section-pad { padding: 28px; }
.eyebrow { display: inline-block; padding: 8px 12px; border-radius: 999px; background: rgba(245, 158, 11, .15); color: #fcd34d; border: 1px solid rgba(245,158,11,.25); font-size: .82rem; }
.hero h1 { font-size: clamp(2rem, 4vw, 3.6rem); line-height: 1.03; margin: 14px 0 12px; max-width: 14ch; }
.hero p { color: var(--muted); max-width: 58ch; line-height: 1.7; }
.hero-actions, .stack-row, .pill-row, .card-actions, .auth-actions, .toolbar-row { display: flex; gap: 10px; flex-wrap: wrap; }
.panel-dark { background: linear-gradient(180deg, #ffffff, #f8fbff); border-radius: 26px; padding: 24px; border: 1px solid var(--line); }
.metric-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 16px 0; border-bottom: 1px solid var(--line); }
.metric-row:last-of-type { border-bottom: 0; }
.metric-row span { color: var(--muted); }
.metric-row strong { font-size: 1.45rem; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; background: #fff; border: 1px solid var(--line); border-radius: 999px; color: var(--text); font-size: .82rem; }
.pill.success { color: #bbf7d0; }
.pill.warn { color: #fde68a; }
.primary-btn, .ghost-btn, .danger-btn, .google-btn { border: 0; padding: 13px 18px; border-radius: 16px; font-weight: 700; transition: .2s transform ease, .2s opacity ease; }
.primary-btn { background: linear-gradient(135deg, #f59e0b, #fbbf24); color: #111827; }
.primary-btn.small { padding: 10px 14px; border-radius: 14px; }
.ghost-btn { background: #fff; color: var(--text); border: 1px solid var(--line); }
.danger-btn { background: rgba(251,113,133,.12); color: #fecdd3; border: 1px solid rgba(251,113,133,.24); }
.google-btn { background: #fff; color: #111827; }
.icon-btn, .user-menu-btn { display: inline-flex; align-items: center; gap: 8px; border-radius: 16px; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 12px 14px; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 40px; height: 40px; border-radius: 14px; object-fit: cover; background: var(--line); }
.view-card { border-radius: 26px; padding: 22px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 1.55rem; }
.page-head p { margin: 8px 0 0; color: var(--muted); }
.toolbar { display: grid; grid-template-columns: 1.2fr .8fr .8fr; gap: 12px; margin-bottom: 18px; }
.input, .select, textarea, .modal input, .modal select, .modal textarea { width: 100%; border-radius: 16px; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 14px 15px; outline: none; }
input::placeholder, textarea::placeholder { color: #8ea1bf; }
.grid { display: grid; gap: 18px; }
.product-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.product-card { border-radius: 24px; overflow: hidden; border: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; min-height: 100%; }
.product-image { aspect-ratio: 1 / 1; background: linear-gradient(180deg, #f8fbff, #eef4fb); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.product-image img { width: 100%; height: 100%; object-fit: cover; }
.product-body { padding: 16px; display: grid; gap: 10px; }
.product-title { font-size: 1rem; font-weight: 700; line-height: 1.35; }
.product-sub { color: var(--muted); font-size: .9rem; }
.price-stack { display: grid; gap: 6px; }
.price-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.price-row span { color: var(--muted); font-size: .88rem; }
.price-row strong { font-size: 1rem; }
.badge-row { display: flex; gap: 8px; flex-wrap: wrap; }
.badge { padding: 7px 10px; border-radius: 999px; font-size: .75rem; border: 1px solid var(--line); background: #f8fbff; color: var(--text); }
.badge.manual { color: #fde68a; }
.badge.auto { color: #bfdbfe; }
.empty-state { text-align: center; padding: 42px 18px; color: var(--muted); border: 1px dashed var(--line); border-radius: 22px; background:#fff; }
.table-wrap { overflow: auto; border-radius: 22px; border: 1px solid var(--line); background:#fff; }
.table { width: 100%; border-collapse: collapse; min-width: 780px; }
.table th, .table td { padding: 14px 16px; border-bottom: 1px solid rgba(37,99,235,.08); text-align: left; vertical-align: top; }
.table th { font-size: .82rem; color: var(--muted); background: #f8fbff; }
.table td { font-size: .94rem; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 20px; border-radius: 22px; background: #fff; border: 1px solid var(--line); }
.kpi span { display: block; color: var(--muted); font-size: .84rem; margin-bottom: 8px; }
.kpi strong { font-size: 1.45rem; }
.split-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-grid.one { grid-template-columns: 1fr; }
.fieldset { border: 1px solid var(--line); padding: 16px; border-radius: 22px; display: grid; gap: 12px; background:#fff; }
.fieldset legend { padding: 0 8px; color: #fde68a; }
label { display: grid; gap: 8px; font-size: .9rem; color: var(--text); }
.modal { border: 0; padding: 0; background: transparent; color: var(--text); width: min(92vw, 580px); }
.modal.wide { width: min(94vw, 860px); }
.modal::backdrop { background: rgba(2, 6, 23, .72); backdrop-filter: blur(8px); }
.modal-inner { border-radius: 24px; padding: 22px; display: grid; gap: 16px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.close-btn { width: 40px; height: 40px; border-radius: 14px; border: 1px solid var(--line); background: #fff; color: var(--text); }
.divider { position: relative; text-align: center; margin: 6px 0; }
.divider::before { content: ""; position: absolute; inset: 50% 0 auto 0; height: 1px; background: var(--line); }
.divider span { position: relative; background: #fff; padding: 0 10px; color: var(--muted); font-size: .82rem; }
.auth-stack { display: grid; gap: 12px; }
.toast { position: fixed; inset: auto 18px 18px auto; padding: 14px 16px; border-radius: 16px; border: 1px solid var(--line); background: #fff; color: var(--text); }
.checkout-total { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 1.1rem; padding: 18px 0; }
.mobile-only { display: none; }
@media (max-width: 1080px) {
  .hero, .split-grid, .toolbar, .kpi-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; padding: 14px; }
  .sidebar { position: fixed; left: 14px; right: 14px; top: 82px; min-height: auto; z-index: 9; transform: translateY(-140%); transition: .25s ease; }
  .sidebar.open { transform: translateY(0); }
  .nav-toggle { display: inline-grid; place-items: center; }
  .hero h1 { max-width: unset; }
  .form-grid { grid-template-columns: 1fr; }
  .mobile-only { display: inline-flex; }
}
@media (max-width: 640px) {
  .topbar { align-items: flex-start; }
  .top-actions { justify-content: flex-end; }
  .section-pad, .view-card { padding: 18px; }
  .product-grid { grid-template-columns: 1fr; }
}


#authDialog .modal-inner { background: #fff; padding: 28px; width: min(92vw, 560px); }
#authDialog .modal-head h3 { margin: 0; font-size: 1.8rem; }
#authDialog .modal-head p, #authDialog .product-title-wrap small { color: var(--muted); }
#authDialog .google-btn, #authDialog .auth-actions button { min-height: 56px; }
#authDialog label { font-weight: 600; }
#authDialog .auth-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
#productDialog { width: min(96vw, 980px); max-height: 92vh; }
#productDialog .modal-inner { background: #fff; padding: 0; overflow: hidden; max-height: 92vh; }
.product-dialog-head { padding: 22px 22px 0; }
.product-title-wrap h3 { margin: 0; font-size: clamp(1.4rem, 2vw, 2rem); line-height: 1.2; }
.product-title-wrap small { display: block; margin-top: 6px; }
.product-modal-grid { display: grid; grid-template-columns: minmax(280px, 380px) 1fr; min-height: 0; }
.product-modal-media { padding: 22px; background: linear-gradient(180deg, #f8fbff, #eef4fb); border-right: 1px solid var(--line); display: flex; align-items: center; justify-content: center; }
.product-modal-media img { width: 100%; max-height: 420px; object-fit: contain; border-radius: 24px; background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); }
.product-modal-content { padding: 22px; display: grid; gap: 16px; align-content: start; overflow: auto; }
.field-label { font-weight: 600; }
.price-card { display: grid; gap: 10px; padding: 18px; background: linear-gradient(180deg, #fff, #fbfdff); border: 1px solid var(--line); border-radius: 20px; }
.dialog-actions { margin-top: 4px; }
.dialog-actions > * { flex: 1 1 220px; min-height: 54px; }
.placeholder-big { min-height: 360px; border-radius: 24px; }
@media (max-width: 860px) {
  #authDialog .auth-actions { grid-template-columns: 1fr; }
  #productDialog { width: min(96vw, 620px); }
  .product-modal-grid { grid-template-columns: 1fr; }
  .product-modal-media { border-right: 0; border-bottom: 1px solid var(--line); }
  .product-modal-media img { max-height: 280px; }
  .dialog-actions { grid-template-columns: 1fr; }
}


/* Stabilized modal layouts */
#productDialog.modal.wide { width: min(96vw, 1040px); }
#productDialog .modal-inner { border-radius: 28px; background:#fff; }
.product-dialog-head { padding: 20px 24px 0; }
.product-title-wrap h3 { margin: 0; font-size: clamp(1.25rem, 2vw, 2rem); line-height: 1.15; }
.product-modal-grid { display:grid; grid-template-columns: minmax(320px, 46%) minmax(0, 1fr); align-items: stretch; max-height: calc(92vh - 72px); }
.product-modal-media { min-height: 420px; overflow: hidden; }
.product-modal-media img { width: 100%; height: 100%; max-height: none; object-fit: contain; }
.product-modal-content { min-width: 0; overflow: auto; }
.dialog-actions { display:grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-actions .primary-btn, .dialog-actions .ghost-btn { width: 100%; justify-content: center; }
#authDialog .modal-inner { border-radius: 28px; box-shadow: 0 24px 80px rgba(15,23,42,.24); }
#authDialog .auth-actions { display:grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 820px) {
  #productDialog.modal.wide { width: min(96vw, 720px); }
  .product-modal-grid { grid-template-columns: 1fr; max-height: none; }
  .product-modal-media { min-height: 280px; }
  .product-modal-media img { max-height: 300px; height: auto; }
  .dialog-actions { grid-template-columns: 1fr; }
}


/* --- final stability overrides --- */
.user-chip { display:flex; align-items:center; gap:12px; }
.user-chip-copy { min-width: 0; max-width: 180px; }
.user-chip-copy small { display:block; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

#authDialog::backdrop, #productDialog::backdrop { background: rgba(15,23,42,.46); backdrop-filter: blur(6px); }
#authDialog .modal-inner { width:min(92vw, 520px); padding:28px; border-radius:28px; }
#authDialog .google-btn { width:100%; min-height:56px; border-radius:18px; background:#fff; border:1px solid var(--line); font-weight:700; }
#authDialog .auth-actions { display:grid; grid-template-columns:1fr 1fr; gap:12px; }

#productDialog { width:min(96vw, 1080px); max-height:92vh; border:none; background:transparent; padding:0; }
#productDialog .modal-inner { padding:0; width:100%; max-height:92vh; overflow:hidden; border-radius:28px; background:#fff; box-shadow:0 32px 90px rgba(15,23,42,.22); }
#productDialog .modal-head { display:flex; align-items:flex-start; justify-content:space-between; gap:16px; }
.product-dialog-head { padding:24px 24px 0; }
.product-title-wrap { min-width:0; }
.product-title-wrap h3 { margin:0; font-size:clamp(1.3rem, 2vw, 2rem); line-height:1.15; color:#111827; }
.product-title-wrap small { display:block; margin-top:6px; color:var(--muted); }
.product-modal-grid.improved { display:grid; grid-template-columns:minmax(320px, 42%) minmax(0, 1fr); align-items:stretch; max-height:calc(92vh - 84px); }
.product-modal-media.improved { display:flex; align-items:center; justify-content:center; padding:24px; min-height:420px; background:linear-gradient(180deg,#f8fbff,#eef4fb); border-right:1px solid var(--line); overflow:hidden; }
.product-modal-media.improved img { display:block; width:100%; max-width:100%; max-height:360px; height:auto; object-fit:contain; border-radius:22px; background:#fff; border:1px solid var(--line); box-shadow:var(--shadow); }
.product-modal-content.improved { padding:24px; display:grid; gap:16px; align-content:start; min-width:0; overflow:auto; }
.price-card { border-radius:20px; }
.price-card .price-row.emphasis strong { color:#0f172a; font-size:1.2rem; }
.dialog-actions.improved { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.dialog-actions.improved > * { width:100%; justify-content:center; min-height:52px; }
.order-pay-block { display:grid; gap:12px; }
.order-qr-card { background:#fff; border:1px solid var(--line); border-radius:20px; padding:16px; text-align:center; }
.order-qr-image { width:100%; max-width:220px; aspect-ratio:1/1; object-fit:contain; border-radius:16px; background:#fff; }
.order-pay-actions { display:grid; grid-template-columns:1fr; gap:10px; }

@media (max-width: 860px) {
  #authDialog .auth-actions { grid-template-columns:1fr; }
  #productDialog { width:min(96vw, 680px); }
  .product-modal-grid.improved { grid-template-columns:1fr; max-height:none; }
  .product-modal-media.improved { min-height:260px; border-right:none; border-bottom:1px solid var(--line); padding:18px; }
  .product-modal-media.improved img { max-height:240px; }
  .dialog-actions.improved { grid-template-columns:1fr; }
  .product-modal-content.improved { padding:18px; }
}
