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

:root {
  --bg:        #0b0f1a;
  --surface:   #111827;
  --surface2:  #1a2236;
  --surface3:  #222d45;
  --border:    #2a3a55;
  --accent:    #3b82f6;
  --accent2:   #6366f1;
  --green:     #10b981;
  --red:       #ef4444;
  --orange:    #f59e0b;
  --purple:    #8b5cf6;
  --text:      #e2e8f0;
  --text-dim:  #94a3b8;
  --text-muted:#475569;
  --shadow:    0 4px 24px rgba(0,0,0,0.4);
  --radius:    12px;
}

html, body { height: 100%; font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; -webkit-font-smoothing: antialiased; }
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── LOGIN ─────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at 40% 20%, rgba(16,185,129,0.10) 0%, transparent 60%), var(--bg); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 44px 36px; width: 380px; box-shadow: var(--shadow); }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo .icon { width: 60px; height: 60px; background: linear-gradient(135deg, var(--green), var(--accent)); border-radius: 16px; margin: 0 auto 14px; display: flex; align-items: center; justify-content: center; font-size: 26px; }
.login-logo h1 { font-size: 22px; font-weight: 700; }
.login-logo p { font-size: 13px; color: var(--text-dim); margin-top: 4px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; letter-spacing: 0.5px; text-transform: uppercase; }
.form-group input { width: 100%; padding: 11px 14px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 14px; outline: none; transition: border-color .2s, box-shadow .2s; }
.form-group input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(16,185,129,.15); }
.form-group input::placeholder { color: var(--text-muted); }
.btn-login { width: 100%; padding: 12px; background: var(--green); border: none; border-radius: 8px; color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; transition: all .2s; margin-top: 4px; }
.btn-login:hover { background: #059669; transform: translateY(-1px); }
.btn-login:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.error-msg { background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3); color: #fca5a5; border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px; display: none; }

/* ─── APP LAYOUT ─────────────────────────────────────── */
.app { display: grid; grid-template-rows: 56px auto 1fr; min-height: 100vh; }

/* ─── TOPBAR ─────────────────────────────────────────── */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 24px; gap: 16px; position: sticky; top: 0; z-index: 50; }
.topbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; margin-right: auto; }
.brand-icon { width: 32px; height: 32px; background: linear-gradient(135deg, var(--green), var(--accent)); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
.topbar-badge { font-size: 11px; background: var(--surface2); border: 1px solid var(--border); color: var(--text-dim); padding: 2px 8px; border-radius: 20px; }
.btn-refresh, .btn-logout { padding: 7px 14px; border-radius: 7px; font-size: 13px; font-weight: 500; cursor: pointer; border: 1px solid var(--border); transition: all .15s; }
.btn-refresh { background: var(--surface2); color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.btn-refresh:hover { color: var(--text); border-color: var(--green); }
.btn-refresh.spinning svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-logout { background: transparent; color: var(--text-muted); }
.btn-logout:hover { color: var(--red); border-color: var(--red); }
.last-updated { font-size: 11px; color: var(--text-muted); }

/* ─── TAB NAV ─────────────────────────────────────────── */
.tab-nav { display: flex; gap: 4px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 56px; z-index: 40; overflow-x: auto; }
.tab-btn { padding: 12px 18px; font-size: 13px; font-weight: 500; color: var(--text-muted); background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; transition: all .15s; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--green); border-bottom-color: var(--green); font-weight: 600; }

/* ─── MAIN ────────────────────────────────────────────── */
.main { padding: 24px; overflow-y: auto; }
.section-title { font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 12px; }

/* ─── TAB CONTENT ────────────────────────────────────────── */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ─── FILTER BAR ─────────────────────────────────────── */
.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.filter-bar select, .filter-bar input[type="text"] { padding: 7px 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: 7px; color: var(--text); font-size: 12px; outline: none; }
.filter-bar select:focus, .filter-bar input:focus { border-color: var(--green); }
.filter-bar select option { background: var(--surface2); }
.filter-label { font-size: 11px; color: var(--text-muted); font-weight: 600; letter-spacing: .5px; text-transform: uppercase; white-space: nowrap; }
.filter-count { font-size: 11px; color: var(--text-dim); margin-left: auto; }
.filter-sep { width: 1px; height: 20px; background: var(--border); margin: 0 2px; flex-shrink: 0; }
.btn-filter-reset { padding: 7px 14px; background: var(--green); border: none; border-radius: 7px; color: #fff; font-size: 12px; font-weight: 600; cursor: pointer; transition: all .15s; white-space: nowrap; }
.btn-filter-reset:hover { background: #059669; }

/* ─── CARDS GRID ─────────────────────────────────────── */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; position: relative; overflow: hidden; transition: border-color .2s; }
.card:hover { border-color: var(--accent); }
.card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.card.blue::before   { background: var(--accent); }
.card.green::before  { background: var(--green); }
.card.red::before    { background: var(--red); }
.card.orange::before { background: var(--orange); }
.card.purple::before { background: var(--purple); }
.card-label { font-size: 11px; color: var(--text-muted); font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase; margin-bottom: 8px; }
.card-value { font-size: 24px; font-weight: 700; line-height: 1.1; margin-bottom: 4px; }
.card-value.rp { font-size: 17px; }
.card-sub { font-size: 11px; color: var(--text-dim); }
.card-icon { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); font-size: 32px; opacity: .12; }

/* ─── PANEL ─────────────────────────────────────────── */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.panel-title { font-size: 13px; font-weight: 600; }
.panel-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ─── TABLE ─────────────────────────────────────────── */
.table-wrap { overflow-x: auto; max-height: 460px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
thead { position: sticky; top: 0; z-index: 1; }
thead th { background: var(--surface2); padding: 9px 12px; text-align: left; font-size: 10px; font-weight: 700; color: var(--text-muted); letter-spacing: .5px; text-transform: uppercase; white-space: nowrap; border-bottom: 1px solid var(--border); }
tbody tr { border-bottom: 1px solid rgba(42,58,85,.5); transition: background .1s; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 9px 12px; color: var(--text); vertical-align: middle; }
.td-wrap { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── BADGE ─────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.badge-acq     { background: rgba(59,130,246,.15);  color: #93c5fd; }
.badge-high    { background: rgba(239,68,68,.15);   color: #fca5a5; border: 1px solid rgba(239,68,68,.3); }
.badge-medium  { background: rgba(245,158,11,.15);  color: #fcd34d; border: 1px solid rgba(245,158,11,.3); }
.badge-low     { background: rgba(148,163,184,.1);  color: var(--text-dim); border: 1px solid var(--border); }
.badge-cheapest { background: rgba(16,185,129,.15); color: #6ee7b7; border: 1px solid rgba(16,185,129,.3); }
.badge-priciest { background: rgba(239,68,68,.15);  color: #fca5a5; border: 1px solid rgba(239,68,68,.3); }
.seg-platinum { background: rgba(168,85,247,.2);  color: #d8b4fe; border: 1px solid rgba(168,85,247,.4); }
.seg-gold     { background: rgba(234,179,8,.2);   color: #fde047; border: 1px solid rgba(234,179,8,.4); }
.seg-silver   { background: rgba(148,163,184,.2); color: #cbd5e1; border: 1px solid rgba(148,163,184,.4); }
.seg-bronze   { background: rgba(180,83,9,.2);    color: #fdba74; border: 1px solid rgba(180,83,9,.4); }
.seg-new      { background: rgba(16,185,129,.15); color: #6ee7b7; border: 1px solid rgba(16,185,129,.3); }
.seg-inactive { background: rgba(148,163,184,.08);color: var(--text-dim); border: 1px solid var(--border); }

/* ─── MODE TOGGLE ────────────────────────────────────────── */
.mode-toggle { display: flex; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 3px; width: fit-content; margin-bottom: 16px; }
.mode-btn { padding: 6px 18px; border-radius: 6px; border: none; background: none; color: var(--text-muted); font-size: 12px; font-weight: 500; cursor: pointer; transition: all .15s; }
.mode-btn.active { background: var(--green); color: #fff; font-weight: 600; }

/* ─── PRODUCT GRID ──────────────────────────────────────── */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; margin-top: 4px; }
.product-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; transition: all .2s; }
.product-card:hover { border-color: var(--green); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.3); }
.product-card-img { width: 100%; height: 150px; object-fit: cover; background: var(--surface2); display: block; }
.product-card-img-placeholder { width: 100%; height: 150px; background: var(--surface2); display: flex; align-items: center; justify-content: center; font-size: 40px; color: var(--text-muted); }
.product-card-body { padding: 12px; }
.product-card-code { font-size: 10px; color: var(--text-muted); font-weight: 600; letter-spacing: .5px; margin-bottom: 4px; }
.product-card-name { font-size: 12px; font-weight: 600; color: var(--text); line-height: 1.4; margin-bottom: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 34px; }
.product-card-composition { font-size: 10px; color: var(--accent); margin-bottom: 6px; }
.product-card-price { font-size: 15px; font-weight: 700; color: var(--green); margin-bottom: 6px; }
.product-card-meta { display: flex; justify-content: space-between; align-items: center; }
.product-card-suppliers { font-size: 10px; color: var(--text-muted); }
.product-card-gap { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; }
.gap-high { background: rgba(239,68,68,.15); color: #fca5a5; }
.gap-mid  { background: rgba(245,158,11,.15); color: #fcd34d; }
.gap-low  { background: rgba(16,185,129,.15); color: #6ee7b7; }

/* ─── DRAWER ────────────────────────────────────────── */
.drawer-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 100; backdrop-filter: blur(2px); }
.drawer-overlay.open { display: block; }
.drawer { position: fixed; right: 0; top: 0; bottom: 0; width: min(520px, 100vw); background: var(--surface); border-left: 1px solid var(--border); z-index: 101; transform: translateX(100%); transition: transform .3s ease; overflow-y: auto; display: flex; flex-direction: column; }
.drawer.open { transform: translateX(0); }
.drawer-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; gap: 14px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.drawer-product-img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; background: var(--surface2); flex-shrink: 0; }
.drawer-product-info { flex: 1; min-width: 0; }
.drawer-product-code { font-size: 10px; color: var(--text-muted); font-weight: 600; letter-spacing: .5px; }
.drawer-product-name { font-size: 14px; font-weight: 700; margin: 3px 0 5px; line-height: 1.3; }
.drawer-product-meta { font-size: 11px; color: var(--text-dim); }
.drawer-close { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; font-size: 16px; color: var(--text-dim); transition: all .15s; line-height: 1; }
.drawer-close:hover { border-color: var(--red); color: var(--red); }
.drawer-body { padding: 20px 24px; flex: 1; }

/* ─── AI INSIGHT ─────────────────────────────────────── */
.ai-insight-content { font-size: 13px; line-height: 1.7; color: var(--text-dim); white-space: pre-wrap; max-height: 360px; overflow-y: auto; }
.ai-insight-content.loading { color: var(--text-muted); font-style: italic; }
.btn-gen-ai { padding: 7px 14px; background: linear-gradient(135deg, var(--green), var(--accent)); border: none; border-radius: 7px; color: #fff; font-size: 12px; font-weight: 600; cursor: pointer; transition: all .15s; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn-gen-ai:hover { opacity: .88; }
.btn-gen-ai:disabled { opacity: .5; cursor: not-allowed; }

/* ─── CITY COLOR CODING ─────────────────────────────── */
.city-above { color: #fca5a5; font-weight: 600; }
.city-below { color: #6ee7b7; font-weight: 600; }
.city-neutral { color: var(--text-dim); }

/* ─── CHAT FLOAT ────────────────────────────────────────── */
.chat-float-btn { position: fixed; bottom: 28px; right: 28px; width: 54px; height: 54px; border-radius: 50%; background: linear-gradient(135deg, var(--green), var(--accent)); border: none; cursor: pointer; box-shadow: 0 4px 20px rgba(16,185,129,.4); display: flex; align-items: center; justify-content: center; font-size: 22px; z-index: 90; transition: transform .2s, box-shadow .2s; }
.chat-float-btn:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(16,185,129,.5); }
.chat-panel { position: fixed; bottom: 96px; right: 28px; width: 380px; max-height: 540px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); z-index: 91; display: none; flex-direction: column; overflow: hidden; }
.chat-panel.open { display: flex; }
.chat-panel-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; background: var(--surface2); flex-shrink: 0; }
.chat-panel-title { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.chat-panel-body { flex: 1; overflow-y: auto; padding: 14px 16px 0; min-height: 0; }
.chat-panel-footer { padding: 12px 16px 14px; border-top: 1px solid var(--border); flex-shrink: 0; }
.chat-messages { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.chat-msg { max-width: 92%; }
.chat-msg.user { align-self: flex-end; }
.chat-msg.bot  { align-self: flex-start; }
.chat-bubble { padding: 10px 14px; border-radius: 12px; font-size: 13px; line-height: 1.55; }
.chat-msg.user .chat-bubble { background: var(--green); color: #fff; border-bottom-right-radius: 3px; }
.chat-msg.bot .chat-bubble  { background: var(--surface2); border: 1px solid var(--border); color: var(--text); border-bottom-left-radius: 3px; }
.chat-input-row { display: flex; gap: 8px; }
.chat-input { flex: 1; padding: 9px 13px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); font-size: 13px; font-family: inherit; outline: none; transition: border-color .2s; resize: none; }
.chat-input:focus { border-color: var(--green); }
.chat-input::placeholder { color: var(--text-muted); }
.btn-chat-send { padding: 9px 15px; background: var(--green); border: none; border-radius: 8px; color: #fff; font-size: 16px; cursor: pointer; transition: background .15s; flex-shrink: 0; }
.btn-chat-send:hover { background: #059669; }
.btn-chat-send:disabled { opacity: .4; cursor: not-allowed; }
.chat-disclaimer { font-size: 10px; color: var(--text-muted); text-align: center; margin-top: 7px; }
.chat-suggestions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.suggestion-chip { padding: 5px 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: 20px; color: var(--text-dim); font-size: 11px; cursor: pointer; transition: all .15s; white-space: nowrap; }
.suggestion-chip:hover { border-color: var(--green); color: var(--green); background: rgba(16,185,129,.08); }
.btn-clear-chat { padding: 5px 10px; background: transparent; border: 1px solid var(--border); border-radius: 6px; color: var(--text-muted); font-size: 12px; cursor: pointer; transition: all .15s; }
.btn-clear-chat:hover { border-color: var(--red); color: var(--red); }
.chat-bubble strong { font-weight: 600; }
.chat-bubble em { opacity: .8; }
.chat-bubble code { background: rgba(0,0,0,.3); padding: 1px 5px; border-radius: 3px; font-family: monospace; font-size: 11px; }
.chat-bubble ul, .chat-bubble ol { padding-left: 16px; margin: 4px 0; }
.chat-bubble li { margin: 2px 0; }

/* ─── TOAST ─────────────────────────────────────────── */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(8px); background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 11px 20px; font-size: 13px; box-shadow: var(--shadow); z-index: 200; opacity: 0; transition: all .2s; max-width: 340px; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: rgba(239,68,68,.4); color: #fca5a5; }
.toast.success { border-color: rgba(16,185,129,.4); color: #6ee7b7; }

/* ─── MULTI-SELECT DROPDOWN ─────────────────────────── */
.ms-wrap { position: relative; display: inline-block; }
.ms-btn { padding: 7px 28px 7px 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: 7px; color: var(--text); font-size: 12px; cursor: pointer; white-space: nowrap; min-width: 130px; text-align: left; position: relative; transition: border-color .15s; user-select: none; }
.ms-btn:hover, .ms-btn.open { border-color: var(--green); }
.ms-btn::after { content: '▾'; position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 10px; color: var(--text-muted); }
.ms-dropdown { display: none; position: absolute; top: calc(100% + 4px); left: 0; min-width: 200px; max-height: 240px; overflow-y: auto; background: var(--surface2); border: 1px solid var(--green); border-radius: 8px; z-index: 200; box-shadow: var(--shadow); }
.ms-dropdown.open { display: block; }
.ms-search { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.ms-search input { width: 100%; padding: 5px 8px; background: var(--surface3); border: 1px solid var(--border); border-radius: 5px; color: var(--text); font-size: 11px; outline: none; }
.ms-search input:focus { border-color: var(--green); }
.ms-option { display: flex; align-items: center; gap: 8px; padding: 7px 12px; cursor: pointer; font-size: 12px; color: var(--text-dim); transition: background .1s; }
.ms-option:hover { background: var(--surface3); color: var(--text); }
.ms-option input[type=checkbox] { accent-color: var(--green); cursor: pointer; flex-shrink: 0; }
.ms-option.checked { color: var(--green); }
.ms-footer { padding: 7px 10px; border-top: 1px solid var(--border); display: flex; gap: 6px; }
.ms-footer button { flex: 1; padding: 5px; border-radius: 5px; border: 1px solid var(--border); background: var(--surface3); color: var(--text-dim); font-size: 11px; cursor: pointer; transition: all .15s; }
.ms-footer button:hover { border-color: var(--green); color: var(--green); }
.ms-badge { display: inline-block; background: var(--green); color: #fff; border-radius: 10px; font-size: 10px; font-weight: 700; padding: 1px 5px; margin-left: 4px; }

/* ─── RESPONSIVE ────────────────────────────────────── */
@media (max-width: 768px) {
  .main { padding: 14px; }
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .chat-panel { width: calc(100vw - 20px); right: 10px; }
  .drawer { width: 100vw; }
  .cards-grid { grid-template-columns: 1fr 1fr; }
  .tab-nav { padding: 0 12px; }
  .tab-btn { padding: 10px 12px; font-size: 12px; }
}
