:root {
  --bg: #eef6fb;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dbe7ef;
  --accent: #2aabee;
  --accent-dark: #168acd;
  --accent-soft: #e3f4ff;
  --accent-border: #b9e4fb;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --danger-soft: #fee2e2;
  --good: #047857;
  --good-soft: #dcfce7;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.d-shell {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
  transition: grid-template-columns .18s ease;
}

.d-sidebar {
  background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
  border-right: 1px solid var(--border);
  padding: 14px 12px;
  min-width: 0;
}

.d-sidebar-head {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.d-main { min-width: 0; }

.d-topbar {
  background: rgba(255, 255, 255, .92);
  border-bottom: 1px solid var(--border);
  padding: 18px 24px;
}

.d-topbar h1 {
  margin: 0 0 4px;
  font-size: 24px;
  letter-spacing: -0.02em;
}

.d-content { padding: 20px 24px 40px; }

.d-brand {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
  padding: 6px;
}

.d-brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  box-shadow: 0 10px 22px rgba(42, 171, 238, .25);
}

.d-brand-text { min-width: 0; }
.d-brand-title { font-weight: 900; line-height: 1.1; }
.d-brand-subtitle { color: var(--muted); font-size: 12px; white-space: nowrap; }

.d-sidebar-toggle {
  width: 36px;
  height: 36px;
  border: 1px solid var(--accent-border);
  border-radius: 12px;
  background: var(--accent-soft);
  cursor: pointer;
  display: inline-grid;
  place-content: center;
  gap: 4px;
  padding: 0;
}

.d-sidebar-toggle:hover { background: #d6efff; }
.d-sidebar-toggle span { display: block; width: 16px; height: 2px; border-radius: 999px; background: var(--accent-dark); }

.d-nav { display: grid; gap: 6px; }

.d-nav-item {
  display: flex;
  gap: 10px;
  align-items: center;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 13px;
  color: #1e293b;
  text-decoration: none;
  font-weight: 800;
  border: 1px solid transparent;
}

.d-nav-icon { width: 22px; flex: 0 0 22px; display: inline-flex; justify-content: center; }
.d-nav-text { white-space: nowrap; }

.d-nav-item:hover {
  background: #f0f9ff;
  border-color: var(--accent-border);
  color: #075985;
}

.d-nav-item.is-active {
  background: var(--accent-soft);
  color: #075985;
  border-color: var(--accent-border);
  box-shadow: inset 4px 0 0 var(--accent);
}

.d-nav-item.is-disabled {
  opacity: .45;
  cursor: not-allowed;
}

body.d-sidebar-collapsed .d-shell { grid-template-columns: 76px 1fr; }
body.d-sidebar-collapsed .d-brand-text,
body.d-sidebar-collapsed .d-nav-text { display: none; }
body.d-sidebar-collapsed .d-sidebar { padding-left: 10px; padding-right: 10px; }
body.d-sidebar-collapsed .d-sidebar-head { justify-content: center; flex-wrap: wrap; }
body.d-sidebar-collapsed .d-brand { padding: 0; }
body.d-sidebar-collapsed .d-nav-item { justify-content: center; padding-left: 8px; padding-right: 8px; }
body.d-sidebar-collapsed .d-nav-icon { width: auto; flex-basis: auto; }

.card { background: transparent; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 26px rgba(15, 23, 42, .04);
}

.panel-title {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 900;
}

.panel-body { padding: 16px; }
.muted { color: var(--muted); }
.mt-16 { margin-top: 16px; }
.w-100 { width: 100%; }

.d-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.d-kpi {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 8px 26px rgba(15, 23, 42, .04);
}

.d-kpi-label { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.d-kpi-value { font-size: 30px; font-weight: 900; line-height: 1; }
.d-kpi-note { color: var(--muted); font-size: 12px; margin-top: 8px; }

.table { border-collapse: collapse; font-size: 14px; }
.table th,
.table td { border-bottom: 1px solid var(--border); padding: 10px; text-align: left; vertical-align: top; }
.table th { color: var(--muted); font-size: 12px; text-transform: uppercase; }

.btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 18px rgba(42, 171, 238, .18);
}

.btn:hover { background: var(--accent-dark); }

.btn-danger,
.btn-delete,
.btn-cancel,
button[name="delete"],
button[name="cancel"],
a[href*="delete"],
a[href*="cancel"] {
  background: var(--danger) !important;
  color: #fff !important;
  box-shadow: 0 8px 18px rgba(220, 38, 38, .18) !important;
}

.btn-danger:hover,
.btn-delete:hover,
.btn-cancel:hover,
button[name="delete"]:hover,
button[name="cancel"]:hover,
a[href*="delete"]:hover,
a[href*="cancel"]:hover {
  background: var(--danger-dark) !important;
}

.d-form { display: grid; gap: 12px; }
.d-form-inline { grid-template-columns: repeat(3, minmax(160px, 1fr)) auto; align-items: end; }
.d-form label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 800; }
input { border: 1px solid var(--border); border-radius: 10px; padding: 10px 11px; font-size: 14px; background: #fff; }
input:focus { outline: 2px solid var(--accent-border); border-color: var(--accent); }

.pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 8px; background: #f1f5f9; color: #334155; font-size: 12px; font-weight: 900; }
.pill.good { background: var(--good-soft); color: var(--good); }
.muted-pill { background: #f1f5f9; color: var(--muted); }
.text-danger { color: var(--danger); }
.d-empty { color: var(--muted); border: 1px dashed var(--border); border-radius: 14px; padding: 18px; background: #f8fafc; }

@media (max-width: 900px) {
  .d-shell,
  body.d-sidebar-collapsed .d-shell { grid-template-columns: 1fr; }
  .d-sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  body.d-sidebar-collapsed .d-brand-text,
  body.d-sidebar-collapsed .d-nav-text { display: block; }
  body.d-sidebar-collapsed .d-nav-item { justify-content: flex-start; }
  .d-kpi-grid,
  .d-form-inline { grid-template-columns: 1fr; }
}

/* --- Sellers modal and extended forms --- */

.d-form-grid {
  display: grid;
  gap: 12px;
}

.d-form-grid.two { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
.d-form-grid.three { grid-template-columns: repeat(3, minmax(180px, 1fr)); }

textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 11px;
  font-size: 14px;
  background: #fff;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
}

textarea:focus {
  outline: 2px solid var(--accent-border);
  border-color: var(--accent);
}

.d-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
}

.d-modal.is-open { display: block; }
body.d-modal-open { overflow: hidden; }

.d-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .38);
  backdrop-filter: blur(2px);
}

