/* === Warm Stone Theme Variables === */
:root {
  --bg-primary: #0c0a09;
  --bg-secondary: #1c1917;
  --bg-hover: #292524;
  --border: #292524;
  --border-hover: #44403c;
  --text-primary: #fafaf9;
  --text-secondary: #a8a29e;
  --text-muted: #78716c;
  --accent: #f97316;
  --accent-dark: #ea580c;
  --accent-gradient: linear-gradient(135deg, #f97316, #ea580c);
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --blue: #3b82f6;
  --sidebar-collapsed: 52px;
  --sidebar-expanded: 180px;
  --radius: 8px;
  --radius-sm: 6px;
  --radius-xs: 4px;
  --font: system-ui, -apple-system, sans-serif;
}

/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--text-primary); }

/* === Login Page === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-primary);
}
.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 400px;
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo h1 { font-size: 18px; color: var(--text-primary); margin-top: 12px; }
.login-logo .subtitle { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.logo-icon {
  width: 40px; height: 40px;
  background: var(--accent-gradient);
  border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center;
  color: white; font-weight: bold; font-size: 14px;
}
.logo-icon.large { width: 56px; height: 56px; font-size: 18px; border-radius: 12px; }
.login-tabs { display: flex; gap: 4px; margin-bottom: 20px; }
.login-tabs .tab {
  flex: 1; padding: 8px; border: 1px solid var(--border);
  background: var(--bg-primary); color: var(--text-secondary);
  border-radius: var(--radius-sm); cursor: pointer; font-size: 12px;
  transition: all 0.15s;
}
.login-tabs .tab.active {
  background: var(--accent); color: white; border-color: var(--accent);
}
.login-form { display: flex; flex-direction: column; gap: 12px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.form-error { color: var(--red); font-size: 11px; min-height: 16px; }

/* === Form Inputs === */
input, select, textarea {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px 12px;
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-muted); }

/* === Buttons === */
.btn {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-secondary);
  transition: all 0.15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--border-hover); color: var(--text-primary); }
.btn-primary {
  background: var(--accent-gradient);
  color: white; border: none;
}
.btn-primary:hover { opacity: 0.9; }
.btn-danger { background: var(--red); color: white; border: none; }
.btn-danger:hover { opacity: 0.9; }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 4px 10px; font-size: 11px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* === App Layout === */
.app-layout { display: flex; min-height: 100vh; }

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-expanded);
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 10px 6px;
  gap: 2px;
  transition: width 0.2s ease;
  overflow: hidden;
  flex-shrink: 0;
  height: 100vh;
  position: sticky;
  top: 0;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .logo-text { display: none; }
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 6px; margin-bottom: 8px;
}
.logo-text { font-size: 13px; color: var(--text-primary); font-weight: 700; white-space: nowrap; }
.sidebar-toggle { cursor: pointer; }
.nav-items { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-secondary); font-size: 12px;
  transition: all 0.15s; position: relative; white-space: nowrap;
}
.nav-item:hover { background: var(--bg-secondary); color: var(--text-primary); }
.nav-item.active { background: var(--bg-secondary); color: var(--text-primary); border: 1px solid var(--accent); }
.nav-icon { font-size: 16px; min-width: 20px; text-align: center; }
.nav-label { font-size: 12px; }
.nav-badge {
  position: absolute; top: 4px; right: 4px;
  background: var(--red); color: white;
  font-size: 9px; font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 8px; display: flex;
  align-items: center; justify-content: center;
  padding: 0 4px;
}
.nav-bottom { margin-top: auto; padding-top: 8px; border-top: 1px solid var(--border); }

/* === Main Content === */
.main-content { flex: 1; padding: 20px; overflow-y: auto; }

