:root {
  color-scheme: dark;
  --bg: #06130f;
  --panel: #0d211b;
  --panel-2: #112a23;
  --line: #2b4c41;
  --text: #eef5f1;
  --muted: #9db5ac;
  --green: #27d7ae;
  --gold: #f3c969;
  --red: #ff6f66;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  min-width: 320px;
  margin: 0;
  direction: rtl;
  background:
    radial-gradient(circle at 12% 8%, rgba(39, 215, 174, 0.08), transparent 27%),
    var(--bg);
  color: var(--text);
  font-family: Arial, "Noto Sans Arabic", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
select,
input {
  font: inherit;
}

.gradio-container {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 34px;
}

#nabdah-hero {
  margin-bottom: 14px;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(135deg, #102a22, #081914);
}

#nabdah-hero h1 {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: clamp(28px, 4vw, 43px);
}

#nabdah-hero p {
  margin: 0;
  color: var(--text);
  font-size: 17px;
  line-height: 1.8;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 4fr) minmax(420px, 7fr);
  gap: 14px;
  align-items: start;
}

.input-panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
}

.input-panel h3 {
  margin: 2px 0 20px;
  color: var(--text);
  font-size: 22px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 17px;
}

.field > span,
.location-field legend {
  color: #f0f2ee;
  font-size: 15px;
  font-weight: 600;
}

.field small,
.checkbox-row small {
  display: block;
  color: #aeb7b3;
  font-size: 12px;
  line-height: 1.55;
}

select {
  width: 100%;
  min-height: 54px;
  padding: 0 16px;
  border: 1px solid #4b4f53;
  border-radius: 8px;
  outline: none;
  background: #27282a;
  color: #f1f2ef;
}

select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(39, 215, 174, 0.16);
}

.location-field {
  min-width: 0;
  margin: 0 0 16px;
  padding: 0;
  border: 0;
}

.location-field legend {
  margin-bottom: 10px;
}

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

.radio-grid label {
  position: relative;
}

.radio-grid input {
  position: absolute;
  opacity: 0;
}

.radio-grid span {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 8px 42px 8px 12px;
  border: 1px solid #4b4f53;
  border-radius: 8px;
  background: #27282a;
  color: #f0f1ef;
  font-size: 14px;
}

.radio-grid span::before {
  position: absolute;
  right: 13px;
  width: 20px;
  height: 20px;
  border: 2px solid #4a4e52;
  border-radius: 50%;
  content: "";
}

.radio-grid input:checked + span::before {
  border: 6px solid #ff7a1a;
  background: #fff;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 2px 0 18px;
  padding: 12px 14px;
  border: 1px solid #4b4f53;
  border-radius: 8px;
  background: #27282a;
}

.checkbox-row input {
  width: 21px;
  height: 21px;
  margin: 2px 0 0;
  accent-color: #ff7a1a;
}

.checkbox-row strong {
  display: block;
  margin-bottom: 3px;
  color: #f1f2ef;
  font-size: 15px;
}

#analyze-button {
  width: 100%;
  min-height: 56px;
  border: 0;
  border-radius: 9px;
  background: var(--green);
  color: #06130f;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
}

#analyze-button:active {
  transform: translateY(1px);
}

.map-help {
  margin-top: 22px;
  color: #e0e7e3;
  font-size: 14px;
  line-height: 1.75;
}

.map-help strong {
  font-size: 16px;
}

.map-help ul {
  margin: 7px 0 0;
  padding-right: 22px;
}

.map-column {
  min-width: 0;
}

.map-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #071612;
}

.map-frame h2 {
  margin: 0;
  padding: 20px 72px 4px 20px;
  color: #f6f1e5;
  text-align: center;
  font-size: 22px;
}

.canvas-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 1.08 / 1;
  min-height: 560px;
}

#mataf-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.density-bar {
  position: absolute;
  top: 13%;
  right: 2.5%;
  bottom: 12%;
  display: grid;
  grid-template-columns: 30px 16px 20px;
  grid-template-rows: 42px 1fr;
  column-gap: 4px;
  padding: 7px 5px;
  border: 1px solid #35564d;
  background: rgba(16, 37, 31, 0.9);
  color: #9fb7ae;
  pointer-events: none;
}

.density-bar strong {
  grid-column: 1 / -1;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.3;
  text-align: center;
}

.density-gradient {
  grid-column: 2;
  grid-row: 2;
  background: linear-gradient(
    to top,
    #071612,
    #0d2a23 24%,
    #155345 48%,
    #26836c 68%,
    #bd934e 82%,
    #df844c 92%,
    #d95555
  );
}

.density-bar ol {
  grid-column: 3;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 10px;
}

.plot-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 9px 18px;
  width: min(760px, calc(100% - 28px));
  margin: -4px auto 14px;
  padding: 11px 14px;
  border: 1px solid #35564d;
  background: rgba(16, 37, 31, 0.92);
  color: #edf4ef;
  font-size: 11px;
}

.plot-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.plot-legend i,
.plot-legend b {
  display: inline-block;
}

.crowd-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(244, 242, 232, 0.82);
}

.direct-line {
  width: 30px;
  border-top: 4px dashed var(--red);
}

.nabdah-line {
  width: 30px;
  border-top: 6px solid var(--green);
}

.team-star {
  color: var(--gold);
  font-size: 18px;
  line-height: 1;
}

.case-mark {
  color: var(--red);
  font-size: 22px;
  line-height: 1;
}

#motion-note {
  margin: 9px 0 0;
  color: #b7ccc4;
  text-align: center;
  font-size: 13px;
}

.result-card {
  margin-top: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  color: var(--text);
}

.result-card .eyebrow,
.result-card .box-label {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 13px;
}

.result-card h2 {
  margin: 4px 0 16px;
  color: var(--green);
  font-size: 24px;
}

.instruction-box {
  padding: 16px;
  border-right: 5px solid var(--green);
  border-radius: 13px;
  background: #102d25;
}

.instruction-text {
  color: #fff;
  font-size: 18px;
  line-height: 2;
}

.location-line {
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: 10px;
  background: #0a1b16;
  color: #dfeae5;
}

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

.metric {
  padding: 13px;
  border: 1px solid #29493f;
  border-radius: 12px;
  background: var(--panel-2);
}

.metric span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  color: var(--gold);
  font-size: 20px;
}

.reason-box {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid #29493f;
  border-radius: 12px;
  background: #0a1b16;
  line-height: 1.9;
}

.comparison-table {
  width: 100%;
  margin-top: 14px;
  border-collapse: collapse;
  text-align: center;
}

.comparison-table th,
.comparison-table td {
  padding: 10px 6px;
  border-bottom: 1px solid #29493f;
}

.comparison-table th {
  color: var(--muted);
  font-size: 12px;
}

.comparison-table td:last-child {
  color: var(--green);
  font-weight: 700;
}

.simulation-note {
  margin-top: 13px;
  color: #829a91;
  font-size: 11px;
  line-height: 1.7;
}

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

  .input-panel {
    order: 1;
  }

  .map-column {
    order: 2;
  }
}

@media (max-width: 720px) {
  .gradio-container {
    width: min(100% - 18px, 1480px);
    padding-top: 9px;
  }

  #nabdah-hero {
    padding: 17px;
  }

  #nabdah-hero p {
    font-size: 15px;
  }

  .input-panel {
    padding: 13px;
  }

  .radio-grid,
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .map-frame h2 {
    padding-inline: 12px;
    font-size: 18px;
  }

  .canvas-shell {
    min-height: 440px;
  }

  .density-bar {
    right: 1%;
  }

  .instruction-text {
    font-size: 16px;
  }
}
