/* ============================================================
   TOOLBOX PROXY — TOOLBOXLAP "workshop" identity
   Flat, hard 2px outlines, no shadows, no gradients except the
   6px hazard stripe. Arabic-first, RTL, mobile-first.
   Light + dark "lab" theme.
   ============================================================ */

:root {
  --bg: #e7e8e3;
  --bg-2: #f1f1ec;
  --card: #f8f8f4;
  --dash: #c8cac2;
  --secondary-soft: #e2e3dd;
  --line: #17171a;
  --text: #17171a;
  --text-soft: #3b3b37;
  --muted: #55554f;
  --primary: #ffc20e;
  --primary-soft: #fff0bf;
  --primary-hover: #f2b500;
  --panel: #17171a;
  --panel-2: #24242a;
  --panel-3: #3a3a40;
  --on-panel: #f1f1ec;
  --on-panel-muted: #a9a9a2;
  --live: #3f9a1b;
  --danger: #e62117;
  --dots: #c8cac2;
  --on-primary: #17171a;
  --bar-bg: rgba(231, 232, 227, 0.94);
  --warn-text: #8a6100;
  --danger-soft: #fde8e6;
  color-scheme: light;

  --radius: 18px;
  --radius-sm: 12px;
  --tap: 44px;
}

/* ---------------- dark "lab" theme ---------------- */
:root[data-theme='dark'] {
  --bg: #0b0c0e;
  --bg-2: #15161a;
  --card: #111216;
  --dash: #2a2b31;
  --secondary-soft: #1a1b20;
  --line: #2a2b31;
  --text: #ecece6;
  --text-soft: #c8c8c1;
  --muted: #9a9a93;
  --primary-soft: #2a2410;
  --primary-hover: #ffd23d;
  --panel: #15161a;
  --panel-2: #1a1b20;
  --panel-3: #2a2b31;
  --on-panel: #ecece6;
  --on-panel-muted: #9a9a93;
  --live: #9be85c;
  --dots: #16171b;
  --bar-bg: rgba(11, 12, 14, 0.94);
  --warn-text: #ffc20e;
  --danger-soft: #2a1210;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0b0c0e;
    --bg-2: #15161a;
    --card: #111216;
    --dash: #2a2b31;
    --secondary-soft: #1a1b20;
    --line: #2a2b31;
    --text: #ecece6;
    --text-soft: #c8c8c1;
    --muted: #9a9a93;
    --primary-soft: #2a2410;
    --primary-hover: #ffd23d;
    --panel: #15161a;
    --panel-2: #1a1b20;
    --panel-3: #2a2b31;
    --on-panel: #ecece6;
    --on-panel-muted: #9a9a93;
    --live: #9be85c;
    --dots: #16171b;
    --bar-bg: rgba(11, 12, 14, 0.94);
    --warn-text: #ffc20e;
    --danger-soft: #2a1210;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

/*
 * The UA rule for [hidden] loses against any author `display` rule, so the
 * login screen would stay on top of the panel. Make `hidden` win.
 */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg);
  background-image: radial-gradient(var(--dots) 1.6px, transparent 1.9px);
  background-size: 22px 22px;
  color: var(--text);
  font-family: 'Almarai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 17px;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3,
.metric-value,
.sheet-title,
.sheet-btn,
.act-btn {
  font-family: 'Changa', 'Almarai', system-ui, sans-serif;
}

