:root {
  --app-sidebar-width: clamp(188px, calc(180px + 1.1vw), 220px);
  --ag-green: #367c2b;
  --ag-green-dk: #2a611f;
  --ag-surface: #ffffff;
  --ag-surface-2: #f8f9f8;
  --ag-surface-3: #f3f6f3;
  --ag-text: #1f2a23;
  --ag-text-muted: #5b675f;
  --ag-border: #d6ddd5;
  --ag-border-strong: #c5cec3;
  --shell-bg: #eef2ee;
  --shell-main-surface: #f8f9f8;
  --shell-main-surface-strong: #ffffff;
  --shell-card-soft: #f3f6f3;
  --shell-border: #d6ddd5;
  --shell-border-strong: #c5cec3;
  --shell-text: #1f2a23;
  --shell-text-muted: #5b675f;
  --shell-title: #162119;
  --shell-primary: #367c2b;
  --shell-primary-strong: #2a611f;
  --shell-primary-soft: rgba(54, 124, 43, 0.2);
  --shell-shadow: 0 10px 28px rgba(14, 20, 14, 0.14);
  --shell-sidebar-bg: #2b2b2b;
  --shell-sidebar-accent: #367c2b;
  --shell-sidebar-text: #ffffff;
  --shell-sidebar-muted: rgba(255, 255, 255, 0.84);
  --shell-sidebar-hover: rgba(54, 124, 43, 0.24);
  --shell-sidebar-active: rgba(54, 124, 43, 0.34);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-size: clamp(12.5px, calc(11px + 0.18vw), 15px);
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--shell-bg);
  color: var(--shell-text);
  line-height: 1.5;
}
body { min-height: 100vh; }
.hidden { display: none !important; }
.screen { min-height: 100vh; }
.centered { display: flex; align-items: center; justify-content: center; padding: 24px; }
.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ag-text-muted);
  font-weight: 700;
}
h1, h2, h3 { margin: 0; color: var(--shell-title); font-family: 'Segoe UI', sans-serif; }
p { margin: 0; }
.muted { color: var(--shell-text-muted); }
.small { font-size: 12px; }
.error { color: #a52121; font-size: 13px; min-height: 18px; }
.sticky-error { margin-top: 6px; }

.login-card, .card {
  background: var(--shell-main-surface-strong);
  border: 1px solid var(--shell-border);
  border-radius: 16px;
  box-shadow: var(--shell-shadow);
}
.login-card { width: 100%; max-width: 420px; padding: 24px; display: grid; gap: 12px; }
.login-brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--shell-primary-soft);
  border: 2px solid var(--shell-primary);
  color: var(--shell-primary-strong);
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; color: #364039; }
input, textarea, select, button { font: inherit; }
input, textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--shell-border-strong);
  border-radius: 10px;
  background: #fff;
  color: var(--shell-text);
}
textarea { resize: vertical; min-height: 92px; }
.portal-textarea-code { min-height: 180px; font-family: Consolas, monospace; font-size: 12px; }

.abm-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.5rem;
  padding: 0 0.85rem;
  font-size: 0.8rem;
  font-weight: 700;
  border-radius: 0.625rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}