.d-modal-dialog {
  position: relative;
  width: min(1120px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  margin: 16px auto;
  overflow: auto;
  background: #fff;
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: 0 24px 80px rgba(15, 23, 42, .22);
  padding: 18px;
}

.d-modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.d-modal-title {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.02em;
}

.d-modal-close {
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
  border-radius: 12px;
}

.d-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.d-modal-actions.split {
  justify-content: space-between;
}

.d-session-box {
  display: grid;
  grid-template-columns: 1fr minmax(260px, .5fr);
  gap: 12px;
  align-items: center;
  border: 1px dashed var(--accent-border);
  background: var(--accent-soft);
  border-radius: 14px;
  padding: 12px;
}

.d-session-title {
  color: #075985;
  font-weight: 900;
  margin-bottom: 4px;
}

.d-file-label {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 12px;
  padding: 10px;
}

input[type="file"] {
  margin-top: 8px;
  width: 100%;
}

@media (max-width: 900px) {
  .d-form-grid.two,
  .d-form-grid.three,
  .d-session-box { grid-template-columns: 1fr; }
}


/* --- Sellers list controls --- */
.d-panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.d-icon-add {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 13px;
  font-size: 24px;
  line-height: 1;
  flex: 0 0 auto;
}

.btn-small {
  padding: 7px 10px;
  border-radius: 10px;
  font-size: 12px;
  box-shadow: none;
}

.btn-ghost {
  background: #fff;
  color: var(--accent-dark);
  border: 1px solid var(--accent-border);
  box-shadow: none;
}

.btn-ghost:hover {
  background: var(--accent-soft);
  color: #075985;
}

.d-form-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.text-right { text-align: right !important; }

@media (max-width: 900px) {
  .d-modal-actions.split {
    display: grid;
    grid-template-columns: 1fr;
  }
}

/* --- OpenAI fields --- */
.d-openai-grid {
  grid-template-columns: minmax(420px, 1fr) 180px;
  align-items: end;
}

.d-model-field {
  max-width: 190px;
}

.d-model-input {
  width: 100%;
}

.d-secret-input {
  position: relative;
  display: block;
}

.d-secret-input input {
  width: 100%;
  padding-right: 46px;
}

.d-secret-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

.d-secret-toggle:hover {
  background: #e0f2fe;
}

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

  .d-model-field {
    max-width: none;
  }
}

