/* ============================================================
   KPI Tracker — app.css
   Design: Dark industrial-precision aesthetic
   ============================================================ */

:root {
  --sidebar-w:      240px;
  --sidebar-collapsed-w: 64px;
  --topbar-h:       56px;
  --footer-h:       36px;

  --bg-base:        #0d0f14;
  --bg-surface:     #141720;
  --bg-elevated:    #1c2030;
  --bg-input:       #111420;
  --border-color:   #252a38;
  --border-subtle:  #1e2233;

  --text-primary:   #e8eaf0;
  --text-secondary: #8990a8;
  --text-muted:     #555e78;

  --accent:         #5b6af8;
  --accent-hover:   #7381ff;
  --accent-subtle:  rgba(91,106,248,.12);

  --success:        #10b981;
  --warning:        #f59e0b;
  --danger:         #ef4444;
  --info:           #06b6d4;

  --success-bg:     rgba(16,185,129,.1);
  --warning-bg:     rgba(245,158,11,.1);
  --danger-bg:      rgba(239,68,68,.1);

  --radius:         10px;
  --radius-sm:      6px;
  --radius-lg:      16px;
  --shadow:         0 2px 12px rgba(0,0,0,.4);
  --shadow-lg:      0 8px 32px rgba(0,0,0,.5);

  --font-sans:      'DM Sans', system-ui, sans-serif;
  --font-mono:      'DM Mono', monospace;

  --transition:     all .2s ease;
}

/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family:    var(--font-sans);
  background:     var(--bg-base);
  color:          var(--text-primary);
  line-height:    1.6;
  min-height:     100vh;
}

a { color: var(--accent); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--accent-hover); }

/* ── Layout ───────────────────────────────────────────────── */
.kpi-layout { min-height: 100vh; }

/* ── Sidebar ─────────────────────────────────────────────── */
.kpi-sidebar {
  width:         var(--sidebar-w);
  min-height:    100vh;
  background:    var(--bg-surface);
  border-right:  1px solid var(--border-color);
  position:      sticky;
  top:           0;
  flex-shrink:   0;
  overflow-y:    auto;
  overflow-x:    hidden;
  transition:    width .25s ease;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.sidebar-brand {
  display:     flex;
  align-items: center;
  gap:         12px;
  padding:     20px 18px 16px;
  border-bottom: 1px solid var(--border-color);
}

.brand-icon {
  width:           34px;
  height:          34px;
  background:      var(--accent);
  border-radius:   var(--radius-sm);
  display:         flex;
  align-items:     center;
  justify-content: center;
  color:           #fff;
  font-size:       14px;
  flex-shrink:     0;
}

.brand-name {
  font-weight:     700;
  font-size:       15px;
  letter-spacing:  .3px;
  white-space:     nowrap;
  overflow:        hidden;
}

.brand-logo {
  max-height:  42px;
  max-width:   160px;
  width:       auto;
  object-fit:  contain;
}

/* Nav */
.sidebar-nav { list-style: none; padding: 12px 0; }

.nav-section {
  font-size:      10px;
  font-weight:    700;
  letter-spacing: 1.2px;
  color:          var(--text-muted);
  padding:        14px 18px 4px;
  white-space:    nowrap;
  overflow:       hidden;
}

.sidebar-nav li a {
  display:      flex;
  align-items:  center;
  gap:          10px;
  padding:      9px 18px;
  color:        var(--text-secondary);
  font-size:    13.5px;
  font-weight:  500;
  border-left:  3px solid transparent;
  transition:   var(--transition);
  white-space:  nowrap;
  overflow:     hidden;
}

.sidebar-nav li a i { width: 18px; text-align: center; flex-shrink: 0; font-size: 14px; }

.sidebar-nav li a:hover {
  background:   var(--bg-elevated);
  color:        var(--text-primary);
  border-color: var(--accent-subtle);
}

.sidebar-nav li a.active {
  background:   var(--accent-subtle);
  color:        var(--accent);
  border-color: var(--accent);
}

.sidebar-nav li a span { transition: opacity .25s; }

/* Sidebar footer */
.sidebar-footer { border-top: 1px solid var(--border-color); padding: 14px 14px; }

.user-pill {
  display:     flex;
  align-items: center;
  gap:         10px;
}

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

.user-info { flex-grow: 1; overflow: hidden; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-muted); }

