:root {
  color-scheme: light;
  --primary: #5636e8;
  --primary-2: #2563eb;
  --accent: #13a37b;
  --bg: #f5f7fd;
  --surface: #ffffff;
  --surface-2: #f0f2fb;
  --text: #111a3a;
  --muted: #68708c;
  --line: #e2e6f1;
  --danger: #d9344e;
  --shadow: 0 10px 30px rgba(34, 45, 98, 0.08);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #07101f;
  --surface: #0d182a;
  --surface-2: #131f34;
  --text: #f5f7ff;
  --muted: #9fa9c3;
  --line: #25324a;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
body { margin: 0; min-width: 320px; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(360px, 1.05fr) minmax(420px, .95fr); }
.login-visual { padding: clamp(32px, 6vw, 88px); display: flex; flex-direction: column; justify-content: space-between; background: linear-gradient(140deg, #121b4d 0%, #5636e8 65%, #2977ee 100%); color: #fff; min-height: 100vh; }
.login-visual h1 { max-width: 680px; margin: 10px 0 18px; font-size: clamp(42px, 6vw, 78px); line-height: 1.02; letter-spacing: 0; }
.login-visual p { max-width: 620px; font-size: 18px; line-height: 1.7; color: #e8e9ff; }
.login-points { list-style: none; padding: 0; margin: 28px 0 0; display: flex; flex-wrap: wrap; gap: 10px; }
.login-points li { padding: 10px 14px; border: 1px solid rgba(255,255,255,.25); border-radius: 8px; background: rgba(255,255,255,.08); }
.login-panel { position: relative; display: grid; place-items: center; padding: 32px; background: var(--bg); }
.login-tools { position: absolute; top: 28px; right: 28px; display: flex; gap: 8px; }
.login-card { width: min(480px, 100%); padding: 40px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.login-card h2 { margin: 8px 0; font-size: 30px; }
.login-card form { display: grid; gap: 18px; margin: 30px 0 18px; }

.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; font-weight: 800; font-size: 18px; }
.brand img { width: 38px; height: 38px; object-fit: contain; border-radius: 8px; }
.brand strong { color: var(--primary); }
.brand-large { color: #fff; font-size: 22px; }
.brand-large img { width: 48px; height: 48px; }
.brand-large strong { color: #b5c8ff; }

.eyebrow { margin: 0; color: var(--primary); font-size: 12px !important; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.muted { color: var(--muted); }
label { display: grid; gap: 8px; font-weight: 700; font-size: 14px; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 7px; padding: 12px 13px; background: var(--surface); color: var(--text); outline: none; }
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
.button { border: 0; border-radius: 7px; padding: 12px 18px; font-weight: 800; cursor: pointer; }
.button-primary { color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.button-secondary { color: var(--primary); background: var(--surface-2); border: 1px solid var(--line); }
.button-danger { color: #fff; background: var(--danger); }
.button-block { width: 100%; }
.text-link { color: var(--primary); font-weight: 700; text-decoration: none; }
.form-error { min-height: 20px; color: var(--danger); font-weight: 700; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 28px; padding: 22px 16px; background: var(--surface); border-right: 1px solid var(--line); z-index: 30; }
.sidebar .brand { padding: 0 10px; }
.sidebar nav { display: grid; gap: 4px; overflow-y: auto; }
.nav-item { width: 100%; display: flex; align-items: center; gap: 12px; min-height: 44px; border: 0; border-radius: 7px; padding: 9px 12px; background: transparent; cursor: pointer; text-align: left; color: var(--muted); }
.nav-item span { min-width: 27px; font-size: 14px; font-weight: 900; color: var(--primary); text-align: center; }
.nav-item b { font-size: 14px; }
.nav-item:hover, .nav-item.active { background: color-mix(in srgb, var(--primary) 10%, var(--surface)); color: var(--primary); }
.sidebar-foot { display: grid; gap: 8px; margin-top: auto; }
.role-pill { display: block; margin: 0 10px; padding: 8px 10px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 800; text-align: center; }

.workspace { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; min-height: 78px; display: flex; align-items: center; gap: 16px; padding: 14px clamp(18px, 3vw, 38px); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(16px); border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 2px 0 0; font-size: 23px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.icon-button, .user-button { min-width: 42px; min-height: 42px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); cursor: pointer; }
.user-button { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 5px; }
.user-button > span { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 6px; color: #fff; background: var(--primary); font-weight: 900; }
.user-button small { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: 700; }
.status { display: inline-flex; align-items: center; gap: 7px; margin-right: 8px; color: var(--muted); font-size: 12px; font-weight: 800; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 14%, transparent); }
.status.offline i { background: var(--danger); }

.page-content { padding: 26px clamp(18px, 3vw, 38px) 60px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.page-head h2 { margin: 0 0 6px; font-size: 26px; }
.page-head p { margin: 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric, .panel { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; box-shadow: var(--shadow); }
.metric { padding: 18px; }
.metric span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.metric strong { display: block; margin-top: 10px; font-size: 28px; }
.panel { padding: 20px; margin-bottom: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.panel-head h3 { margin: 0; font-size: 17px; }
.panel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
td { font-size: 14px; }
.badge { display: inline-flex; align-items: center; padding: 5px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 800; }
.badge.success { color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.badge.warning { color: #c47606; background: color-mix(in srgb, #f59e0b 13%, var(--surface)); }
.badge.danger { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.search-row { display: flex; gap: 9px; margin-bottom: 16px; }
.search-row input { max-width: 460px; }
.provider-list, .flag-list, .plan-grid, .setting-list { display: grid; gap: 12px; }
.plan-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.integration-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.provider-card, .flag-row, .plan-card, .integration-card { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding: 18px; }
.provider-card.active { border-color: var(--primary); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 10%, transparent); }
.provider-card .card-top, .integration-card .card-top, .flag-row, .plan-card .card-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.provider-card h3, .integration-card h3, .plan-card h3 { margin: 0; }
.provider-card p, .integration-card p, .plan-card p { color: var(--muted); }
.integration-card .actions { align-items: center; justify-content: space-between; margin-top: 16px; }
.secret-summary { display: flex; flex-wrap: wrap; gap: 7px; min-height: 30px; margin-top: 14px; }
.role-grid { margin: 0; padding: 14px; border: 1px solid var(--line); border-radius: 8px; }
.role-grid legend { padding: 0 7px; color: var(--muted); font-weight: 800; }
.role-grid label { display: inline-flex; margin: 6px 14px 6px 0; }
.checkbox-row { display: flex; align-items: center; gap: 9px; }
.checkbox-row input { width: 18px; height: 18px; flex: 0 0 auto; }
.form-note { margin: 0; padding: 12px 14px; border-radius: 7px; background: var(--surface-2); color: var(--muted); font-size: 13px; line-height: 1.5; }
.message-list { display: grid; gap: 10px; max-height: 360px; margin-bottom: 20px; overflow-y: auto; }
.message { padding: 13px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }
.message.internal { border-color: color-mix(in srgb, #f59e0b 45%, var(--line)); background: color-mix(in srgb, #f59e0b 8%, var(--surface)); }
.message p { margin: 7px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message small { color: var(--muted); }
.setting-list .flag-row > div { min-width: 0; }
.setting-list .flag-row p { max-width: 68vw; margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.switch { position: relative; display: inline-flex; width: 44px; height: 24px; }
.switch input { position: absolute; opacity: 0; }
.switch i { width: 100%; border-radius: 20px; background: var(--line); transition: .2s; }
.switch i::after { content: ""; display: block; width: 18px; height: 18px; margin: 3px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 2px 5px rgba(0,0,0,.2); }
.switch input:checked + i { background: var(--primary); }
.switch input:checked + i::after { transform: translateX(20px); }
.color-input { display: grid; grid-template-columns: 48px 1fr; gap: 8px; }
.color-input input[type="color"] { min-height: 44px; padding: 4px; }
.entitlement-list { display: grid; gap: 8px; max-height: 390px; overflow-y: auto; }
.entitlement-row { display: grid; grid-template-columns: minmax(0, 1fr) 150px; align-items: center; gap: 14px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.entitlement-row small { display: block; margin-top: 4px; color: var(--muted); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.loading { min-height: 55vh; display: grid; place-items: center; align-content: center; gap: 12px; color: var(--muted); }
.loading span { width: 38px; height: 38px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast-region { position: fixed; right: 18px; top: 18px; z-index: 100; display: grid; gap: 8px; }
.toast { max-width: 360px; padding: 12px 15px; border-radius: 7px; color: #fff; background: #18233f; box-shadow: var(--shadow); font-weight: 700; }
.toast.error { background: var(--danger); }
.modal { width: min(720px, calc(100% - 28px)); max-height: 90vh; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0,0,0,.3); }
.modal::backdrop { background: rgba(7, 16, 31, .62); backdrop-filter: blur(4px); }
.modal-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--line); background: var(--surface); z-index: 2; }
.modal-head h2 { margin: 2px 0 0; }
.modal-body { padding: 20px; overflow-y: auto; }
.mobile-only, .sidebar-backdrop { display: none; }

@media (max-width: 1150px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .plan-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .integration-grid { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-visual { min-height: auto; padding: 28px; gap: 70px; }
  .login-visual h1 { font-size: 42px; }
  .login-panel { min-height: 620px; padding: 80px 18px 30px; }
  .app-shell { display: block; }
  .sidebar { position: fixed; left: 0; transform: translateX(-105%); width: min(290px, 86vw); transition: transform .2s; }
  body.menu-open .sidebar { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 25; background: rgba(7,16,31,.48); }
  body.menu-open .sidebar-backdrop { display: block; }
  .mobile-only { display: inline-grid; place-items: center; }
  .topbar { padding: 11px 14px; }
  .status, .user-button small { display: none; }
  .page-content { padding: 20px 14px 50px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-grid, .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .plan-grid { grid-template-columns: 1fr; }
  .search-row { flex-wrap: wrap; }
  .search-row input, .search-row select { max-width: none; flex: 1 1 220px; }
  .setting-list .flag-row p { max-width: 70vw; }
}

@media (max-width: 520px) {
  .login-card { padding: 25px 20px; }
  .login-visual h1 { font-size: 36px; }
  .topbar h1 { font-size: 19px; }
  .topbar .eyebrow { display: none; }
  .topbar-actions { gap: 5px; }
  .icon-button { min-width: 38px; min-height: 38px; }
  .user-button { min-width: 38px; padding: 3px; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .metric { padding: 14px; }
  .metric strong { font-size: 23px; }
  .page-head { display: grid; }
  .page-head .button { width: 100%; }
  .entitlement-row { grid-template-columns: 1fr; }
  .integration-card .card-top, .integration-card .actions, .setting-list .flag-row { align-items: flex-start; }
  .setting-list .flag-row { display: grid; }
  .setting-list .flag-row p { max-width: 100%; }
}