/* --- Seller active toggle --- */
.d-inline-form {
  display: inline-flex;
  margin: 0;
}

.d-toggle {
  width: 42px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  padding: 3px;
  cursor: pointer;
  background: #cbd5e1;
  display: inline-flex;
  align-items: center;
  transition: background .15s ease;
}

.d-toggle span {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .18);
  transition: transform .15s ease;
}

.d-toggle.is-on {
  background: var(--accent);
}

.d-toggle.is-on span {
  transform: translateX(18px);
}

.d-toggle.is-off {
  background: #cbd5e1;
}

.d-switch-row {
  display: inline-flex !important;
  grid-template-columns: auto !important;
  align-items: center;
  gap: 10px !important;
  width: fit-content;
  color: var(--text) !important;
  font-weight: 900 !important;
  cursor: pointer;
  user-select: none;
}

.d-switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.d-switch-ui {
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: #cbd5e1;
  position: relative;
  flex: 0 0 46px;
  transition: background .15s ease;
}

.d-switch-ui::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, .18);
  transition: transform .15s ease;
}

.d-switch-row input:checked + .d-switch-ui {
  background: var(--accent);
}

.d-switch-row input:checked + .d-switch-ui::after {
  transform: translateX(20px);
}

.pill.off {
  background: #f1f5f9;
  color: #64748b;
}

/* --- Seller detail page --- */
.d-row-title-link {
  color: var(--text);
  text-decoration: none;
}
.d-row-title-link:hover {
  color: var(--accent-dark);
  text-decoration: underline;
}
.d-detail-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 26px rgba(15, 23, 42, .04);
}
.d-detail-head h2 {
  margin: 4px 0 6px;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: -0.03em;
}
.d-back-link {
  color: var(--accent-dark);
  font-weight: 900;
  text-decoration: none;
  font-size: 13px;
}
.d-back-link:hover { text-decoration: underline; }
.d-detail-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.d-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 2px 2px;
}
.d-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: #334155;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
}
.d-tab:hover {
  border-color: var(--accent-border);
  background: #f0f9ff;
  color: #075985;
}
.d-tab.is-active {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: #075985;
  box-shadow: inset 0 -3px 0 var(--accent);
}
.d-info-grid,
.d-settings-grid,
.d-diagnostics-grid {
  display: grid;
  gap: 12px;
}
.d-info-grid {
  grid-template-columns: repeat(4, minmax(160px, 1fr));
}
.d-info-grid > div,
.d-setting-card,
.d-diagnostic-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  padding: 12px;
}
.d-info-grid span,
.d-setting-card span {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 900;
}
.d-settings-grid {
  grid-template-columns: repeat(3, minmax(220px, 1fr));
}
.d-setting-card code {
  overflow-wrap: anywhere;
}
.d-alert {
  border-radius: 14px;
  padding: 12px;
  font-weight: 800;
}
.d-alert.danger,
.d-alert.danger.mt-16 {
  background: var(--danger-soft);
  color: var(--danger-dark);
  border: 1px solid #fecaca;
}

.d-panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.d-auto-refresh-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
}
.d-auto-refresh-control input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}
.d-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.d-log-box {
  margin: 12px 0 0;
  min-height: 320px;
  max-height: 560px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: #0f172a;
  color: #e5e7eb;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}
.d-event-list {
  display: grid;
  gap: 8px;
}
.d-event-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 10px 12px;
}
.d-event-item.warning {
  border-color: #fde68a;
  background: #fffbeb;
}
.d-event-item.error {
  border-color: #fecaca;
  background: #fef2f2;
}
.d-event-top {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 5px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 800;
}
.d-event-type {
  border-radius: 999px;
  background: #f1f5f9;
  padding: 3px 7px;
  color: #475569;
}
.d-event-title {
  font-weight: 900;
  margin-bottom: 4px;
}
.d-event-description {
  color: #475569;
  font-size: 13px;
  line-height: 1.45;
}
.d-diagnostics-grid {
  grid-template-columns: repeat(3, minmax(220px, 1fr));
}
.d-diagnostic-card {
  display: grid;
  gap: 10px;
  align-content: start;
}
@media (max-width: 1100px) {
  .d-info-grid,
  .d-settings-grid,
  .d-diagnostics-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 700px) {
  .d-detail-head { display: grid; }
  .d-info-grid,
  .d-settings-grid,
  .d-diagnostics-grid { grid-template-columns: 1fr; }
}

