:root {
  --primary: #0f172a;
  --primary-light: #1e293b;
  --accent: #22c55e;
  --accent-hover: #16a34a;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --card-bg: #1e293b;
  --sidebar-w: 260px;
  --topbar-h: 64px;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --font: 'Inter', sans-serif;
}
[data-theme="light"] {
  --primary: #f8fafc; --primary-light: #ffffff; --accent: #16a34a;
  --text: #0f172a; --text-muted: #64748b; --border: #e2e8f0;
  --card-bg: #ffffff; --shadow: 0 4px 24px rgba(0,0,0,0.08);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--primary); color: var(--text); min-height: 100vh; display: flex; }

/* ── Sidebar ─────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); min-height: 100vh; background: var(--primary-light);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; z-index: 100; transition: transform .3s ease;
}
.sidebar-brand {
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.sidebar-brand .logo-icon {
  width: 40px; height: 40px; background: var(--accent);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.sidebar-brand .brand-text h5 { font-size: 15px; font-weight: 700; color: var(--text); }
.sidebar-brand .brand-text small { font-size: 11px; color: var(--text-muted); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 16px 0; }
.nav-section-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--text-muted); padding: 8px 24px 4px;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 24px;
  color: var(--text-muted); text-decoration: none; font-size: 14px;
  font-weight: 500; border-left: 3px solid transparent;
  transition: all .2s ease; position: relative;
}
.sidebar-nav a:hover { color: var(--text); background: rgba(255,255,255,.05); }
.sidebar-nav a.active { color: var(--accent); background: rgba(34,197,94,.08); border-left-color: var(--accent); }
.sidebar-nav a .nav-icon { font-size: 18px; width: 22px; text-align: center; flex-shrink: 0; }
.sidebar-nav a .badge-count {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 99px;
}
.sidebar-footer { padding: 16px 24px; border-top: 1px solid var(--border); }

/* ── Main Layout ─────────────────────────────────── */
.main-wrapper { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

/* ── Top Bar ─────────────────────────────────────── */
.topbar {
  height: var(--topbar-h); background: var(--primary-light);
  border-bottom: 1px solid var(--border); display: flex; align-items: center;
  padding: 0 24px; gap: 16px; position: sticky; top: 0; z-index: 99;
}
.topbar-search {
  flex: 1; max-width: 400px; position: relative;
}
.topbar-search input {
  width: 100%; background: var(--primary); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 8px 16px 8px 40px;
  font-size: 14px; outline: none; transition: border-color .2s;
}
.topbar-search input:focus { border-color: var(--accent); }
.topbar-search .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar-btn {
  width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; transition: all .2s; position: relative;
}
.topbar-btn:hover { border-color: var(--accent); color: var(--accent); }
.topbar-btn .notif-badge {
  position: absolute; top: -4px; right: -4px; background: var(--danger);
  color: #fff; font-size: 9px; font-weight: 700; width: 16px; height: 16px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.user-menu { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); transition: all .2s; }
.user-menu:hover { border-color: var(--accent); }
.user-avatar {
  width: 32px; height: 32px; border-radius: 8px; background: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; color: #fff;
}
.user-info .user-name { font-size: 13px; font-weight: 600; }
.user-info .user-role { font-size: 11px; color: var(--text-muted); }

/* ── Page Content ────────────────────────────────── */
.page-content { flex: 1; padding: 28px 28px; }
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 24px; font-weight: 700; }
.page-header .breadcrumb { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.page-header .breadcrumb a { color: var(--accent); text-decoration: none; }

/* ── Cards ───────────────────────────────────────── */
.card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-header h5 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--border); }

/* ── KPI Cards ───────────────────────────────────── */
.kpi-card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; position: relative; overflow: hidden;
  transition: transform .2s, box-shadow .2s;
}
.kpi-card:hover { transform: translateY(-3px); box-shadow: 0 8px 32px rgba(0,0,0,.4); }
.kpi-card .kpi-icon {
  width: 52px; height: 52px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 24px; margin-bottom: 16px;
}
.kpi-card .kpi-value { font-size: 32px; font-weight: 800; line-height: 1; }
.kpi-card .kpi-label { font-size: 13px; color: var(--text-muted); margin-top: 6px; }
.kpi-card .kpi-trend { font-size: 12px; margin-top: 8px; }
.kpi-card::after {
  content: ''; position: absolute; right: -20px; top: -20px;
  width: 100px; height: 100px; border-radius: 50%;
  background: currentColor; opacity: .04;
}
.kpi-green { color: var(--accent); } .kpi-green .kpi-icon { background: rgba(34,197,94,.15); }
.kpi-red   { color: var(--danger); } .kpi-red .kpi-icon   { background: rgba(239,68,68,.15);  }
.kpi-amber { color: var(--warning);} .kpi-amber .kpi-icon { background: rgba(245,158,11,.15); }
.kpi-blue  { color: var(--info);   } .kpi-blue .kpi-icon  { background: rgba(59,130,246,.15); }