.abm-btn-primary { background-color: var(--shell-primary); color: #fff; border-color: var(--shell-primary-strong); }
.abm-btn-primary:hover { background-color: var(--shell-primary-strong); }
.abm-btn-secondary { background-color: var(--shell-card-soft); color: var(--shell-text); border-color: var(--shell-border-strong); }
.abm-btn-secondary:hover { border-color: var(--shell-primary); }
.abm-btn-icon { font-size: 0.95rem; line-height: 1; }
.abm-filter-input { min-height: 2.45rem; }

.appshell-container {
  min-height: 100vh;
  width: 100%;
  margin: 0;
  padding: 0;
  background: var(--shell-bg);
}
.appshell-platform { min-height: 100vh; background: var(--shell-main-surface); }
.appshell-sidebar {
  width: var(--app-sidebar-width);
  min-width: var(--app-sidebar-width);
  max-width: var(--app-sidebar-width);
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  background: var(--shell-sidebar-bg);
  color: var(--shell-sidebar-text);
  border-right: 3px solid var(--shell-sidebar-accent);
  border-radius: 0 12px 12px 0;
  box-shadow: 5px 0 10px rgba(0,0,0,0.22);
}
.appshell-brand {
  padding: 12px 8px 12px;
  border-bottom: 3px solid var(--shell-sidebar-accent);
  display: grid;
  justify-items: center;
  gap: 6px;
}
.appshell-brand h2 { margin: 4px 0 0; color: var(--shell-sidebar-text); font-size: 1.05rem; line-height: 1.15; }
.appshell-brand-logo {
  width: 44px; height: 44px; border-radius: 999px; border: 2px solid var(--shell-primary);
  display: inline-flex; align-items: center; justify-content: center; font-size: .82rem; font-weight: 800;
  color: var(--shell-sidebar-text); background: var(--shell-primary-soft);
}
.appshell-brand-subtitle { margin: 0; font-size: .76rem; text-transform: uppercase; letter-spacing: .08em; color: var(--shell-sidebar-muted); }
.appshell-nav { margin-top: 16px; display: grid; gap: 4px; flex: 1; align-content: start; overflow-y: auto; }
.appshell-link {
  display: flex; align-items: center; gap: 8px; text-align: left; border: 0; border-left: 3px solid transparent;
  background: transparent; border-radius: 6px; color: var(--shell-sidebar-muted); padding: 7px 12px;
  font-size: .76rem; font-weight: 500; cursor: pointer;
}
.appshell-link:hover { background: var(--shell-sidebar-hover); color: var(--shell-sidebar-text); }
.appshell-link.active { border-left-color: var(--shell-primary); background: var(--shell-sidebar-active); color: var(--shell-sidebar-text); font-weight: 700; }
.appshell-link-icon {
  width: 26px; min-width: 26px; height: 20px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 700; color: var(--shell-sidebar-muted); background: rgba(255,255,255,.08);
}
.appshell-sidebar-footer { display: grid; gap: 10px; padding: 10px 6px 0; border-top: 1px solid rgba(255,255,255,.12); }
.appshell-logout-btn { width: 100%; }

.appshell-main {
  margin-left: var(--app-sidebar-width);
  min-height: 100vh;
  padding: 18px;
  display: grid;
  gap: 16px;
}

.portal-header-shell {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  padding: 18px 20px; border: 1px solid var(--shell-border); border-radius: 16px;
  background: var(--shell-main-surface-strong); box-shadow: 0 8px 22px rgba(18,24,17,.06);
}
.portal-header-copy { display: grid; gap: 4px; }
.portal-header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.summary-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.summary-item {
  background: var(--shell-main-surface-strong); border: 1px solid var(--shell-border); border-radius: 14px; padding: 14px 16px;
  box-shadow: 0 8px 22px rgba(18,24,17,.05);
}
.summary-item strong { display: block; margin-top: 6px; font-size: 1.55rem; color: var(--shell-title); }

.abm-toolbar {
  display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; padding: 0.75rem;
  border: 1px solid var(--shell-border); background: var(--shell-main-surface-strong); border-radius: 0.75rem;
}
.portal-toolbar { justify-content: space-between; flex-wrap: wrap; }
.portal-search-field { min-width: min(520px, 100%); position: relative; display: flex; align-items: center; }
.portal-search-field input { padding-left: 36px; }
.portal-search-icon { position: absolute; left: 12px; color: var(--shell-text-muted); font-size: 14px; }
.portal-toolbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.compact-select { min-width: 190px; }

.portal-two-pane { display: grid; grid-template-columns: 1fr; gap: 16px; }
.abm-table-container { border: 1px solid var(--shell-border); border-radius: 0.5rem; overflow: hidden; background: #fff; }
.abm-table-container.abm-table-scrollable { overflow: hidden; max-width: 100%; min-width: 0; }
.abm-table-wrapper { overflow-x: auto; overflow-y: auto; width: 100%; max-width: 100%; min-width: 0; max-height: 72vh; position: relative; }
.abm-table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 880px; }
.abm-table th, .abm-table td { padding: 10px 12px; border-bottom: 1px solid #edf1ed; vertical-align: top; text-align: left; }
.abm-table thead th { position: sticky; top: 0; z-index: 3; background: #f8faf8; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--shell-text-muted); }
.abm-table tbody tr { cursor: pointer; }
.abm-table tbody tr:hover { background: #f7faf7; }
.abm-col-actions { position: sticky; left: 0; z-index: 4 !important; background: #f8faf8; width: 120px; min-width: 120px; }
.abm-actions-cell { position: sticky; left: 0; z-index: 2; background: #fff; }
.abm-icon-btn {
  width: 32px; height: 32px; border-radius: 10px; border: 1px solid var(--shell-border-strong); background: #fff; cursor: pointer;
}
.abm-icon-btn-edit { color: var(--shell-primary-strong); }
.abm-icon-btn-delete { color: #a52121; }

.portal-side-panel { padding: 16px; min-height: 420px; }
.detail-card { overflow: auto; }
.portal-empty-state { padding: 6px 0; }
.portal-results-bar,
.portal-pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--shell-text-muted);
  font-size: 0.82rem;
}
.portal-pagination-bar {
  margin-top: 10px;
  justify-content: flex-end;
}
.portal-th-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 0;
  margin: 0 0 8px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
}
.portal-template-modal {
  max-width: 880px;
}
.portal-docs-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.portal-doc-card {
  padding: 18px 20px;
  display: grid;
  gap: 10px;
}
.portal-doc-span {
  grid-column: 1 / -1;
}
.portal-doc-list {
  margin: 0;
  padding-left: 18px;
  color: var(--shell-text);
}
.portal-doc-list li + li {
  margin-top: 6px;
}
.portal-doc-code {
  margin: 0;
  padding: 14px 16px;
  background: #f6f8f6;
  border: 1px solid var(--shell-border);
  border-radius: 12px;
  overflow-x: auto;
}
.badge { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.sent { background: #e8f4e5; color: #1f6b16; }
.badge.dead { background: #fdeaea; color: #9d1d1d; }
.badge.retry_wait, .badge.processing, .badge.queued { background: #fff4dd; color: #8a5a00; }
.portal-detail-grid { display: grid; gap: 8px; margin-bottom: 16px; }
.portal-detail-grid strong { color: var(--shell-title); }
.portal-detail-block { margin-top: 16px; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: Consolas, monospace; font-size: 12px; color: #243128; }

.portal-form-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.portal-form-span { grid-column: 1 / -1; }
.checkbox-field { display: flex; align-items: center; gap: 8px; padding-top: 28px; font-weight: 700; }
.checkbox-field input { width: 16px; height: 16px; }
.portal-row-actions { display: flex; gap: 8px; align-items: center; }
.row-active-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; }
.row-active-chip::before { content: ''; width: 8px; height: 8px; border-radius: 999px; background: #b4232c; }
.row-active-chip.active::before { background: var(--shell-primary); }

.abm-modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}
.abm-modal {
  background: #fff;
  border-radius: 0.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.abm-modal-header,
.abm-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e5e5e5;
}
.abm-modal-footer {
  border-bottom: 0;
  border-top: 1px solid #e5e5e5;
  justify-content: flex-end;
}
.abm-modal-body { padding: 1.25rem; }
.abm-modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: #666;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
}
.abm-modal-close:hover { background: #f5f5f5; color: #333; }

@media (max-width: 1100px) {
  .appshell-main { margin-left: 0; padding: 14px; }
  .appshell-sidebar { position: static; width: 100%; min-width: 0; max-width: none; height: auto; border-radius: 0; }
  .appshell-platform { display: grid; }
  .portal-form-grid { grid-template-columns: 1fr; }
  .checkbox-field { padding-top: 0; }
  .portal-results-bar,
  .portal-pagination-bar { flex-direction: column; align-items: flex-start; }
  .portal-docs-grid { grid-template-columns: 1fr; }
}