/* Patch 07: global settings, prompts, dialogs */
.d-alert.info {
  border: 1px solid #bae6fd;
  background: #e0f2fe;
  color: #075985;
}

.d-alert.warning {
  border: 1px solid #fde68a;
  background: #fffbeb;
  color: #92400e;
}

.d-text-preview {
  max-width: 520px;
  margin-top: 4px;
  line-height: 1.35;
}

.d-modal-dialog-small {
  max-width: 560px;
}

.d-compact-form {
  margin: 0;
}

.d-form select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

.d-proxy-grid input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

/* Patch 10: seller worker runtime */
.d-runtime-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.btn:disabled,
.btn-white:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}
.pill.good {
  background: #dcfce7;
  color: #047857;
}
.pill.off {
  background: #f1f5f9;
  color: #475569;
}

/* Dialog detail */
.d-chat-list {
  display: grid;
  gap: 10px;
}

.d-chat-message {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
  max-width: 980px;
  white-space: pre-wrap;
}

.d-chat-message.outgoing,
.d-chat-message.assistant {
  margin-left: auto;
  background: #e0f2fe;
  border-color: #bae6fd;
}

.d-chat-message.incoming,
.d-chat-message.user {
  margin-right: auto;
  background: #f8fafc;
}

.d-chat-message.system {
  max-width: 100%;
  background: #fff7ed;
  border-color: #fed7aa;
}

.d-chat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 7px;
}

.d-chat-text {
  color: #0f172a;
  font-size: 14px;
  line-height: 1.5;
}

/* --- Tasks directory refinement --- */
.d-panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.d-plus-btn {
  width: 42px;
  height: 42px;
  padding: 0 !important;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  line-height: 1;
}

.d-row-actions,
.d-actions-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.d-form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.d-info-grid.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 12px;
}

.d-info-grid.four {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 12px;
}

.d-info-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
  min-height: 72px;
  white-space: pre-wrap;
}

.d-pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  white-space: normal;
}

.pill.neutral {
  background: #eef6ff;
  color: #0369a1;
}

@media (max-width: 980px) {
  .d-info-grid.two,
  .d-info-grid.four {
    grid-template-columns: 1fr;
  }
}


/* Patch 20: restore layout, compact manual modal, icon actions */
.d-shell {
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
  transition: grid-template-columns .18s ease;
}

.d-sidebar {
  min-width: 0;
}

.d-main {
  min-width: 0;
}

.d-modal-dialog-manual {
  width: min(860px, calc(100vw - 36px));
  margin-top: 56px;
}

.d-icon-action {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent-border);
  border-radius: 10px;
  background: #fff;
  color: var(--accent-dark);
  text-decoration: none;
  font-size: 16px;
  line-height: 1;
}

.d-icon-action:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.d-actions-cell {
  white-space: nowrap;
}

@media (max-width: 900px) {
  .d-modal-dialog-manual {
    width: calc(100vw - 24px);
    margin-top: 12px;
  }
}


.d-parser-role-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border: 1px solid #d6ebfa;
  border-radius: 14px;
  background: #eef8ff;
}

@media (max-width: 720px) {
  .d-parser-role-box {
    align-items: flex-start;
    flex-direction: column;
  }
}

.d-inline-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.d-check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--text);
}

.d-check-row input {
  width: 18px;
  height: 18px;
}


/* Patch 26: accounts cleanup, compact role cards and dangerous chat actions */
.d-icon-action {
  cursor: pointer;
  box-shadow: none;
}
button.d-icon-action {
  padding: 0;
}
.d-icon-danger {
  border-color: #fecaca;
  color: var(--danger-dark);
}
.d-icon-danger:hover {
  background: var(--danger-soft);
  border-color: #fca5a5;
  color: var(--danger-dark);
}
.d-role-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 12px;
}
.d-role-card-clean {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  padding: 14px 16px;
}
.d-role-title {
  font-weight: 900;
  margin-bottom: 4px;
}
.d-settings-section .d-section-head p {
  display: none;
}
.d-modal-dialog-small {
  width: min(560px, calc(100vw - 32px));
  margin-top: 80px;
}
@media (max-width: 900px) {
  .d-role-grid { grid-template-columns: 1fr; }
}

