:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #6f7c91;
  --line: #dce4ef;
  --blue: #155eef;
  --blue-dark: #0f46b8;
  --navy: #111827;
  --green: #148447;
  --red: #c5343d;
  --amber: #9a6700;
  --violet: #6046c9;
  --shadow: 0 16px 40px rgba(23, 32, 51, 0.08);
}

* { box-sizing: border-box; }
html { overflow-x: hidden; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, #eaf1ff 0, rgba(234, 241, 255, 0) 330px),
    var(--bg);
  overflow-x: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 72px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 28px;
  border-bottom: 1px solid rgba(17, 24, 39, 0.12);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
}

.brand, .top-actions, .actions, .toolbar, .filters, .bulkbar, .row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.brand, .brand > div, .top-actions { min-width: 0; }
.brand strong { display: block; font-size: 20px; }
.brand strong, .brand span { overflow: hidden; text-overflow: ellipsis; }
.brand span { display: block; color: var(--muted); font-size: 13px; }
.brand-mark {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--navy), var(--blue));
  color: white;
  font-weight: 800;
  letter-spacing: 0;
}
.brand-mark.small { width: 40px; height: 40px; }

.layout { padding: 28px; display: grid; gap: 22px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 22px; align-items: start; }
.workspace.slim { grid-template-columns: minmax(0, 1fr) 420px; }

.stats article, .panel, .login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.stats article { padding: 18px; min-height: 104px; }
.stats article:first-child { background: linear-gradient(135deg, #111827, #173b7a); color: white; }
.stats article:first-child span { color: rgba(255,255,255,.72); }
.stats article:first-child strong { color: white; }
.stats span { display: block; color: var(--muted); margin-bottom: 12px; font-size: 13px; }
.stats strong { display: block; color: var(--blue); font-size: 26px; overflow: hidden; text-overflow: ellipsis; }

.panel { padding: 20px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.panel-head.compact { align-items: center; }
.panel-head.subhead { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
h1, h2 { margin: 0; font-weight: 700; }
h2 { font-size: 18px; }
p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

button {
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  color: white;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  min-height: 38px;
  max-width: 100%;
  white-space: nowrap;
}
button:hover { background: var(--blue-dark); }
button.secondary { background: #26344d; }
button.secondary:hover { background: #172033; }
button.ghost { background: transparent; color: var(--blue); border: 1px solid var(--line); }
button.danger { background: var(--red); }
button.mini { min-height: 30px; padding: 6px 9px; font-size: 12px; }

.grid-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; align-items: end; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  color: var(--ink);
  font: inherit;
  background: white;
  min-height: 42px;
}
textarea { resize: vertical; min-height: 96px; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(11, 99, 246, 0.16);
  border-color: var(--blue);
}
.wide { grid-column: span 2; }
.stack-form { display: grid; gap: 12px; }

.client-cards { display: grid; gap: 10px; }
.client-card {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  padding: 12px;
  border-radius: 8px;
  min-height: 74px;
  text-align: left;
  background: #f8fafc;
  border: 1px solid var(--line);
  color: var(--ink);
}
.client-card:hover, .client-card.selected { background: #eaf2ff; border-color: #a9c9ff; }
.client-card span { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.client-card strong { color: var(--blue); }
.client-card small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 16px; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; }
.account-card, .order-card { align-items: center; }

.server-grid, .plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 18px;
}
.server-card, .plan-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.server-card h3, .plan-card h3 { margin: 4px 0 0; font-size: 17px; }
.server-card dl {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 6px 10px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
.server-card dt { font-weight: 700; color: var(--ink); }
.server-card dd { margin: 0; overflow: hidden; text-overflow: ellipsis; }
.plan-card strong { color: var(--blue); font-size: 24px; }
.plan-card small { color: var(--muted); min-height: 18px; }
.card-actions, .pay-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.payment-info {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.payment-info a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  color: white;
  background: var(--navy);
  text-decoration: none;
  font-weight: 700;
}

.filters {
  display: grid;
  grid-template-columns: 220px 220px 180px minmax(260px, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}
body[data-role="customer"] .filters {
  grid-template-columns: 220px 180px minmax(260px, 1fr);
}
.bulkbar {
  justify-content: flex-start;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}
.bulkbar span { color: var(--muted); font-weight: 700; margin-right: auto; }

.table-wrap { max-width: 100%; overflow: auto; border: 1px solid var(--line); border-radius: 8px; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; min-width: 1360px; background: white; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 1; background: #f8fafc; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0; }
tbody tr { transition: background 120ms ease; }
tbody tr:hover { background: #eef5ff; }
code { font-family: "Cascadia Mono", Consolas, monospace; font-size: 12px; }
.proxy-cell { cursor: copy; max-width: 420px; overflow: hidden; text-overflow: ellipsis; }

.pill, .sync-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef1f6;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.pill.ok, .sync-pill { background: #e7f7ee; color: var(--green); }
.pill.expired { background: #fff4d9; color: var(--amber); }
.pill.disabled { background: #f0eefb; color: var(--violet); }
.expired-row { background: #fffaf0; }
.disabled-row { background: #f8f7ff; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #172033;
  color: white;
  padding: 12px 14px;
  border-radius: 7px;
  opacity: 0;
  transform: translateY(8px);
  transition: 160ms ease;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateY(0); }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 10%, rgba(21, 94, 239, .16), transparent 34%),
    linear-gradient(135deg, #f6f8fb, #e9eef7);
}
.login-shell { width: min(420px, calc(100vw - 32px)); }
.login-panel { padding: 30px; }
.login-panel p { color: var(--muted); }
.login-form { display: grid; gap: 14px; margin-top: 22px; }
.login-form button { width: 100%; }
.alert { padding: 10px 12px; color: var(--red); background: #fff0f1; border-radius: 6px; }

@media (max-width: 1200px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .workspace, .workspace.slim { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
  .grid-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters, body[data-role="customer"] .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side-panel { order: 2; }
}

@media (max-width: 760px) {
  .stats, .grid-form, .filters, body[data-role="customer"] .filters { grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .layout { padding: 16px; }
  .topbar { align-items: flex-start; padding: 14px 16px; display: grid; grid-template-columns: 1fr; }
  .top-actions { width: 100%; justify-content: flex-start; }
  .panel-head { display: grid; }
  .panel { padding: 16px; }
  .stats article { min-height: 88px; }
  .stats strong { font-size: 22px; }
  .actions, .bulkbar, .row-actions, .card-actions { align-items: stretch; }
  .actions button, .bulkbar button, .card-actions button, .top-actions button { flex: 1 1 auto; }
  .client-card, .account-card, .order-card { grid-template-columns: 1fr; }
  .server-grid, .plan-grid { grid-template-columns: 1fr; }
  .proxy-cell { max-width: 260px; }
  .toast { left: 16px; right: 16px; bottom: 16px; }
}

@media (max-width: 460px) {
  .layout { padding: 12px; gap: 14px; }
  .panel { padding: 14px; }
  .brand strong { font-size: 18px; }
  .brand-mark.small { width: 36px; height: 36px; }
  .user-chip, .sync-pill { width: 100%; justify-content: center; }
  button { width: 100%; }
  .bulkbar span { width: 100%; margin-right: 0; }
  .server-card dl { grid-template-columns: 1fr; }
  th, td { padding: 10px 12px; }
}
