:root {
  --bg0: #0b0d12;
  --bg1: #12151d;
  --panel: rgba(22, 26, 36, 0.92);
  --card: #1b2030;
  --card-2: #222839;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f3f1ec;
  --muted: #9aa3b5;
  --accent: #e44848;
  --accent-2: #ff6b5a;
  --teal: #2dd4bf;
  --blue: #60a5fa;
  --amber: #fbbf24;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --font: "Cairo", "Tahoma", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.65 var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 480px at 100% -10%, rgba(228, 72, 72, 0.18), transparent 55%),
    radial-gradient(700px 420px at 0% 100%, rgba(45, 212, 191, 0.1), transparent 50%),
    linear-gradient(165deg, var(--bg0), var(--bg1) 48%, #10131a);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.authShell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.authCard, .formCard, .dialogCard {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: 28px;
  display: grid;
  gap: 12px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.stackCard { width: min(560px, 100%); margin-bottom: 16px; }
.dialogWide { width: min(680px, 100%); }

.brandRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brandMark {
  letter-spacing: 0.24em;
  font-weight: 800;
  color: var(--accent);
  font-size: 18px;
}

.brandChip, .navBadge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(228, 72, 72, 0.16);
  color: #ffb4b0;
  font-size: 12px;
  font-weight: 700;
}

h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
.muted { color: var(--muted); margin: 0; }
.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

label { display: grid; gap: 6px; font-weight: 600; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #0f131b;
  color: var(--text);
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(228, 72, 72, 0.55);
  box-shadow: 0 0 0 3px rgba(228, 72, 72, 0.15);
}

button, .navBtn {
  border: 0;
  border-radius: 12px;
  padding: 11px 14px;
  background: linear-gradient(135deg, var(--accent), #c93a3a);
  color: #fff;
  font-weight: 700;
}

.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}

.danger { background: linear-gradient(135deg, #ef4444, #b91c1c); }
.error { color: #ffb4b4; margin: 0; }
.msg { color: #b8f0cd; margin: 0; }

.app {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
}

.sidebarBackdrop {
  display: none;
}

.sidebar {
  background: rgba(10, 12, 18, 0.88);
  border-left: 1px solid var(--line);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
}

.sideBrand {
  padding: 4px 8px 12px;
  position: relative;
}
.sideTitle { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.sideNav { display: grid; gap: 6px; }
.sideClose { display: none; }

.iconBtn {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  flex: 0 0 auto;
}

.menuToggle { display: none; }

.topStart {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.navBtn {
  text-align: right;
  background: transparent;
  border: 1px solid transparent;
  color: #d7dce8;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.navBtn.active, .navBtn:hover {
  background: linear-gradient(90deg, rgba(228, 72, 72, 0.16), rgba(255, 255, 255, 0.03));
  border-color: rgba(228, 72, 72, 0.28);
}

.sideFoot { margin-top: auto; display: grid; gap: 8px; padding-top: 12px; }

.main {
  padding: 26px;
  min-width: 0;
  width: 100%;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.top h2 {
  font-size: clamp(1.25rem, 2.5vw, 1.75rem);
  word-break: break-word;
}

.topActions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

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

.kpi {
  position: relative;
  overflow: hidden;
  background: linear-gradient(160deg, var(--card), var(--card-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.kpi::after {
  content: "";
  position: absolute;
  inset: auto -20% -40% auto;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(228, 72, 72, 0.18), transparent 70%);
  pointer-events: none;
}

.kpi .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi .value {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.04em;
}
.kpi .hint { margin-top: 4px; color: var(--muted); font-size: 12px; }
.kpi.teal .value { color: var(--teal); }
.kpi.amber .value { color: var(--amber); }
.kpi.blue .value { color: var(--blue); }
.kpi.red .value { color: var(--accent-2); }

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

.chartCard {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-height: 280px;
}

.chartHead { margin-bottom: 10px; }
.chartHead h3 { font-size: 16px; }
.chartBody { min-height: 210px; }

.chartEmpty {
  min-height: 210px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 14px;
}

.barChart, .donutWrap, .hBarChart {
  width: 100%;
  height: 210px;
}

.chartLegend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

.legendDot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-left: 6px;
}

.ordersSummary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summaryChip {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
}

.summaryChip b {
  display: block;
  font-family: var(--mono);
  font-size: 22px;
  margin-top: 4px;
}
.summaryChip b.amber { color: var(--amber); }
.summaryChip b.teal { color: var(--teal); }
.summaryChip b.red { color: var(--accent-2); }

.summaryChip.clickable { cursor: pointer; transition: transform .12s ease, border-color .12s ease; }
.summaryChip.clickable:hover { transform: translateY(-1px); border-color: rgba(228, 72, 72, 0.4); }
.summaryChip.active { border-color: rgba(228, 72, 72, 0.55); background: rgba(228, 72, 72, 0.08); }

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.toolbar input, .toolbar select {
  max-width: 320px;
  width: 100%;
  min-width: 0;
}
.toolbar > button {
  flex: 0 0 auto;
}

.tableWrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  max-width: 100%;
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}
th, td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: top;
}
th {
  color: var(--muted);
  font-weight: 700;
  background: rgba(255, 255, 255, 0.02);
  position: sticky;
  top: 0;
}
tr:hover td { background: rgba(255, 255, 255, 0.015); }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  font-weight: 700;
}
.badge.ok { color: #b9f3d2; background: rgba(52, 211, 153, 0.12); }
.badge.warn { color: #ffe1a8; background: rgba(251, 191, 36, 0.12); }
.badge.bad { color: #ffc1c1; background: rgba(248, 113, 113, 0.12); }

.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions button { padding: 7px 10px; font-size: 13px; }
.actions .secondary, .secondary { background: #355572; }
.actions .danger, button.danger { background: var(--bad); }
.actions .ghost { background: transparent; }

dialog {
  border: 0;
  border-radius: calc(var(--radius) + 2px);
  padding: 0;
  background: transparent;
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.62); }
.dialogActions { display: flex; justify-content: flex-start; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
.orderImageBox { text-align: center; min-height: 120px; }
.orderImageBox img {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 12px;
  border: 1px solid var(--line);
}

@media (max-width: 1200px) {
  .kpiGrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chartsGrid { grid-template-columns: 1fr; }
}

@media (max-width: 1100px) {
  .ordersSummary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

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

  .menuToggle { display: inline-flex; align-items: center; justify-content: center; }
  .sideClose {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 0;
    left: 0;
  }

  .sidebarBackdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 45;
  }
  .sidebarBackdrop[hidden] { display: none !important; }

  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(300px, 86vw);
    height: 100vh;
    height: 100dvh;
    border-left: 1px solid var(--line);
    border-bottom: 0;
    transform: translateX(105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
    background: rgba(10, 12, 18, 0.98);
  }
  .app.nav-open .sidebar { transform: translateX(0); }
  body.nav-open { overflow: hidden; }

  .main { padding: 16px; }
  .top { gap: 12px; }
  .topActions { width: 100%; }
  .topActions .ghost { width: 100%; }

  .kpiGrid,
  .ordersSummary,
  .chartsGrid { grid-template-columns: 1fr; }

  .chartCard { min-height: 0; }
  .chartBody, .chartEmpty, .barChart, .donutWrap, .hBarChart { min-height: 180px; }

  .toolbar input,
  .toolbar select { max-width: none; flex: 1 1 100%; }
  .toolbar > button { width: 100%; }

  .authCard, .formCard, .dialogCard, .stackCard {
    width: 100%;
    padding: 20px 16px;
  }

  dialog { width: calc(100vw - 24px); max-width: calc(100vw - 24px); }
  .dialogWide { width: min(680px, 100%); }

  .actions { gap: 8px; }
  .actions button { flex: 1 1 auto; min-height: 38px; }
}

@media (max-width: 560px) {
  .kpi .value { font-size: 24px; }
  .summaryChip b { font-size: 18px; }
  .brandMark { font-size: 16px; letter-spacing: 0.18em; }
  table { min-width: 640px; }
  th, td { padding: 10px 8px; font-size: 13px; }
  .eyebrow { font-size: 11px; }
}
