:root {
  --ink: #171727;
  --muted: #707184;
  --line: #e8e8f0;
  --panel: #ffffff;
  --canvas: #f6f7fb;
  --primary: #6557ed;
  --primary-dark: #4d40cf;
  --primary-soft: #efedff;
  --danger: #df3e59;
  --danger-soft: #fff0f3;
  --success: #159a62;
  --success-soft: #ebfaf3;
  --sidebar: #171624;
  --shadow: 0 22px 70px rgba(37, 32, 86, .10);
  --radius-lg: 24px;
  --radius-md: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { margin: 0; min-height: 100vh; font-size: 16px; line-height: 1.5; background: var(--canvas); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { letter-spacing: -.035em; line-height: 1.12; }
h1 { font-size: clamp(1.7rem, 2.2vw, 2.35rem); margin-bottom: .25rem; }
h2 { font-size: 1.45rem; margin-bottom: .5rem; }
h3 { font-size: 1.18rem; margin-bottom: .4rem; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 .5rem; font-size: .75rem; font-weight: 800; letter-spacing: .14em; color: var(--primary); }
.hint { color: #9b9bab; font-weight: 500; font-size: .8rem; }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: .7rem 1rem; border: 1px solid transparent; border-radius: 12px;
  text-decoration: none; font-weight: 750; font-size: .9rem; transition: transform .18s, box-shadow .18s, background .18s;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:focus-visible, input:focus-visible, select:focus-visible, .icon-button:focus-visible, a:focus-visible { outline: 3px solid rgba(101, 87, 237, .28); outline-offset: 2px; }
.button.primary { color: white; background: linear-gradient(135deg, #7567f2, #5948df); box-shadow: 0 10px 24px rgba(90, 72, 223, .24); }
.button.primary:hover:not(:disabled) { box-shadow: 0 13px 30px rgba(90, 72, 223, .32); }
.button.secondary { border-color: var(--line); background: white; color: var(--ink); }
.button.ghost { border-color: transparent; background: #f5f5f9; color: #59596a; }
.button.danger-fill { color: white; background: var(--danger); }
.button.wide { width: 100%; }
.button.small { min-height: 36px; padding: .45rem .75rem; font-size: .8rem; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.text-button { border: 0; background: transparent; color: #a5a3b3; padding: .25rem 0; font-size: .85rem; }

.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px;
  color: white; font-size: 1.15rem; font-weight: 900; background: linear-gradient(145deg, #8171ff, #5141dc);
  box-shadow: 0 12px 30px rgba(98, 81, 231, .35);
}
.brand-lockup { display: inline-flex; align-items: center; gap: .75rem; font-weight: 900; letter-spacing: .08em; text-decoration: none; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 999px; background: #aaa; flex: 0 0 auto; }
.status-dot.online { background: #18b878; box-shadow: 0 0 0 4px rgba(24, 184, 120, .12); }
.status-dot.offline { background: #aaa9b4; }

label { display: grid; gap: .45rem; color: #454554; font-weight: 700; font-size: .88rem; }
input, select {
  width: 100%; min-height: 46px; padding: .75rem .85rem; border: 1px solid #dedee8; border-radius: 12px;
  color: var(--ink); background: white; font-size: .95rem; transition: border .18s, box-shadow .18s;
}
input:hover, select:hover { border-color: #c4c1df; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(101, 87, 237, .1); outline: none; }
.stack-form { display: grid; gap: 1rem; }
.field-grid { display: grid; gap: .9rem; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-note { color: #89899a; font-size: .77rem; font-weight: 500; }
.stack-form hr { width: 100%; border: 0; border-top: 1px solid var(--line); margin: .25rem 0; }

.alert { padding: .8rem 1rem; border-radius: 12px; font-size: .9rem; border: 1px solid transparent; }
.alert.error { color: #a9283d; background: var(--danger-soft); border-color: #ffd5dd; }
.alert.success { color: #08794b; background: var(--success-soft); border-color: #c9f0df; }
.workspace-alert { margin: 0 2rem 1.25rem; }

/* Installer */
.installer-page { background: #131221; color: white; }
.installer-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(420px, 610px); }
.installer-brand { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: center; padding: clamp(3rem, 7vw, 7rem); background: radial-gradient(circle at 15% 20%, rgba(112, 93, 245, .35), transparent 28%), radial-gradient(circle at 80% 80%, rgba(43, 199, 151, .18), transparent 30%); }
.installer-brand::after { content: ""; position: absolute; right: -8rem; bottom: -10rem; width: 32rem; height: 32rem; border: 1px solid rgba(255,255,255,.08); border-radius: 50%; box-shadow: 0 0 0 80px rgba(255,255,255,.025), 0 0 0 160px rgba(255,255,255,.018); }
.installer-brand .brand-mark { margin-bottom: 2.5rem; }
.installer-brand h1 { max-width: 700px; font-size: clamp(2.6rem, 5vw, 5.8rem); }
.installer-brand > p:not(.eyebrow) { max-width: 600px; color: #b7b4c7; font-size: 1.08rem; }
.requirements-card { position: relative; z-index: 1; margin-top: 2rem; max-width: 560px; padding: 1rem 1.15rem; border: 1px solid rgba(255,255,255,.1); border-radius: 18px; background: rgba(255,255,255,.045); backdrop-filter: blur(10px); }
.requirement-row { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .75rem; padding: .55rem 0; color: #d9d7e2; font-size: .88rem; }
.requirement-row + .requirement-row { border-top: 1px solid rgba(255,255,255,.07); }
.requirement-row strong { color: white; font-size: .75rem; }
.installer-form-card { display: flex; flex-direction: column; justify-content: center; gap: 1.5rem; padding: clamp(2rem, 5vw, 5rem); color: var(--ink); background: white; }

/* Login */
.login-page { background: #131221; }
.login-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(430px, .8fr); }
.login-visual { position: relative; overflow: hidden; display: flex; flex-direction: column; padding: clamp(2rem, 5vw, 5rem); color: white; background: radial-gradient(circle at 15% 25%, rgba(113, 91, 245, .45), transparent 27%), radial-gradient(circle at 85% 72%, rgba(32, 197, 144, .22), transparent 28%), #171526; }
.login-copy { margin: auto 0; position: relative; z-index: 2; }
.login-copy h1 { margin: 0 0 1.2rem; font-size: clamp(3rem, 6vw, 6.8rem); }
.login-copy > p:last-child { max-width: 560px; color: #b9b6c8; font-size: 1.1rem; }
.login-panel { display: grid; place-items: center; padding: 2rem; background: white; }
.login-card { display: grid; gap: 1.15rem; width: min(100%, 430px); }
.login-card h2 { font-size: 2rem; }
.secure-note { display: flex; align-items: center; justify-content: center; gap: .55rem; margin: .25rem 0 0; color: #898898; font-size: .78rem; }
.domain-orbit { position: absolute; inset: 0; pointer-events: none; opacity: .85; }
.orbit-card { position: absolute; display: flex; align-items: center; gap: .65rem; padding: .8rem 1rem; border: 1px solid rgba(255,255,255,.14); border-radius: 14px; background: rgba(255,255,255,.07); color: #dedbea; font-size: .76rem; font-weight: 800; letter-spacing: .08em; backdrop-filter: blur(8px); }
.orbit-card span { width: 10px; height: 10px; border-radius: 50%; background: #38d39a; box-shadow: 0 0 0 5px rgba(56,211,154,.1); }
.card-a { right: 8%; top: 21%; transform: rotate(3deg); }
.card-b { right: 20%; bottom: 14%; transform: rotate(-4deg); }
.card-c { right: -2%; bottom: 39%; opacity: .55; }

/* App shell */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 238px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 1.4rem 1rem; color: white; background: var(--sidebar); }
.sidebar-brand { margin: .25rem .5rem 2.2rem; color: white; }
.main-nav { display: grid; gap: .35rem; }
.main-nav a { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; min-height: 48px; padding: .65rem .8rem; border-radius: 12px; color: #aaa7b9; text-decoration: none; font-size: .9rem; font-weight: 700; }
.main-nav a:hover { background: rgba(255,255,255,.055); color: white; }
.main-nav a.active { color: white; background: linear-gradient(135deg, rgba(116,100,242,.28), rgba(77,61,198,.14)); box-shadow: inset 0 0 0 1px rgba(136,123,255,.18); }
.main-nav a b { min-width: 25px; padding: .1rem .4rem; border-radius: 999px; color: #bcb9cb; background: rgba(255,255,255,.07); text-align: center; font-size: .68rem; }
.nav-icon { font-size: 1.15rem; color: #77738e; }
.main-nav a.active .nav-icon { color: #a99dff; }
.sidebar-bottom { margin-top: auto; display: grid; gap: 1rem; padding: .9rem .65rem; }
.connection-summary { display: flex; align-items: center; gap: .65rem; }
.connection-summary div { display: grid; }
.connection-summary strong { font-size: .78rem; }
.connection-summary small { color: #777485; font-size: .7rem; }
.workspace { min-width: 0; padding-bottom: 3rem; }
.workspace-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.75rem 2rem 1.4rem; }
.header-actions { display: flex; align-items: center; gap: .8rem; }
.user-chip { display: flex; align-items: center; gap: .65rem; padding: .35rem .65rem; border: 1px solid var(--line); border-radius: 13px; background: white; }
.user-chip > span { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; color: #5a4bd7; background: var(--primary-soft); font-weight: 850; }
.user-chip div { display: grid; }
.user-chip strong { font-size: .78rem; }
.user-chip small { color: var(--muted); font-size: .68rem; }

.metric-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; padding: 0 2rem 1rem; }
.metric-card { position: relative; overflow: hidden; min-height: 138px; padding: 1.15rem 1.25rem; border: 1px solid var(--line); border-radius: 18px; background: white; box-shadow: 0 10px 35px rgba(48,44,85,.045); }
.metric-card::after { content: ""; position: absolute; width: 84px; height: 84px; right: -25px; top: -25px; border-radius: 50%; background: #f4f2ff; }
.metric-card.accent { color: white; border: 0; background: linear-gradient(145deg, #6e5ce9, #5141c9); }
.metric-card.accent::after { width: 130px; height: 130px; background: rgba(255,255,255,.08); }
.metric-card > * { position: relative; z-index: 1; }
.metric-label { display: block; color: #7c7c8e; font-size: .76rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.metric-card.accent .metric-label, .metric-card.accent small { color: #d7d2ff; }
.metric-card strong { display: block; margin: .65rem 0 .2rem; font-size: 2rem; letter-spacing: -.05em; }
.metric-card strong em { margin-left: .2rem; opacity: .6; font-style: normal; font-size: 1rem; }
.metric-card small { color: #9595a3; }

.content-panel { margin: 0 2rem; border: 1px solid var(--line); border-radius: 20px; background: white; box-shadow: 0 18px 55px rgba(42,38,76,.055); overflow: hidden; }
.toolbar { display: grid; grid-template-columns: minmax(260px, 1fr) 230px auto; gap: .75rem; align-items: center; padding: 1rem; border-bottom: 1px solid var(--line); }
.search-box { position: relative; display: block; }
.search-box span { position: absolute; left: .9rem; top: 50%; transform: translateY(-50%); color: #9998a8; font-size: 1.2rem; }
.search-box input { padding-left: 2.6rem; }
.inline-error { display: flex; gap: .6rem; margin: 1rem; padding: .7rem .9rem; border-radius: 10px; color: #9b2b3f; background: var(--danger-soft); font-size: .82rem; }
.link-list { padding: .3rem 0; }
.link-row { display: grid; grid-template-columns: auto minmax(260px, 1fr) auto auto; gap: 1rem; align-items: center; min-height: 84px; padding: .85rem 1rem; border-bottom: 1px solid #efeff4; transition: background .15s; }
.link-row:last-child { border-bottom: 0; }
.link-row:hover { background: #fbfbfe; }
.domain-avatar { position: relative; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; border: 1px solid #e7e6ed; background: white; box-shadow: inset 0 0 0 4px #fafafe; }
.domain-avatar span { width: 17px; height: 17px; border-radius: 50%; background: linear-gradient(145deg, var(--domain-accent, #6d5dfb), #2ed39d); box-shadow: 0 5px 10px color-mix(in srgb, var(--domain-accent, #6d5dfb) 30%, transparent); }
.domain-avatar.large { width: 50px; height: 50px; }
.domain-avatar.large span { width: 22px; height: 22px; }
.link-main { min-width: 0; }
.short-line { display: flex; align-items: center; gap: .45rem; min-width: 0; }
.short-line a { overflow: hidden; color: #272638; font-weight: 800; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.short-line a:hover { color: var(--primary); }
.copy-button { border: 0; background: transparent; color: #858496; font-size: 1rem; }
.destination-line { display: flex; align-items: center; gap: .4rem; margin-top: .24rem; color: #838394; font-size: .78rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-meta { display: flex; align-items: center; gap: .75rem; color: #878797; font-size: .74rem; white-space: nowrap; }
.instance-pill { padding: .25rem .55rem; border: 1px solid color-mix(in srgb, var(--domain-accent) 25%, white); border-radius: 999px; color: color-mix(in srgb, var(--domain-accent) 78%, #151522); background: color-mix(in srgb, var(--domain-accent) 8%, white); font-weight: 800; }
.row-actions { display: flex; gap: .3rem; opacity: .5; transition: opacity .15s; }
.link-row:hover .row-actions { opacity: 1; }
.icon-button { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 10px; color: #686879; background: white; font-size: 1rem; }
.icon-button:hover { border-color: #cbc8e5; color: var(--primary); background: #faf9ff; }
.icon-button.danger:hover { border-color: #ffd4dc; color: var(--danger); background: var(--danger-soft); }
.list-note { margin: 0; padding: .8rem 1rem; border-top: 1px solid var(--line); color: #8c8c9b; background: #fafafe; font-size: .75rem; text-align: center; }
.empty-state { display: grid; justify-items: center; padding: 4.5rem 2rem; text-align: center; }
.empty-state p { max-width: 480px; color: var(--muted); }
.empty-icon { display: grid; place-items: center; width: 64px; height: 64px; margin-bottom: 1rem; border-radius: 20px; color: var(--primary); background: var(--primary-soft); font-size: 1.7rem; }

.integration-intro { display: flex; align-items: center; justify-content: space-between; gap: 2rem; margin: 0 2rem 1.25rem; padding: 1.25rem 1.4rem; border: 1px solid #dbd8ff; border-radius: 18px; background: linear-gradient(110deg, #f5f3ff, #fafffe); }
.integration-intro p { margin: 0; max-width: 680px; color: var(--muted); }
.flow-badges { display: flex; align-items: center; gap: .45rem; white-space: nowrap; }
.flow-badges span { padding: .4rem .65rem; border: 1px solid #dedbee; border-radius: 9px; background: white; font-size: .72rem; font-weight: 850; }
.flow-badges i { color: #9c99b0; font-style: normal; }
.integration-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; padding: 0 2rem; }
.integration-card { min-width: 0; padding: 1.25rem; border: 1px solid var(--line); border-radius: 18px; background: white; box-shadow: 0 15px 45px rgba(46,42,78,.05); }
.integration-card.disabled-card { opacity: .68; }
.integration-top { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 1.2rem; }
.integration-card > a { display: block; overflow: hidden; margin-bottom: .4rem; color: var(--primary); font-size: .86rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.integration-card > p { overflow: hidden; color: #9998a5; font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
.status-badge { display: inline-flex; align-items: center; gap: .5rem; padding: .35rem .6rem; border-radius: 999px; font-size: .72rem; font-weight: 800; }
.status-badge.success { color: #0a7a4c; background: var(--success-soft); }
.status-badge.neutral { color: #73727e; background: #f1f1f4; }
.integration-actions { display: flex; align-items: center; gap: .45rem; margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.integration-actions form { display: contents; }
.integration-actions .icon-button { margin-left: auto; }
.add-card { display: grid; place-items: center; align-content: center; min-height: 280px; color: #7c7b8c; border-style: dashed; }
.add-card > span { display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: .7rem; border-radius: 15px; color: var(--primary); background: var(--primary-soft); font-size: 1.5rem; }
.add-card strong { color: var(--ink); }
.add-card small { margin-top: .35rem; }

.settings-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1rem; padding: 0 2rem; }
.settings-card { padding: 1.5rem; border: 1px solid var(--line); border-radius: 20px; background: white; box-shadow: 0 15px 45px rgba(46,42,78,.05); }
.settings-card .stack-form { margin-top: 1.4rem; }
.security-list { display: grid; gap: .25rem; margin: 1.2rem 0 0; padding: 0; list-style: none; }
.security-list li { display: flex; gap: .8rem; padding: .9rem 0; border-top: 1px solid var(--line); }
.security-list li > span { display: grid; place-items: center; width: 29px; height: 29px; flex: 0 0 auto; border-radius: 9px; color: var(--success); background: var(--success-soft); font-weight: 900; }
.security-list li div { display: grid; }
.security-list strong { font-size: .88rem; }
.security-list small { color: var(--muted); font-size: .75rem; }

/* Dialogs */
.modal { width: min(92vw, 620px); max-height: 90vh; padding: 0; border: 0; border-radius: 20px; color: var(--ink); background: transparent; box-shadow: 0 30px 100px rgba(20,18,39,.3); }
.modal::backdrop { background: rgba(22,20,39,.62); backdrop-filter: blur(5px); }
.modal-card { display: grid; gap: 1rem; padding: 1.35rem; background: white; }
.modal-card.compact { justify-items: center; text-align: center; padding: 1.8rem; }
.modal-head { display: flex; justify-content: space-between; gap: 1rem; }
.modal-close { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 11px; color: #777687; background: white; font-size: 1.4rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: .25rem; }
.modal-context { margin: -.25rem 0 0; padding: .65rem .8rem; border-radius: 10px; color: #646376; background: #f5f5fa; font-size: .82rem; }
.danger-symbol { display: grid; place-items: center; width: 55px; height: 55px; border-radius: 18px; color: var(--danger); background: var(--danger-soft); font-size: 1.5rem; font-weight: 900; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: 1.5rem; transform: translate(-50%, 20px); padding: .7rem 1rem; border-radius: 11px; color: white; background: #242235; box-shadow: 0 12px 35px rgba(0,0,0,.2); opacity: 0; pointer-events: none; transition: .2s; font-size: .85rem; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 1100px) {
  .integration-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .link-row { grid-template-columns: auto minmax(200px, 1fr) auto; }
  .link-meta { grid-column: 2 / 3; }
  .row-actions { grid-column: 3; grid-row: 1 / span 2; }
}

@media (max-width: 820px) {
  .installer-shell, .login-shell { grid-template-columns: 1fr; }
  .installer-brand { min-height: 55vh; }
  .login-visual { min-height: 48vh; }
  .login-panel { padding: 3rem 1.3rem; }
  .app-shell { display: block; }
  .sidebar { position: sticky; z-index: 20; width: 100%; height: auto; padding: .7rem 1rem; flex-direction: row; align-items: center; }
  .sidebar-brand { margin: 0 1rem 0 0; }
  .sidebar-brand span { display: none; }
  .sidebar-brand .brand-mark { width: 38px; height: 38px; }
  .main-nav { display: flex; overflow-x: auto; }
  .main-nav a { grid-template-columns: auto auto; min-height: 42px; padding: .55rem .7rem; white-space: nowrap; }
  .main-nav a b, .nav-icon { display: none; }
  .sidebar-bottom { margin: 0 0 0 auto; padding: 0; }
  .connection-summary { display: none; }
  .sidebar-bottom form { display: none; }
  .workspace-header { align-items: flex-start; padding: 1.25rem 1rem; }
  .header-actions .user-chip { display: none; }
  .workspace-alert, .content-panel, .integration-intro { margin-left: 1rem; margin-right: 1rem; }
  .metric-grid, .integration-grid, .settings-grid { padding-left: 1rem; padding-right: 1rem; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 115px; }
  .integration-grid, .settings-grid { grid-template-columns: 1fr; }
  .integration-intro { align-items: flex-start; flex-direction: column; }
  .toolbar { grid-template-columns: 1fr; }
  .link-row { grid-template-columns: auto minmax(0, 1fr) auto; gap: .7rem; }
  .link-meta { display: flex; flex-wrap: wrap; grid-column: 2 / 4; }
  .row-actions { grid-column: 3; grid-row: 1; }
  .domain-orbit { display: none; }
}

@media (max-width: 520px) {
  .installer-brand { padding: 2rem 1.25rem; }
  .installer-form-card { padding: 2rem 1.25rem; }
  .field-grid.two { grid-template-columns: 1fr; }
  .workspace-header { display: grid; }
  .header-actions { width: 100%; }
  .header-actions .button { width: 100%; }
  .link-row { align-items: start; }
  .domain-avatar { width: 36px; height: 36px; }
  .link-meta time { display: none; }
  .integration-actions { flex-wrap: wrap; }
  .modal-actions { display: grid; grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