.btn-logout {
  color:       var(--text-muted);
  padding:     6px;
  border-radius: var(--radius-sm);
  transition:  var(--transition);
}
.btn-logout:hover { color: var(--danger); background: var(--danger-bg); }

/* Collapsed sidebar */
.sidebar-collapsed .kpi-sidebar { width: var(--sidebar-collapsed-w); }
.sidebar-collapsed .brand-name,
.sidebar-collapsed .nav-section,
.sidebar-collapsed .sidebar-nav li a span,
.sidebar-collapsed .user-info,
.sidebar-collapsed .btn-logout { opacity: 0; pointer-events: none; }

/* ── Top bar ─────────────────────────────────────────────── */
.kpi-topbar {
  height:       var(--topbar-h);
  background:   var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding:      0 20px;
  position:     sticky;
  top:          0;
  z-index:      100;
}

.btn-sidebar-toggle {
  background: none;
  border:     none;
  color:      var(--text-secondary);
  font-size:  16px;
  padding:    6px 8px;
  cursor:     pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.btn-sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-elevated); }

.topbar-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }

.topbar-clock {
  font-family: var(--font-mono);
  font-size:   12px;
  color:       var(--text-muted);
}

/* ── Main content ────────────────────────────────────────── */
.kpi-content { padding: 24px; min-height: calc(100vh - var(--topbar-h) - var(--footer-h)); }

.kpi-footer {
  height:       var(--footer-h);
  background:   var(--bg-surface);
  border-top:   1px solid var(--border-color);
  display:      flex;
  align-items:  center;
  padding:      0 20px;
  font-size:    11px;
  color:        var(--text-muted);
}

/* ── Cards ───────────────────────────────────────────────── */
.kpi-card {
  background:   var(--bg-surface);
  border:       1px solid var(--border-color);
  border-radius: var(--radius);
  padding:      20px;
  transition:   border-color .2s;
}
.kpi-card:hover { border-color: var(--border-color); }
.kpi-card.kpi-card--elevated { background: var(--bg-elevated); }

.card-header-row {
  display:       flex;
  align-items:   center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size:   13px;
  font-weight: 600;
  color:       var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .8px;
}

/* ── Stat tiles ──────────────────────────────────────────── */
.stat-tile {
  background:   var(--bg-surface);
  border:       1px solid var(--border-color);
  border-radius: var(--radius);
  padding:      18px 20px;
  position:     relative;
  overflow:     hidden;
  transition:   var(--transition);
}
.stat-tile:hover { transform: translateY(-2px); border-color: var(--accent-subtle); box-shadow: var(--shadow); }

