/* ── Variables ─────────────────────────────────────────────────── */
:root {
  --bg:         #f0f3fa;
  --sidebar:    #1a2535;
  --sidebar2:   #243044;
  --white:      #ffffff;
  --border:     #e0eaf4;
  --text:       #1a2535;
  --text-muted: #7a90a8;
  --primary:    #185fa5;
  --elec:       #f9c784;
  --elec-dark:  #c47800;
  --elec-bg:    #fef3d8;
  --water:      #7ec8e3;
  --water-dark: #0c447c;
  --water-bg:   #ddf0fa;
  --success:    #a8d8a8;
  --success-bg: #e4f4ea;
  --success-dk: #1e5c2e;
  --danger:     #f4a4a4;
  --danger-bg:  #fce8e8;
  --danger-dk:  #7a1f1f;
  --warn-bg:    #fef5db;
  --warn-dk:    #7a4a00;
  --radius:     8px;
  --radius-lg:  12px;
  --shadow:     0 1px 3px rgba(0,0,0,0.06);
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

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

/* ── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
}
.sidebar-logo {
  padding: 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo-icon {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: rgba(126,200,227,.18);
  display: flex; align-items: center; justify-content: center;
  color: var(--water);
  font-size: 18px;
  flex-shrink: 0;
}
.sidebar-logo-text { font-size: 14px; font-weight: 600; color: #fff; }
.sidebar-logo-sub  { font-size: 10px; color: rgba(255,255,255,.35); margin-top: 1px; }

.sidebar-nav { flex: 1; padding: 8px 0; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px;
  font-size: 12.5px; color: rgba(255,255,255,.55);
  cursor: pointer; border: none; background: none;
  width: 100%; text-align: left;
  border-right: 2px solid transparent;
  transition: all .15s;
  text-decoration: none;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: rgba(255,255,255,.9); text-decoration: none; }
.nav-item.active {
  background: rgba(126,200,227,.12);
  color: #b0e0f2;
  border-right-color: var(--water);
}
.nav-item i { font-size: 16px; flex-shrink: 0; }
.nav-badge {
  min-width: 18px; height: 18px; border-radius: 9px;
  background: var(--danger); color: var(--danger-dk);
  font-size: 10px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  margin-left: auto; padding: 0 5px;
}
.nav-section {
  padding: 12px 16px 4px;
  font-size: 9px; font-weight: 600;
  color: rgba(255,255,255,.25);
  text-transform: uppercase; letter-spacing: .8px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.07);
}
.user-card {
  display: flex; align-items: center; gap: 9px; margin-bottom: 10px;
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--water); color: var(--water-dark);
  font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-name  { font-size: 11.5px; color: rgba(255,255,255,.85); font-weight: 500; }
.user-role  { font-size: 9.5px;  color: rgba(255,255,255,.35); }
.logout-link {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: rgba(255,255,255,.35);
  cursor: pointer; text-decoration: none;
}
.logout-link:hover { color: rgba(255,255,255,.65); text-decoration: none; }

/* ── Main content ──────────────────────────────────────────────── */
.main-content {
  margin-left: 220px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ────────────────────────────────────────────────────── */
.topbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 14px; font-weight: 600; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.lang-btn {
  font-size: 10px; border: 1px solid var(--border);
  border-radius: 4px; padding: 3px 8px;
  color: var(--text-muted); cursor: pointer;
  background: none; transition: all .15s;
}
.lang-btn.active, .lang-btn:hover {
  background: var(--water-bg); border-color: var(--water); color: var(--water-dark);
}
.notif-btn {
  position: relative; cursor: pointer;
  display: flex; align-items: center;
  padding: 4px; border: none; background: none;
  color: var(--text-muted);
}
.notif-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--danger);
  position: absolute; top: 0; right: 0;
}
.hamburger {
  display: none; border: none; background: none;
  color: var(--text-muted); cursor: pointer; font-size: 20px;
  padding: 4px;
}

/* ── Page content ──────────────────────────────────────────────── */
.page-content { padding: 20px; flex: 1; }
.page-header { margin-bottom: 18px; }
.page-header h1 { font-size: 20px; font-weight: 600; }
.page-header p  { font-size: 13px; color: var(--text-muted); margin-top: 3px; }

