:root {
  --bg: #eef2f6;
  --ink: #111827;
  --text: #243041;
  --muted: #697586;
  --line: #d7dee8;
  --line-strong: #bcc8d8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --nav: #172033;
  --nav-2: #202b3c;
  --brand: #087f8c;
  --brand-2: #0f766e;
  --brand-soft: #e6f7f8;
  --accent: #2563eb;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --warn: #b54708;
  --warn-soft: #fff7ed;
  --ok: #067647;
  --ok-soft: #ecfdf3;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 14px 32px rgba(16, 24, 40, .12);
  --radius: 8px;
  --focus: 0 0 0 3px rgba(8, 127, 140, .18);
}

* { box-sizing: border-box; }

html,
body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, #e4ebf3 0, #f3f6fa 340px, var(--bg) 100%);
  font-family: "Segoe UI", "Cairo", Tahoma, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  background-image:
    linear-gradient(rgba(17, 24, 39, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(17, 24, 39, .035) 1px, transparent 1px);
  background-size: 32px 32px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 22px;
  color: #e5edf6;
  background: linear-gradient(90deg, var(--nav), var(--nav-2));
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  box-shadow: 0 10px 28px rgba(17, 24, 39, .18);
}

.brand,
.topbar-actions,
.user-chip,
.api-label {
  display: flex;
  align-items: center;
}

.brand { gap: 12px; }
.brand strong {
  display: block;
  color: #ffffff;
  font-size: 15px;
}
.brand small {
  display: block;
  color: #aebacc;
  font-size: 12px;
}

.logo {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: #8ee7df;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .12);
  border-radius: 8px;
  font-size: 21px;
}

.topbar-actions {
  flex-wrap: wrap;
  gap: 12px;
}

.api-label {
  gap: 8px;
  color: #c4cedd;
  font-size: 12px;
}

.api-label input {
  width: 250px;
  padding: 7px 10px;
  direction: ltr;
  color: #eef6ff;
  background: rgba(255, 255, 255, .08);
  border-color: rgba(255, 255, 255, .16);
}

.user-chip {
  gap: 9px;
  min-height: 36px;
  padding: 5px 7px 5px 12px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 999px;
}