.stat-tile .stat-label { font-size: 11px; font-weight: 700; letter-spacing: 1px; color: var(--text-muted); text-transform: uppercase; margin-bottom: 6px; }
.stat-tile .stat-value { font-size: 28px; font-weight: 700; line-height: 1; font-family: var(--font-mono); color: var(--text-primary); }
.stat-tile .stat-sub   { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

.stat-tile .stat-icon {
  position:  absolute;
  right:     16px;
  top:       50%;
  transform: translateY(-50%);
  font-size: 32px;
  opacity:   .08;
}

.stat-tile.stat--success { border-color: rgba(16,185,129,.3); }
.stat-tile.stat--success .stat-value { color: var(--success); }
.stat-tile.stat--warning { border-color: rgba(245,158,11,.3); }
.stat-tile.stat--warning .stat-value { color: var(--warning); }
.stat-tile.stat--danger  { border-color: rgba(239,68,68,.3); }
.stat-tile.stat--danger  .stat-value  { color: var(--danger); }
.stat-tile.stat--info    { border-color: rgba(6,182,212,.3); }
.stat-tile.stat--info    .stat-value  { color: var(--info); }

/* ── Status badges ───────────────────────────────────────── */
.badge-normal   { background: var(--success-bg); color: var(--success); border: 1px solid rgba(16,185,129,.3); }
.badge-warning  { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(245,158,11,.3); }
.badge-critical { background: var(--danger-bg);  color: var(--danger);  border: 1px solid rgba(239,68,68,.3); }

.badge-status {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .5px;
  padding: 3px 10px;
  border-radius: 20px;
  text-transform: uppercase;
}

/* ── Tables ──────────────────────────────────────────────── */
.kpi-table { width: 100%; border-collapse: collapse; font-size: 13px; }

.kpi-table th {
  background:     var(--bg-elevated);
  color:          var(--text-muted);
  font-size:      11px;
  font-weight:    700;
  letter-spacing: .8px;
  text-transform: uppercase;
  padding:        10px 14px;
  text-align:     left;
  border-bottom:  1px solid var(--border-color);
  white-space:    nowrap;
}

.kpi-table td {
  padding:     11px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color:       var(--text-primary);
  vertical-align: middle;
}

.kpi-table tbody tr { transition: background .15s; }
.kpi-table tbody tr:hover { background: var(--bg-elevated); }
.kpi-table tbody tr:last-child td { border-bottom: none; }

.kpi-value {
  font-family: var(--font-mono);
  font-size:   13.5px;
  font-weight: 500;
}

/* ── Forms ───────────────────────────────────────────────── */
.form-control, .form-select {
  background:   var(--bg-input) !important;
  border:       1px solid var(--border-color) !important;
  color:        var(--text-primary) !important;
  border-radius: var(--radius-sm) !important;
  font-size:    13px;
  padding:      8px 12px;
  transition:   var(--transition);
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent) !important;
  box-shadow:   0 0 0 3px var(--accent-subtle) !important;
  outline:      none;
}
.form-label { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; letter-spacing: .3px; }
.form-text  { font-size: 11px; color: var(--text-muted); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn { border-radius: var(--radius-sm) !important; font-size: 13px; font-weight: 500; }

.btn-primary {
  background:   var(--accent) !important;
  border-color: var(--accent) !important;
}
.btn-primary:hover {
  background:   var(--accent-hover) !important;
  border-color: var(--accent-hover) !important;
}

/* ── Filter bar ──────────────────────────────────────────── */
.filter-bar {
  background:   var(--bg-surface);
  border:       1px solid var(--border-color);
  border-radius: var(--radius);
  padding:      14px 18px;
  margin-bottom: 20px;
}
.filter-bar .row { align-items: flex-end; }

/* ── Pagination ──────────────────────────────────────────── */
.kpi-pagination { display: flex; align-items: center; gap: 4px; justify-content: center; padding: 16px 0; flex-wrap: wrap; }
.kpi-pagination a,
.kpi-pagination span {
  width:           32px;
  height:          32px;
  display:         flex;
  align-items:     center;
  justify-content: center;
  border-radius:   var(--radius-sm);
  font-size:       13px;
  font-weight:     500;
  color:           var(--text-secondary);
  background:      var(--bg-elevated);
  border:          1px solid var(--border-color);
  transition:      var(--transition);
}
.kpi-pagination a:hover { background: var(--accent-subtle); color: var(--accent); border-color: var(--accent); }
.kpi-pagination span.current { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Charts ──────────────────────────────────────────────── */
.chart-container { position: relative; }

/* ── Login page ──────────────────────────────────────────── */
.login-bg {
  min-height:      100vh;
  background:      var(--bg-base);
  display:         flex;
  align-items:     center;
  justify-content: center;
  position:        relative;
  overflow:        hidden;
}

.login-bg::before {
  content:   '';
  position:  absolute;
  inset:     0;
  background: radial-gradient(ellipse 80% 60% at 50% -10%, rgba(91,106,248,.2), transparent),
              radial-gradient(ellipse 50% 50% at 90% 90%, rgba(139,92,246,.1), transparent);
  pointer-events: none;
}

.login-card {
  background:   var(--bg-surface);
  border:       1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding:      40px 36px;
  width:        100%;
  max-width:    400px;
  box-shadow:   var(--shadow-lg);
  position:     relative;
  z-index:      1;
}

.login-logo {
  text-align:   center;
  margin-bottom: 28px;
}
.login-logo .logo-icon {
  width:  60px;
  height: 60px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  color: #fff;
  margin-bottom: 14px;
}
.login-logo h1 { font-size: 22px; font-weight: 700; color: var(--text-primary); }
.login-logo p  { font-size: 13px; color: var(--text-muted); }
.login-logo-img {
  max-height:    80px;
  max-width:     220px;
  width:         auto;
  object-fit:    contain;
  margin-bottom: 12px;
}

/* ── Employee avatar ─────────────────────────────────────── */
.emp-avatar {
  width:           44px;
  height:          44px;
  border-radius:   50%;
  background:      linear-gradient(135deg, var(--accent), #8b5cf6);
  display:         inline-flex;
  align-items:     center;
  justify-content: center;
  font-weight:     700;
  font-size:       16px;
  color:           #fff;
  flex-shrink:     0;
}
.emp-avatar.sm { width: 32px; height: 32px; font-size: 13px; }

/* ── KPI trend indicator ─────────────────────────────────── */
.trend-up   { color: var(--success); }
.trend-down { color: var(--danger); }

/* ── Fullscreen mode ─────────────────────────────────────── */
.fullscreen-mode .kpi-sidebar,
.fullscreen-mode .filter-bar,
.fullscreen-mode .kpi-topbar,
.fullscreen-mode .kpi-footer { display: none !important; }
.fullscreen-mode .kpi-content { padding: 16px; }
.fullscreen-mode .kpi-main { max-width: 100%; }

/* ── Progress bar KPI ────────────────────────────────────── */
.kpi-progress { height: 6px; border-radius: 3px; background: var(--bg-elevated); overflow: hidden; margin-top: 8px; }
.kpi-progress-fill { height: 100%; border-radius: 3px; transition: width .5s ease; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .kpi-sidebar { position: fixed; left: -var(--sidebar-w); z-index: 1000; }
  .sidebar-open .kpi-sidebar { left: 0; }
  .kpi-content { padding: 16px; }
}

/* ── Utility ─────────────────────────────────────────────── */
.text-mono { font-family: var(--font-mono); }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-danger  { color: var(--danger)  !important; }
.text-info    { color: var(--info)    !important; }
.text-muted   { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }

.bg-surface   { background: var(--bg-surface) !important; }
.bg-elevated  { background: var(--bg-elevated) !important; }

.border-subtle { border-color: var(--border-color) !important; }

.section-title {
  font-size:   11px;
  font-weight: 700;
  letter-spacing: 1px;
  color:       var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 14px;
}

/* ── Alert overrides ─────────────────────────────────────── */
.alert { font-size: 13px; border-radius: var(--radius); }
.alert-danger  { background: var(--danger-bg);  border-color: rgba(239,68,68,.3);  color: #fca5a5; }
.alert-success { background: var(--success-bg); border-color: rgba(16,185,129,.3); color: #6ee7b7; }
.alert-warning { background: var(--warning-bg); border-color: rgba(245,158,11,.3); color: #fcd34d; }

/* ── Modal overrides ─────────────────────────────────────── */
.modal-content { background: var(--bg-surface); border-color: var(--border-color); }
.modal-header  { border-color: var(--border-color); }
.modal-footer  { border-color: var(--border-color); }

/* ── Tooltip ─────────────────────────────────────────────── */
.kpi-tooltip {
  position:    relative;
  cursor:      help;
}
.kpi-tooltip::after {
  content:     attr(data-tip);
  position:    absolute;
  bottom:      calc(100% + 6px);
  left:        50%;
  transform:   translateX(-50%);
  background:  var(--bg-elevated);
  color:       var(--text-primary);
  border:      1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding:     4px 10px;
  font-size:   11px;
  white-space: nowrap;
  pointer-events: none;
  opacity:     0;
  transition:  opacity .2s;
  z-index:     999;
}
.kpi-tooltip:hover::after { opacity: 1; }
