/* =============================================================
   TBPanel admin UI — sidebar layout + content
   ============================================================= */

* { box-sizing: border-box; }

:root {
  --bg:        #f4f6fa;
  --panel:     #ffffff;
  --ink:       #111827;
  --ink-soft:  #6b7280;
  --line:      #e5e7eb;
  --line-strong: #d1d5db;
  --brand:     #ffffff;
  --brand-ink: #111827;
  --accent:    #2563eb;
  --accent-h:  #1d4ed8;
  --accent-soft: #eff6ff;
  --danger:    #dc2626;
  --danger-h:  #b91c1c;
  --sidebar-w: 232px;
  --topbar-h:  60px;
}

html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

/* ---------- Public layout (login / signup) ---------- */
body.layout-public {
  display: block;
  background: var(--bg);
}
/* Reset the shared `main.content` dashboard chrome (1.5rem padding +
   1280px max-width) so the marketing/login surfaces can paint edge-to-edge.
   Without this the 1280px ceiling squeezes the login card into the middle
   of a wide viewport and leaves a ~200px gutter on either side that the
   .login-shell radial-gradient then has to bleed across, which reads as
   the page "floating" instead of being framed. */
.layout-public .content-public {
  display: block;
  max-width: none;
  padding: 0;
  width: auto;
}

