:root{--bg:#eef4fb;--surface:#fff;--surface2:#e3ecf7;--ink:#14202e;--muted:#68778a;--brand:#8b1e3f;--brand2:#c23b63;--ok:#168b5b;--warn:#d4a72c;--bad:#c74848;--radius:14px}
*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--ink);font-family:Inter,system-ui,-apple-system,sans-serif;font-size:14px}body.dark{--bg:#0d1520;--surface:#16212f;--surface2:#1e2c3d;--ink:#e6eef7;--muted:#9aabba}
.sidebar{position:fixed;inset:0 auto 0 0;width:240px;background:var(--surface);padding:24px 16px;box-shadow:8px 0 30px rgba(20,32,46,.05)}main{margin-left:240px;padding:20px 24px;min-height:100vh}.brand{display:flex;align-items:center;gap:10px;color:var(--ink);text-decoration:none;margin-bottom:32px}.brand-mark{display:grid;place-items:center;width:42px;height:42px;border-radius:14px;background:linear-gradient(145deg,var(--brand2),var(--brand));color:#fff;font-weight:800;font-size:20px}.sidebar nav{display:grid;gap:6px}.sidebar nav a{padding:12px 14px;border-radius:12px;color:var(--muted);text-decoration:none}.sidebar nav a.active{background:var(--surface2);color:var(--brand);font-weight:700}.logout{position:absolute;bottom:24px;border:0;background:none;color:var(--muted)}
.card{background:var(--surface);border-radius:var(--radius);box-shadow:0 6px 18px rgba(20,32,46,.055);padding:14px}.page-head,.section-title{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:12px}.page-head h1{font-size:24px;margin:2px 0}.page-head .eyebrow{font-size:12px}.card h2{font-size:16px;margin:0 0 10px}.eyebrow{color:var(--brand);margin:0;font-weight:700}.metrics-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:12px;margin-bottom:12px}.metric{height:76px;padding:10px 14px}.metric span,.metric small{display:block;color:var(--muted);font-size:12px}.metric strong{display:block;font-size:24px;line-height:1.05;margin-top:7px}.metric .metric-rate{font-size:19px}.metric .metric-medium{font-size:20px}
.dashboard-grid{display:grid;grid-template-columns:minmax(220px,.8fr) minmax(320px,1.2fr);gap:12px;margin-bottom:12px}.services-card,.server-load-card{min-width:0}.service-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:8px}.service-item{position:relative;min-width:0;border:1px solid var(--surface2);border-radius:10px;padding:8px}.service-item summary{list-style:none;display:grid;grid-template-columns:auto minmax(0,1fr) auto;align-items:center;gap:7px;cursor:pointer;font-size:12px}.service-item summary::-webkit-details-marker{display:none}.service-item summary span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.service-item summary b{font-size:10px;font-weight:600;color:var(--muted);text-transform:none}.service-item form{position:absolute;z-index:5;right:4px;top:100%;display:none}.service-item[open] form{display:block}.service-restart{font-size:11px;padding:7px 9px}.status-dot{width:8px;height:8px;border-radius:50%;background:#98a3af}.status-dot.active{background:var(--ok)}.status-dot.failed,.status-dot.offline{background:var(--bad)}.status-dot.unknown{background:#98a3af}
.server-summary{display:grid;grid-template-columns:repeat(4,1fr);gap:8px;margin-bottom:7px;font-size:12px}.server-summary>span{border-radius:8px;background:var(--surface2);padding:7px;white-space:nowrap}.tunnel-status{color:var(--muted);font-size:11px;margin-bottom:2px}.server-load-card canvas{height:140px!important;width:100%!important}.load-dots{display:inline-flex;gap:3px;vertical-align:middle}.load-dots i{width:6px;height:6px;border-radius:50%;background:var(--surface2)}.load-dots.low i:first-child,.load-dots.medium i:nth-child(-n+2),.load-dots.high i{background:var(--brand)}
.clients-card{padding-bottom:8px}.clients-toolbar{align-items:center}.table-tools{display:flex;align-items:center;gap:8px}.table-tools .search{width:180px}.text-link{font-size:12px;color:var(--brand);white-space:nowrap;text-decoration:none}.table-wrap{overflow-x:auto}table{width:100%;border-collapse:collapse;font-size:13px}th,td{text-align:left;padding:6px 8px;border-bottom:1px solid var(--surface2);white-space:nowrap;height:36px}th{height:32px;color:var(--muted);font-size:11px;font-weight:600}.status-pill{border-radius:999px;padding:3px 7px;background:var(--surface2);color:var(--muted);font-size:11px}.status-pill.online,.status-pill.active{color:var(--ok)}.status-pill.offline,.status-pill.failed{color:var(--bad)}
.list-row{display:flex;justify-content:space-between;padding:8px 0;border-bottom:1px solid var(--surface2)}input,select{border:1px solid var(--surface2);border-radius:10px;background:var(--surface);color:var(--ink);padding:8px 10px;font-size:13px}.search,select{height:34px}.primary,button{border:0;border-radius:10px;background:var(--brand);color:#fff;padding:8px 12px}.icon-btn{text-decoration:none;color:var(--brand);font-size:20px}.warning{border-left:4px solid var(--warn);margin-bottom:12px}.muted{color:var(--muted);font-size:12px}.logs{height:55vh;overflow:auto;background:#101823;color:#dce8f6;border-radius:14px;padding:16px}.login-page{min-height:100vh;display:grid;place-items:center}.login-card{width:min(390px,calc(100vw - 32px));text-align:center}.login-card form{display:grid;gap:14px;text-align:left}.login-card label{display:grid;gap:6px}.login-card h1{margin-bottom:4px}.login-card p{color:var(--muted)}.alert.error{background:#ffe9ee;color:#8b1e3f;padding:10px;border-radius:12px}.toast{position:fixed;right:20px;bottom:20px}.settings-form{display:grid;gap:12px}.grid-2{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:12px;margin-bottom:12px}
@media(max-width:1100px){.sidebar{width:210px}main{margin-left:210px}.metrics-grid{grid-template-columns:repeat(4,minmax(150px,1fr))}.service-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.dashboard-grid{grid-template-columns:1fr}}
@media(max-width:900px){.sidebar{position:static;width:auto;height:auto}.sidebar nav{grid-template-columns:repeat(5,1fr);overflow:auto}.sidebar nav a{white-space:nowrap;text-align:center}.brand{margin-bottom:12px}.logout{position:static}main{margin-left:0;padding:16px}.metrics-grid{grid-template-columns:repeat(3,minmax(130px,1fr))}.dashboard-grid{grid-template-columns:1fr}}
@media(max-width:520px){main{padding:12px}.sidebar nav{grid-template-columns:repeat(3,1fr)}.metrics-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.metric{height:72px}.service-grid{grid-template-columns:1fr 1fr}.server-summary{grid-template-columns:repeat(2,1fr)}.clients-toolbar{align-items:flex-start;flex-direction:column}.table-tools{width:100%;flex-wrap:wrap}.table-tools .search{width:100%}.dashboard-grid{grid-template-columns:minmax(0,1fr)}.card{padding:12px}}

.servers-page{height:calc(100vh - 40px);display:flex;flex-direction:column;min-height:0;overflow:hidden}
.servers-page>.page-head{flex:0 0 auto}
.servers-page>.warning{flex:0 0 auto}
.server-grid{flex:1 1 auto;min-height:0;display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));grid-auto-rows:max-content;gap:12px;overflow:auto;padding:0 2px 12px;align-content:start}
.server-card{min-width:0;height:auto}.server-card h2{font-size:17px;margin:4px 0}
.server-card-head,.server-state{display:flex;align-items:center;gap:7px}.country-code{font-weight:700;font-size:10px;border-radius:7px;background:var(--surface2);padding:3px 6px}.tier-pill{margin-left:auto;border-radius:999px;background:var(--surface2);padding:3px 7px;font-size:11px}.tier-pill.pro{color:var(--brand)}
.server-dots{display:flex;justify-content:space-between;margin:10px 0;font-size:12px;color:var(--muted)}
.server-facts{display:grid;gap:5px;margin:0}.server-facts div{display:grid;grid-template-columns:90px minmax(0,1fr);font-size:12px}.server-facts dt{color:var(--muted)}.server-facts dd{margin:0;overflow:hidden;text-overflow:ellipsis}
.server-actions{margin-top:8px;border-top:1px solid var(--surface2);padding-top:5px}.server-actions summary{cursor:pointer;font-size:12px;color:var(--brand);font-weight:700}.server-actions form{display:grid;gap:7px;margin-top:8px}.server-actions label{display:grid;gap:3px;font-size:12px}.server-actions .check{grid-template-columns:16px 1fr;align-items:center;gap:7px;min-height:28px;margin:0}.server-actions .check input{width:16px;height:16px;margin:0;accent-color:var(--brand)}.server-actions input,.server-actions select{height:32px;width:100%}
.inline-action,.delete-server{grid-template-columns:1fr auto!important}.delete-server button{background:#a83d49}
.server-create-form{width:min(520px,calc(100vw - 32px));display:grid;gap:10px;border:0;border-radius:14px;padding:18px}.server-create-form header{display:flex;justify-content:space-between;align-items:center}.server-create-form label{display:grid;gap:4px}.server-create-form input,.server-create-form select{height:36px}.server-create-form .muted{color:var(--muted);font-size:12px}

.server-load-card{flex:0 0 auto!important;align-self:start;min-height:0;display:block}
.server-load-card h2{margin-bottom:6px}
.load-bars{display:grid;gap:5px;margin-top:5px}
.load-bars>div>span{display:flex;justify-content:space-between;font-size:11px}
.load-bars>div>i{display:block;height:5px;border-radius:4px;background:var(--surface2);overflow:hidden}
.load-bars>div>i>em{display:block;height:100%;background:var(--brand)}
.load-lines{display:grid;grid-template-columns:repeat(2,1fr);grid-auto-rows:28px;flex:none;gap:4px;font-size:11px;margin-top:7px}
.load-lines span{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;gap:8px;background:var(--surface2);border-radius:7px;padding:5px 7px}
.load-lines span b{min-width:max-content;text-align:right}
.servers-card{min-height:0;max-height:190px;flex:0 0 auto!important;overflow:hidden}
.server-list{max-height:150px;overflow-y:auto}
.server-row{min-height:30px;display:grid;grid-template-columns:auto minmax(80px,1fr) auto minmax(90px,.8fr) minmax(150px,1fr);align-items:center;gap:8px;border-bottom:1px solid var(--surface2);color:var(--ink);text-decoration:none;font-size:12px}
.charts-card{height:auto;max-height:none;min-height:0;flex:0 0 auto!important;overflow:hidden}
.charts-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;height:auto}
.mini-chart-card{height:clamp(120px,18vh,180px);min-width:0;border:1px solid var(--surface2);border-radius:10px;padding:5px 7px;overflow:hidden}
.mini-chart-wrap{position:relative;height:calc(100% - 22px);min-width:0;overflow:hidden}
.mini-chart-card canvas{display:block;width:100%!important;height:100%!important}
.chart-mini-head{height:22px;display:flex;align-items:center;justify-content:space-between;font-size:11px}
.chart-mini-head small{font-size:9px;color:var(--muted)}
.chart-mini-head i{display:inline-block;width:7px;height:2px;margin-left:7px}
.legend-rx{background:#168b5b}.legend-tx{background:#c23b63}
@media(max-width:900px){.charts-grid{grid-template-columns:1fr;height:auto}.mini-chart-card{height:150px}.server-row{grid-template-columns:auto 1fr auto}}

/* Fixed, viewport-aware dashboard layout. */
html,body{height:100dvh;overflow:hidden}
.sidebar{width:192px;padding:18px 12px}
main{margin-left:192px;height:100dvh;overflow:hidden;padding:10px clamp(10px,1vw,16px)}
.dashboard{height:100%;min-height:0;display:grid;grid-template-rows:auto clamp(56px,8vh,72px) minmax(0,1fr);gap:10px}
.dashboard-head{height:40px;margin:0}
.dashboard-head h1{font-size:clamp(18px,1.5vw,22px)}
.dashboard-head .status-pill{font-size:11px}
.metrics-grid{grid-template-columns:repeat(8,minmax(0,1fr));gap:8px;margin:0;height:100%}
.metric{height:100%;min-width:0;padding:8px 10px;border-radius:12px}
.metric>span{font-size:clamp(10px,.65vw,12px);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.metric strong{font-size:clamp(17px,1.4vw,20px);margin-top:3px}
.metric .metric-rate{font-size:clamp(14px,1.1vw,17px)}
.metric small{font-size:10px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.dashboard-content{min-height:0;display:grid;grid-template-columns:minmax(260px,1fr) minmax(520px,2fr);gap:10px}
.left-column,.right-column{min-height:0;display:flex;flex-direction:column;gap:10px}
.services-card{flex:0 0 auto;min-height:0;padding:10px 12px}
.card h2{font-size:clamp(14px,1vw,15px);margin-bottom:7px}
.service-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:6px;overflow:auto}
.service-item{height:38px;padding:0 6px;border-radius:8px;display:flex;align-items:center}
.service-main{width:100%;min-width:0;display:grid;grid-template-columns:auto minmax(0,1fr) auto auto;align-items:center;gap:5px;font-size:11px}
.service-main>span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.service-label{display:block;overflow:hidden;text-overflow:ellipsis;color:var(--ink);font-size:11px;font-weight:700}
.service-unit{display:block;overflow:hidden;text-overflow:ellipsis;color:var(--muted);font-size:8px;font-weight:400}
.service-status{font-size:9px;font-style:normal;color:var(--muted)}
.service-main>b{font-size:9px;color:var(--muted)}
.service-menu{width:22px;height:22px;padding:0;background:transparent;color:var(--muted);font-size:16px}
.service-item form{right:4px;top:34px;z-index:20;box-shadow:0 4px 14px rgba(20,32,46,.16);display:none}
.service-item.open form{display:block}
.server-load-card{width:100%;padding:10px 12px;overflow:hidden}
.server-summary{grid-template-columns:repeat(2,1fr);gap:5px;margin:0 0 6px;font-size:11px}
.server-summary>span{padding:5px 6px}
.load-lines{display:grid;grid-template-columns:1fr 1fr;grid-auto-rows:28px;flex:none;gap:4px;font-size:11px;color:var(--muted)}
.load-lines span{padding:3px 6px;border-radius:7px;background:var(--surface2)}
.load-lines b{float:right;color:var(--ink)}
.chart-card{flex:1;min-height:160px;display:flex;flex-direction:column;padding:10px 12px}
.chart-head{display:flex;align-items:center;justify-content:space-between}
.chart-head h2{margin:0}
.periods{display:flex;gap:3px}
.period{height:24px;padding:0 8px;background:var(--surface2);color:var(--muted);font-size:11px}
.period.active{background:var(--brand);color:#fff}
.chart-legend{display:flex;gap:8px;margin-left:auto;margin-right:8px;color:var(--muted);font-size:10px}
.chart-legend span::before{content:"";display:inline-block;width:8px;height:2px;margin-right:3px;vertical-align:middle;background:currentColor}
.legend-online{color:#8b1e3f}.legend-rx{color:#168b5b}.legend-tx{color:#c23b63}
.chart-wrap{position:relative;min-height:0;flex:1}
.chart-wrap canvas{width:100%!important;height:100%!important}
.clients-card{flex:1;min-height:0;padding:10px 12px 6px;display:flex;flex-direction:column}
.clients-toolbar{margin:0 0 5px;height:32px}
.table-tools{gap:6px}
.table-tools .search{width:clamp(120px,16vw,210px)}
.table-tools input,.table-tools select{height:32px;font-size:12px;padding:5px 9px}
.text-link{height:32px;display:inline-flex;align-items:center;padding:0 10px;border-radius:9px;background:var(--surface2)}
.table-wrap{min-height:0;overflow:auto;flex:1}
table{font-size:13px}
thead{position:sticky;top:0;background:var(--surface);z-index:2}
th{height:30px;padding:4px 8px}
td{height:34px;padding:3px 8px}
.status-pill{padding:2px 7px}

@media(max-height:820px){
  .dashboard{grid-template-rows:auto clamp(54px,7.4vh,62px) minmax(0,1fr);gap:7px}
  .dashboard-head{height:34px}
  main{padding-top:7px;padding-bottom:7px}
  .dashboard-content,.left-column,.right-column{gap:7px}
  .card{padding-top:8px;padding-bottom:8px}
  .service-item{height:34px}
  .chart-card{min-height:145px}
  th{height:28px}td{height:32px;padding-top:2px;padding-bottom:2px}
}
@media(max-width:1099px){
  .metrics-grid{grid-template-columns:repeat(4,minmax(0,1fr))}
  .dashboard{grid-template-rows:auto 124px minmax(0,1fr)}
}
@media(max-width:899px){
  html,body{height:auto;overflow-y:auto;overflow-x:hidden;max-width:100vw}
  .sidebar{position:static;width:auto;height:auto}
  main{margin-left:0;height:auto;overflow-x:hidden;width:100%}
  .dashboard{height:auto;display:block}
  .metrics-grid{height:auto;grid-template-columns:repeat(2,minmax(0,1fr));margin:10px 0}
  .metric{height:72px}
  .dashboard-content{display:grid;grid-template-columns:1fr}
  .left-column,.right-column{display:contents}
  .services-card,.server-load-card,.chart-card,.clients-card{min-height:auto;margin-bottom:10px}
  .chart-wrap{height:220px}
  .table-wrap{max-height:420px;width:100%}
  .clients-card,.chart-card{width:100%;overflow:hidden}
  .clients-toolbar{height:auto!important;align-items:flex-start;flex-direction:column}
  .table-tools{flex-wrap:wrap}
  .table-tools .search{width:100%;flex-basis:100%}
}