/* Patch 27: compact account form rows */
.d-switch-row-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 12px;
  align-items: center;
}
.d-switch-row-grid .d-switch-row {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
.d-openai-grid {
  grid-template-columns: minmax(420px, 1fr) 190px 190px;
  align-items: end;
}
@media (max-width: 900px) {
  .d-switch-row-grid,
  .d-openai-grid { grid-template-columns: 1fr; }
}

/* Patch 29: Telegram-like dialog UI */
.d-dialog-page {
  display: grid;
  gap: 14px;
}

.d-dialog-head {
  align-items: flex-start;
}

.d-dialog-subline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.d-alert {
  border-radius: 14px;
  padding: 12px 14px;
  font-weight: 800;
  border: 1px solid var(--border);
}

.d-alert-info {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: #075985;
}

.d-alert-warning {
  background: #fff7ed;
  border-color: #fed7aa;
  color: #9a3412;
}

.d-chat-panel {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 250px);
  min-height: 540px;
}

.d-chat-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.d-chat-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  background:
    radial-gradient(circle at 20px 20px, rgba(42, 171, 238, .045) 0 2px, transparent 3px),
    linear-gradient(180deg, #eef8ff 0%, #f8fbff 100%);
}

.d-chat-messenger {
  display: grid;
  gap: 10px;
}

.d-chat-row {
  display: flex;
  width: 100%;
}

.d-chat-row.is-in { justify-content: flex-start; }
.d-chat-row.is-out { justify-content: flex-end; }
.d-chat-row.system { justify-content: center; }

.d-chat-message {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 8px 10px 7px;
  max-width: min(90%, 980px);
  min-width: min(260px, 90%);
  white-space: pre-wrap;
  box-shadow: 0 8px 20px rgba(15, 23, 42, .04);
}

.d-chat-message.incoming,
.d-chat-message.user {
  background: #ffffff;
  border-color: #dbe7ef;
  border-top-left-radius: 6px;
}

.d-chat-message.outgoing,
.d-chat-message.assistant,
.d-chat-message.operator,
.d-chat-message.outgoing_pending {
  background: #dff3ff;
  border-color: #b9e4fb;
  border-top-right-radius: 6px;
}

.d-chat-message.outgoing_pending {
  opacity: .82;
  border-style: dashed;
}

.d-chat-message.system {
  max-width: min(90%, 1120px);
  background: #fff7ed;
  border-color: #fed7aa;
  border-radius: 14px;
}

.d-chat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  margin-bottom: 4px;
}

.d-chat-text {
  color: #0f172a;
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.d-chat-message.is-collapsed .d-chat-text {
  max-height: calc(1.35em * 10);
  overflow: hidden;
}

.d-chat-message.is-collapsed::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 28px;
  height: 42px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,0), rgba(255,255,255,.92));
}

.d-chat-message.outgoing.is-collapsed::after,
.d-chat-message.assistant.is-collapsed::after,
.d-chat-message.operator.is-collapsed::after,
.d-chat-message.outgoing_pending.is-collapsed::after {
  background: linear-gradient(180deg, rgba(223,243,255,0), rgba(223,243,255,.94));
}

.d-chat-message.system.is-collapsed::after {
  background: linear-gradient(180deg, rgba(255,247,237,0), rgba(255,247,237,.94));
}

.d-chat-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
  min-height: 18px;
}

.d-chat-time {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.d-chat-expand {
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
  padding: 0;
}

.d-chat-expand:hover { text-decoration: underline; }

.d-manual-reply-box {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  background: #fff;
  padding: 12px 14px;
}

.d-manual-reply-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

.d-manual-reply-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 72px;
  max-height: 180px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  font: inherit;
}

.d-manual-reply-form textarea:focus {
  outline: 2px solid var(--accent-border);
  border-color: var(--accent);
}

.d-manual-reply-note {
  margin-top: 8px;
  font-size: 12px;
}

