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

:root {
  --brand: #1D9E75;
  --brand-light: #E1F5EE;
  --brand-mid: #5DCAA5;
  --brand-dark: #0F6E56;
  --accent: #378ADD;
  --accent-light: #E6F1FB;
  --danger: #E24B4A;
  --danger-light: #FCEBEB;
  --warning: #EF9F27;
  --warning-light: #FAEEDA;
  --sidebar-w: 230px;
  --topbar-h: 58px;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --font: 'DM Sans', system-ui, sans-serif;
  --font-display: 'Fraunces', Georgia, serif;
}

html, body { height: 100%; font-family: var(--font); font-size: 14px; color: #1a1a1a; background: #f5f4f0; }

/* ── LOGIN ── */
#login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
}
.login-bg {
  position: absolute; inset: 0;
  background: linear-gradient(135deg, #f0f7f4 0%, #e8f4ef 40%, #dff0f3 100%);
}
.login-bg::before {
  content: ''; position: absolute; inset: 0;
  background-image: radial-gradient(circle at 20% 50%, rgba(29,158,117,.06) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(55,138,221,.05) 0%, transparent 40%);
}
.login-card {
  position: relative; z-index: 1;
  background: white; border-radius: 18px; padding: 2.5rem 2rem;
  width: 100%; max-width: 400px;
  box-shadow: 0 8px 40px rgba(0,0,0,.1), 0 2px 8px rgba(0,0,0,.06);
}
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 2rem; }
.login-brand { font-family: var(--font-display); font-size: 22px; color: #1a1a1a; }
.login-tagline { font-size: 12px; color: #888; margin-top: 1px; }
.login-title { font-size: 20px; font-weight: 500; margin-bottom: 1.5rem; color: #1a1a1a; }
.login-error { background: var(--danger-light); color: var(--danger); padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 1rem; }
.login-hint { margin-top: 1.2rem; font-size: 11.5px; color: #999; line-height: 1.8; background: #f9f9f7; padding: 10px 12px; border-radius: 8px; }

/* ── FORMS ── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 12px; font-weight: 500; color: #555; margin-bottom: 5px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 9px 12px; border: 1px solid #e0e0e0; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 13.5px; color: #1a1a1a; background: white;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--brand-mid); box-shadow: 0 0 0 3px rgba(29,158,117,.1);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-group textarea { resize: vertical; min-height: 80px; }

/* ── BUTTONS ── */
.btn-primary {
  width: 100%; padding: 11px; background: var(--brand); color: white; border: none;
  border-radius: var(--radius-sm); font-family: var(--font); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background .15s, transform .1s;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:active { transform: scale(.99); }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border: 1px solid #e0e0e0; border-radius: var(--radius-sm); background: white; color: #333; font-family: var(--font); font-size: 13px; cursor: pointer; transition: all .15s; white-space: nowrap; }
.btn:hover { background: #f5f5f3; border-color: #ccc; }
.btn.btn-green { background: var(--brand); color: white; border-color: var(--brand-dark); }
.btn.btn-green:hover { background: var(--brand-dark); }
.btn.btn-danger { background: var(--danger-light); color: var(--danger); border-color: #f0b0b0; }
.btn.btn-danger:hover { background: #f8dada; }
.btn.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn.btn-ghost { border-color: transparent; background: transparent; }
.btn.btn-ghost:hover { background: #f0f0ee; }
.btn svg { flex-shrink: 0; }

/* ── LAYOUT ── */
#app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; height: 100vh; overflow-y: auto;
  background: white; border-right: 1px solid #ebebeb;
  display: flex; flex-direction: column;
  padding: 0 0 1rem;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 1.2rem 1.2rem 1rem; border-bottom: 1px solid #f0f0ee;
  margin-bottom: .5rem;
}
.sidebar-brand { font-family: var(--font-display); font-size: 17px; color: #1a1a1a; }

.nav-group { padding: 0 .75rem; flex: 1; }
.nav-label { font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: .08em; color: #bbb; padding: .5rem .5rem .3rem; }
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: #555; text-decoration: none; font-size: 13.5px;
  cursor: pointer; margin-bottom: 2px; transition: all .12s;
}
.nav-item:hover { background: #f5f4f0; color: #1a1a1a; }
.nav-item.active { background: var(--brand-light); color: var(--brand-dark); font-weight: 500; }

.sidebar-user {
  margin-top: auto; padding: .75rem 1rem 0;
  border-top: 1px solid #f0f0ee;
  display: flex; align-items: center; gap: 10px;
}
.sidebar-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-light); color: var(--brand-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 500; flex-shrink: 0;
}
.sidebar-userinfo { flex: 1; min-width: 0; }
.sidebar-userinfo div:first-child { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-userinfo div:last-child { font-size: 11px; color: #aaa; }
.logout-btn { background: none; border: none; cursor: pointer; color: #bbb; padding: 4px; border-radius: 6px; display: flex; align-items: center; }
.logout-btn:hover { color: var(--danger); background: var(--danger-light); }

.main-content { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: var(--topbar-h); background: white; border-bottom: 1px solid #ebebeb;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem; flex-shrink: 0;
}
.page-title { font-family: var(--font-display); font-size: 20px; font-weight: 600; color: #1a1a1a; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.content-area { flex: 1; overflow-y: auto; padding: 1.5rem; }

/* ── CARDS & METRICS ── */
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 1.25rem; }
.metric-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 1.25rem; }
.metric-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 1.25rem; }

.metric-card {
  background: white; border-radius: var(--radius); padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow); border: 1px solid #f0f0ee;
}
.metric-label { font-size: 11.5px; color: #999; margin-bottom: 4px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.metric-value { font-size: 26px; font-weight: 500; color: #1a1a1a; font-family: var(--font-display); line-height: 1.1; }
.metric-delta { font-size: 11.5px; margin-top: 4px; }
.delta-up { color: var(--brand); }
.delta-down { color: var(--danger); }
.delta-neutral { color: #aaa; }

.card {
  background: white; border-radius: var(--radius); padding: 1.2rem 1.4rem;
  box-shadow: var(--shadow); border: 1px solid #f0f0ee; margin-bottom: 1.25rem;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.card-title { font-size: 13.5px; font-weight: 500; color: #1a1a1a; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; }

/* ── TABLES ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 8px 12px; font-size: 11px; font-weight: 500;
  color: #aaa; text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid #f0f0ee; white-space: nowrap;
}
tbody td { padding: 11px 12px; border-bottom: 1px solid #f7f7f5; color: #333; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafaf8; }

/* ── BADGES & PILLS ── */
.pill { display: inline-block; font-size: 11px; padding: 3px 9px; border-radius: 20px; font-weight: 500; white-space: nowrap; }
.pill-green { background: var(--brand-light); color: var(--brand-dark); }
.pill-amber { background: var(--warning-light); color: #854F0B; }
.pill-red { background: var(--danger-light); color: var(--danger); }
.pill-blue { background: var(--accent-light); color: #185FA5; }
.pill-gray { background: #f0f0ee; color: #666; }

/* ── AVATAR ── */
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11.5px; font-weight: 500; vertical-align: middle;
}
.av-g { background: #E1F5EE; color: #0F6E56; }
.av-b { background: #E6F1FB; color: #185FA5; }
.av-a { background: #FAEEDA; color: #854F0B; }
.av-p { background: #FBEAF0; color: #72243E; }
.av-v { background: #EEEDFE; color: #3C3489; }

/* ── BAR CHARTS ── */
.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-lbl { font-size: 12px; color: #888; width: 90px; flex-shrink: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 8px; background: #f0f0ee; border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width .8s cubic-bezier(.25,.46,.45,.94); }
.bar-val { font-size: 12px; color: #888; width: 55px; flex-shrink: 0; text-align: right; }

/* ── SPARKLINE ── */
.sparkline-wrap { position: relative; height: 90px; overflow: hidden; }
.sparkline-wrap svg { width: 100%; height: 100%; }

/* ── STOCK ITEMS ── */
.stock-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid #f7f7f5; }
.stock-row:last-child { border-bottom: none; }
.stock-name { font-size: 13.5px; color: #1a1a1a; }
.stock-brand { font-size: 11.5px; color: #aaa; }
.stock-qty { font-size: 14px; font-weight: 500; width: 45px; text-align: right; }
.stock-mini-bar { width: 70px; height: 5px; background: #f0f0ee; border-radius: 3px; overflow: hidden; }
.stock-mini-fill { height: 100%; border-radius: 3px; }

/* ── AI CHAT ── */
.ai-chat { background: #f9f8f6; border-radius: var(--radius); padding: 1rem; min-height: 200px; max-height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.ai-msg { display: flex; gap: 8px; align-items: flex-start; }
.ai-msg.user { flex-direction: row-reverse; }
.ai-icon { width: 28px; height: 28px; border-radius: 50%; background: var(--brand-light); display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; margin-top: 2px; }
.ai-bubble {
  background: white; border: 1px solid #eee; border-radius: 12px; border-top-left-radius: 4px;
  padding: 9px 13px; font-size: 13px; color: #333; line-height: 1.55; max-width: 82%;
}
.ai-msg.user .ai-bubble { background: var(--brand-light); border-color: var(--brand-mid); border-radius: 12px; border-top-right-radius: 4px; color: var(--brand-dark); }
.ai-input-row { display: flex; gap: 8px; margin-top: 10px; }
.ai-input-row input { flex: 1; }

/* ── TAGS / PREFS ── */
.tag-group { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag {
  font-size: 12px; padding: 4px 10px; border-radius: 20px; cursor: pointer;
  border: 1px solid #e0e0e0; background: white; color: #555; transition: all .12s;
}
.tag:hover { border-color: var(--brand-mid); color: var(--brand-dark); }
.tag.active { background: var(--brand-light); border-color: var(--brand-mid); color: var(--brand-dark); }

/* ── PROMO CARDS ── */
.promo-card { border: 1px solid #f0f0ee; border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: .75rem; transition: box-shadow .15s; }
.promo-card:hover { box-shadow: var(--shadow-md); }
.promo-title { font-size: 14px; font-weight: 500; color: #1a1a1a; margin-bottom: 4px; }
.promo-desc { font-size: 12.5px; color: #888; margin-bottom: 10px; line-height: 1.5; }

/* ── MODAL ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1000; display: flex; align-items: center; justify-content: center; animation: fade-in .15s ease; }
.modal { background: white; border-radius: 14px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.18); margin: 1rem; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1.2rem 1.4rem; border-bottom: 1px solid #f0f0ee; position: sticky; top: 0; background: white; z-index: 1; }
.modal-title { font-size: 16px; font-weight: 500; font-family: var(--font-display); }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: #aaa; padding: 2px 6px; border-radius: 4px; }
.modal-close:hover { background: #f5f5f3; color: #333; }
.modal-body { padding: 1.4rem; }
.modal-footer { padding: 1rem 1.4rem; border-top: 1px solid #f0f0ee; display: flex; gap: 8px; justify-content: flex-end; }

/* ── NOTICE ── */
.notice { display: flex; align-items: center; gap: 8px; padding: 9px 13px; border-radius: var(--radius-sm); font-size: 12.5px; margin-bottom: 1rem; }
.notice-info { background: var(--accent-light); color: #185FA5; border: 1px solid #B5D4F4; }
.notice-warn { background: var(--warning-light); color: #854F0B; border: 1px solid #FAC775; }
.notice-danger { background: var(--danger-light); color: var(--danger); border: 1px solid #F7C1C1; }
.notice-success { background: var(--brand-light); color: var(--brand-dark); border: 1px solid var(--brand-mid); }

/* ── KM SLIDER ── */
.km-slider-wrap { display: flex; align-items: center; gap: 12px; }
.km-slider-wrap input[type=range] { flex: 1; accent-color: var(--brand); }
.km-val { font-size: 13px; font-weight: 500; color: var(--brand-dark); min-width: 60px; }

/* ── CONFIG API KEYS ── */
.apikey-row { display: flex; align-items: center; gap: 8px; }
.apikey-status { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 4px 10px; border-radius: 20px; }
.apikey-ok { background: var(--brand-light); color: var(--brand-dark); }
.apikey-no { background: #f5f4f0; color: #bbb; }

/* ── CLIENT DETAIL HEADER ── */
.client-header {
  display: flex; align-items: center; gap: 1.2rem; padding: 1.4rem;
  background: white; border-radius: var(--radius); border: 1px solid #f0f0ee;
  box-shadow: var(--shadow); margin-bottom: 1.25rem;
}
.client-header-avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--brand-light); color: var(--brand-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 500; flex-shrink: 0;
}
.client-header-name { font-size: 18px; font-weight: 500; font-family: var(--font-display); }
.client-header-meta { font-size: 12.5px; color: #aaa; margin-top: 3px; }

/* ── ANIMATIONS ── */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.content-area > * { animation: slide-up .2s ease; }

/* ── EMPTY STATE ── */
.empty-state { text-align: center; padding: 3rem 1rem; color: #bbb; }
.empty-state svg { opacity: .3; margin-bottom: .75rem; }
.empty-state p { font-size: 14px; }

/* ── LOADING ── */
.loading { display: inline-block; width: 18px; height: 18px; border: 2px solid #e0e0e0; border-top-color: var(--brand); border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ddd; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #ccc; }

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .sidebar { display: none; }
  .metric-grid, .metric-grid-3 { grid-template-columns: repeat(2, 1fr); }
}

/* ── STOCK VARIANTS ── */
.variant-expand-row td { padding-top: 0 !important; }
#stock-table tbody tr { transition: background .1s; }
#stock-table tbody tr[id^="variants-"] td { border-top: none; }
#stock-table tbody tr[id^="variants-"] { border-bottom: 1px solid #f0f0ee; }

/* Filter bar inputs */
#st-search:focus, #st-f-brand:focus, #st-f-cat:focus, #st-f-status:focus, #st-f-sort:focus {
  outline: none;
  border-color: var(--brand-mid);
  box-shadow: 0 0 0 3px rgba(29,158,117,.08);
}