/* === Page Header === */
.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px;
}
.page-header h1 { font-size: 18px; color: var(--text-primary); font-weight: 700; }
.page-header .subtitle { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.header-actions { display: flex; gap: 8px; }

/* === KPI Cards === */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 20px; }
.kpi-grid-3 { grid-template-columns: repeat(3, 1fr); }
.kpi-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.kpi-card .kpi-label {
  font-size: 9px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.kpi-card .kpi-value {
  font-size: 22px; color: var(--text-primary);
  font-weight: 700; margin-top: 4px;
}
.kpi-card .kpi-value .kpi-unit { font-size: 11px; color: var(--text-muted); }
.kpi-card .kpi-change { font-size: 10px; margin-top: 4px; }
.kpi-change.up { color: var(--green); }
.kpi-change.down { color: var(--red); }
.kpi-change.neutral { color: var(--text-muted); }

/* === Store Cards === */
.store-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.store-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px; cursor: pointer;
  transition: border-color 0.15s;
}
.store-card:hover { border-color: var(--border-hover); }
.store-card-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 10px; }
.store-card-name { font-size: 14px; color: var(--text-primary); font-weight: 600; }
.store-card-meta { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.store-card-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.store-card-stats .stat-label { font-size: 9px; color: var(--text-muted); }
.store-card-stats .stat-value { font-size: 12px; color: var(--text-primary); font-weight: 600; }
.store-card-add {
  background: var(--bg-primary);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  min-height: 120px;
  transition: border-color 0.15s;
}
.store-card-add:hover { border-color: var(--accent); }
.store-card-add .add-icon { font-size: 28px; color: var(--border-hover); }
.store-card-add .add-label { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* === RFM Bar === */
.rfm-bar { display: flex; gap: 1px; height: 6px; margin-top: 8px; }
.rfm-bar .rfm-segment { border-radius: 1px; }
.rfm-bar .champion { background: var(--green); }
.rfm-bar .loyal { background: var(--accent); }
.rfm-bar .at-risk { background: var(--yellow); }
.rfm-bar .lost { background: var(--red); }

/* === Data Tables === */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 10px 12px;
  font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
}
.data-table td {
  padding: 10px 12px; font-size: 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
}
.data-table tr:hover td { background: var(--bg-primary); }
.data-table td.text-primary { color: var(--text-primary); font-weight: 500; }

/* === Status Badges === */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: var(--radius-xs);
  font-size: 10px; font-weight: 500;
}
.badge-active { background: rgba(34, 197, 94, 0.1); color: var(--green); }
.badge-pending { background: rgba(249, 115, 22, 0.1); color: var(--accent); }
.badge-approved { background: rgba(34, 197, 94, 0.1); color: var(--green); }
.badge-rejected { background: rgba(239, 68, 68, 0.1); color: var(--red); }
.badge-executed { background: rgba(59, 130, 246, 0.1); color: var(--blue); }

/* === Modal === */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%; max-width: 480px;
  max-height: 80vh; overflow-y: auto;
}
.modal h2 { font-size: 16px; color: var(--text-primary); margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* === Section Headers === */
.section-title {
  font-size: 13px; color: var(--text-primary);
  font-weight: 600; margin-bottom: 10px; margin-top: 20px;
}

/* === Filter Bar === */
.filter-bar {
  display: flex; gap: 8px; align-items: center;
  margin-bottom: 16px; flex-wrap: wrap;
}
.filter-bar select, .filter-bar input {
  padding: 6px 10px; font-size: 12px;
}

/* === Loading & Error === */
.loading {
  display: flex; align-items: center; justify-content: center;
  min-height: 200px; color: var(--text-muted); font-size: 14px;
}
.error-message {
  color: var(--red); text-align: center;
  padding: 40px; font-size: 14px;
}
.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Control Panel (Store Detail) === */
.control-panel {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px; margin-bottom: 20px;
}
.control-btn {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s;
}
.control-btn:hover { border-color: var(--accent); }
.control-btn .control-icon { font-size: 20px; margin-bottom: 4px; }
.control-btn .control-label { font-size: 11px; color: var(--text-secondary); }
.control-btn.running { opacity: 0.85; pointer-events: none; }
.control-btn .control-result { font-size: 10px; margin-top: 4px; }
.control-result.success { color: var(--green); }
.control-result.error { color: var(--red); }

/* Sync progress bar */
.sync-progress-wrap {
  width: 100%; height: 4px;
  background: var(--border);
  border-radius: 2px; overflow: hidden;
  margin: 4px 0 2px;
}
.sync-progress-bar {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: 2px;
  transition: width 0.6s ease;
}
.sync-progress-msg {
  font-size: 9px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* === Responsive === */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .store-grid { grid-template-columns: 1fr; }
  .sidebar { width: var(--sidebar-collapsed); }
  .sidebar .nav-label, .sidebar .logo-text { display: none; }
}