.d-icon-action {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  text-decoration: none;
}

.d-icon-action:hover { background: #d6efff; }

@media (max-width: 900px) {
  .d-chat-panel {
    height: calc(100vh - 290px);
    min-height: 460px;
  }
  .d-manual-reply-form {
    grid-template-columns: 1fr;
  }
  .d-chat-message {
    max-width: 96%;
  }
}

/* Patch 30: compact messenger dialog cleanup */
.d-dialog-page {
  gap: 10px;
  height: calc(100vh - 112px);
  min-height: 620px;
}

.d-dialog-head-compact {
  padding: 14px 18px;
  align-items: center;
}

.d-dialog-identity {
  display: grid;
  gap: 6px;
}

.d-dialog-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.d-dialog-line a {
  color: var(--accent-dark);
}

.d-chat-panel {
  min-height: 0;
  height: auto;
  flex: 1 1 auto;
  overflow: hidden;
}

.d-chat-scroll {
  padding: 12px 16px;
  min-height: 0;
}

.d-chat-messenger {
  gap: 7px;
}

.d-chat-message {
  width: fit-content;
  min-width: 0;
  max-width: min(88%, 980px);
  border-radius: 13px;
  padding: 7px 9px 5px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, .035);
}

.d-chat-message.system {
  width: fit-content;
  max-width: min(88%, 1120px);
  padding: 8px 10px 6px;
}

.d-chat-meta {
  margin: 0 0 3px;
  font-size: 11px;
  line-height: 1.15;
  color: #64748b;
}

.d-chat-text {
  font-size: 14px;
  line-height: 1.28;
}

.d-chat-message.is-collapsed .d-chat-text {
  max-height: calc(1.28em * 10);
}

.d-chat-message.is-collapsed::after {
  bottom: 22px;
  height: 24px;
}

.d-chat-footer {
  margin-top: 2px;
  min-height: 14px;
  gap: 8px;
}

.d-chat-time {
  font-size: 10.5px;
  line-height: 1;
  opacity: .78;
}

.d-chat-expand {
  font-size: 11px;
  line-height: 1;
}

.d-manual-reply-box {
  padding: 9px 12px;
}

.d-manual-reply-form {
  display: grid;
  grid-template-columns: 1fr 48px;
  gap: 8px;
  align-items: end;
}

.d-manual-reply-form textarea {
  min-height: 44px;
  height: 44px;
  max-height: 160px;
  resize: none;
  border-radius: 14px;
  padding: 10px 12px;
  overflow-y: auto;
}

.d-send-icon {
  width: 48px;
  height: 44px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 14px;
  font-size: 18px;
}

@media (max-width: 900px) {
  .d-dialog-page {
    height: calc(100vh - 96px);
    min-height: 520px;
  }
  .d-dialog-head-compact {
    align-items: flex-start;
  }
  .d-chat-message {
    max-width: 96%;
  }
}

/* Patch 31: remove excessive empty space inside messenger bubbles */
.d-chat-panel {
  height: calc(100vh - 210px);
}

.d-chat-scroll {
  padding: 8px 12px;
}

.d-chat-messenger {
  gap: 5px;
}

.d-chat-message {
  padding: 5px 8px 4px !important;
  border-radius: 12px;
}

.d-chat-message.system {
  padding: 6px 8px 5px !important;
}

.d-chat-meta {
  margin: 0 0 2px !important;
  line-height: 1.05 !important;
}

.d-chat-text {
  margin: 0 !important;
  line-height: 1.24 !important;
}

.d-chat-text p,
.d-chat-text pre {
  margin: 0 !important;
}

.d-chat-footer {
  margin-top: 2px !important;
  min-height: 12px !important;
  line-height: 1 !important;
}

.d-chat-message.is-collapsed .d-chat-text {
  max-height: calc(1.24em * 10) !important;
}

.d-chat-message.is-collapsed::after {
  bottom: 18px !important;
  height: 18px !important;
}

.d-manual-reply-box {
  padding: 7px 10px !important;
}

.d-manual-reply-form textarea {
  min-height: 40px !important;
  height: 40px;
  padding: 8px 10px !important;
}

.d-send-icon {
  height: 40px !important;
}

/* Patch 32: fix preserved template whitespace inside chat bubbles.
   The parent bubble must not use pre-wrap, otherwise HTML indentation around child divs
   becomes visible as large empty areas. Preserve line breaks only in message text. */
