:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --info: #0891b2;
  --info-light: #cffafe;
  --sidebar-bg: #14162b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #4f46e5;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------------- Login ---------------- */
.login-screen {
  height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4f46e5 0%, #14162b 100%);
}
.login-card {
  background: var(--surface); padding: 40px; border-radius: 16px; width: 360px;
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 10px;
}
.login-logo { font-size: 24px; font-weight: 700; text-align: center; }
.login-sub { text-align: center; color: var(--text-muted); margin: 0 0 10px; font-size: 13px; }
.login-card label { font-size: 13px; font-weight: 600; margin-top: 6px; }
.login-card input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.login-error { background: var(--danger-light); color: var(--danger); padding: 8px 10px; border-radius: 8px; font-size: 13px; margin-top: 6px; }

/* ---------------- Shell ---------------- */
.app-shell { display: flex; height: 100vh; }
.sidebar {
  width: 230px; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; flex-shrink: 0;
}
.sidebar-logo { font-size: 18px; font-weight: 700; color: #fff; padding: 20px 20px 10px; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a {
  color: var(--sidebar-text); padding: 10px 14px; border-radius: 8px; font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 10px; transition: background 0.15s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-nav a.active { background: var(--sidebar-active); color: #fff; }
.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,0.1); }
.sidebar-user { font-size: 13px; margin-bottom: 8px; }
.sidebar-user .role-badge { font-size: 10px; background: rgba(255,255,255,0.15); padding: 2px 6px; border-radius: 4px; margin-left: 4px; }

.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 20px; flex-shrink: 0; position: relative; z-index: 20;
}
.topbar-search { position: relative; width: 340px; }
.topbar-search input {
  width: 100%; padding: 9px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: var(--bg);
}
.search-results {
  position: absolute; top: 42px; left: 0; width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow-lg); max-height: 320px; overflow-y: auto; z-index: 30;
}
.search-results .sr-item { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.search-results .sr-item:hover { background: var(--bg); cursor: pointer; }
.search-results .sr-empty { padding: 14px; color: var(--text-muted); font-size: 13px; }

.topbar-right { display: flex; align-items: center; gap: 14px; }
.icon-btn { background: none; border: none; font-size: 18px; position: relative; padding: 4px; }
.badge-dot { position: absolute; top: 0; right: 0; width: 8px; height: 8px; background: var(--danger); border-radius: 50%; }
.live-indicator { color: #cbd5e1; font-size: 12px; }
.live-indicator.on { color: var(--success); }
.notif-panel {
  position: absolute; top: 55px; right: 20px; width: 320px; max-height: 400px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); z-index: 40;
}
.notif-item { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.notif-item.unread { background: var(--primary-light); }
.notif-item .notif-title { font-weight: 600; }
.notif-item .notif-time { color: var(--text-muted); font-size: 11px; margin-top: 3px; }

.app-content { flex: 1; overflow-y: auto; padding: 24px; }

/* ---------------- Page structure ---------------- */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.page-title { font-size: 20px; font-weight: 700; margin: 0; }
.page-subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ---------------- Cards / KPI ---------------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi-card {
  background: var(--surface); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); border: 1px solid var(--border);
}
.kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.kpi-sub.up { color: var(--success); }
.kpi-sub.down { color: var(--danger); }

.card { background: var(--surface); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 20px; }
.card-title { font-size: 15px; font-weight: 700; margin: 0 0 14px; display: flex; align-items: center; justify-content: space-between; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------------- Progress bar ---------------- */
.progress-bar-track { background: var(--bg); border-radius: 999px; height: 14px; overflow: hidden; border: 1px solid var(--border); }
.progress-bar-fill { background: linear-gradient(90deg, var(--primary), #7c6ff0); height: 100%; transition: width 0.4s; }
.progress-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ---------------- Table ---------------- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data-table th {
  text-align: left; padding: 10px 12px; color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.03em; border-bottom: 2px solid var(--border); white-space: nowrap;
}
table.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data-table tbody tr:hover { background: var(--bg); }
.table-empty { padding: 40px; text-align: center; color: var(--text-muted); }

/* ---------------- Badges ---------------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-normal { background: #f1f5f9; color: #475569; }
.badge-ridicat { background: var(--warning-light); color: var(--warning); }
.badge-urgent { background: var(--danger-light); color: var(--danger); }
.badge-nou { background: #f1f5f9; color: #475569; }
.badge-in-lucru { background: var(--primary-light); color: var(--primary); }
.badge-finalizat { background: var(--success-light); color: var(--success); }
.badge-generic { background: #f1f5f9; color: #475569; }

/* ---------------- Buttons ---------------- */
.btn { border: none; border-radius: 8px; padding: 9px 16px; font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--sidebar-text); }
.btn-ghost:hover { background: rgba(255,255,255,0.08); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------------- Forms ---------------- */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--text-muted); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-family: inherit;
}
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: flex-end; }
.filter-bar .form-group { margin-bottom: 0; min-width: 140px; }

/* ---------------- Modal ---------------- */
.modal-root { position: fixed; inset: 0; background: rgba(15,23,42,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box { background: var(--surface); border-radius: 14px; width: 520px; max-width: 92vw; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-box.modal-wide { width: 760px; }
.modal-header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--text-muted); }
.modal-body { padding: 20px 22px; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------------- Toast ---------------- */
.toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: #1e293b; color: #fff; padding: 12px 18px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow-lg); min-width: 220px; animation: toast-in 0.2s ease; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------------- Empty / loading states ---------------- */
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty-state .emoji { font-size: 36px; margin-bottom: 10px; }
.loading-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.spinner { width: 26px; height: 26px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.7s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Misc ---------------- */
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.mt-10 { margin-top: 10px; }
.chart-wrap { position: relative; height: 260px; }
.chart-wrap.small { height: 200px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab-btn { background: none; border: none; padding: 10px 16px; font-size: 13px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; margin-top: 14px; font-size: 13px; }
.confirm-box p { margin: 0 0 6px; }
