:root {
  --ink: #17201e;
  --muted: #687572;
  --surface: #ffffff;
  --canvas: #f3f5f1;
  --line: #dfe5df;
  --teal: #146c60;
  --teal-dark: #0b4d45;
  --teal-soft: #e5f3ef;
  --amber: #a9660b;
  --amber-soft: #fff2d8;
  --red: #a63d42;
  --red-soft: #fce9ea;
  --sidebar: #142724;
  --sidebar-muted: #a8bbb6;
  --shadow: 0 18px 45px rgba(31, 54, 48, .08);
  font-family: Tahoma, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--canvas); color: var(--ink); font-size: 14px; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow {
  margin: 0 0 6px;
  color: var(--teal);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 10% 10%, rgba(38, 137, 119, .17), transparent 30%),
    radial-gradient(circle at 90% 80%, rgba(179, 128, 52, .12), transparent 35%),
    #edf1eb;
}
.login-card {
  width: min(430px, 100%);
  padding: 42px;
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 24px;
  background: rgba(255,255,255,.92);
  box-shadow: 0 28px 80px rgba(23, 55, 48, .14);
  text-align: center;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  margin: 0 auto 20px;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(145deg, #198172, #0c5148);
  box-shadow: 0 12px 25px rgba(20, 108, 96, .26);
  font: 700 28px Georgia, serif;
}
.brand-mark.small {
  width: 38px;
  height: 38px;
  margin: 0;
  border-radius: 11px;
  font-size: 19px;
  box-shadow: none;
}
.login-card h1 { margin: 0; font-size: 26px; }
.login-card .muted { margin: 12px 0 28px; }
.login-card form { text-align: right; }
.login-footnote { margin: 22px 0 0; color: #89938f; font-size: 12px; }
.field-error { min-height: 20px; margin: 6px 0; color: var(--red); font-size: 12px; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: 254px;
  padding: 24px 18px;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(255,255,255,.025), transparent 35%),
    var(--sidebar);
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 28px;
  border-bottom: 1px solid rgba(255,255,255,.09);
}
.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand strong { font-size: 16px; }
.sidebar-brand span { margin-top: 3px; color: var(--sidebar-muted); font-size: 11px; }
nav { display: grid; gap: 7px; padding-top: 26px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 13px;
  border: 0;
  border-radius: 11px;
  color: var(--sidebar-muted);
  background: transparent;
  text-align: right;
  transition: .18s ease;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: rgba(55, 171, 151, .18); }
.nav-icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: rgba(255,255,255,.07);
  font-weight: 700;
}
.nav-item.active .nav-icon { background: var(--teal); }
.sidebar-footer {
  display: flex;
  align-items: center;
  margin-top: auto;
  padding: 18px 8px 2px;
  border-top: 1px solid rgba(255,255,255,.09);
  color: var(--sidebar-muted);
  font-size: 11px;
}
.link-button {
  margin-right: auto;
  padding: 0;
  border: 0;
  color: #fff;
  background: transparent;
}

