/* ═══════════════════════════════════════════════════════════════════
   KPI Reframing Engine – Custom Stylesheet
   ═══════════════════════════════════════════════════════════════════ */

/* ── Variables ─────────────────────────────────────────────────────── */
:root {
  --sidebar-bg: #12172b;
  --sidebar-border: rgba(255,255,255,.06);
  --sidebar-text: #8892b0;
  --sidebar-text-hover: #e2e8f0;
  --sidebar-active-bg: rgba(99,179,237,.12);
  --sidebar-active-text: #63b3ed;
  --sidebar-active-border: #63b3ed;
  --sidebar-width: 260px;

  --topbar-height: 62px;
  --topbar-bg: #ffffff;
  --topbar-border: #e8edf4;

  --body-bg: #f0f4f8;
  --card-bg: #ffffff;
  --card-radius: 14px;
  --card-shadow: 0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --card-border: #e8edf4;

  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #6366f1;

  --color-optimized: #059669;
  --color-original: #475569;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --font-base: 'Inter', system-ui, -apple-system, sans-serif;
  --transition: .18s ease;
}

/* ── Reset & Base ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  font-family: var(--font-base);
  font-size: .9375rem;
  color: var(--text-primary);
  background: var(--body-bg);
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

/* ═══════════════════════════════════════════════════════════════════
   APP LAYOUT
   ═══════════════════════════════════════════════════════════════════ */
.app-body { overflow-x: hidden; }

.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: 1.5rem 1.25rem 1.25rem;
  border-bottom: 1px solid var(--sidebar-border);
}

.brand-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.brand-name {
  display: block;
  font-weight: 700;
  font-size: .95rem;
  color: #e2e8f0;
  line-height: 1.2;
}
.brand-sub {
  display: block;
  font-size: .7rem;
  color: var(--sidebar-text);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.sidebar-nav {
  padding: 1rem .75rem;
  flex: 1;
}

.nav-section-label {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .1em;
  color: var(--sidebar-text);
  opacity: .6;
  padding: .5rem .75rem .3rem;
  text-transform: uppercase;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem .75rem;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 450;
  margin-bottom: 2px;
  transition: background var(--transition), color var(--transition);
  border-left: 2px solid transparent;
}

.nav-link i { font-size: 1rem; flex-shrink: 0; }

.nav-link:hover {
  background: rgba(255,255,255,.06);
  color: var(--sidebar-text-hover);
}

.nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-left-color: var(--sidebar-active-border);
  font-weight: 600;
}

.text-danger-soft { color: #fc8181 !important; }
.text-danger-soft:hover { color: #fc8181 !important; background: rgba(252,129,129,.08) !important; }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--sidebar-border);
  margin-top: auto;
}

.user-avatar {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: .8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.user-name { font-size: .8rem; font-weight: 600; color: #e2e8f0; line-height: 1.2; }
.user-role { font-size: .7rem; color: var(--sidebar-text); }

/* ── Main content ──────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--body-bg);
}

.topbar {
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  display: flex;
  align-items: center;
  padding: 0 1.75rem;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-breadcrumb { flex: 1; }

.page-content {
  padding: 2rem 1.75rem;
  flex: 1;
}

/* ── Page header ───────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 .2rem;
  line-height: 1.2;
}

.page-subtitle {
  color: var(--text-secondary);
  margin: 0;
  font-size: .875rem;
}

/* ── Card section ──────────────────────────────────────────────────── */
.card-section {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--card-radius);
  padding: 1.5rem;
  box-shadow: var(--card-shadow);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

/* ═══════════════════════════════════════════════════════════════════
   STAT CARDS
   ═══════════════════════════════════════════════════════════════════ */
.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--card-radius);
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  box-shadow: var(--card-shadow);
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0,0,0,.1); }