/* ── Tables ──────────────────────────────────────── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { background: var(--primary); color: var(--text-muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px; padding: 12px 16px; text-align: left; }
.table td { padding: 12px 16px; border-top: 1px solid var(--border); vertical-align: middle; color: var(--text); }
.table tbody tr { transition: background .15s; }
.table tbody tr:hover { background: rgba(255,255,255,.03); }
.table-striped tbody tr:nth-child(even) { background: rgba(255,255,255,.02); }

/* ── Badges ──────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 99px; font-size: 11px; font-weight: 600; }
.badge-success  { background: rgba(34,197,94,.15);  color: #22c55e; }
.badge-danger   { background: rgba(239,68,68,.15);  color: #ef4444; }
.badge-warning  { background: rgba(245,158,11,.15); color: #f59e0b; }
.badge-info     { background: rgba(59,130,246,.15); color: #3b82f6; }
.badge-secondary{ background: rgba(148,163,184,.15);color: #94a3b8; }
.badge-dark     { background: rgba(30,41,59,.6);    color: #94a3b8; }

/* ── Buttons ─────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 18px; border-radius: 8px;
  border: none; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: all .2s; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-danger:hover  { background: #dc2626; }
.btn-secondary { background: var(--primary); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 6px; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: 8px; justify-content: center; border: 1px solid var(--border); background: transparent; color: var(--text-muted); }
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }

/* ── Forms ───────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.form-control, .form-select {
  width: 100%; background: var(--primary); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; padding: 10px 14px; font-size: 14px;
  outline: none; transition: border-color .2s; font-family: var(--font);
}
.form-control:focus, .form-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(34,197,94,.1); }
.form-control::placeholder { color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 90px; }
.form-select option { background: var(--primary-light); }
.form-check { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.form-check-input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.form-check-label { font-size: 14px; cursor: pointer; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.input-group { display: flex; align-items: stretch; }
.input-group .form-control { border-radius: 8px 0 0 8px; }
.input-group .btn { border-radius: 0 8px 8px 0; }

/* ── Alert / Flash ───────────────────────────────── */
.alert { padding: 12px 16px; border-radius: 8px; font-size: 14px; margin-bottom: 16px; display: flex; align-items: flex-start; gap: 10px; }
.alert-success  { background: rgba(34,197,94,.1);  color: #4ade80; border: 1px solid rgba(34,197,94,.2);  }
.alert-danger   { background: rgba(239,68,68,.1);  color: #f87171; border: 1px solid rgba(239,68,68,.2);  }
.alert-warning  { background: rgba(245,158,11,.1); color: #fbbf24; border: 1px solid rgba(245,158,11,.2); }
.alert-info     { background: rgba(59,130,246,.1); color: #60a5fa; border: 1px solid rgba(59,130,246,.2); }

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

/* ── Timeline ────────────────────────────────────── */
.timeline { position: relative; padding-left: 24px; }
.timeline::before { content:''; position: absolute; left: 8px; top: 0; bottom: 0; width: 2px; background: var(--border); }
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-item::before { content:''; position: absolute; left: -20px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 2px solid var(--primary-light); }
.timeline-date { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.timeline-body { background: var(--primary); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; }

/* ── Machine image ───────────────────────────────── */
.machine-img { width: 100%; height: 200px; object-fit: cover; border-radius: var(--radius); background: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 60px; }
.machine-img-placeholder { height: 200px; background: var(--primary); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; font-size: 60px; border: 2px dashed var(--border); }
.engineer-avatar { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; }
.engineer-avatar-placeholder { width: 56px; height: 56px; border-radius: 12px; background: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; font-size: 20px; }

/* ── Progress bars ───────────────────────────────── */
.progress-bar-wrap { background: var(--primary); border-radius: 99px; height: 8px; overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 99px; transition: width .5s ease; }

/* ── Modals ──────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 200; display: none; align-items: center; justify-content: center; }
.modal-overlay.show { display: flex; }
.modal-box { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-body { padding: 20px; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Toast Notifications ─────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 18px; min-width: 280px; box-shadow: var(--shadow);
  display: flex; align-items: flex-start; gap: 12px; animation: slideInRight .3s ease;
}
.toast-success { border-left: 4px solid var(--accent); }
.toast-danger  { border-left: 4px solid var(--danger); }
.toast-warning { border-left: 4px solid var(--warning); }
.toast-info    { border-left: 4px solid var(--info); }
.toast-title   { font-size: 13px; font-weight: 700; }
.toast-msg     { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Login page ──────────────────────────────────── */
.login-page { min-height: 100vh; background: var(--primary); display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 20px; padding: 40px; width: 100%; max-width: 420px; box-shadow: var(--shadow); }
.login-logo { text-align: center; margin-bottom: 32px; }
.login-logo .logo-icon { width: 64px; height: 64px; background: var(--accent); border-radius: 16px; display: inline-flex; align-items: center; justify-content: center; font-size: 32px; margin-bottom: 12px; }
.login-logo h1 { font-size: 24px; font-weight: 800; }
.login-logo p  { font-size: 13px; color: var(--text-muted); }

/* ── Dropdown ────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px;
  min-width: 200px; box-shadow: var(--shadow); z-index: 150; display: none;
}
.dropdown-menu.show { display: block; animation: fadeInDown .2s ease; }
.dropdown-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; font-size: 13px; color: var(--text); text-decoration: none; transition: background .15s; }
.dropdown-item:hover { background: rgba(255,255,255,.05); color: var(--accent); }
.dropdown-divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ── Animations ──────────────────────────────────── */
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeInDown   { from { transform: translateY(-10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes fadeIn       { from { opacity: 0; } to { opacity: 1; } }
.fade-in { animation: fadeIn .4s ease; }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .page-content { padding: 16px; }
  .kpi-card .kpi-value { font-size: 24px; }
}

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

/* ── DataTables overrides ────────────────────────── */
.dataTables_wrapper { color: var(--text); }
.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input { background: var(--primary); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 4px 10px; }
.dataTables_wrapper .dataTables_paginate .paginate_button { background: var(--primary); border: 1px solid var(--border) !important; color: var(--text) !important; border-radius: 6px; margin: 2px; }
.dataTables_wrapper .dataTables_paginate .paginate_button.current { background: var(--accent) !important; color: #fff !important; border-color: var(--accent) !important; }
.dataTables_info, .dataTables_length, .dataTables_filter { color: var(--text-muted) !important; font-size: 13px; }
