:root {
  --sa-bg: #141820;
  --sa-sidebar: #10151d;
  --sa-panel: #191f29;
  --sa-panel-2: #202734;
  --sa-border: #303949;
  --sa-text: #eef2f7;
  --sa-muted: #94a0b1;
  --sa-accent: #20c8c0;
  --sa-blue: #2f7cf6;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--sa-bg) !important; color: var(--sa-text); letter-spacing: 0; }
.hidden { display: none !important; }

.sa-shell { min-height: 100vh; display: grid; grid-template-columns: 244px minmax(0, 1fr); }
.sa-sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; border-right: 1px solid var(--sa-border); background: var(--sa-sidebar); z-index: 20; }
.sa-brand { min-height: 76px; display: flex; align-items: center; gap: 11px; padding: 15px 20px; border-bottom: 1px solid var(--sa-border); color: var(--sa-text); }
.sa-brand:hover { color: var(--sa-text); }
.sa-brand img { width: 42px; height: 42px; object-fit: contain; }
.sa-brand span { min-width: 0; }
.sa-brand strong, .sa-brand small { display: block; }
.sa-brand strong { font-size: 17px; }
.sa-brand small { margin-top: 2px; color: var(--sa-muted); font-size: 11px; }

.sa-nav { padding: 18px 12px; display: grid; gap: 5px; }
.sa-nav button { min-height: 44px; display: flex; align-items: center; gap: 11px; width: 100%; padding: 10px 13px; border: 0; border-left: 3px solid transparent; border-radius: 5px; background: transparent; color: #aeb8c7; font: inherit; text-align: left; cursor: pointer; }
.sa-nav button:hover { background: #18212c; color: #fff; }
.sa-nav button.active { border-left-color: var(--sa-accent); background: #153039; color: #77eee7; }
.sa-nav i.icon { width: 19px; margin: 0 !important; }

.sa-sidebar-footer { margin-top: auto; padding: 12px; border-top: 1px solid var(--sa-border); }
.sa-back-link { min-height: 38px; display: flex; align-items: center; gap: 8px; padding: 8px 10px; color: #aab5c4; }
.sa-back-link:hover { color: #fff; }
.sa-user { min-height: 58px; display: grid; grid-template-columns: 36px minmax(0, 1fr) 32px; gap: 9px; align-items: center; margin-top: 7px; padding: 8px; border: 1px solid var(--sa-border); border-radius: 6px; background: #171d26; }
.sa-user img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.sa-user strong, .sa-user small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sa-user small { margin-top: 2px; color: var(--sa-muted); font-size: 10px; }
.sa-user button { width: 32px; height: 32px; border: 0; border-radius: 4px; background: transparent; color: #aab5c4; cursor: pointer; }
.sa-user button:hover { background: #2a3341; color: #fff; }

.sa-main { min-width: 0; padding: 26px clamp(22px, 4vw, 58px) 52px; }
.sa-topbar { min-height: 70px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding-bottom: 18px; border-bottom: 1px solid var(--sa-border); }
.sa-eyebrow { display: block; margin-bottom: 6px; color: var(--sa-accent); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.sa-topbar h1 { margin: 0; color: #fff; font-size: 26px; letter-spacing: 0; }
.sa-view { display: none; }
.sa-view.active { display: block; }
.sa-action-row { min-height: 90px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.sa-action-row h2 { margin: 0; color: #fff; font-size: 19px; letter-spacing: 0; }
.sa-action-row p { margin: 5px 0 0; color: var(--sa-muted); }

.sa-kpis { display: grid; grid-template-columns: repeat(5, minmax(130px, 1fr)); margin-bottom: 26px; border-top: 1px solid var(--sa-border); border-bottom: 1px solid var(--sa-border); }
.sa-kpis > div { position: relative; min-height: 116px; padding: 22px 18px; border-right: 1px solid var(--sa-border); }
.sa-kpis > div:last-child { border-right: 0; }
.sa-kpis i { position: absolute; top: 22px; right: 18px; color: #69778a; font-size: 20px; }
.sa-kpis span { display: block; color: #98a9bf; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.sa-kpis strong { display: block; margin-top: 11px; color: #fff; font-size: 30px; line-height: 1; }

.sa-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.sa-search { width: min(480px, 100%); }
.sa-toolbar .ui.input > input, .sa-toolbar select { min-height: 42px; border: 1px solid var(--sa-border) !important; border-radius: 5px !important; background: #11161e !important; color: var(--sa-text) !important; }
.sa-toolbar select { min-width: 170px; padding: 8px 10px; }
.sa-check { display: inline-flex; align-items: center; gap: 7px; color: #b7c1cf; cursor: pointer; white-space: nowrap; }
.sa-check input { accent-color: var(--sa-accent); }
.sa-user-filters { justify-content: flex-start; }
.sa-user-filters .sa-search { margin-right: auto; }
.sa-result-count { color: var(--sa-muted); font-size: 12px; }

.sa-table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--sa-border); border-radius: 5px; }
.ui.table.sa-table { min-width: 900px; margin: 0 !important; border: 0 !important; border-radius: 0 !important; background: transparent !important; color: var(--sa-text) !important; }
.ui.table.sa-table thead th { padding: 12px !important; border-color: var(--sa-border) !important; background: var(--sa-panel-2) !important; color: #60ddd5 !important; font-size: 11px; text-transform: uppercase; }
.ui.table.sa-table tbody td { padding: 12px !important; border-color: #29313e !important; background: #171c24 !important; color: #e8edf3 !important; vertical-align: middle; }
.ui.table.sa-table tbody tr:hover td { background: #1c232e !important; }
.sa-company-name, .sa-person-name { display: block; color: #fff; font-weight: 700; }
.sa-table-meta { display: block; margin-top: 3px; color: #8794a6; font-size: 11px; }
.sa-table-code { max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: monospace; }
.sa-usage { display: flex; flex-wrap: wrap; gap: 7px; }
.sa-usage span, .sa-channel { display: inline-flex; align-items: center; gap: 4px; padding: 4px 7px; border: 1px solid #3b485a; border-radius: 4px; color: #c8d2de; font-size: 11px; }
.sa-channels { display: flex; flex-wrap: wrap; gap: 5px; }
.sa-company-avatar, .sa-user-avatar { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto; border-radius: 50%; background: #2a4261; color: #dcecff; font-size: 11px; font-weight: 800; }
.sa-person-cell { display: flex; align-items: center; gap: 9px; }
.sa-role, .sa-status, .sa-test-badge { display: inline-flex; align-items: center; min-height: 23px; padding: 3px 7px; border-radius: 4px; font-size: 10px; font-weight: 700; text-transform: uppercase; }
.sa-role { border: 1px solid #4a5568; color: #cbd5e1; }
.sa-role.platform { border-color: #2a9a94; color: #77eee7; }
.sa-status.active { background: #184b2c; color: #8af0ad; }
.sa-status.suspended, .sa-status.inactive { background: #5a2730; color: #ffabb3; }
.sa-test-badge { margin-left: 6px; background: #5b431b; color: #ffd98c; }
.sa-confirmed { color: #78dda0; }
.sa-pending { color: #f4b75e; }
.sa-empty { padding: 34px !important; color: var(--sa-muted) !important; text-align: center; }
.sa-row-actions { display: inline-flex; align-items: center; gap: 5px; }
.sa-row-actions .ui.icon.button { width: 34px; height: 34px; margin: 0 !important; padding: 0 !important; }
.sa-row-actions .ui.button:disabled { cursor: not-allowed; opacity: 0.35 !important; }

.sa-form { max-width: 920px; padding-top: 12px; }
.sa-form label { color: #c5cfdb !important; }
.sa-form input, .sa-form select { border-color: var(--sa-border) !important; background: #11161e !important; color: #fff !important; }
.sa-inline-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.sa-meta-endpoints { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 16px 0 22px; }
.sa-endpoint { display: flex; align-items: center; gap: 12px; margin: 16px 0 22px; padding: 12px; border: 1px solid var(--sa-border); border-radius: 5px; background: #11161e; }
.sa-meta-endpoints .sa-endpoint { display: block; min-width: 0; margin: 0; }
.sa-endpoint-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 30px; }
.sa-endpoint-heading .button { flex: 0 0 auto; margin: 0 !important; }
.sa-endpoint-primary { border-color: rgba(31, 199, 190, .55); box-shadow: inset 3px 0 0 #1fc7be; }
.sa-endpoint-success { border-color: rgba(33, 186, 69, .45); box-shadow: inset 3px 0 0 #21ba45; }
.sa-endpoint span { color: var(--sa-muted); font-size: 11px; text-transform: uppercase; }
.sa-endpoint code { display: block; margin-top: 6px; color: #70e5df; overflow-wrap: anywhere; }
.sa-form-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sa-webhook-test { margin: -8px 0 16px; padding: 12px 14px; border: 1px solid var(--sa-border); border-radius: 5px; color: var(--sa-muted); background: #11161e; }
.sa-webhook-test.success { border-color: rgba(33, 186, 69, .55); color: #75df90; }
.sa-webhook-test.error { border-color: rgba(219, 40, 40, .65); color: #ff8b8b; }
.sa-meta-oauth-guide { margin: -8px 0 20px; padding: 14px 16px; border: 1px solid rgba(242, 192, 55, .48); border-radius: 5px; background: rgba(242, 192, 55, .07); }
.sa-meta-oauth-guide strong { color: #ffd978; }
.sa-meta-oauth-guide p { margin: 4px 0 10px; color: var(--sa-muted); }
.sa-meta-oauth-guide p.ready { color: #75df90; }
.sa-meta-oauth-guide p.incomplete { color: #ffb3b3; }
.sa-meta-oauth-guide ol { margin: 0 0 14px; padding-left: 22px; color: var(--sa-muted); }
.sa-meta-oauth-guide li + li { margin-top: 5px; }
.sa-meta-oauth-guide li code { color: #70e5df; }
.sa-toggle-row { display: flex; flex-wrap: wrap; gap: 24px; margin: 18px 0 24px; color: #d2dae4; }
.sa-toggle-row label { display: inline-flex; gap: 8px; align-items: center; }
.sa-toggle-row input { accent-color: var(--sa-accent); }
.sa-section-divider { margin: 38px 0 24px !important; border-color: var(--sa-border) !important; }
.sa-template-form { display: grid; gap: 18px; }
.sa-template-card { padding: 18px; border: 1px solid var(--sa-border); border-radius: 7px; background: #141a22; }
.sa-template-card > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.sa-template-card h3 { margin: 0 0 5px; color: #fff; }
.sa-template-card p { margin: 0; color: var(--sa-muted); }
.sa-template-card textarea { width: 100%; resize: vertical; border: 1px solid var(--sa-border) !important; border-radius: 5px; background: #0d1219 !important; color: #dfe8f3 !important; font: 12px/1.5 Consolas, monospace; }
.sa-template-variables { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 0 0 14px; }
.sa-template-variables span { color: var(--sa-muted); font-size: 12px; }
.sa-template-variables button { padding: 5px 8px; border: 1px solid #36516c; border-radius: 4px; background: #172536; color: #79ddd7; cursor: pointer; font-size: 11px; }
.sa-template-variables button:hover { border-color: var(--sa-accent); background: #1b3143; }
.sa-template-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, .9fr); gap: 16px; }
.sa-template-editor > div > label { display: block; margin-bottom: 6px; color: #c5cfdb; font-size: 13px; font-weight: 700; }
.sa-template-editor iframe { width: 100%; min-height: 420px; border: 1px solid var(--sa-border); border-radius: 5px; background: #fff; }
.sa-template-actions { position: sticky; bottom: 12px; z-index: 3; padding: 12px; border: 1px solid var(--sa-border); border-radius: 6px; background: rgba(17, 22, 30, .96); }
.sa-modal-check { margin-top: 14px; }
.sa-delete-warning { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 20px; padding: 13px; border: 1px solid #713840; border-radius: 5px; background: #321d23; color: #ffd7db; }
.sa-delete-warning > i.icon { margin: 2px 0 0 !important; color: #ff707c; font-size: 19px; }
.sa-delete-warning strong { display: block; color: #fff; }
.sa-delete-warning p { margin: 5px 0 0; color: #eebbc0; line-height: 1.45; }
#saDeleteModal .content label { color: #d7dee8 !important; }
#saDeleteModal .content input { border-color: var(--sa-border) !important; background: #11161e !important; color: #fff !important; }

.sa-loading { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(10, 13, 18, 0.62); z-index: 3000; }
.sa-loading.active { display: flex; }

@media (max-width: 1100px) {
  .sa-kpis { grid-template-columns: repeat(3, 1fr); }
  .sa-kpis > div:nth-child(3) { border-right: 0; }
  .sa-kpis > div:nth-child(-n+3) { border-bottom: 1px solid var(--sa-border); }
  .sa-user-filters { flex-wrap: wrap; }
  .sa-user-filters .sa-search { width: 100%; flex-basis: 100%; }
  .sa-meta-endpoints { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .sa-shell { grid-template-columns: 68px minmax(0, 1fr); }
  .sa-sidebar { width: 68px; }
  .sa-brand { justify-content: center; padding: 12px; }
  .sa-brand img { width: 38px; height: 38px; }
  .sa-brand span, .sa-nav span, .sa-back-link, .sa-user div { display: none; }
  .sa-nav { padding: 14px 8px; }
  .sa-nav button { justify-content: center; padding: 10px; }
  .sa-nav i.icon { width: auto; }
  .sa-user { grid-template-columns: 36px; justify-content: center; }
  .sa-user button { display: none; }
  .sa-main { padding: 20px 14px 38px; }
  .sa-action-row, .sa-toolbar { align-items: stretch; flex-direction: column; }
  .sa-kpis { grid-template-columns: repeat(2, 1fr); }
  .sa-kpis > div { border-bottom: 1px solid var(--sa-border); }
  .sa-kpis > div:nth-child(odd) { border-right: 1px solid var(--sa-border); }
  .sa-kpis > div:nth-child(even) { border-right: 0; }
  .sa-kpis > div:last-child { border-bottom: 0; }
  .sa-toolbar select { width: 100%; }
  .sa-check { white-space: normal; }
  .sa-inline-field { grid-template-columns: 1fr; }
  .sa-template-editor { grid-template-columns: 1fr; }
  .sa-template-card > header { flex-direction: column; }
}