.stat-icon {
  width: 52px; height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-card-total .stat-icon   { background: #eff6ff; color: var(--primary); }
.stat-card-optimized .stat-icon { background: #ecfdf5; color: var(--success); }
.stat-card-pending .stat-icon { background: #fffbeb; color: var(--warning); }
.stat-card-exported .stat-icon { background: #f5f3ff; color: var(--info); }

.stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: .15rem;
}

.stat-label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ═══════════════════════════════════════════════════════════════════
   STATUS & TYPE BADGES
   ═══════════════════════════════════════════════════════════════════ */
.status-badge {
  display: inline-flex;
  align-items: center;
  padding: .2rem .65rem;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
  text-transform: capitalize;
}

.badge-draft    { background: #f1f5f9; color: #64748b; }
.badge-imported { background: #eff6ff; color: #3b82f6; }
.badge-optimized { background: #ecfdf5; color: #059669; }
.badge-exported { background: #f5f3ff; color: #7c3aed; }

.type-badge {
  display: inline-flex;
  align-items: center;
  padding: .2rem .65rem;
  border-radius: 6px;
  font-size: .72rem;
  font-weight: 600;
}

.type-badge-project       { background: #eff6ff; color: #2563eb; }
.type-badge-operational   { background: #ecfdf5; color: #059669; }
.type-badge-cross_department { background: #fff7ed; color: #d97706; }

/* ═══════════════════════════════════════════════════════════════════
   TABLE
   ═══════════════════════════════════════════════════════════════════ */
.table thead th {
  font-size: .75rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 2px solid var(--card-border);
  background: #f8fafc;
  padding: .75rem 1rem;
}
.table td { padding: .85rem 1rem; vertical-align: middle; border-color: #f1f5f9; }
.table tbody tr:hover { background: #f8fbff; }
.row-title:hover { color: var(--primary) !important; }

/* ── Small buttons ─────────────────────────────────────────────────── */
.btn-xs {
  padding: .25rem .5rem;
  font-size: .75rem;
  border-radius: 6px;
  line-height: 1.4;
}

.btn-ghost {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: #f1f5f9; color: var(--text-primary); }

.btn-optimize {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #059669;
  font-size: .75rem;
  padding: .25rem .5rem;
  border-radius: 6px;
}
.btn-optimize:hover { background: #d1fae5; color: #047857; }

.btn-optimize-lg {
  background: linear-gradient(135deg, #059669, #10b981);
  border: none;
  color: white;
  font-weight: 600;
  padding: .6rem 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(5,150,105,.3);
}
.btn-optimize-lg:hover {
  background: linear-gradient(135deg, #047857, #059669);
  color: white;
  box-shadow: 0 4px 12px rgba(5,150,105,.4);
}

/* ═══════════════════════════════════════════════════════════════════
   GATE COMPARISON
   ═══════════════════════════════════════════════════════════════════ */
.gate-comparison-row {
  display: grid;
  grid-template-columns: 36px 120px 1fr 1px 1fr;
  gap: 0;
  align-items: stretch;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  margin-bottom: .75rem;
  overflow: hidden;
  background: var(--card-bg);
  transition: box-shadow .15s;
}
.gate-comparison-row:hover { box-shadow: 0 2px 8px rgba(0,0,0,.07); }

.gate-number-col {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem .5rem;
  background: #f8fafc;
  border-right: 1px solid #f1f5f9;
}

.gate-circle {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 800;
  color: white;
  flex-shrink: 0;
}
.gate-circle-1 { background: #ef4444; }
.gate-circle-2 { background: #f97316; }
.gate-circle-3 { background: #3b82f6; }
.gate-circle-4 { background: #06b6d4; }
.gate-circle-5 { background: #10b981; }

.gate-label-col {
  display: flex;
  align-items: center;
  padding: 1rem .75rem;
  background: #f8fafc;
  border-right: 1px solid #f1f5f9;
}

.gate-label-text {
  font-size: .72rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .05em;
  writing-mode: horizontal-tb;
}

.gate-text-col {
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.gate-orig { background: #fafbfc; }
.gate-opt  { background: #f0fdf8; }

.gate-text {
  font-size: .875rem;
  line-height: 1.6;
  color: var(--text-primary);
}

.gate-divider {
  background: var(--card-border);
  width: 1px;
}

.gate-header-row { display: grid; grid-template-columns: 36px 120px 1fr 1fr; }

/* ── Gate input blocks ─────────────────────────────────────────────── */
.gate-input-block {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--card-border);
}

.gate-input-label {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--card-border);
}

.gate-badge {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  font-weight: 800;
  color: white;
  flex-shrink: 0;
}
.gate-badge-1 { background: #ef4444; }
.gate-badge-2 { background: #f97316; }
.gate-badge-3 { background: #3b82f6; }
.gate-badge-4 { background: #06b6d4; }
.gate-badge-5 { background: #10b981; }

.gate-input-block textarea { border: none; border-radius: 0; resize: vertical; }
.gate-input-block textarea:focus { box-shadow: none; border-color: transparent; background: #fffef0; }

/* ═══════════════════════════════════════════════════════════════════
   COMPARISON CARDS
   ═══════════════════════════════════════════════════════════════════ */
.comparison-card {
  border: 1px solid var(--card-border);
  border-radius: var(--card-radius);
  overflow: hidden;
  height: 100%;
  box-shadow: var(--card-shadow);
}

.comparison-card-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .75rem 1.25rem;
  font-size: .85rem;
  font-weight: 600;
}

.comparison-original .comparison-card-header { background: #f8fafc; border-bottom: 1px solid #e8edf4; }
.comparison-optimized .comparison-card-header { background: #ecfdf5; border-bottom: 1px solid #a7f3d0; }

.comparison-card-body {
  padding: 1.25rem;
  font-size: .9rem;
  line-height: 1.7;
}

.comparison-label {
  display: inline-flex;
  align-items: center;
  padding: .15rem .55rem;
  border-radius: 5px;
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.comparison-label.original  { background: #e2e8f0; color: #475569; }
.comparison-label.optimized { background: #d1fae5; color: #047857; }

/* ═══════════════════════════════════════════════════════════════════
   SUGGESTIONS
   ═══════════════════════════════════════════════════════════════════ */
.suggestions-list { display: flex; flex-direction: column; gap: .75rem; }

.suggestion-item {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .875rem 1rem;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 10px;
  font-size: .875rem;
  line-height: 1.6;
}

/* ═══════════════════════════════════════════════════════════════════
   UPLOAD
   ═══════════════════════════════════════════════════════════════════ */
.upload-dropzone {
  border: 2px dashed #cbd5e1;
  border-radius: 12px;
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: border-color .2s, background .2s;
  background: #f8fafc;
}
.upload-dropzone:hover, .upload-dropzone.drag-over {
  border-color: var(--primary);
  background: #eff6ff;
}
.upload-dropzone.has-file {
  border-color: var(--success);
  background: #f0fdf4;
}

.upload-dropzone input[type=file] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.upload-icon { font-size: 2.5rem; color: var(--text-muted); display: block; margin-bottom: .75rem; }
.upload-title { font-size: 1rem; font-weight: 600; color: var(--text-primary); margin-bottom: .25rem; }
.upload-subtitle { font-size: .85rem; color: var(--text-muted); margin: 0; }
.upload-filename { font-size: .875rem; font-weight: 600; color: var(--success); }

/* ── Flow steps ─────────────────────────────────────────────────────── */
.flow-steps { display: flex; align-items: center; gap: 0; flex-wrap: wrap; }
.flow-step {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .8rem;
  color: var(--text-muted);
  padding: .4rem .5rem;
}
.flow-step.active { color: var(--primary); font-weight: 600; }
.flow-step-num {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
  font-weight: 700;
  color: #64748b;
  flex-shrink: 0;
}
.flow-step.active .flow-step-num { background: var(--primary); color: white; }
.flow-connector { width: 24px; height: 2px; background: #e2e8f0; }

/* ── Tips list ──────────────────────────────────────────────────────── */
.tips-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.tips-list li {
  font-size: .875rem;
  color: var(--text-secondary);
  padding-left: 1.25rem;
  position: relative;
  line-height: 1.6;
}
.tips-list li::before {
  content: '•';
  position: absolute;
  left: 0;
  color: var(--primary);
  font-weight: 700;
}

/* ── Type breakdown ─────────────────────────────────────────────────── */
.type-breakdown-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem 0;
  border-bottom: 1px solid #f1f5f9;
}
.type-breakdown-row:last-child { border-bottom: none; }

.import-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem 0;
  border-bottom: 1px solid #f1f5f9;
}
.import-row:last-child { border-bottom: none; }
.import-name { font-size: .8rem; font-weight: 600; }

/* ── Empty state ────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
}
.empty-icon { font-size: 3rem; color: #cbd5e1; display: block; margin-bottom: 1rem; }
.empty-title { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); margin-bottom: .5rem; }
.empty-subtitle { color: var(--text-secondary); font-size: .9rem; margin: 0; }

/* ── Optimize overlay ───────────────────────────────────────────────── */
.optimize-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.65);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.optimize-overlay-inner {
  background: white;
  border-radius: 16px;
  padding: 2.5rem 3rem;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  max-width: 380px;
}

/* ── Messages container ─────────────────────────────────────────────── */
.messages-container { margin-bottom: 1.5rem; }
.alert { border-radius: 10px; }
.alert-success { background: #f0fdf4; border-color: #a7f3d0; color: #047857; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-error, .alert-danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }

/* ── Help panel ─────────────────────────────────────────────────────── */
.help-panel { background: #fafbfc; }
.help-item p { font-size: .85rem; }

/* ── Model guide ─────────────────────────────────────────────────────── */
.model-guide { display: flex; flex-direction: column; gap: .6rem; }
.model-row { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.model-row code { font-size: .8rem; }

/* ── Settings ────────────────────────────────────────────────────────── */
.form-label { font-size: .85rem; font-weight: 600; color: var(--text-secondary); margin-bottom: .4rem; }
.form-control, .form-select {
  border-color: #e2e8f0;
  border-radius: 8px;
  font-size: .9rem;
  padding: .55rem .85rem;
  color: var(--text-primary);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
.form-text { font-size: .8rem; color: var(--text-muted); margin-top: .35rem; }

/* ═══════════════════════════════════════════════════════════════════
   LOGIN PAGE
   ═══════════════════════════════════════════════════════════════════ */
.login-body {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  min-height: 100vh;
}

.login-wrapper {
  display: flex;
  min-height: 100vh;
}

.login-brand-panel {
  width: 52%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem;
  background: transparent;
}

.login-brand-content { max-width: 420px; }

.login-brand-icon {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  color: white;
  margin-bottom: 1.5rem;
}

.login-brand-title {
  font-size: 2.5rem;
  font-weight: 800;
  color: white;
  line-height: 1.15;
  margin-bottom: 1rem;
}

.login-brand-tagline {
  color: #94a3b8;
  font-size: .95rem;
  line-height: 1.7;
  margin-bottom: 0;
}

.login-feature {
  font-size: .875rem;
  color: #cbd5e1;
  padding: .35rem 0;
}

.login-form-panel {
  flex: 1;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 2rem;
  border-radius: 24px 0 0 24px;
}

.login-form-box { width: 100%; max-width: 400px; }

.login-logo {
  width: 48px; height: 48px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: white;
}

.login-form-title {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: .3rem;
}
.login-form-subtitle { font-size: .9rem; }

.login-hint { font-size: .8rem; }

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 991.98px) {
  .sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-100%);
    z-index: 1050;
  }
  .sidebar.show { transform: translateX(0); }
  .main-content { width: 100%; }
  .page-content { padding: 1.25rem 1rem; }
  .topbar { padding: 0 1rem; }
  .gate-comparison-row { grid-template-columns: 30px 80px 1fr; }
  .gate-divider, .gate-opt { display: none; }
  .login-form-panel { border-radius: 0; }
}

@media (max-width: 575.98px) {
  .page-title { font-size: 1.3rem; }
  .stat-value { font-size: 1.6rem; }
  .card-section { padding: 1rem; }
}

/* ── Utility overrides ──────────────────────────────────────────────── */
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); }
code { background: #f1f5f9; color: #7c3aed; padding: .1em .4em; border-radius: 4px; font-size: .85em; }
