:root {
  --ink: #171a20;
  --ink-soft: #5f6773;
  --line: #dfe3e8;
  --line-strong: #c7cdd4;
  --surface: #ffffff;
  --surface-soft: #f5f7f8;
  --surface-muted: #edf0f2;
  --sidebar: #151b23;
  --sidebar-hover: #202936;
  --emerald: #087f5b;
  --emerald-dark: #066348;
  --emerald-soft: #e6f4ef;
  --amber: #b86709;
  --amber-soft: #fff3df;
  --red: #c43838;
  --red-soft: #fdeaea;
  --blue: #2368b5;
  --blue-soft: #e9f2fc;
  --shadow: 0 10px 28px rgba(18, 24, 32, 0.08);
  --radius: 6px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--surface-soft);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { min-width: 320px; background: var(--surface-soft); }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.hidden { display: none !important; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, #151b23 0, #151b23 34%, #f5f7f8 34%, #f5f7f8 100%);
}
.login-panel {
  width: min(840px, 100%);
  min-height: 520px;
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 22px 60px rgba(12, 17, 23, 0.18);
}
.brand {
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
}
.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: var(--radius);
  color: #062c22;
  background: #56d6ae;
}
.brand-mark svg { width: 22px; height: 22px; }
.brand div { display: flex; flex-direction: column; line-height: 1.1; }
.brand strong { font-size: 18px; }
.brand span:last-child { margin-top: 4px; font-size: 11px; color: #9da8b5; text-transform: uppercase; }
.brand-login {
  min-height: 100%;
  padding: 38px;
  align-items: flex-start;
  background: var(--sidebar);
}
.brand-login .brand-mark { margin-top: 2px; }
.brand-login div { padding-top: 5px; }
.login-form {
  width: min(380px, 100%);
  align-self: center;
  justify-self: center;
  display: grid;
  gap: 18px;
  padding: 48px 32px;
}
.login-heading { margin-bottom: 12px; }
.login-heading h1 { margin: 0 0 8px; font-size: 26px; font-weight: 700; }
.login-heading p { margin: 0; color: var(--ink-soft); font-size: 14px; }
label { display: grid; gap: 7px; color: #424a55; font-size: 13px; font-weight: 600; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  outline: none;
  color: var(--ink);
  background: var(--surface);
  transition: border-color 120ms, box-shadow 120ms;
}
input, select { min-height: 40px; padding: 0 11px; }
textarea { min-height: 100px; padding: 10px 11px; resize: vertical; }
input:focus, textarea:focus, select:focus {
  border-color: var(--emerald);
  box-shadow: 0 0 0 3px rgba(8, 127, 91, 0.11);
}
.password-field { position: relative; display: block; }
.password-field input { padding-right: 45px; }
.input-action { position: absolute; top: 3px; right: 3px; }
.form-error { min-height: 18px; margin: -3px 0 0; color: var(--red); font-size: 13px; }

.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 650;
  font-size: 13px;
  white-space: nowrap;
}
.button svg { width: 17px; height: 17px; }
.button-primary { color: #fff; background: var(--emerald); }
.button-primary:hover { background: var(--emerald-dark); }
.button-secondary { border-color: var(--line-strong); color: var(--ink); background: var(--surface); }
.button-secondary:hover { background: var(--surface-soft); }
.button-danger { color: #fff; background: var(--red); }
.button-danger:hover { background: #9e2c2c; }
.button-warning { color: #6b3800; background: var(--amber-soft); border-color: #efca95; }
.button-quiet { color: var(--ink-soft); background: transparent; }
.button:disabled { opacity: .48; cursor: not-allowed; }
.login-submit { margin-top: 2px; }
.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  color: inherit;
  background: transparent;
}
.icon-button:hover { background: var(--surface-muted); }
.icon-button svg { width: 19px; height: 19px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 236px minmax(0, 1fr); }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 236px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  padding: 0 14px 14px;
  color: #dbe2e9;
  background: var(--sidebar);
}
.sidebar > .brand { padding: 8px 8px 2px; }
.main-nav { display: grid; gap: 4px; margin-top: 22px; }
.nav-item {
  min-height: 42px;
  width: 100%;
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 0 11px;
  border: 0;
  border-radius: var(--radius);
  color: #aeb8c4;
  background: transparent;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
}
.nav-item:hover { color: #fff; background: var(--sidebar-hover); }
.nav-item.active { color: #fff; background: #263142; }
.nav-item.active::before {
  content: "";
  position: absolute;
  width: 3px;
  height: 22px;
  margin-left: -11px;
  border-radius: 2px;
  background: #56d6ae;
}
.nav-item svg { width: 18px; height: 18px; }
.nav-count {
  min-width: 22px;
  padding: 2px 6px;
  border-radius: 10px;
  color: #c4ced8;
  background: #333e4d;
  font-size: 11px;
  text-align: center;
}
.sidebar-footer {
  margin-top: auto;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 8px 0;
  border-top: 1px solid #2a3441;
}
.bot-connection { display: flex; align-items: center; gap: 9px; }
.bot-connection div { display: grid; gap: 2px; }
.bot-connection strong { color: #e8edf2; font-size: 12px; }
.bot-connection span:last-child { color: #7e8b99; font-size: 11px; }
.sidebar-footer .icon-button:hover { background: var(--sidebar-hover); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #8a929c; }
.status-dot.online { background: #37c99a; box-shadow: 0 0 0 3px rgba(55, 201, 154, .14); }
.status-dot.offline { background: #ef6a6a; box-shadow: 0 0 0 3px rgba(239, 106, 106, .14); }
.workspace { min-width: 0; grid-column: 2; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 70px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .95);
}
.page-title { min-width: 0; }
.page-title span { display: block; margin-bottom: 2px; color: var(--ink-soft); font-size: 10px; text-transform: uppercase; font-weight: 700; }
.page-title h1 { margin: 0; overflow: hidden; text-overflow: ellipsis; font-size: 20px; line-height: 1.2; white-space: nowrap; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 7px; }
.last-update { margin-right: 5px; color: var(--ink-soft); font-size: 11px; }
.user-chip {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border-left: 1px solid var(--line);
  color: #3d4651;
  font-size: 12px;
  font-weight: 650;
}
.user-chip svg { width: 17px; height: 17px; }
.main-content { width: 100%; max-width: 1520px; margin: 0 auto; padding: 24px 28px 52px; outline: none; }
.mobile-only { display: none; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}
.section-head h2 { margin: 0; font-size: 16px; }
.section-head p { margin: 5px 0 0; color: var(--ink-soft); font-size: 12px; }
.section-actions { display: flex; align-items: center; gap: 8px; }
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.metric-card {
  min-height: 112px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-content: space-between;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.metric-card .metric-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: var(--emerald);
  background: var(--emerald-soft);
}
.metric-card .metric-icon.amber { color: var(--amber); background: var(--amber-soft); }
.metric-card .metric-icon.red { color: var(--red); background: var(--red-soft); }
.metric-card .metric-icon.blue { color: var(--blue); background: var(--blue-soft); }
.metric-card .metric-icon svg { width: 18px; height: 18px; }
.metric-value { align-self: end; font-size: 25px; font-weight: 720; line-height: 1; }
.metric-label { grid-column: 1 / -1; color: var(--ink-soft); font-size: 11px; font-weight: 650; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, .75fr); gap: 18px; }
.dashboard-grid > *, .detail-grid > * { min-width: 0; }
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.panel-head {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}
.panel-head h2, .panel-head h3 { margin: 0; font-size: 14px; }
.panel-body { padding: 16px; }

.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; table-layout: auto; }
.data-table th {
  height: 38px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 750;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.data-table td {
  min-height: 50px;
  padding: 11px 12px;
  border-bottom: 1px solid #ebedf0;
  color: #353c46;
  font-size: 12px;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: 0; }
.data-table tbody tr.clickable:hover { background: #f7faf9; cursor: pointer; }
.cell-main { display: grid; gap: 3px; min-width: 150px; }
.cell-main strong { overflow-wrap: anywhere; color: var(--ink); font-size: 12px; }
.cell-main span { color: var(--ink-soft); font-size: 10px; }
.cell-actions { width: 42px; text-align: right !important; }
.cell-actions svg { width: 16px; height: 16px; color: var(--ink-soft); }
.badge {
  min-height: 23px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.success { color: #087452; background: var(--emerald-soft); border-color: #b9dfd2; }
.badge.warning { color: #965409; background: var(--amber-soft); border-color: #efd2aa; }
.badge.danger { color: #a93030; background: var(--red-soft); border-color: #efc0c0; }
.badge.info { color: #205b9d; background: var(--blue-soft); border-color: #bed6ef; }
.badge.neutral { color: #59616c; background: var(--surface-muted); border-color: var(--line); }
.empty-state { min-height: 180px; display: grid; place-items: center; padding: 30px; color: var(--ink-soft); text-align: center; }
.empty-state svg { width: 28px; height: 28px; margin-bottom: 8px; }

.distribution { display: grid; gap: 17px; }
.distribution-row { display: grid; gap: 7px; }
.distribution-label { display: flex; justify-content: space-between; color: #424a54; font-size: 11px; }
.distribution-label strong { color: var(--ink); }
.progress { width: 100%; height: 7px; overflow: hidden; border: 0; border-radius: 4px; appearance: none; background: var(--surface-muted); }
.progress::-webkit-progress-bar { border-radius: 4px; background: var(--surface-muted); }
.progress::-webkit-progress-value { border-radius: 4px; background: var(--emerald); }
.progress::-moz-progress-bar { border-radius: 4px; background: var(--emerald); }
.progress.amber::-webkit-progress-value { background: #d78a2f; }
.progress.amber::-moz-progress-bar { background: #d78a2f; }
.progress.red::-webkit-progress-value { background: #d65757; }
.progress.red::-moz-progress-bar { background: #d65757; }
.progress.neutral-progress::-webkit-progress-value { background: #7b8794; }
.progress.neutral-progress::-moz-progress-bar { background: #7b8794; }
.connection-strip {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 11px;
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}
.connection-strip svg { color: var(--emerald); }
.connection-strip div { display: grid; gap: 2px; }
.connection-strip strong { font-size: 12px; }
.connection-strip span { color: var(--ink-soft); font-size: 10px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.search-box { position: relative; flex: 1; max-width: 420px; }
.search-box svg { position: absolute; top: 10px; left: 11px; width: 17px; height: 17px; color: #7a838e; pointer-events: none; }
.search-box input { padding-left: 37px; }
.filter-select { width: 170px; }

.detail-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}
.back-button { flex: 0 0 auto; }
.detail-identity { min-width: 0; flex: 1; }
.detail-identity h2 { margin: 0 0 5px; overflow-wrap: anywhere; font-size: 20px; }
.detail-identity p { margin: 0; color: var(--ink-soft); font-size: 11px; overflow-wrap: anywhere; }
.detail-actions { display: flex; gap: 8px; }
.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  margin-bottom: 18px;
  padding-bottom: 1px;
  border-bottom: 1px solid var(--line);
}
.tab {
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--ink-soft);
  background: transparent;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}
.tab.active { color: var(--emerald); border-bottom-color: var(--emerald); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.info-list { display: grid; gap: 0; }
.info-row {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid #ebedf0;
  font-size: 12px;
}
.info-row:last-child { border-bottom: 0; }
.info-row span { color: var(--ink-soft); }
.info-row strong { text-align: right; overflow-wrap: anywhere; }
.quick-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

.settings-section { margin-bottom: 24px; }
.settings-section > header { margin-bottom: 10px; }
.settings-section h3 { margin: 0 0 4px; font-size: 14px; }
.settings-section p { margin: 0; color: var(--ink-soft); font-size: 11px; }
.settings-list { border-top: 1px solid var(--line); }
.setting-row {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
}
.setting-copy { min-width: 0; }
.setting-copy strong { display: block; margin-bottom: 3px; font-size: 12px; }
.setting-copy span { display: block; color: var(--ink-soft); font-size: 10px; }
.switch { position: relative; width: 42px; height: 24px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span { display: block; width: 100%; height: 100%; border-radius: 12px; background: #bec5cc; transition: 150ms; }
.switch span::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.22);
  transition: 150ms;
}
.switch input:checked + span { background: var(--emerald); }
.switch input:checked + span::after { transform: translateX(18px); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.section-gap { margin-top: 18px; }
.rules-copy { margin: 0; white-space: pre-wrap; font-size: 12px; line-height: 1.65; }
.panel-actions { display: flex; gap: 8px; padding-top: 0; }
.panel-actions-wrap { flex-wrap: wrap; }
.plan-box { border: 1px solid var(--line); border-radius: var(--radius); }
.plan-heading { margin-bottom: 12px; }
.danger-zone { margin-top: 28px; border-top: 1px solid #e8baba; padding-top: 18px; }
.danger-zone h3 { color: var(--red); }
.danger-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.timeline { display: grid; }
.timeline-item {
  position: relative;
  display: grid;
  grid-template-columns: 27px 1fr auto;
  gap: 10px;
  min-height: 54px;
  padding: 8px 0;
}
.timeline-icon {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--blue);
  background: var(--blue-soft);
}
.timeline-icon svg { width: 14px; height: 14px; }
.timeline-copy { display: grid; align-content: start; gap: 3px; min-width: 0; }
.timeline-copy strong { font-size: 11px; overflow-wrap: anywhere; }
.timeline-copy span { color: var(--ink-soft); font-size: 10px; overflow-wrap: anywhere; }
.timeline-time { color: var(--ink-soft); font-size: 9px; white-space: nowrap; }

.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 12, 17, .58); }
.modal-dialog {
  position: relative;
  width: min(560px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.modal-dialog > header {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-dialog > header span { display: block; margin-bottom: 3px; color: var(--ink-soft); font-size: 9px; text-transform: uppercase; font-weight: 700; }
.modal-dialog > header h2 { margin: 0; font-size: 17px; }
.modal-body { overflow-y: auto; padding: 18px; }
.modal-dialog > footer {
  min-height: 62px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  padding: 11px 18px;
  border-top: 1px solid var(--line);
}
.toast-region { position: fixed; z-index: 150; right: 18px; bottom: 18px; display: grid; gap: 8px; }
.toast {
  width: min(360px, calc(100vw - 36px));
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--emerald);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 12px;
  animation: toast-in 180ms ease-out;
}
.toast.error { border-left-color: var(--red); }
.toast svg { width: 18px; height: 18px; color: var(--emerald); }
.toast.error svg { color: var(--red); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
.skeleton {
  min-height: 14px;
  border-radius: 3px;
  background: linear-gradient(90deg, #eef0f2, #f7f8f9, #eef0f2);
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
}
.skeleton-tall { height: 260px; }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 1180px) {
  .metrics-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 860px) {
  .app-shell { display: block; }
  .workspace { margin-left: 0; }
  .sidebar { transform: translateX(-100%); transition: transform 180ms ease; box-shadow: 16px 0 40px rgba(8, 12, 17, .22); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 25; display: none; background: rgba(8, 12, 17, .4); }
  .sidebar-backdrop.open { display: block; }
  .mobile-only { display: inline-grid; }
  .topbar { padding: 10px 16px; }
  .main-content { padding: 20px 16px 44px; }
  .dashboard-grid, .detail-grid { grid-template-columns: 1fr; }
  .last-update, .user-chip { display: none; }
}
@media (max-width: 640px) {
  .login-view { padding: 0; background: var(--surface); }
  .login-panel { min-height: 100vh; display: block; border: 0; box-shadow: none; }
  .brand-login { min-height: 108px; padding: 25px 24px; }
  .login-form { padding: 38px 24px; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .metric-card { min-height: 100px; padding: 13px; }
  .metric-value { font-size: 22px; }
  .section-head, .detail-header { align-items: flex-start; }
  .section-head { flex-direction: column; }
  .detail-header { flex-wrap: wrap; }
  .detail-actions { width: 100%; overflow-x: auto; }
  .toolbar { align-items: stretch; flex-wrap: wrap; }
  .search-box { max-width: none; width: 100%; flex-basis: 100%; }
  .filter-select { flex: 1; min-width: 120px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .quick-actions { grid-template-columns: 1fr; }
  .modal { padding: 0; align-items: end; }
  .modal-dialog { width: 100%; max-height: 92vh; border-radius: var(--radius) var(--radius) 0 0; }
}
@media (max-width: 390px) {
  .topbar-actions { gap: 2px; }
  .page-title h1 { font-size: 17px; }
}