.user-chip .u-name { color: #ffffff; font-weight: 800; }
.user-chip .u-role { color: #8ee7df; font-size: 12px; font-weight: 800; }
.user-chip button {
  padding: 5px 10px;
  color: #ffd8d3;
  background: rgba(180, 35, 24, .22);
  border: 1px solid rgba(255, 216, 211, .24);
  border-radius: 999px;
  cursor: pointer;
}

.container {
  width: min(1440px, calc(100% - 36px));
  margin: 0 auto;
  padding: 26px 0 58px;
}

.login-shell {
  display: grid;
  grid-template-columns: minmax(320px, 1.2fr) minmax(340px, 460px);
  gap: 24px;
  align-items: stretch;
  max-width: 1040px;
  margin: 54px auto 0;
}

.login-copy {
  min-height: 420px;
  padding: 38px;
  color: #ffffff;
  background:
    linear-gradient(140deg, rgba(8, 127, 140, .92), rgba(23, 32, 51, .98)),
    linear-gradient(90deg, transparent, rgba(255, 255, 255, .08));
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
}

.login-copy h1 {
  max-width: 620px;
  margin: 12px 0;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1.15;
}

.login-copy p {
  max-width: 560px;
  margin: 0;
  color: #dbe8ee;
  font-size: 16px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  color: var(--brand-2);
  background: var(--brand-soft);
  border: 1px solid #bfe8ea;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
}

.login-copy .eyebrow {
  color: #e3fbfb;
  background: rgba(255, 255, 255, .13);
  border-color: rgba(255, 255, 255, .18);
}

.panel,
.workspace-shell,
.panel-lite {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.panel {
  min-width: 0;
  padding: 18px;
}

.login-panel {
  max-width: none;
  margin: 0;
  padding: 28px;
}

.panel-lite {
  margin: 14px 0;
  padding: 14px;
  background: var(--panel-soft);
  box-shadow: none;
}

.workspace-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.panel-head h1 {
  margin: 8px 0 4px;
  color: var(--ink);
  font-size: 30px;
  line-height: 1.2;
}

.panel-head p { margin: 0; }

.panel h1,
.panel h2,
.panel h3 {
  color: var(--ink);
  letter-spacing: 0;
}

.panel h1 { margin: 0 0 8px; font-size: 24px; }
.panel h2 { margin: 0 0 14px; font-size: 16px; }
.panel h3 { margin: 0 0 10px; font-size: 14px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.empty {
  padding: 20px;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  text-align: center;
}

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

.stat-card {
  min-height: 102px;
  padding: 15px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 3px solid var(--brand);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stat-card strong {
  display: block;
  margin: 4px 0;
  color: var(--ink);
  font-size: 28px;
  line-height: 1.1;
}

.stat-card small {
  display: block;
  direction: ltr;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 520px;
  margin: 0;
  padding: 12px;
  background: #f4f7fb;
  border-left: 1px solid var(--line);
}

.tab-btn {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  color: #475467;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  text-align: right;
  transition: background .15s, color .15s, border-color .15s;
}

.tab-btn:hover {
  color: var(--ink);
  background: #ffffff;
  border-color: var(--line);
}

.tab-btn.active {
  color: #ffffff;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  border-color: transparent;
  box-shadow: 0 10px 22px rgba(8, 127, 140, .18);
}

.tab-pane {
  display: none;
  min-width: 0;
  padding: 18px;
  animation: fade .18s;
}

.tab-pane.active { display: block; }

@keyframes fade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.tab-pane > .grid-2,
#view-provider > .grid-2 {
  display: grid;
  grid-template-columns: minmax(380px, .9fr) minmax(480px, 1.25fr);
  gap: 16px;
  align-items: start;
}

.form .grid-2,
.panel .form .grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

#tab-register .panel {
  max-width: 100%;
}

.form {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.form-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}

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

.field label,
.repeat-item .field label {
  color: #475467;
  font-size: 12px;
  font-weight: 900;
}

.field .req { color: var(--danger); }

input,
textarea,
select {
  max-width: 100%;
  width: 100%;
  min-height: 39px;
  padding: 9px 11px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  font: inherit;
  transition: border-color .15s, box-shadow .15s, background .15s;
}

textarea {
  min-height: 84px;
  resize: vertical;
  direction: ltr;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12.5px;
  line-height: 1.6;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus);
}

input[type="checkbox"] {
  width: auto;
  min-height: 0;
  accent-color: var(--brand);
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
}

.checks label,
label.checks {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
  font-size: 13px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 39px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 7px;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 900;
  transition: transform .08s, box-shadow .15s, background .15s, border-color .15s;
}

.btn:hover { transform: translateY(-1px); }
.btn:disabled {
  opacity: .58;
  cursor: not-allowed;
  transform: none;
}

.btn.primary {
  color: #ffffff;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  border-color: var(--brand);
  box-shadow: 0 10px 22px rgba(8, 127, 140, .18);
}

.btn.secondary {
  color: #344054;
  background: #ffffff;
  border-color: var(--line-strong);
}

.btn.danger {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #fecdca;
}

.btn-block { width: 100%; }
.btn-sm {
  min-height: 31px;
  padding: 6px 10px;
  font-size: 12px;
}

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

.panel-title-row h2,
.panel-title-row h3 { margin: 0; }

.list-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.list-item {
  display: grid;
  gap: 5px;
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-right: 4px solid transparent;
  border-radius: 7px;
  font-size: 13px;
  transition: border-color .15s, box-shadow .15s, background .15s;
}

.provider-row,
.topic-row { cursor: pointer; }

.provider-row:hover,
.topic-row:hover {
  background: #fbfdff;
  border-color: #9ddce1;
  border-right-color: var(--brand);
  box-shadow: 0 8px 20px rgba(8, 127, 140, .09);
}

.list-item .lb {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
  font-weight: 900;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 7px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

code,
.list-item code {
  display: inline-flex;
  align-items: center;
  direction: ltr;
  max-width: 100%;
  padding: 2px 7px;
  color: #075985;
  background: #eef7ff;
  border: 1px solid #cce7ff;
  border-radius: 999px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  font-weight: 800;
}

.result-box {
  max-height: 430px;
  margin-top: 12px;
  padding: 12px;
  overflow: auto;
  direction: ltr;
  color: #dbeafe;
  background: #111827;
  border: 1px solid #344054;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.6;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
}

.result-box.ok { border-color: var(--ok); }
.result-box.err { border-color: var(--danger); }

.meta {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  gap: 9px 12px;
  margin: 0 0 16px;
  padding: 12px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.meta dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.meta dd {
  margin: 0;
  color: var(--ink);
  font-weight: 900;
}

.subhead {
  margin: 18px 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.repeater {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.repeat-item {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr)) auto;
  gap: 9px;
  align-items: end;
  padding: 11px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.repeat-item.compact {
  grid-template-columns: repeat(5, minmax(110px, 1fr)) auto;
}

.repeat-item .rm-btn {
  width: 33px;
  height: 33px;
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid #fecdca;
  border-radius: 7px;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}

.add-btn {
  min-height: 36px;
  color: var(--brand-2);
  background: var(--brand-soft);
  border: 1px dashed #80cfd5;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
}

.form-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.form-section h3 {
  color: var(--ink);
  font-size: 14px;
}

.field-hint {
  display: block;
  margin-top: 2px;
  color: var(--warn);
  font-size: 11.5px;
  line-height: 1.55;
}

.section-hint {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.7;
}

.permission-disabled {
  opacity: .55;
  cursor: not-allowed;
}

.toasts {
  position: fixed;
  bottom: 18px;
  left: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  max-width: 410px;
  padding: 12px 15px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-right: 4px solid var(--brand);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  animation: fade .18s;
}

.toast.err { border-right-color: var(--danger); }
.toast.warn { border-right-color: var(--warn); }

.error-msg {
  color: var(--danger);
  font-size: 13px;
}

.notice ol {
  padding-right: 18px;
  line-height: 1.8;
  font-size: 14px;
}

.notice li + li { margin-top: 10px; }

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

  .tabs {
    flex-direction: row;
    min-height: 0;
    overflow-x: auto;
    border-left: 0;
    border-bottom: 1px solid var(--line);
  }

  .tab-btn {
    width: auto;
    white-space: nowrap;
  }

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

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

@media (max-width: 760px) {
  .container {
    width: min(100% - 20px, 1440px);
    padding-top: 18px;
  }

  .topbar,
  .topbar-actions,
  .api-label {
    align-items: stretch;
    flex-direction: column;
  }

  .api-label input {
    width: 100%;
  }

  .login-shell,
  .ops-strip,
  .form .grid-2,
  .panel .form .grid-2,
  .tab-pane > .grid-2,
  #view-provider > .grid-2,
  .repeat-item,
  .repeat-item.compact {
    grid-template-columns: 1fr;
  }

  .login-copy {
    min-height: 0;
    padding: 26px;
  }

  .login-copy h1 {
    font-size: 30px;
  }

  .panel,
  .tab-pane {
    padding: 14px;
  }

  .panel-title-row,
  .list-item .lb {
    align-items: stretch;
    flex-direction: column;
  }
}
