:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-soft: #fafafa;
  --surface-strong: #f3f4f6;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --muted-strong: #4b5563;
  --accent: #0f766e;
  --accent-strong: #0f5f59;
  --accent-soft: #f0fdfa;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --warning: #9a6200;
  --warning-soft: #fff7df;
  --success: #146c43;
  --success-soft: #eef8f2;
  --info: #315f7c;
  --info-soft: #edf7fb;
  --shadow: none;
  --focus: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Inter, Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select, textarea { font: inherit; }
button, .button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}
button:hover, .button:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
button:focus-visible, .button:focus-visible, input:focus, select:focus, textarea:focus { outline: none; box-shadow: var(--focus); border-color: var(--accent); }
button:active, .button:active { transform: translateY(1px); }
button.secondary, .button.secondary { border-color: var(--line-strong); background: #fff; color: var(--text); }
button.secondary:hover, .button.secondary:hover { background: var(--surface-strong); border-color: #97a6b8; }
button.danger { border-color: var(--danger); background: var(--danger); }
button.danger:hover { border-color: #8f1d14; background: #8f1d14; }

input, select, textarea {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 7px 10px;
  background: #fff;
  color: var(--text);
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
select { cursor: pointer; }
textarea { min-height: 76px; resize: vertical; }
label { display: grid; gap: 6px; color: var(--muted-strong); font-size: 12px; font-weight: 750; }
small { color: var(--muted); font-size: 12px; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
  padding: 18px 12px;
  border-right: 1px solid var(--line);
  background: #ffffff;
}
.brand {
  display: grid;
  gap: 5px;
  padding: 4px 8px 15px;
  border-bottom: 1px solid var(--line);
}
.brand strong { font-size: 19px; font-weight: 750; color: #111827; }
.brand span { color: var(--muted); font-size: 12px; font-weight: 600; }

nav { display: grid; align-content: start; gap: 5px; }
nav a, summary {
  display: block;
  padding: 9px 10px;
  color: var(--muted-strong);
  text-decoration: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  transition: background .16s ease, color .16s ease;
}
nav a:hover, summary:hover { background: var(--surface-strong); color: var(--text); }
details { display: grid; gap: 2px; }
details a { margin-left: 10px; font-weight: 650; color: #334155; }
.full { width: 100%; }

.workspace {
  min-width: 0;
  padding: 24px;
  display: grid;
  align-content: start;
  gap: 16px;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding-bottom: 2px;
}
h1 { margin: 0; font-size: 25px; line-height: 1.18; font-weight: 750; color: #111827; }
h2 { margin: 0 0 12px; font-size: 16px; line-height: 1.25; font-weight: 750; color: #111827; }
p { margin: 4px 0 0; color: var(--muted); line-height: 1.45; }

.card, .login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.metrics { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 10px; }
.metrics article {
  min-height: 84px;
  display: grid;
  align-content: center;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  box-shadow: none;
}
.metrics span { color: var(--muted); font-size: 11px; font-weight: 750; text-transform: uppercase; }
.metrics strong { font-size: 24px; line-height: 1; color: #111827; font-weight: 750; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.report-grid { display: grid; gap: 12px; }
.report-grid .card { overflow-x: auto; }
.report-grid .card:first-child { max-width: 720px; }
.session-activity { max-width: 720px; overflow-x: auto; }
.form { display: grid; gap: 12px; }
.forms-two { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 12px; }
.connection-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 12px; }
.connection-grid.single { grid-template-columns: minmax(0, 1fr); }
.connection-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--line);
}
.connection-tab {
  flex: 0 0 auto;
  min-width: 150px;
  display: grid;
  gap: 2px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 4px 4px 0 0;
  background: var(--surface);
  color: var(--muted-strong);
  text-decoration: none;
  font-weight: 750;
}
.connection-tab:hover { background: var(--surface-strong); color: var(--text); }
.connection-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}
.connection-tab small { color: inherit; font-size: 11px; font-weight: 650; text-transform: capitalize; }
.connection-card textarea { min-height: 120px; font-family: Consolas, "Courier New", monospace; font-size: 12px; }
.connection-head, .connection-foot { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.connection-head h2 { margin-bottom: 3px; }
.connection-foot { align-items: center; }
.settings-help dl { display: grid; grid-template-columns: 180px 1fr; gap: 10px 18px; margin: 0; }
.settings-help dt { font-weight: 800; }
.settings-help dd { margin: 0; color: var(--muted); }
.card table form { display: contents; }

.permission-box { display: grid; gap: 9px; border-top: 1px solid var(--line); padding-top: 13px; }
.permission-box p { margin: 0; font-size: 12px; }
.permission-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 9px; }
.permission-grid label {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 9px;
  color: var(--text);
  font-weight: 700;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px;
  background: var(--surface-soft);
}
.permission-grid input { width: auto; min-height: auto; margin-top: 2px; }
.permission-grid span { display: grid; gap: 3px; }
.checks { display: flex; flex-wrap: wrap; gap: 14px; }
.checks label { display: flex; align-items: center; gap: 7px; color: var(--text); font-weight: 600; }
.checks input { width: auto; min-height: auto; }

.search, .filters { display: flex; gap: 8px; width: min(980px, 66vw); align-items: center; }
.filters input { min-width: 210px; }
.filters select { width: 160px; }
.summary-strip { display: flex; flex-wrap: wrap; gap: 8px; }
.summary-strip span {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  padding: 5px 10px;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 650;
}

.tabs { display: flex; flex-wrap: wrap; gap: 0; border-bottom: 1px solid var(--line); }
.tab {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 4px 4px 0 0;
  color: var(--muted-strong);
  background: transparent;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}
.tab:hover { color: var(--text); background: var(--surface-strong); }
.tab.active { color: var(--accent-strong); background: #fff; border-color: var(--line); margin-bottom: -1px; }

table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
th, td {
  max-width: 340px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}
th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted-strong);
  background: #f9fafb;
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}
tbody tr:hover td { background: #fafafa; }
tbody tr:last-child td { border-bottom: 0; }

.actions, .inline, .status-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.actions form { display: inline; }
.inline input { width: 150px; }
.status-form select { width: 132px; font-weight: 700; }
.status-select.active { color: var(--success); background: var(--success-soft); border-color: #a7d7c3; }
.status-select.suspended { color: var(--warning); background: var(--warning-soft); border-color: #efd08a; }

.pill {
  display: inline-flex;
  min-height: 23px;
  align-items: center;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}
.pill.active, .pill.available, .pill.configured, .pill.success { color: var(--success); background: var(--success-soft); border-color: #a7d7c3; }
.pill.paused, .pill.suspended, .pill.assigned, .pill.not_configured, .pill.untested { color: var(--warning); background: var(--warning-soft); border-color: #efd08a; }
.pill.inactive, .pill.expired, .pill.recovered, .pill.revoked, .pill.error, .pill.failed { color: var(--danger); background: var(--danger-soft); border-color: #efb4af; }
.pill.disabled { color: var(--muted-strong); background: var(--surface-strong); border-color: var(--line-strong); }
.pill.demo { color: var(--info); background: var(--info-soft); border-color: #afd4e7; }

.messages { display: grid; gap: 8px; }
.message { padding: 11px 12px; border-radius: 4px; border: 1px solid var(--line); background: #fff; font-weight: 650; }
.message.error { color: var(--danger); border-color: #efb4af; background: var(--danger-soft); }
.message.success { color: var(--success); border-color: #a7d7c3; background: var(--success-soft); }
.danger-zone { border-color: #efb4af; }
.timer { color: var(--danger); font-weight: 850; align-self: center; }
.tx.add td { background: #f7fbf8; }
.tx.remove td { background: #fff8f8; }
.tx.add td:first-child { color: var(--success); font-weight: 850; }
.tx.remove td:first-child { color: var(--danger); font-weight: 850; }
.tx.add:hover td { background: #f0f8f3; }
.tx.remove:hover td { background: #fff1f0; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(390px, calc(100vw - 32px)); display: grid; gap: 15px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .workspace { padding: 18px; }
  .topbar, .search, .filters { width: 100%; flex-direction: column; align-items: stretch; }
  .filters select { width: 100%; }
  .metrics { grid-template-columns: repeat(2, minmax(120px, 1fr)); }
  .forms-two { grid-template-columns: 1fr; }
  .connection-grid { grid-template-columns: 1fr; }
  .connection-head, .connection-foot { flex-direction: column; align-items: stretch; }
}

@media (max-width: 560px) {
  .workspace { padding: 14px; }
  h1 { font-size: 22px; }
  .metrics { grid-template-columns: 1fr; }
  th, td { padding: 9px 10px; }
  button, .button { width: 100%; }
}
