:root {
  color-scheme: light;
  --ink: #132230;
  --muted: #687888;
  --line: #dbe3ea;
  --line-strong: #c7d2dd;
  --paper: #ffffff;
  --canvas: #f4f7f9;
  --nav: #0c2135;
  --nav-soft: #173650;
  --blue: #087dd8;
  --blue-soft: #eaf5fc;
  --green: #15965a;
  --green-soft: #e9f7ef;
  --red: #d94452;
  --red-soft: #fcecef;
  --amber: #c77a08;
  --amber-soft: #fff5df;
  --shadow: 0 18px 45px rgba(18, 34, 48, .13);
  font-family: Tahoma, Arial, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; max-width: 100%; overflow-x: hidden; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-size: 14px; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, select { cursor: pointer; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
.muted { color: var(--muted); }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(90deg, var(--canvas) 0 68%, var(--nav) 68% 100%); }
.login-panel { width: min(420px, 100%); padding: 36px; background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 6px; }
.login-panel h1 { margin: 40px 0 8px; font-size: 27px; }
.login-panel > p { margin: 0 0 28px; }
.brand { display: flex; align-items: center; gap: 12px; direction: ltr; color: #fff; }
.brand-login { color: var(--ink); }
.brand-mark { width: 43px; height: 50px; display: grid; place-items: center; color: #fff; background: var(--blue); clip-path: polygon(50% 0, 94% 17%, 88% 73%, 50% 100%, 12% 73%, 6% 17%); font-weight: 800; font-size: 14px; }
.brand b, .brand small { display: block; letter-spacing: 0; }
.brand b { font-size: 19px; }
.brand small { margin-top: 3px; opacity: .72; font-size: 11px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 1fr 242px; direction: ltr; }
.sidebar { position: fixed; inset: 0 0 0 auto; z-index: 30; width: 242px; padding: 24px 14px 18px; display: flex; flex-direction: column; background: var(--nav); color: #dfeaf2; direction: rtl; }
.sidebar .brand { padding: 0 13px 25px; border-bottom: 1px solid rgba(255,255,255,.1); margin-bottom: 18px; }
.sidebar nav { display: grid; gap: 5px; }
.nav-item { appearance: none; border: 0; border-radius: 5px; background: transparent; color: inherit; min-height: 46px; padding: 0 13px; display: flex; align-items: center; gap: 13px; text-align: right; transition: background .18s, color .18s; }
.nav-item:hover { background: rgba(255,255,255,.07); }
.nav-item.active { background: var(--nav-soft); color: #45b9f3; box-shadow: inset -3px 0 #26b7f3; }
.nav-icon { width: 25px; text-align: center; font-size: 22px; line-height: 1; }
.logout { margin-top: auto; }
.page { grid-column: 1; min-width: 0; direction: rtl; }
.topbar { height: 76px; padding: 0 28px; display: flex; align-items: center; gap: 16px; background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar h1 { margin: 0 0 4px; font-size: 20px; }
.topbar p { margin: 0; font-size: 12px; color: var(--muted); }
.topbar-actions { margin-right: auto; display: flex; align-items: center; gap: 14px; color: var(--muted); font-size: 12px; direction: ltr; }
.live-indicator { display: inline-flex; align-items: center; gap: 7px; direction: rtl; }
.live-indicator i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.icon-button { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 5px; background: var(--paper); color: var(--ink); display: grid; place-items: center; font-size: 20px; }
.icon-button:hover { border-color: var(--blue); color: var(--blue); }
.menu-button { display: none; }
.content { padding: 20px 26px 38px; }
.view { display: none; }
.active-view { display: block; }

.summary-band { min-height: 105px; display: grid; grid-template-columns: repeat(6, 1fr); background: var(--paper); border: 1px solid var(--line); border-radius: 5px; }
.metric { position: relative; padding: 20px 18px; display: grid; grid-template-columns: 42px 1fr; align-items: center; gap: 11px; }
.metric:not(:last-child)::after { content: ""; position: absolute; inset: 22px auto 22px 0; width: 1px; background: var(--line); }
.metric-icon { width: 42px; height: 42px; border-radius: 5px; display: grid; place-items: center; font-size: 21px; font-weight: 700; }
.metric-icon.blue { background: var(--blue-soft); color: var(--blue); }
.metric-icon.green { background: var(--green-soft); color: var(--green); }
.metric-icon.red { background: var(--red-soft); color: var(--red); }
.metric-icon.amber { background: var(--amber-soft); color: var(--amber); }
.metric span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 7px; white-space: nowrap; }
.metric strong { font-size: 20px; direction: ltr; display: inline-block; }

.section { margin-top: 18px; background: var(--paper); border: 1px solid var(--line); border-radius: 5px; }
.section-header { min-height: 70px; padding: 14px 17px; display: flex; align-items: center; justify-content: space-between; gap: 14px; border-bottom: 1px solid var(--line); }
.section-header h2, .page-heading h2 { margin: 0 0 5px; font-size: 17px; }
.section-header p, .page-heading p { margin: 0; font-size: 12px; }
.section-actions { display: flex; align-items: center; gap: 9px; }
.search { min-width: 235px; height: 38px; display: flex; align-items: center; gap: 7px; padding: 0 11px; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--muted); }
.search:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(8,125,216,.1); }
.search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); }
select, input, textarea { border: 1px solid var(--line-strong); border-radius: 4px; background: var(--paper); color: var(--ink); outline: none; }
select { height: 38px; padding: 0 12px; }
input { height: 42px; padding: 0 11px; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(8,125,216,.1); }
.button { min-height: 38px; padding: 0 15px; border-radius: 4px; border: 1px solid transparent; display: inline-flex; align-items: center; justify-content: center; gap: 7px; text-decoration: none; white-space: nowrap; }
.button.primary { color: #fff; background: var(--blue); border-color: var(--blue); }
.button.primary:hover { background: #006cbd; }
.button.secondary { color: var(--ink); background: var(--paper); border-color: var(--line-strong); }
.button.secondary:hover { border-color: var(--blue); color: var(--blue); }
.button.danger { color: #fff; background: var(--red); border-color: var(--red); }
.button.wide { width: 100%; }
.button:disabled { opacity: .52; cursor: not-allowed; }
.text-button { border: 0; background: transparent; color: var(--blue); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 980px; }
th { height: 42px; padding: 0 14px; color: #526371; font-size: 11px; font-weight: 700; text-align: right; background: #f9fbfc; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { height: 54px; padding: 0 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr { transition: background .16s; cursor: pointer; }
tbody tr:hover, tbody tr.selected { background: #edf7fd; }
tbody tr:last-child td { border-bottom: 0; }
.router-cell { display: flex; align-items: center; gap: 10px; }
.router-avatar { width: 30px; height: 30px; border-radius: 4px; display: grid; place-items: center; background: var(--blue-soft); color: var(--blue); font-size: 12px; font-weight: 800; }
.router-cell b { font-size: 13px; }
.code { direction: ltr; text-align: right; font-family: Consolas, monospace; font-size: 12px; }
.status { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; font-size: 12px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.online, .status-online { color: var(--green); }
.status.offline { color: var(--red); }
.status.disabled { color: var(--muted); }
.more-button { width: 31px; height: 31px; border: 1px solid var(--line); border-radius: 4px; background: #fff; color: var(--muted); font-size: 20px; }
.empty-state { min-height: 180px; display: grid; place-content: center; text-align: center; color: var(--muted); gap: 6px; }
.empty-state strong { color: var(--ink); }

.lower-grid { display: grid; grid-template-columns: 1fr 1.05fr; gap: 18px; }
.detail-section, .activity-section { min-width: 0; }
.details-empty { min-height: 190px; display: grid; place-items: center; color: var(--muted); }
.detail-grid { min-height: 190px; padding: 19px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 17px 28px; }
.detail-item span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 5px; }
.detail-item strong { font-size: 13px; }
.detail-actions { min-height: 58px; padding: 10px 15px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 8px; }
.activity-list { min-height: 248px; }
.activity-row { min-height: 49px; padding: 9px 15px; display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 9px; border-bottom: 1px solid var(--line); }
.activity-row:last-child { border-bottom: 0; }
.activity-symbol { width: 23px; height: 23px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; background: var(--blue-soft); color: var(--blue); }
.activity-symbol.connected { background: var(--green-soft); color: var(--green); }
.activity-symbol.disconnected, .activity-symbol.deleted { background: var(--red-soft); color: var(--red); }
.activity-row p { margin: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-row time { color: var(--muted); font-size: 10px; direction: ltr; }

.page-heading { min-height: 66px; display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 16px; }
.connection-list { display: grid; gap: 10px; }
.connection-row { min-height: 86px; padding: 15px 17px; display: grid; grid-template-columns: minmax(180px, 1.4fr) repeat(4, 1fr) auto; align-items: center; gap: 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 5px; }
.connection-row .label { display: block; color: var(--muted); font-size: 10px; margin-bottom: 6px; }
.connection-actions { display: flex; gap: 6px; }
.timeline { margin: 0; }
.timeline .activity-row { min-height: 62px; }
.system-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.system-card { padding: 19px; background: var(--paper); border: 1px solid var(--line); border-radius: 5px; }
.system-card span { color: var(--muted); font-size: 11px; }
.system-card strong { display: block; font-size: 23px; margin: 12px 0 10px; direction: ltr; text-align: right; }
.progress { height: 6px; background: #e7edf2; border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--blue); border-radius: inherit; }
.service-status { max-width: 740px; padding: 18px; }
.service-status h3, .settings-section h3, .certificate-section h3 { margin: 0 0 18px; font-size: 15px; }
.service-row { min-height: 47px; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); }
.settings-layout { display: grid; grid-template-columns: minmax(400px, 1fr) 320px; gap: 18px; }
.settings-section, .certificate-section { margin-top: 0; padding: 20px; }
.certificate-section p { color: var(--muted); margin: 0 0 23px; direction: ltr; text-align: right; }

.backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(12, 28, 42, .42); backdrop-filter: blur(2px); }
.drawer { position: fixed; inset: 0 0 0 auto; z-index: 60; width: min(520px, 100%); background: var(--paper); box-shadow: var(--shadow); display: none; flex-direction: column; }
.drawer.open { display: flex; }
.drawer-header { min-height: 82px; padding: 17px 21px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.drawer-header h2 { margin: 5px 0 0; font-size: 20px; }
.eyebrow { color: var(--blue); font-size: 11px; font-weight: 700; }
.drawer-body { padding: 22px; overflow-y: auto; display: flex; flex-direction: column; flex: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 17px 14px; }
.form-stack, .single-column { display: grid; grid-template-columns: 1fr; gap: 16px; }
.form-grid label, .form-stack label { display: grid; gap: 7px; font-size: 12px; font-weight: 700; color: #465866; }
.span-2 { grid-column: 1 / -1; }
.switch-row { margin-top: 23px; min-height: 64px; padding: 12px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.switch-row strong, .switch-row small { display: block; }
.switch-row small { margin-top: 5px; color: var(--muted); font-size: 10px; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch-row i { width: 42px; height: 23px; border-radius: 12px; background: #b8c4ce; position: relative; transition: background .2s; }
.switch-row i::after { content: ""; position: absolute; top: 3px; right: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch-row input:checked + i { background: var(--green); }
.switch-row input:checked + i::after { transform: translateX(-19px); }
.drawer-footer { margin-top: auto; padding-top: 20px; display: flex; justify-content: flex-end; gap: 9px; }
.form-error { min-height: 18px; margin: 12px 0 0; color: var(--red); font-size: 11px; }

dialog { width: min(700px, calc(100% - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); color: var(--ink); }
dialog::backdrop { background: rgba(12, 28, 42, .48); backdrop-filter: blur(2px); }
.dialog-header { min-height: 82px; padding: 15px 19px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.dialog-header > div { display: flex; align-items: center; gap: 12px; }
.dialog-header h2 { margin: 0 0 5px; font-size: 18px; }
.dialog-header p { margin: 0; color: var(--muted); font-size: 11px; }
.success-mark { width: 39px; height: 39px; display: grid; place-items: center; border-radius: 50%; color: var(--green); background: var(--green-soft); font-size: 21px; }
.result-endpoint { margin: 18px 20px; padding: 13px 15px; background: var(--blue-soft); border: 1px solid #cbe8f8; display: flex; align-items: center; justify-content: space-between; border-radius: 4px; }
.result-endpoint span { color: var(--muted); font-size: 11px; }
.code-label { display: grid; gap: 7px; margin: 0 20px; font-size: 11px; font-weight: 700; }
.code-label textarea { width: 100%; min-height: 190px; resize: vertical; padding: 12px; font: 12px/1.6 Consolas, monospace; text-align: left; background: #10202e; color: #d9e7f0; border: 0; }
.dialog-actions { padding: 16px 20px 20px; display: flex; justify-content: flex-end; gap: 8px; }
.confirm-dialog { max-width: 430px; padding: 24px; }
.confirm-dialog h2 { margin: 0 0 10px; font-size: 18px; }
.confirm-dialog p { margin: 0; color: var(--muted); line-height: 1.8; }
.confirm-dialog .dialog-actions { padding: 24px 0 0; }
.toast-region { position: fixed; z-index: 100; left: 20px; bottom: 20px; display: grid; gap: 8px; width: min(360px, calc(100% - 40px)); }
.toast { padding: 13px 15px; background: #132b3c; color: #fff; border-radius: 5px; box-shadow: var(--shadow); animation: toast-in .22s ease; }
.toast.error { background: #9e2835; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

@media (max-width: 1180px) {
  .summary-band { grid-template-columns: repeat(3, 1fr); }
  .metric:nth-child(3)::after { display: none; }
  .connection-row { grid-template-columns: minmax(180px, 1fr) repeat(2, 1fr) auto; }
  .connection-row > :nth-child(4), .connection-row > :nth-child(5) { display: none; }
}

@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar { display: none; box-shadow: var(--shadow); }
  .sidebar.open { display: flex; }
  .page { width: 100%; }
  .menu-button { display: grid; }
  .content { padding: 14px; }
  .summary-band { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(2)::after, .metric:nth-child(4)::after { display: none; }
  .section-header { align-items: flex-start; }
  .connections-section .section-header { display: grid; }
  .section-actions { flex-wrap: wrap; }
  .search { min-width: 100%; }
  .lower-grid, .settings-layout { grid-template-columns: 1fr; }
  .system-grid { grid-template-columns: repeat(2, 1fr); }
  .connection-row { grid-template-columns: 1fr 1fr auto; }
  .connection-row > :nth-child(3), .connection-row > :nth-child(4), .connection-row > :nth-child(5) { display: none; }
}

@media (max-width: 560px) {
  .topbar { height: 68px; padding: 0 13px; }
  .topbar h1 { font-size: 17px; }
  .topbar p, .live-indicator, #lastUpdate { display: none; }
  .summary-band { grid-template-columns: 1fr 1fr; }
  .metric { padding: 14px 11px; grid-template-columns: 35px 1fr; gap: 8px; }
  .metric-icon { width: 35px; height: 35px; font-size: 17px; }
  .metric span { white-space: normal; margin-bottom: 4px; }
  .metric strong { font-size: 16px; }
  .section-actions select { flex: 1; }
  .section-actions .button { flex: 1; }
  .lower-grid { gap: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .drawer-body { padding: 17px; }
  .connection-row { grid-template-columns: 1fr auto; }
  .connection-row > :not(:first-child):not(:last-child) { display: none; }
  .system-grid { grid-template-columns: 1fr; }
  .page-heading { align-items: flex-start; }
  .dialog-actions { flex-direction: column; }
  .dialog-actions .button { width: 100%; }
}