.d-chat-message {
  white-space: normal !important;
  display: inline-flex !important;
  flex-direction: column !important;
  gap: 2px !important;
}

.d-chat-meta,
.d-chat-footer {
  white-space: normal !important;
}

.d-chat-text {
  white-space: pre-wrap !important;
  display: block !important;
}

.d-chat-message.is-collapsed .d-chat-text {
  max-height: calc(1.24em * 10) !important;
}

/* Patch 41: dialog auto-refresh and operator alerts */
.d-nav-item {
  position: relative;
}

.d-nav-badge {
  margin-left: auto;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 6px 14px rgba(239, 68, 68, .22);
}

body.d-sidebar-collapsed .d-nav-badge {
  position: absolute;
  right: 4px;
  top: 4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  font-size: 10px;
}

.d-badge-inline {
  display: inline-flex;
  margin-left: 10px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 12px;
  font-weight: 900;
  vertical-align: middle;
}

.d-row-needs-attention {
  background: #fff7ed;
  box-shadow: inset 4px 0 0 #f59e0b;
}

.d-row-needs-attention td {
  border-bottom-color: #fed7aa;
}

.d-unread-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-left: 8px;
  border-radius: 999px;
  background: #ef4444;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, .12);
}

.d-small-alert {
  display: inline-flex;
  margin-top: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 11px;
  font-weight: 900;
}

.d-chat-panel {
  position: relative;
}

.d-new-messages-button {
  position: absolute;
  left: 50%;
  bottom: 68px;
  transform: translateX(-50%);
  display: none;
  border: 0;
  border-radius: 999px;
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(42, 171, 238, .28);
  z-index: 5;
}

.d-new-messages-button.is-visible {
  display: inline-flex;
}

@media (max-width: 900px) {
  .d-nav-badge {
    margin-left: 8px;
  }
  body.d-sidebar-collapsed .d-nav-badge {
    position: static;
  }
}

.d-checkline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  color: #334155;
}

.d-parser-checks-table td {
  vertical-align: top;
}

.d-parser-checks-table .row-positive {
  background: #f0fdf4;
}

.d-preview-cell {
  max-width: 360px;
  white-space: normal;
  line-height: 1.35;
}

.badge.success {
  background: #dcfce7;
  color: #166534;
}

/* Patch 48: parser statistics */
.d-period-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.d-period-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: #334155;
  text-decoration: none;
  font-size: 13px;
  font-weight: 800;
}

.d-period-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.d-stats-columns {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.d-mini-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 900;
  color: #0f172a;
}

@media (max-width: 1200px) {
  .d-stats-columns {
    grid-template-columns: 1fr;
  }
}

/* Patch 49: cleaner seller detail diagnostics/statistics/events */
.d-stats-groups {
  display: grid;
  gap: 18px;
}

.d-stats-group {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}

.d-stats-group h3 {
  margin: 0 0 12px;
  font-size: 17px;
  font-weight: 900;
  color: #0f172a;
}

.d-kpi-grid-compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.d-kpi-word {
  font-size: 20px;
  line-height: 1.15;
}

.d-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.d-page-state {
  color: #64748b;
  font-weight: 800;
}

.d-check-list {
  display: grid;
  gap: 12px;
}

.d-check-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}

.d-check-card.is-positive {
  border-color: #86efac;
  background: #f0fdf4;
}

.d-check-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.d-check-title {
  font-weight: 900;
  font-size: 16px;
  color: #0f172a;
}

.d-check-score {
  min-width: 92px;
  text-align: right;
  font-weight: 900;
  color: #0f172a;
}

.d-check-score span {
  font-size: 12px;
  color: #64748b;
}

.d-check-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.d-check-grid > div {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: rgba(248, 250, 252, .75);
  min-height: 58px;
  overflow-wrap: anywhere;
}

.d-check-text {
  border-left: 3px solid var(--accent);
  padding: 8px 10px;
  background: #f8fafc;
  border-radius: 8px;
  line-height: 1.4;
}

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

@media (max-width: 700px) {
  .d-kpi-grid-compact,
  .d-check-grid {
    grid-template-columns: 1fr;
  }
  .d-check-head {
    flex-direction: column;
  }
  .d-check-score {
    text-align: left;
  }
}