.mono {
  font-family: 'JetBrains Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

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

/* Latin/digit runs keep their own order inside RTL text. */
.ltr {
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
}

/* ---------------- hazard stripe ---------------- */

.hazard {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 6px;
  background: repeating-linear-gradient(45deg, #ffc20e 0 12px, #17171a 12px 24px);
  z-index: 40;
}

/* ---------------- header ---------------- */

.topbar {
  position: sticky;
  top: 6px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: var(--bar-bg);
  border-bottom: 2px solid var(--line);
  backdrop-filter: blur(6px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.logo-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 2px solid var(--line);
  border-radius: 9px;
  background: var(--panel);
  flex: none;
}

.wordmark {
  font-family: 'Changa', sans-serif;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 0.02em;
  color: var(--text);
}

.lap {
  font-family: 'Changa', sans-serif;
  font-weight: 800;
  font-size: 15px;
  background: var(--primary);
  color: var(--on-primary);
  border: 2px solid var(--line);
  border-radius: 6px;
  padding: 1px 7px;
  line-height: 1.25;
}

.header-side {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  background: var(--card);
  color: var(--text);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* ---------------- layout ---------------- */

.content {
  padding: 14px 14px calc(var(--tap) + 34px + env(safe-area-inset-bottom));
  max-width: 1080px;
  margin: 0 auto;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------------- login ---------------- */

.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 14px;
}

.login-card {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-title {
  margin: 6px 0 0;
  font-size: 24px;
  font-weight: 800;
}

.login-sub {
  margin: 0;
  font-size: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 14px;
  font-weight: 700;
}

.field-input {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 17px;
}

.field-input:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 1px;
}

.code-input {
  font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  font-size: 22px;
  letter-spacing: 0.35em;
  text-align: center;
}

.login-err {
  margin: 0;
  padding: 9px 12px;
  background: var(--danger-soft);
  border: 2px solid var(--danger);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-weight: 700;
  font-size: 15px;
}

.login-err[hidden] {
  display: none;
}

/* ---------------- cards ---------------- */

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

.chip {
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 2px 8px;
  background: var(--card);
  white-space: nowrap;
}

.empty {
  text-align: center;
  padding: 28px 16px;
  background: var(--card);
  border: 2px dashed var(--dash);
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 700;
}

.notice {
  margin-bottom: 10px;
}

/* ---------------- buttons ---------------- */

.act-btn {
  flex: none;
  min-height: var(--tap);
  min-width: 78px;
  padding: 0 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: 'Changa', sans-serif;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
}

.act-btn.amber {
  background: var(--primary);
  color: var(--on-primary);
}

.act-btn.dark {
  background: var(--panel);
  color: var(--on-panel);
}

.act-btn.ghost {
  background: var(--bg-2);
  color: var(--text);
}

.act-btn.danger {
  background: var(--danger);
  color: #fff;
}

.act-btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.act-btn.icon-only {
  min-width: var(--tap);
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ---------------- sheets ---------------- */

.sheets {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
}

.sheets.open {
  display: block;
}

.sheets[hidden] {
  display: none;
}

.sheet-overlay {
  position: absolute;
  inset: 0;
  background: rgba(23, 23, 26, 0.45);
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 720px;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 auto;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 22px 22px 0 0;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-title {
  font-family: 'Changa', sans-serif;
  font-weight: 700;
  font-size: 19px;
  margin: 0;
}

.sheet-note {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.warn-note {
  color: var(--danger);
  font-weight: 700;
}

.sheet-sub {
  font-family: 'Changa', sans-serif;
  font-weight: 700;
  font-size: 15px;
  margin: 6px 0 0;
}

.sheet-btn {
  min-height: var(--tap);
  width: 100%;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: 'Changa', sans-serif;
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
}

.sheet-btn.amber {
  background: var(--primary);
  color: var(--on-primary);
}

.sheet-btn.dark {
  background: var(--panel);
  color: var(--on-panel);
}

.sheet-btn.ghost {
  background: var(--card);
  color: var(--text);
}

.sheet-btn.danger {
  background: var(--danger);
  color: #fff;
}

.sheet-btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* ---------------- toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  z-index: 70;
  max-width: min(92vw, 460px);
  padding: 10px 16px;
  background: var(--panel);
  color: var(--on-panel);
  border: 2px solid var(--line);
  border-radius: 999px;
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.16s ease, transform 0.16s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast[hidden] {
  display: none;
}

/* ---------------- proxy bar ---------------- */

.proxy-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.proxy-bar-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.proxy-bar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ---------------- proxy grid ---------------- */

.proxy-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 10px;
}

@media (min-width: 720px) {
  .proxy-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1040px) {
  .proxy-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.proxy-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.proxy-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.proxy-num {
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  direction: ltr;
  unicode-bidi: isolate;
}

.chip-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
}

.chip-state.off {
  color: var(--muted);
}

.chip-state.connecting {
  background: var(--primary-soft);
  color: var(--warn-text);
  border-color: var(--primary);
}

.chip-state.up {
  background: var(--live);
  color: #fff;
  border-color: var(--line);
}

.chip-state.error {
  background: var(--danger);
  color: #fff;
  border-color: var(--line);
}

.chip-open {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 700;
}

.chip-soft {
  display: inline-flex;
  align-items: center;
  border-style: dashed;
  color: var(--muted);
  font-size: 12px;
  padding: 0 8px;
}

.proxy-country {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.proxy-flag {
  font-size: 20px;
  line-height: 1;
}

.proxy-country-name {
  font-family: 'Changa', sans-serif;
  font-weight: 700;
  font-size: 16px;
}

.proxy-facts {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.proxy-facts .mono {
  overflow-wrap: anywhere;
}

.proxy-endpoint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  min-width: 0;
}

.proxy-endpoint .mono {
  overflow-wrap: anywhere;
}

.proxy-usage {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--bg-2);
  border: 2px dashed var(--dash);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text-soft);
}

.proxy-usage .sep {
  color: var(--muted);
}

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

.proxy-actions .act-btn {
  min-width: 0;
  flex: 1 1 auto;
  padding: 0 12px;
  font-size: 14px;
}

.proxy-switch {
  flex: 1 1 100%;
  min-height: var(--tap);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--text);
  font-family: 'Changa', sans-serif;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.proxy-switch::before {
  content: '';
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--muted);
  flex: none;
}

.proxy-switch.on {
  background: var(--primary);
  color: var(--on-primary);
}

.proxy-switch.on::before {
  background: var(--on-primary);
}

.proxy-switch:disabled {
  opacity: 0.6;
  cursor: progress;
}

.proxy-creds {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--primary-soft);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.proxy-creds[hidden] {
  display: none;
}

.proxy-country-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 46vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.proxy-country-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  padding: 6px 10px;
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  text-align: start;
  cursor: pointer;
}

.proxy-country-row.sel {
  background: var(--primary);
  color: var(--on-primary);
}

.proxy-country-row .proxy-country-name {
  flex: 1;
  min-width: 0;
}

.voice-input {
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
}

/* ---------------- activity drawer ---------------- */

.act-summary {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.act-dest {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.act-dest-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  font-size: 13px;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
}

.act-dest-bytes {
  flex: none;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.act-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 44vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.act-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 7px 10px;
  background: var(--bg-2);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px;
  min-width: 0;
}

.act-row-main {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.act-row-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
}

.act-row .act-time {
  flex: none;
  font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  font-size: 11px;
  direction: ltr;
  unicode-bidi: isolate;
}

.act-row .act-dst {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
}

.act-row .act-port {
  flex: none;
  font-size: 11px;
  color: var(--muted);
  direction: ltr;
  unicode-bidi: isolate;
}

.act-row .act-io {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  font-size: 11px;
  color: var(--text-soft);
  direction: ltr;
  unicode-bidi: isolate;
}

.act-row .act-ms {
  flex: none;
  font-size: 11px;
  min-width: 48px;
  text-align: end;
}

.act-err {
  flex: none;
  background: var(--danger);
  color: #fff;
  border-radius: 6px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
}

.act-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

/* ---------------- skeleton ---------------- */

.proxy-skel {
  height: 190px;
  position: relative;
  overflow: hidden;
}

.proxy-skel::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--secondary-soft), transparent);
  animation: proxy-shimmer 1.4s ease-in-out infinite;
}

@keyframes proxy-shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

.spin-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--line);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.35;
    transform: scale(0.7);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
  .proxy-skel::after {
    animation: none;
  }
}

@media (max-width: 380px) {
  .content {
    padding-left: 10px;
    padding-right: 10px;
  }

  .wordmark {
    font-size: 17px;
  }

  .proxy-bar-actions .act-btn {
    font-size: 13px;
    padding: 0 10px;
  }
}