/* ── Cards & Grids ─────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.card-body   { padding: 16px; }
.card-header { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title  { font-size: 13px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 6px; }
.card-dot    { width: 8px; height: 8px; border-radius: 50%; }

.kpi-grid  { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.chart-grid{ display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }

.kpi-card { padding: 14px 16px; }
.kpi-label { font-size: 11px; color: var(--text-muted); margin-bottom: 5px; display: flex; align-items: center; gap: 5px; }
.kpi-value { font-size: 22px; font-weight: 600; }
.kpi-sub   { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.kpi-elec  .kpi-value { color: var(--elec-dark); }
.kpi-water .kpi-value { color: var(--water-dark); }
.kpi-total .kpi-value { color: var(--text); }
.kpi-alert .kpi-value { color: var(--danger-dk); }

.progress-bg   { background: #eef2f8; border-radius: 4px; height: 6px; overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; border-radius: 4px; }

/* ── Alert / Banner ────────────────────────────────────────────── */
.alert {
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
  display: flex; align-items: flex-start; gap: 9px;
  font-size: 12.5px;
}
.alert i   { flex-shrink: 0; font-size: 15px; margin-top: 1px; }
.alert-info    { background: var(--water-bg); color: var(--water-dark); border: 1px solid #b8d8ec; }
.alert-warn    { background: var(--warn-bg);  color: var(--warn-dk);    border: 1px solid #fde8a8; }
.alert-success { background: var(--success-bg); color: var(--success-dk); border: 1px solid #b8ddb8; }
.alert-danger  { background: var(--danger-bg);  color: var(--danger-dk);  border: 1px solid #f0b8b8; }
.alert-badge   { margin-left: auto; padding: 2px 8px; border-radius: 8px; font-size: 10px; font-weight: 600; background: #febc2e; color: #412402; white-space: nowrap; }

/* ── Table ─────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%; border-collapse: collapse;
  font-size: 12px; table-layout: fixed;
}
.data-table th {
  background: #f4f8fc; color: var(--text-muted);
  font-weight: 600; font-size: 10.5px;
  padding: 8px 10px; text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #f2f6fa;
  color: var(--text);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafcff; }

/* ── Badges ────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 8px;
  border-radius: 8px; font-size: 10px; font-weight: 600;
  white-space: nowrap;
}
.badge-elec    { background: var(--elec-bg);    color: var(--elec-dark); }
.badge-water   { background: var(--water-bg);   color: var(--water-dark); }
.badge-success { background: var(--success-bg); color: var(--success-dk); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger-dk); }
.badge-warn    { background: var(--warn-bg);    color: var(--warn-dk); }
.badge-gray    { background: #f0f3fa; color: var(--text-muted); }

/* ── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 12.5px; font-weight: 500;
  cursor: pointer; transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: #1450a0; }
.btn-dark    { background: var(--sidebar); color: #fff; border-color: var(--sidebar); }
.btn-dark:hover { background: #243044; }
.btn-success { background: #2e7d32; color: #fff; border-color: #2e7d32; }
.btn-success:hover { background: #246227; }
.btn-outline { background: none; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-danger  { background: #b03030; color: #fff; border-color: #b03030; }
.btn-danger:hover { background: #922828; }
.btn-sm { padding: 4px 9px; font-size: 11px; }
.btn-pdf { background: var(--water-bg); color: var(--water-dark); border-color: #b8d4ec; }
.btn-pdf:hover { background: #cde9f6; }

/* ── Forms ─────────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; font-weight: 500; color: var(--text); margin-bottom: 5px; }
.form-control {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; color: var(--text);
  background: #f9fbfe;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  outline: none; border-color: var(--water);
  box-shadow: 0 0 0 3px rgba(126,200,227,.2);
  background: #fff;
}
.form-select {
  width: 100%; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 12px; color: var(--text); background: var(--white);
  cursor: pointer;
}
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 11px; color: var(--danger-dk); margin-top: 4px; }
.input-group { display: flex; gap: 8px; }
.input-group .form-control { flex: 1; }

/* ── Toggle ────────────────────────────────────────────────────── */
.toggle-wrap { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; }
.toggle-label { font-size: 12px; color: var(--text); }
.toggle {
  width: 36px; height: 20px; border-radius: 10px;
  background: var(--border); position: relative;
  cursor: pointer; transition: background .2s;
  flex-shrink: 0;
}
.toggle.on { background: var(--water); }
.toggle-knob {
  width: 16px; height: 16px; border-radius: 50%;
  background: white; position: absolute;
  top: 2px; left: 2px; transition: left .2s;
}
.toggle.on .toggle-knob { left: 18px; }

/* ── Settings sections ─────────────────────────────────────────── */
.settings-section { margin-bottom: 16px; }
.settings-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid #f4f8fa; font-size: 12.5px; }
.settings-row:last-child { border-bottom: none; }
.settings-row label { color: var(--text-muted); }
.settings-row .value { color: var(--text); font-weight: 500; font-size: 12px; }

/* ── Sync progress ─────────────────────────────────────────────── */
.sync-log { background: #0d1117; border-radius: var(--radius); padding: 14px; font-family: 'Fira Code', 'Courier New', monospace; font-size: 11.5px; max-height: 240px; overflow-y: auto; }
.sync-log-item { margin-bottom: 4px; display: flex; gap: 10px; }
.sync-log-time { color: #5a7090; flex-shrink: 0; }
.sync-log-msg.info    { color: #a0b4c8; }
.sync-log-msg.success { color: #7ec8e3; }
.sync-log-msg.error   { color: var(--danger); }

/* ── Login page ────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--white);
  border-radius: 16px;
  border: 1px solid var(--border);
  padding: 32px 28px;
  width: 100%; max-width: 360px;
}
.login-logo {
  text-align: center; margin-bottom: 24px;
}
.login-logo-icon {
  width: 52px; height: 52px; border-radius: 14px;
  background: var(--water-bg);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px; font-size: 26px; color: var(--water);
}
.login-logo h1 { font-size: 20px; font-weight: 700; color: var(--text); }
.login-logo p  { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.login-langs { display: flex; justify-content: center; gap: 6px; margin-bottom: 20px; }
.login-footer { text-align: center; margin-top: 14px; font-size: 11px; color: var(--text-muted); }

/* ── Notifications panel ───────────────────────────────────────── */
.notif-panel { position: absolute; top: 44px; right: 0; width: 300px; background: var(--white); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: 0 4px 16px rgba(0,0,0,.12); z-index: 200; }
.notif-item { padding: 10px 14px; border-bottom: 1px solid #f4f8fa; display: flex; gap: 9px; font-size: 12px; }
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: #f8fbff; }
.notif-dot2 { width: 8px; height: 8px; border-radius: 50%; margin-top: 3px; flex-shrink: 0; }
.notif-time { font-size: 10px; color: var(--text-muted); margin-top: 2px; }

/* ── Admin ─────────────────────────────────────────────────────── */
.user-list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid #f4f8fa;
}
.user-list-item:last-child { border-bottom: none; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .kpi-grid  { grid-template-columns: repeat(2, 1fr); }
  .chart-grid{ grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .hamburger { display: block; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .page-content { padding: 14px; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr; }
  .login-card { padding: 24px 18px; }
}

/* ── RTL (Arabic) ──────────────────────────────────────────────── */
[dir="rtl"] .sidebar {
  left: auto; right: 0;
}
[dir="rtl"] .main-content {
  margin-left: 0; margin-right: 220px;
}
[dir="rtl"] .nav-item {
  border-right: none; border-left: 2px solid transparent;
  text-align: right;
}
[dir="rtl"] .nav-item.active {
  border-left-color: var(--water);
}
[dir="rtl"] .nav-badge { margin-left: 0; margin-right: auto; }
[dir="rtl"] .alert-badge { margin-left: 0; margin-right: auto; }
[dir="rtl"] .data-table th,
[dir="rtl"] .data-table td { text-align: right; }
[dir="rtl"] .topbar-right { flex-direction: row-reverse; }

@media (max-width: 768px) {
  [dir="rtl"] .sidebar {
    transform: translateX(100%);
  }
  [dir="rtl"] .sidebar.open {
    transform: translateX(0);
  }
  [dir="rtl"] .main-content {
    margin-right: 0;
  }
}

/* ── Utilities ─────────────────────────────────────────────────── */
.text-muted   { color: var(--text-muted); }
.text-elec    { color: var(--elec-dark); }
.text-water   { color: var(--water-dark); }
.text-danger  { color: var(--danger-dk); }
.text-success { color: var(--success-dk); }
.fw-600       { font-weight: 600; }
.fs-11        { font-size: 11px; }
.fs-12        { font-size: 12px; }
.d-flex       { display: flex; }
.align-center { align-items: center; }
.gap-8        { gap: 8px; }
.gap-12       { gap: 12px; }
.mb-12        { margin-bottom: 12px; }
.mb-16        { margin-bottom: 16px; }
.mt-8         { margin-top: 8px; }
.mt-12        { margin-top: 12px; }
.ml-auto      { margin-left: auto; }
[dir="rtl"] .ml-auto { margin-left: 0; margin-right: auto; }

/* ── Overlay sidebar mobile ────────────────────────────────────── */
.sidebar-overlay {
  display: none; position: fixed;
  inset: 0; background: rgba(0,0,0,.4); z-index: 99;
}
.sidebar-overlay.show { display: block; }

/* ── Spinner ───────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { animation: spin 1s linear infinite; display: inline-block; }
