:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --sidebar: #0b2540;
  --sidebar-hover: #14365a;
  --primary: #1976b8;
  --primary-hover: #125c91;
  --brand-teal: #00a79d;
  --success: #00a79d;
  --amber: #d97706;
  --danger: #dc2626;
  --purple: #7c3aed;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.hidden { display: none !important; }
.w-full { width: 100%; }
.max-w-2xl { max-width: 720px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 14px; }
.mt-4 { margin-top: 20px; }
.muted { color: var(--muted); font-size: 13.5px; }
.section-title { font-size: 17px; font-weight: 800; margin-bottom: 12px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #0b2540 0%, #1976b8 55%, #00a79d 100%);
}

.login-card {
  background: #fff;
  width: 100%;
  max-width: 420px;
  padding: 32px 28px;
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  text-align: center;
}

.login-logo { margin-bottom: 12px; }
.login-logo-img {
  width: 112px; height: 112px; object-fit: contain;
  border-radius: 18px; background: #fff;
  box-shadow: 0 4px 16px rgba(11, 37, 64, 0.12);
  padding: 4px;
}
.login-card h1 { font-size: 22px; font-weight: 800; }
.login-form { text-align: right; display: flex; flex-direction: column; gap: 14px; margin-top: 22px; }
.login-hint { margin-top: 18px; font-size: 12.5px; color: var(--muted); background: #f8fafc; padding: 10px 12px; border-radius: 10px; }

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

.sidebar {
  width: 265px;
  background: var(--sidebar);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 2px 6px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.brand-img {
  width: 46px; height: 46px; border-radius: 12px;
  object-fit: cover; background: #fff; padding: 2px;
}

.topbar-title-wrap { display: flex; align-items: center; gap: 12px; }
.topbar-logo {
  width: 44px; height: 44px; border-radius: 11px;
  object-fit: cover; background: #fff; padding: 2px;
  border: 1px solid var(--border); box-shadow: var(--shadow);
}

/* Avatars & Photo Upload */
.avatar-img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block;
}
.avatar-sm {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--brand-teal));
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px; overflow: hidden; flex-shrink: 0;
}
.avatar-lg {
  width: 72px; height: 72px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--brand-teal));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 26px; overflow: hidden; flex-shrink: 0;
  border: 3px solid #e2e8f0;
}
.avatar-hero {
  width: 74px; height: 74px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 28px; overflow: hidden; flex-shrink: 0;
  border: 3px solid rgba(255, 255, 255, 0.35);
}
.portal-emp-wrap { display: flex; align-items: center; gap: 16px; }
.portal-emp-name { font-size: 19px; font-weight: 800; margin-bottom: 2px; }
.emp-cell { display: flex; align-items: center; gap: 9px; }
.photo-upload-row {
  display: flex; align-items: center; gap: 16px;
  background: #f8fafc; padding: 14px; border-radius: 12px; border: 1px solid var(--border);
}
.portal-hero { background: linear-gradient(135deg, #0b2540, #1976b8 65%, #00a79d); color: #fff; border: none; }
.brand h1 { font-size: 16px; font-weight: 800; line-height: 1.25; }
.brand small { color: #94a3b8; font-size: 12px; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.06);
  padding: 10px 12px;
  border-radius: 12px;
  margin-top: 14px;
}
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; flex-shrink: 0;
}
.user-chip-info { min-width: 0; }
.user-chip-info strong { display: block; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip-info small { color: #94a3b8; font-size: 11.5px; }

.nav { display: flex; flex-direction: column; gap: 5px; margin-top: 14px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 13px; border: none; background: transparent;
  color: #cbd5e1; border-radius: 10px; cursor: pointer;
  font-family: inherit; font-size: 14.5px; font-weight: 600;
  text-align: right; transition: 0.16s;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }

.sidebar-footer { padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, 0.1); }

/* Main */
.main { flex: 1; padding: 22px 26px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.topbar h2 { font-size: 22px; font-weight: 800; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.clock-pill { background: var(--surface); border: 1px solid var(--border); padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; }

.view { display: none; }
.view.active { display: block; }

/* Cards & Grids */
.card { background: var(--surface); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
.card-header h3 { font-size: 16.5px; font-weight: 700; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 14px; }
.kpi-card { background: var(--surface); border-radius: var(--radius); padding: 16px 18px; border: 1px solid var(--border); box-shadow: var(--shadow); border-right: 4px solid #475569; }
.kpi-green { border-right-color: var(--success); }
.kpi-amber { border-right-color: var(--amber); }
.kpi-red { border-right-color: var(--danger); }
.kpi-blue { border-right-color: var(--primary); }
.kpi-purple { border-right-color: var(--purple); }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 26px; font-weight: 800; margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 16px; }

/* Portal Hero & Balances */
.portal-hero { background: linear-gradient(135deg, #0f172a, #1e3a8a); color: #fff; border: none; }
.portal-hero .muted { color: #cbd5e1; }
.portal-hero-top { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 16px; }
.portal-late-box { background: rgba(255, 255, 255, 0.1); padding: 12px 20px; border-radius: 14px; text-align: center; min-width: 170px; }
.big-num { font-size: 28px; font-weight: 800; color: #fbbf24; }

.balances-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 14px; }
.balance-card {
  background: var(--surface); border-radius: var(--radius); padding: 16px;
  border: 1px solid var(--border); box-shadow: var(--shadow);
  border-top: 4px solid var(--primary);
}
.balance-card h4 { font-size: 14.5px; font-weight: 700; margin-bottom: 6px; }
.balance-rem { font-size: 28px; font-weight: 800; }
.balance-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

.profile-kv { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; font-size: 14px; }
.profile-kv div { background: #f8fafc; padding: 8px 12px; border-radius: 9px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 15px; border-radius: 10px; border: 1px solid transparent;
  font-family: inherit; font-size: 14px; font-weight: 700; cursor: pointer; transition: 0.15s;
}
.btn-lg { padding: 12px 18px; font-size: 15.5px; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; }
.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }
.btn-outline { background: #fff; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: #f8fafc; }
.btn-ghost { background: rgba(255, 255, 255, 0.08); color: #e2e8f0; }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.16); }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 10px; align-items: end; }
.filters-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filters-inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.settings-form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.field input, .field select, .field textarea, .input-sm {
  padding: 8px 11px; border: 1px solid var(--border); border-radius: 9px;
  font-family: inherit; font-size: 13.5px; background: #fff; color: var(--text);
}
.field-btn { flex-direction: row; gap: 6px; align-items: center; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 11px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #f8fafc; color: var(--muted); font-weight: 700; font-size: 12.5px; }
tbody tr:hover { background: #f8fafc; }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-purple { background: #ede9fe; color: #5b21b6; }
.badge-gray { background: #e2e8f0; color: #475569; }

/* Trend Chart */
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-left: 4px; }
.dot-green { background: var(--success); }
.dot-amber { background: var(--amber); }
.dot-red { background: var(--danger); }
.trend-chart { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; height: 185px; padding: 14px 6px 4px; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.trend-bars { display: flex; align-items: flex-end; gap: 4px; height: 130px; }
.bar { width: 11px; border-radius: 5px 5px 0 0; min-height: 3px; }
.bar-green { background: var(--success); }
.bar-amber { background: var(--amber); }
.bar-red { background: var(--danger); }
.trend-label { font-size: 12px; color: var(--muted); font-weight: 600; }

/* Devices */
.devices-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
.device-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.device-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.device-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; font-size: 12.5px; background: #f8fafc; padding: 10px; border-radius: 10px; }
.device-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.device-error { background: #fef2f2; color: #991b1b; padding: 8px 10px; border-radius: 8px; font-size: 12px; }
.device-mini-list { display: flex; flex-direction: column; gap: 8px; }
.device-mini-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: #f8fafc; border-radius: 10px; border: 1px solid var(--border); }

/* Tabs & Summary */
.tabs-bar { display: flex; gap: 8px; border-bottom: 1px solid var(--border); padding-bottom: 12px; flex-wrap: wrap; }
.tab-btn { padding: 7px 16px; border-radius: 9px; border: 1px solid var(--border); background: #f8fafc; font-family: inherit; font-weight: 700; cursor: pointer; }
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.summary-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.summary-pill { background: #f8fafc; border: 1px solid var(--border); padding: 5px 12px; border-radius: 999px; font-size: 12.5px; font-weight: 700; }

/* Modals */
.modal {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 900;
}
.modal-box {
  background: #fff; border-radius: 16px; width: 100%; max-width: 520px;
  max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}
.modal-lg { max-width: 860px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px; overflow-y: auto; }

/* Mobile PWA Bottom Nav */
.mobile-bottom-nav { display: none; }

/* Toast */
.toast-container { position: fixed; bottom: 20px; left: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 1200; }
.toast { background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); max-width: 360px; }
.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }
.empty-state { text-align: center; padding: 28px 14px; color: var(--muted); }

@media (max-width: 900px) {
  .sidebar { display: none; }
  .main { padding: 14px 14px 80px; }
  .topbar h2 { font-size: 19px; }
  .clock-pill { display: none; }
  .mobile-bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--sidebar); border-top: 1px solid rgba(255, 255, 255, 0.1);
    justify-content: space-around; padding: 6px 4px; z-index: 800;
  }
  .mob-btn {
    background: transparent; border: none; color: #94a3b8;
    font-family: inherit; font-size: 11px; font-weight: 700;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 5px 8px; border-radius: 8px; cursor: pointer;
  }
  .mob-btn.active { color: #fff; background: rgba(37, 99, 235, 0.35); }
  .mob-ico { font-size: 18px; }
  .toast-container { bottom: 72px; left: 12px; right: 12px; }
}