.workspace { margin-right: 254px; min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 82px;
  padding: 16px 38px;
  border-bottom: 1px solid rgba(210,219,213,.9);
  background: rgba(243,245,241,.88);
  backdrop-filter: blur(13px);
}
.topbar h2 { margin: 0; font-size: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 9px; margin-right: auto; }
.content { max-width: 1500px; margin: 0 auto; padding: 34px 38px 60px; }
.page-section { display: none; }
.page-section.active { display: block; animation: fade-in .2s ease; }
@keyframes fade-in { from { opacity: .45; transform: translateY(4px); } }
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}
.section-heading h3 { margin: 0; font-size: 21px; }
.section-heading p { margin: 7px 0 0; color: var(--muted); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 16px;
  margin-bottom: 18px;
}
.stat-card, .panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.stat-card { position: relative; overflow: hidden; padding: 21px; }
.stat-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--teal);
  opacity: .7;
}
.stat-label { display: block; color: var(--muted); font-size: 12px; }
.stat-value { display: block; margin-top: 11px; font-size: 29px; font-weight: 700; }
.stat-note { display: block; margin-top: 4px; color: #8b9692; font-size: 11px; }
.panel { padding: 23px; }
.two-column { display: grid; grid-template-columns: 1.35fr 1fr; gap: 18px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.panel-heading h3 { margin: 0; font-size: 18px; }
.panel-heading-actions { display: flex; align-items: center; gap: 8px; }
.details-list { margin: 22px 0; }
.details-list div {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 0;
  border-bottom: 1px solid #edf0ed;
}
.details-list dt { color: var(--muted); }
.details-list dd { margin: 0; direction: ltr; text-align: left; overflow-wrap: anywhere; }

.button {
  padding: 10px 15px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-weight: 600;
  transition: .15s ease;
}
.button:disabled { cursor: not-allowed; opacity: .5; }
.button.primary { color: #fff; background: var(--teal); }
.button.primary:hover { background: var(--teal-dark); }
.button.secondary { border-color: var(--line); color: var(--ink); background: #fff; }
.button.secondary:hover { border-color: #b9c6c0; background: #f8faf8; }
.button.danger { border-color: #efc8ca; color: var(--red); background: var(--red-soft); }
.button.small { padding: 7px 10px; font-size: 12px; }
.button.wide { width: 100%; }
.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
}

label { display: block; margin-bottom: 7px; font-weight: 600; }
input, textarea, select {
  width: 100%;
  border: 1px solid #cfd8d3;
  border-radius: 9px;
  outline: none;
  color: var(--ink);
  background: #fff;
}
input, select { height: 43px; padding: 0 12px; }
textarea { padding: 12px; line-height: 1.8; resize: vertical; }
input:focus, textarea:focus, select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(20,108,96,.1);
}
.form-row { margin-bottom: 18px; }
.form-row small { display: block; margin-top: 7px; color: var(--muted); }
.form-split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.settings-panel { max-width: 720px; }
.notice {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 6px 0 22px;
  padding: 14px 16px;
  border-right: 3px solid var(--teal);
  border-radius: 8px;
  color: var(--muted);
  background: var(--teal-soft);
}
.notice strong { color: var(--teal-dark); }
.instruction-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.editor-panel { min-width: 0; }
.code-editor {
  min-height: 560px;
  margin-top: 18px;
  direction: ltr;
  text-align: left;
  white-space: pre;
  tab-size: 2;
  font: 13px/1.75 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.editor-help { margin: 10px 0 0; color: var(--muted); font-size: 11px; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.search-box { position: relative; flex: 1; margin: 0; }
.search-box span { position: absolute; top: 11px; right: 12px; color: var(--muted); }
.search-box input { padding-right: 35px; }
.toolbar-count { margin-right: auto; white-space: nowrap; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
.table-actions { display: flex; gap: 8px; flex-wrap: wrap; }
th, td { padding: 13px 12px; border-bottom: 1px solid #e8ece9; text-align: right; vertical-align: middle; }
th { color: var(--muted); background: #fafbfa; font-size: 11px; font-weight: 700; white-space: nowrap; }
td { max-width: 420px; }
.cell-question { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.badge.success { color: var(--teal-dark); background: var(--teal-soft); }
.badge.warning { color: var(--amber); background: var(--amber-soft); }
.badge.danger { color: var(--red); background: var(--red-soft); }
.badge.neutral { color: #66726f; background: #edf0ee; }
.pagination { display: flex; justify-content: center; gap: 8px; padding-top: 18px; }
.empty-state { padding: 32px !important; color: var(--muted); text-align: center; }
.monitoring-grid { margin-bottom: 18px; }
.monitor-list { display: grid; gap: 9px; }
.monitor-item {
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  overflow-wrap: anywhere;
}

.dialog {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  padding: 25px;
  border: 0;
  border-radius: 18px;
  box-shadow: 0 30px 100px rgba(8, 34, 29, .3);
}
.dialog::backdrop { background: rgba(8,25,22,.54); backdrop-filter: blur(3px); }
.wide-dialog { width: min(960px, calc(100vw - 32px)); }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 22px; }
.dialog-heading h3 { margin: 0; font-size: 20px; }
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
#detail-dialog {
  padding: 0;
  overflow: auto;
}
#detail-dialog .dialog-heading {
  position: sticky;
  top: 0;
  z-index: 3;
  margin: 0;
  padding: 22px 25px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-raised);
}
#detail-dialog #detail-content {
  padding: 10px 25px 0;
}
#detail-dialog .dialog-actions {
  position: sticky;
  bottom: 0;
  z-index: 3;
  margin-top: 22px;
  padding: 16px 25px 20px;
  background: var(--surface-raised);
  box-shadow: 0 -10px 24px color-mix(in srgb, var(--ink) 7%, transparent);
}
.faq-detail-card, .history-block {
  margin: 12px 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fafbfa;
}
.faq-detail-meta, .run-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 11px;
}
.detail-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.9; }
.detail-question { margin: 0 0 10px; font-weight: 700; }
.message {
  max-width: 82%;
  margin: 9px 0;
  padding: 10px 13px;
  border-radius: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message.inbound { margin-left: auto; background: #edf0ee; }
.message.outbound { margin-right: auto; color: #0b4d45; background: var(--teal-soft); }
.message time { display: block; margin-top: 5px; color: #7f8b87; font-size: 10px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 100;
  max-width: min(420px, calc(100vw - 48px));
  padding: 12px 16px;
  border-radius: 10px;
  color: #fff;
  background: var(--sidebar);
  box-shadow: 0 12px 35px rgba(0,0,0,.2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #813137; }
.busy {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #fff;
  background: rgba(11,35,31,.44);
  backdrop-filter: blur(2px);
}
.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.mobile-only { display: none; }

@media (max-width: 1080px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .instruction-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .sidebar { transform: translateX(100%); transition: .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .workspace { margin-right: 0; }
  .mobile-only { display: grid; }
  .topbar { padding: 13px 18px; }
  .content { padding: 24px 16px 50px; }
  .stat-grid, .two-column { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; }
  .panel { padding: 17px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar-count { width: 100%; }
  .form-split { grid-template-columns: 1fr; }
  .login-card { padding: 30px 23px; }
}
