:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --ink: #17202a;
  --muted: #657384;
  --line: #dce4ee;
  --primary: #126f76;
  --primary-dark: #0b555b;
  --accent: #b85d1c;
  --success: #16794d;
  --warning: #b7791f;
  --danger: #b42318;
  --shadow: 0 14px 40px rgba(20, 33, 61, 0.08);
  --radius: 8px;
  font-family: Tahoma, Arial, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  background: #0e2f36;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f4b04d;
  color: #13282d;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.4;
}

.brand p {
  margin: 3px 0 0;
  color: rgba(255, 255, 255, 0.68);
  font-size: 12px;
}

.side-nav {
  display: grid;
  gap: 8px;
}

.nav-item,
.bottom-item {
  border: 0;
  cursor: pointer;
}

.nav-item {
  text-align: right;
  color: rgba(255, 255, 255, 0.78);
  background: transparent;
  padding: 12px 14px;
  border-radius: var(--radius);
}

.nav-item:hover,
.nav-item.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.security-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.06);
  display: grid;
  gap: 7px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 12px;
  line-height: 1.6;
}

.security-note strong {
  color: #fff;
  font-size: 13px;
}

.main {
  min-width: 0;
  padding-bottom: 30px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 86px;
  padding: 16px 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 247, 251, 0.94);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar-title {
  min-width: 180px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.topbar h2 {
  margin: 3px 0 0;
  font-size: 24px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.field input,
.field select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

.field.compact select {
  min-width: 140px;
}

.button {
  min-height: 40px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

.button.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.button:hover {
  filter: brightness(0.98);
}

.admin-chip {
  min-height: 42px;
  max-width: 300px;
  padding: 7px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  display: grid;
  gap: 2px;
}

.admin-chip span {
  color: var(--muted);
  font-size: 12px;
  direction: ltr;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-chip strong {
  color: var(--primary-dark);
  font-size: 13px;
}

.content {
  padding: 24px 26px;
}

.error-banner {
  margin: 16px 26px 0;
  padding: 13px 15px;
  border-radius: var(--radius);
  border: 1px solid #f2b8b5;
  background: #fff1f0;
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.loading {
  min-height: 220px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.5);
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.metric-card,
.panel,
.agent-card,
.finance-agent {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 18px;
  display: grid;
  gap: 12px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  font-size: 30px;
  line-height: 1;
}

.metric-card small {
  color: var(--muted);
}

.panel {
  margin-top: 18px;
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-header h3 {
  margin: 0;
  font-size: 18px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 840px;
}

th,
td {
  padding: 13px 14px;
  text-align: right;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #f7fafc;
  color: #334155;
  font-size: 12px;
  z-index: 1;
}

td {
  line-height: 1.6;
}

.muted {
  color: var(--muted);
}

.number {
  direction: ltr;
  text-align: right;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 12px;
}

.badge.pending {
  color: #7a4f00;
  background: #fff1c2;
}

.badge.approved {
  color: #075e3c;
  background: #d9f8e8;
}

.badge.rejected {
  color: #8f1d14;
  background: #ffe1de;
}

.badge.neutral {
  color: #44546a;
  background: #edf2f7;
}

.warning-list {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.warning-list li {
  padding: 10px 12px;
  border-radius: var(--radius);
  background: #fff8e5;
  color: #7a4f00;
}

.responsive-cards {
  display: none;
}

.agent-card {
  padding: 14px;
  display: grid;
  gap: 8px;
}

.kv {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px;
}

.kv span:first-child {
  color: var(--muted);
}

.finance-group {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.finance-group h3,
.finance-group h4 {
  margin: 0;
}

.finance-governorate {
  padding: 14px 16px;
  background: #e9f3f4;
  color: #153d43;
}

.finance-hub {
  padding: 12px 16px;
  background: #f7fafc;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: #334155;
}

.finance-agents {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 14px;
}

.finance-agent {
  padding: 14px;
  box-shadow: none;
}

.finance-agent h5 {
  margin: 0 0 12px;
  font-size: 15px;
}

.finance-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid #edf2f7;
}

.finance-row:last-child {
  border-bottom: 0;
}

.empty-state {
  padding: 34px 18px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.62);
}

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

.bottom-nav {
  display: none;
}

@media (max-width: 1020px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .main {
    padding-bottom: 76px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .field.compact,
  .field.compact select,
  .button,
  .admin-chip {
    flex: 1 1 150px;
  }

  .bottom-nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    border-top: 1px solid var(--line);
    background: #fff;
    box-shadow: 0 -10px 30px rgba(20, 33, 61, 0.08);
  }

  .bottom-item {
    min-height: 58px;
    background: #fff;
    color: var(--muted);
    font-weight: 700;
    font-size: 12px;
  }

  .bottom-item.active {
    color: var(--primary);
    background: #edf8f8;
  }

  .cards-grid,
  .settings-grid,
  .finance-agents {
    grid-template-columns: 1fr;
  }

  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .content,
  .topbar {
    padding-inline: 14px;
  }

  .error-banner {
    margin-inline: 14px;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .table-wrap.agents-table {
    display: none;
  }

  .responsive-cards {
    display: grid;
    gap: 12px;
  }
}