/* ---------- Login card + tabs (shared by /login and /signup) ---------- */
.login-shell {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 2rem 1rem;
}
.login-card {
  max-width: 26rem; width: 100%;
  padding: 2rem 2rem 1.5rem;
  background: var(--panel);
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.login-header { display: flex; align-items: center; gap: .65rem; margin-bottom: .75rem; }
.login-title { margin: 0; font-size: 1.35rem; font-weight: 700; color: var(--ink); }
.login-tabs {
  display: flex; gap: .25rem; margin: 0 0 1rem; padding: .25rem;
  background: var(--bg);
  border-radius: 8px;
}
.login-tab {
  flex: 1 1 0; text-align: center; padding: .5rem .25rem;
  border-radius: 6px; color: var(--ink-soft); text-decoration: none;
  font-size: .9em; font-weight: 600;
}
.login-tab.is-active {
  background: var(--panel); color: var(--ink);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.login-tab:hover { color: var(--ink); }
.login-card form { display: flex; flex-direction: column; gap: .5rem; }
.login-card form label { margin-top: .25rem; font-size: .85em; }
.login-card form input {
  padding: .6rem .8rem; border: 1px solid var(--line-strong);
  border-radius: 6px; font: inherit; font-size: .95rem;
}
.login-card form button.primary {
  margin-top: .75rem; padding: .65rem 1rem; border: 0; border-radius: 6px;
  background: var(--ink); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
.login-card form button.primary:hover { background: #2a2a2a; }
.login-card .err {
  background: #fdecea; color: #8a1f17; border: 1px solid #f5c2c0;
  padding: .6rem .8rem; border-radius: 6px; margin-bottom: 1rem; font-size: .9em;
}
.login-lang { margin-top: 1rem; font-size: .85rem; }
.login-lang a { color: var(--ink-soft); text-decoration: none; padding: .25rem .5rem; border-radius: 4px; }
.login-lang a:hover { background: var(--line); color: var(--ink); }
.captcha-row { display: flex; flex-direction: column; gap: .35rem; margin-top: .25rem; }
.captcha-label { margin: 0; }
.captcha-input-wrap { display: flex; align-items: center; gap: .55rem; }
.captcha-input-wrap input { flex: 1 1 auto; min-width: 0; }
.captcha-img {
  flex: 0 0 auto; width: 130px; height: 44px;
  border: 1px solid var(--line-strong); border-radius: 6px;
  cursor: pointer; user-select: none; background: var(--bg);
}
.captcha-img:hover { border-color: var(--ink-soft); }
.captcha-help { margin: 0; }

/* ---------- App shell (sidebar + topbar + content) ---------- */

body.layout-app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr;
  grid-template-areas:
    "sidebar main";
  min-height: 100vh;
}

aside.sidebar {
  grid-area: sidebar;
  background: var(--brand);
  color: var(--brand-ink);
  display: flex;
  flex-direction: column;
  padding: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid var(--line);
}

aside.sidebar .brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: 1rem 1.1rem;
  color: var(--brand-ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  width: 28px; height: 28px;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: -.5px;
}
.brand-text { letter-spacing: -.2px; }

nav.sidenav {
  display: flex;
  flex-direction: column;
  padding: .65rem .65rem;
  gap: 2px;
  flex: 1 1 auto;
  overflow-y: auto;
}
nav.sidenav a {
  display: block;
  padding: .55rem .85rem;
  color: #374151;
  text-decoration: none;
  border-radius: 6px;
  font-size: .92rem;
}
nav.sidenav a:hover { background: #f3f4f6; color: var(--ink); }
nav.sidenav a.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* Grouped sections inside the sidebar — keeps related items close
   without forcing a separate top-level entry per area. */
nav.sidenav .nav-group { display: flex; flex-direction: column; gap: 2px; }
nav.sidenav .nav-group + .nav-group { margin-top: .75rem; }
nav.sidenav .nav-group-label {
  padding: .55rem .85rem .25rem;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
nav.sidenav .nav-group-admin { padding-top: .5rem; border-top: 1px solid var(--line); }

/* ---------- Admin sidebar (separate layout for /admin/*) ---------- */

/* The admin sidebar uses the same shell but a denser, dedicated menu.
   The badge under the brand makes the context explicit. */
body.layout-admin aside.sidebar { background: #0f172a; color: #e2e8f0; border-right-color: #1e293b; }
body.layout-admin aside.sidebar .brand { color: #f1f5f9; border-bottom-color: #1e293b; }
body.layout-admin aside.sidebar .brand .brand-mark { background: #38bdf8; color: #0f172a; }
body.layout-admin aside.sidebar .sidenav a { color: #cbd5e1; }
body.layout-admin aside.sidebar .sidenav a:hover { background: #1e293b; color: #f1f5f9; }
body.layout-admin aside.sidebar .sidenav a.active {
  background: #1d4ed8;
  color: #f1f5f9;
}
body.layout-admin aside.sidebar .nav-group-label { color: #64748b; }
body.layout-admin .admin-sidebar-badge {
  margin: .85rem .85rem 0;
  display: inline-flex;
}
body.layout-admin .admin-sidebar-badge .badge {
  background: #1d4ed8;
  color: #f1f5f9;
  font-size: .65rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}
body.layout-admin .nav-group-settings { margin-top: .5rem; padding-top: .85rem; border-top: 1px solid #1e293b; }
body.layout-admin .nav-group-back {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid #1e293b;
}
body.layout-admin .nav-group-back a { color: #94a3b8; font-size: .82rem; }
body.layout-admin .nav-group-back a:hover { background: #1e293b; color: #f1f5f9; }

/* Tenant chip inside the sidebar */
.tenant-chip {
  margin: .75rem .65rem .25rem;
  padding: .55rem .7rem;
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.tenant-name {
  font-size: .82rem;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tenant-plan {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: .1rem .45rem;
  border-radius: 999px;
  background: #f3f4f6;
  color: #374151;
}
.tenant-plan.plan-pro         { background: #dbeafe; color: #1e3a8a; }
.tenant-plan.plan-enterprise  { background: #fef3c7; color: #92400e; }
.tenant-plan.plan-free        { background: #f3f4f6; color: #4b5563; }

/* ---------- Topbar ---------- */

.app-main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

header.topbar {
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--topbar-h);
  flex: 0 0 auto;
}
header.topbar .page-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-left: auto;
}
.lang-switch {
  font-size: .82rem;
  color: var(--ink-soft);
  text-decoration: none;
  padding: .3rem .65rem;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.lang-switch:hover { background: #f3f4f6; color: var(--ink); }

/* Tenant badge (mirrors sidebar tenant-chip, shown in the topbar for visibility) */
.tenant-badge {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .25rem .55rem .25rem .7rem;
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: .82rem;
}
.tenant-badge .tenant-name {
  font-weight: 600;
  color: var(--ink);
}

/* ---------- User dropdown (top-right) ---------- */

.user-menu { position: relative; }
.user-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .25rem .75rem .25rem .3rem;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.user-menu-trigger:hover { border-color: var(--line-strong); }
.user-menu-trigger:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.user-avatar {
  width: 28px; height: 28px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
}
.user-menu-trigger .user-name {
  font-size: .88rem;
  font-weight: 600;
  color: var(--ink);
}
.user-menu-trigger .user-role {
  font-size: .68rem;
  background: var(--accent-soft);
  color: var(--accent);
  padding: .05rem .4rem;
  border-radius: 999px;
  font-weight: 600;
}
.user-caret {
  font-size: .75rem;
  color: var(--ink-soft);
  margin-left: .15rem;
}
.user-menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 25px -10px rgba(15,23,42,.25), 0 2px 4px rgba(15,23,42,.04);
  padding: .35rem;
  z-index: 20;
}
.user-menu-head {
  padding: .5rem .65rem .6rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: .25rem;
}
.user-menu-name {
  font-weight: 600;
  color: var(--ink);
  font-size: .9rem;
}
.user-menu-role {
  font-size: .72rem;
  color: var(--accent);
  font-weight: 600;
  margin-top: .1rem;
}
.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--ink);
  padding: .45rem .65rem;
  border-radius: 6px;
  font: inherit;
  font-size: .88rem;
  cursor: pointer;
  text-decoration: none;
}
.user-menu-item:hover { background: #f3f4f6; }
.user-menu-item:focus-visible {
  outline: none;
  background: var(--accent-soft);
  color: var(--accent);
}
.user-menu-logout { color: var(--danger); }
.user-menu-logout:hover { background: #fef2f2; }
.user-menu-form { margin: 0; }

main.content {
  padding: 1.5rem;
  flex: 1;
  max-width: 1280px;
  width: 100%;
}

/* ---------- Cards / tables ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.card {
  background: #fff;
  padding: 1rem 1.1rem;
  border-radius: .5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.card .num { font-size: 1.5rem; font-weight: 700; color: #111827; }
.card .lbl { color: var(--ink-soft); font-size: .85rem; margin-top: .25rem; }

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: .5rem;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
th, td {
  padding: .6rem .9rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
th { background: #f3f4f6; font-weight: 600; font-size: .85rem; color: #374151; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: #fafbfc; }

.badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: .25rem;
  font-size: .75rem;
  font-weight: 600;
  background: var(--line);
  color: #374151;
}
.badge.type-in     { background: #dbeafe; color: #1e40af; }
.badge.type-out    { background: #fef3c7; color: #92400e; }
.badge.status-active   { background: #d1fae5; color: #065f46; }
.badge.status-inactive { background: #fee2e2; color: #991b1b; }
.badge.status-suspended{ background: #fef3c7; color: #92400e; }
.badge.status-disabled { background: #e5e7eb; color: #4b5563; }
.badge.status-pending  { background: #dbeafe; color: #1e40af; }
.badge.status-paid     { background: #d1fae5; color: #065f46; }
.badge.status-error    { background: #fee2e2; color: #991b1b; }
.badge.proto-tcp   { background: #ede9fe; color: #5b21b6; }
.badge.proto-icmp  { background: #cffafe; color: #155e75; }

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  padding: .5rem 1rem;
  border-radius: .25rem;
  cursor: pointer;
  font-size: .9rem;
  font-family: inherit;
}
button:hover { background: var(--accent-h); }
button.danger { background: var(--danger); }
button.danger:hover { background: var(--danger-h); }

input, select {
  padding: .4rem .6rem;
  border: 1px solid var(--line);
  border-radius: .25rem;
  font-size: .9rem;
  background: #fff;
  font-family: inherit;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
label {
  display: flex;
  flex-direction: column;
  font-size: .85rem;
  color: #374151;
  gap: .25rem;
}

.row { display: flex; flex-wrap: wrap; gap: .75rem; align-items: end; }
.row label { flex: 1 1 160px; }

details.create-form {
  background: #fff;
  padding: .75rem 1rem;
  border-radius: .5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
  margin-bottom: 1rem;
}
details.create-form summary { cursor: pointer; font-weight: 600; }
details.create-form[open] summary { margin-bottom: .75rem; }

details.install-cmd { display: inline-block; margin-right: .5rem; }
details.install-cmd summary {
  background: var(--accent);
  color: #fff;
  padding: .35rem .75rem;
  border-radius: .25rem;
  font-size: .85rem;
  cursor: pointer;
}
details.install-cmd[open] summary { margin-bottom: .4rem; }
details.install-cmd textarea {
  width: 320px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .8rem;
  margin-bottom: .35rem;
}
.copy-btn { font-size: .8rem; padding: .3rem .65rem; }
.copied { margin-left: .35rem; color: #065f46; font-size: .8rem; }

.row-actions { white-space: nowrap; }

.route-loading {
  position: fixed;
  top: .75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem .75rem;
  color: #1e3a8a;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, .12);
  font-size: .82rem;
  font-weight: 600;
}
.route-loading[hidden] { display: none; }
.route-loading-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid #93c5fd;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: route-spin .7s linear infinite;
}
@keyframes route-spin { to { transform: rotate(360deg); } }

.err { background: #fee2e2; color: #991b1b; padding: .6rem 1rem; border-radius: .25rem; margin-bottom: 1rem; }
.ok  { background: #d1fae5; color: #065f46; padding: .6rem 1rem; border-radius: .25rem; margin-bottom: 1rem; }
.muted { color: var(--ink-soft); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }

/* ---------- Admin section tab nav ---------- */

nav.admin-tabs {
  display: flex;
  gap: .25rem;
  border-bottom: 1px solid var(--line);
  margin: -.25rem 0 1.25rem;
}
nav.admin-tabs a {
  display: inline-block;
  padding: .55rem .9rem;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: .9rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
nav.admin-tabs a:hover { color: var(--ink); }
nav.admin-tabs a.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.btn-link {
  color: var(--ink-soft);
  text-decoration: none;
  padding: .5rem .75rem;
  font-size: .88rem;
}
.btn-link:hover { color: var(--ink); }
.audit-summary { margin-top: .75rem; font-size: .85rem; }

details.inline-details { display: inline-block; vertical-align: middle; margin-right: .35rem; }
details.inline-details summary {
  background: var(--accent);
  color: #fff;
  padding: .35rem .75rem;
  border-radius: .25rem;
  font-size: .85rem;
  cursor: pointer;
  display: inline-block;
}
details.inline-details[open] summary { margin-bottom: .4rem; }
details.inline-details .inline-form { display: flex; flex-wrap: wrap; gap: .35rem; }
.inline-form { display: inline-flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { font-size: .85rem; padding: .3rem .5rem; }
.inline-form button.danger { font-size: .85rem; padding: .35rem .7rem; }
.tenant-slug { background: #f9fafb; padding: .1rem .35rem; border-radius: 4px; }

.button-link {
  display: inline-block;
  vertical-align: middle;
  background: var(--accent);
  color: #fff;
  padding: .35rem .75rem;
  border-radius: .25rem;
  font-size: .85rem;
  text-decoration: none;
  margin-right: .35rem;
}
.button-link:hover { background: var(--accent-h); }

.impersonation-indicator {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  color: #92400e;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 6px;
  padding: .25rem .35rem .25rem .65rem;
  font-size: .78rem;
  font-weight: 600;
}
.impersonation-indicator form { margin: 0; }
.impersonation-indicator button {
  padding: .3rem .55rem;
  background: #92400e;
  font-size: .78rem;
}
.impersonation-indicator button:hover { background: #78350f; }

.detail-heading,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.detail-heading { margin-bottom: 1rem; }
.detail-heading h2 { margin: .25rem 0 0; }
.detail-heading p { margin: .15rem 0 0; }
.detail-back { padding-left: 0; }
.detail-actions { display: flex; align-items: center; }
.detail-actions form { margin: 0; }
.tenant-detail-cards { margin-bottom: 1rem; }
.detail-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: .5rem;
  padding: 1rem;
  margin-bottom: 1rem;
  overflow-x: auto;
}
.detail-panel h3 { margin: 0 0 .8rem; font-size: 1rem; }
.section-heading h3 { margin-bottom: .8rem; }
.detail-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: .75rem;
  margin: 0;
}
.detail-list div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .65rem .75rem;
}
.detail-list dt { color: var(--ink-soft); font-size: .78rem; }
.detail-list dd { margin: .2rem 0 0; font-weight: 600; }
.audit-detail { max-width: 320px; overflow-wrap: anywhere; }

/* ---------- Dashboard ---------- */

/* Cards become clickable shortcuts to the relevant resource page. */
.dashboard-cards .card {
  text-decoration: none;
  color: inherit;
  display: block;
  transition: border-color .15s, box-shadow .15s, transform .15s;
  border: 1px solid transparent;
}
.dashboard-cards .card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px -4px rgba(37, 99, 235, .15);
  transform: translateY(-1px);
}

/* Quota bar: a labelled horizontal progress strip per resource. */
.quota-grid { display: flex; flex-direction: column; gap: .6rem; }
.quota-row {
  display: grid;
  grid-template-columns: 6rem 1fr 7rem;
  align-items: center;
  gap: .85rem;
}
.quota-label { font-size: .85rem; color: var(--ink-soft); }
.quota-bar {
  height: 8px;
  background: #f3f4f6;
  border-radius: 999px;
  overflow: hidden;
}
.quota-fill {
  height: 100%;
  background: var(--accent);
  transition: width .25s ease;
}
.quota-fill-warn { background: var(--danger); }
.quota-value { text-align: right; font-size: .85rem; color: var(--ink); }

/* Inline sparkline — a single 280×60 SVG. */
.spark { display: block; width: 100%; height: 60px; }

/* Event list on the dashboard — compact, one row per audit event. */
.event-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.event-item {
  display: grid;
  grid-template-columns: 11rem 8rem 10rem 1fr;
  align-items: center;
  gap: .75rem;
  padding: .5rem .25rem;
  border-bottom: 1px solid var(--line);
  font-size: .88rem;
}
.event-item:last-child { border-bottom: 0; }
.event-time { font-size: .78rem; white-space: nowrap; }
.event-actor { font-weight: 600; color: var(--ink); }
.event-action {
  background: var(--accent-soft);
  color: var(--accent);
  padding: .1rem .5rem;
  border-radius: 4px;
  font-size: .78rem;
  font-weight: 600;
  justify-self: start;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.event-target { font-size: .82rem; }

@media (max-width: 720px) {
  .quota-row { grid-template-columns: 1fr; }
  .quota-value { text-align: left; }
  .event-item { grid-template-columns: 1fr; gap: .15rem; padding: .65rem 0; }
}

/* Foldable JSON detail on the audit log. The table row stays compact;
   clicking "View JSON" reveals the full payload. */
.audit-detail-fold summary {
  cursor: pointer;
  font-size: .82rem;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .15rem .35rem;
  border-radius: 4px;
}
.audit-detail-fold summary:hover { background: var(--accent-soft); }
.audit-json {
  margin: .4rem 0 0;
  padding: .65rem .75rem;
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: .78rem;
  line-height: 1.45;
  max-width: 480px;
  max-height: 240px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Inline row edit — used by members + tenants for quick updates
   without leaving the table. */
.inline-edit summary {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  padding: .3rem .6rem;
  border-radius: 6px;
  font-size: .82rem;
  cursor: pointer;
  list-style: none;
  margin-right: .25rem;
}
.inline-edit summary::-webkit-details-marker { display: none; }
.inline-edit[open] summary { margin-bottom: .35rem; }
.inline-edit[open] summary { background: var(--accent-h); }
.inline-edit .inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  padding: .4rem 0;
}

/* Plan edit — multi-field form that opens inline under the row's edit
   button. Each label stacks its <span> above the input, and `.inline-edit-wide`
   elements span the full form width so multi-selects/checkboxes can breathe. */
.inline-edit-form {
  display: flex;
  flex-wrap: wrap;
  gap: .55rem .85rem;
  padding: .5rem 0 .25rem;
  min-width: 280px;
  max-width: 360px;
}
.inline-edit-form label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  flex: 1 1 140px;
  min-width: 0;
}
.inline-edit-form label > span {
  font-size: .78rem;
  color: var(--ink-soft);
  font-weight: 600;
}
.inline-edit-form input,
.inline-edit-form select {
  font-size: .85rem;
  padding: .3rem .5rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  width: 100%;
  min-width: 0;
}
.inline-edit-form .form-actions {
  flex: 1 1 100%;
  margin: .35rem 0 0;
}
.inline-edit-wide {
  flex: 1 1 100% !important;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  body.layout-app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "sidebar"
      "main";
  }
  aside.sidebar {
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    padding: .5rem .75rem;
  }
  aside.sidebar .brand { padding: 0; border: 0; }
  nav.sidenav {
    flex-direction: row;
    overflow-x: auto;
    padding: 0 .5rem;
    gap: .25rem;
  }
  nav.sidenav a { white-space: nowrap; }
  nav.sidenav .nav-group { flex-direction: row; }
  nav.sidenav .nav-group + .nav-group { margin-top: 0; padding-left: .5rem; border-left: 1px solid var(--line); }
  nav.sidenav .nav-group-label { display: none; }
  nav.sidenav .nav-group-admin { border-top: 0; padding-top: 0; }
  .tenant-chip { display: none; }
  .topbar-right { gap: .5rem; }
  .tenant-badge .tenant-name { max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .user-menu-trigger .user-name,
  .user-menu-trigger .user-role { display: none; }
  main.content { padding: 1rem; }
}

/* =============================================================
   Page actions (primary "+ 新建..." button + friends)
   ============================================================= */

.page-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .75rem;
  margin: 0 0 1rem;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem .9rem;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }
.btn-primary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem .9rem;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font-size: .9rem;
  cursor: pointer;
  text-decoration: none;
}
.btn-secondary:hover { background: #f9fafb; }

/* ---------- Create form (replaces the old <details> panel) ---------- */

.create-form {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: .5rem;
  padding: 1rem 1.25rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.create-form[hidden] { display: none; }
.create-form-head {
  margin: 0 0 .85rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: .65rem;
}
.create-form-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .85rem 1rem;
}
.form-field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.form-field-full { grid-column: 1 / -1; }
.form-field label {
  font-size: .82rem;
  color: var(--ink-soft);
  font-weight: 600;
}
.form-field input,
.form-field select {
  padding: .45rem .6rem;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
.form-field input:focus,
.form-field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-actions {
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
  margin-top: 1rem;
  padding-top: .85rem;
  border-top: 1px solid var(--line);
}

/* ---------- Empty state ---------- */

.empty-card {
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: .5rem;
  padding: 3rem 1.5rem;
  text-align: center;
  margin-bottom: 1rem;
}
.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 1rem;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.8rem;
  border-radius: 50%;
}
.empty-title {
  margin: 0 0 .4rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
}
.empty-desc {
  margin: 0 auto 1.25rem;
  max-width: 36rem;
  color: var(--ink-soft);
  line-height: 1.55;
}

/* ---------- Filter bar (search + status) ---------- */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: .5rem;
  padding: .6rem .85rem;
  margin-bottom: 1rem;
}
.filter-bar label { flex: 1 1 160px; margin: 0; }
.filter-search { flex: 1 1 220px; min-width: 180px; }
.filter-search input {
  width: 100%;
  padding: .4rem .65rem;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  font: inherit;
}
.filter-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.filter-status { display: inline-flex; align-items: center; gap: .5rem; }
.filter-status span { font-size: .85rem; color: var(--ink-soft); }
.filter-status select {
  padding: .35rem .55rem;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  font: inherit;
}
.filter-count {
  margin-left: auto;
  font-size: .85rem;
  color: var(--ink-soft);
}
.filter-empty {
  margin: .75rem 0 1rem;
  padding: 1rem;
  text-align: center;
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: .5rem;
  color: var(--ink-soft);
}
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Data table baseline ---------- */

.data-table {
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: .5rem;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
}
.data-table th,
.data-table td {
  padding: .6rem .75rem;
  text-align: left;
  font-size: .9rem;
  border-bottom: 1px solid var(--line);
}
.data-table thead th {
  background: #f9fafb;
  font-weight: 600;
  color: var(--ink-soft);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover { background: #f9fafb; }

/* Sticky actions column — keeps the operation reachable on narrow screens
   when the table horizontally scrolls. */
.data-table .sticky-col {
  position: sticky;
  right: 0;
  background: #fff;
  box-shadow: -1px 0 0 var(--line);
  z-index: 1;
}
.data-table tbody tr:hover .sticky-col { background: #f9fafb; }

/* Horizontal scroll wrapper so wide tables don't clip on small screens */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: .5rem;
}
.table-scroll .data-table { min-width: 720px; }

/* Generic tunnel-type badge (mirrors the chain badges) */
.badge.type-tunnel { background: #ede9fe; color: #5b21b6; }

/* Required-field marker + form hints */
.req { color: var(--danger); font-weight: 700; }
.create-form-hint {
  margin: .3rem 0 0;
  font-size: .78rem;
  color: var(--ink-soft);
}
.form-field-hint {
  font-size: .75rem;
  color: var(--ink-soft);
  line-height: 1.35;
}

/* Checkbox label inside a form-field — keeps the box + label on one
   line and uses a muted hint underneath for explanations. */
.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-weight: 500;
  cursor: pointer;
}
.checkbox-row input[type="checkbox"] { margin: 0; }

/* Solid danger button (used inside the confirm dialog) */
.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem .9rem;
  background: var(--danger);
  color: #fff;
  border: 1px solid var(--danger);
  border-radius: 6px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger:hover { background: var(--danger-h); border-color: var(--danger-h); }
.btn-danger:focus-visible { outline: 2px solid var(--danger); outline-offset: 2px; }

/* Low-key in-row delete affordance — full red is reserved for the dialog */
.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
  padding: .3rem .6rem;
  border-radius: 6px;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
}
.btn-danger-ghost:hover { background: #fef2f2; border-color: #fecaca; }
.btn-danger-ghost:focus-visible { outline: 2px solid var(--danger); outline-offset: 1px; }
.row-delete-form { margin: 0; }

/* Confirmation dialog */
.confirm-dialog {
  border: 1px solid var(--line);
  border-radius: .6rem;
  padding: 0;
  width: min(90vw, 380px);
  box-shadow: 0 20px 45px -15px rgba(15,23,42,.35);
  color: var(--ink);
}
.confirm-dialog::backdrop { background: rgba(15,23,42,.4); }
.confirm-dialog-body { margin: 0; padding: 1.25rem; }
.confirm-dialog-title { margin: 0 0 .5rem; font-size: 1.05rem; font-weight: 600; }
.confirm-dialog-msg { margin: 0 0 1.25rem; color: var(--ink-soft); line-height: 1.5; }
.confirm-dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; }

/* ---------- Responsive grid breakpoints ---------- */

@media (max-width: 900px) {
  .form-grid { grid-template-columns: 1fr; }
  .filter-search { flex-basis: 100%; }
  .filter-count { margin-left: 0; }
}
@media (max-width: 640px) {
  .page-actions { flex-direction: column; align-items: stretch; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions button { width: 100%; justify-content: center; }
  .confirm-dialog-actions { flex-direction: column-reverse; }
  .confirm-dialog-actions button { width: 100%; justify-content: center; }
}