:root {
  --bg: #0f172a;
  --bg2: #1e293b;
  --bg3: #334155;
  --border: #475569;
  --text: #f1f5f9;
  --text2: #94a3b8;
  --text3: #64748b;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --purple: #8b5cf6;
  --radius: 8px;
  --shadow: 0 4px 6px -1px rgba(0,0,0,.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

.sidebar {
  width: 240px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.25s;
}

.sidebar-logo {
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo img { width: 32px; height: 32px; }
.sidebar-logo span { font-weight: 700; font-size: 1rem; color: var(--text); }
.sidebar-logo small { display: block; font-size: .7rem; color: var(--text3); }

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-group { margin-bottom: 20px; }
.nav-group-label {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text3);
  padding: 4px 8px;
  margin-bottom: 4px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--text2);
  font-size: .875rem;
  transition: background .15s, color .15s;
  cursor: pointer;
}
.nav-link:hover, .nav-link.active {
  background: var(--bg3);
  color: var(--text);
  text-decoration: none;
}
.nav-link.active { font-weight: 600; }
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius);
}
.user-avatar {
  width: 34px; height: 34px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .875rem; flex-shrink: 0;
}
.user-name { font-size: .8rem; font-weight: 600; }
.user-email { font-size: .7rem; color: var(--text3); }

.main-content {
  margin-left: 240px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 1.125rem; font-weight: 700; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.page-content { padding: 24px; flex: 1; }

/* ======= CARDS ======= */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-sm { padding: 14px 16px; }

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-label { font-size: .75rem; color: var(--text2); font-weight: 500; }
.stat-value { font-size: 2rem; font-weight: 800; line-height: 1; }
.stat-sub { font-size: .75rem; color: var(--text3); }

/* ======= GRIDS ======= */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

/* ======= FORMS ======= */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-label { font-size: .8rem; font-weight: 600; color: var(--text2); }
.form-control {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-size: .875rem;
  width: 100%;
  transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--primary); }
.form-control::placeholder { color: var(--text3); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ======= BUTTONS ======= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-ghost {
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg3); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-icon { padding: 7px; border-radius: var(--radius); }

/* ======= BADGES/STATUS ======= */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-blue { background: #1e40af22; color: #60a5fa; border: 1px solid #1e40af55; }
.badge-yellow { background: #92400e22; color: #fbbf24; border: 1px solid #92400e55; }
.badge-orange { background: #9a3412 22; color: #fb923c; border: 1px solid #9a341255; }
.badge-green { background: #064e3b22; color: #34d399; border: 1px solid #064e3b55; }
.badge-purple { background: #4c1d9522; color: #a78bfa; border: 1px solid #4c1d9555; }
.badge-red { background: #7f1d1d22; color: #f87171; border: 1px solid #7f1d1d55; }
.badge-gray { background: #1e293b; color: var(--text2); border: 1px solid var(--border); }

/* ======= TABLE ======= */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th {
  text-align: left;
  padding: 10px 14px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text3);
  border-bottom: 1px solid var(--border);
}
td {
  padding: 12px 14px;
  border-bottom: 1px solid #1e293b;
  vertical-align: middle;
}
tr:hover td { background: #ffffff06; }
tr:last-child td { border-bottom: none; }

/* ======= KANBAN ======= */
.kanban { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 8px; }
.kanban-col {
  min-width: 260px;
  width: 260px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 200px);
}
.kanban-col-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: .875rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.kanban-col-body { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.kanban-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: border-color .15s;
}
.kanban-card:hover { border-color: var(--primary); }
.kanban-card-title { font-weight: 600; font-size: .875rem; margin-bottom: 6px; }
.kanban-card-meta { font-size: .75rem; color: var(--text3); display: flex; flex-direction: column; gap: 3px; }

/* ======= ALERT ======= */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: .875rem;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.alert-warning { background: #92400e22; border: 1px solid #92400e55; color: #fbbf24; }
.alert-danger { background: #7f1d1d22; border: 1px solid #7f1d1d55; color: #f87171; }
.alert-success { background: #064e3b22; border: 1px solid #064e3b55; color: #34d399; }
.alert-info { background: #1e3a5f22; border: 1px solid #1e40af55; color: #60a5fa; }

/* ======= MODAL ======= */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: translateY(12px);
  transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 1.1rem; font-weight: 700; }
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ======= INDICATOR CARD ======= */
.ind-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: border-color .15s;
}
.ind-card:hover { border-color: var(--primary); }
.ind-card-area { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.ind-card-name { font-weight: 700; font-size: .95rem; }
.ind-card-value { font-size: 1.8rem; font-weight: 800; line-height: 1; }
.ind-card-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ind-card-goal { font-size: .75rem; color: var(--text3); }
.trend-up { color: var(--success); }
.trend-down { color: var(--danger); }
.trend-na { color: var(--text3); }

/* ======= MISC ======= */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-4 { margin-top: 16px; }
.text-sm { font-size: .875rem; }
.text-xs { font-size: .75rem; }
.text-muted { color: var(--text3); }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }
.hidden { display: none !important; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* Alerta visual jiga parada */
.jiga-alerta { border-left: 3px solid var(--danger) !important; }
.jiga-alerta-warn { border-left: 3px solid var(--warning) !important; }

/* Toast */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: .875rem;
  min-width: 220px;
  max-width: 360px;
  box-shadow: var(--shadow);
  animation: slideIn .25s ease;
  pointer-events: all;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--primary); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Spinner */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Loading state */
.loading-state {
  display: flex; align-items: center; justify-content: center;
  padding: 48px;
  gap: 12px;
  color: var(--text3);
}
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px;
  gap: 12px;
  color: var(--text3);
  text-align: center;
}
.empty-state svg { width: 48px; height: 48px; opacity: .4; }

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

/* Responsive */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .grid-4, .grid-3 { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .kanban-col { min-width: 220px; }
}

/* TV Mode */
body.tv-mode .sidebar { display: none; }
body.tv-mode .main-content { margin-left: 0; }
body.tv-mode .topbar { display: none; }
body.tv-mode .page-content { padding: 16px; }
