* {
  box-sizing: border-box;
}

:root {
  --bg-deep: #0b1b2b;
  --bg-mid: #132f45;
  --bg-soft: #f3f7fb;
  --surface: #ffffff;
  --surface-tint: #f8fbff;
  --text-strong: #112234;
  --text-muted: #5b6f81;
  --line: #d7e2ec;
  --primary: #1a6fb0;
  --primary-strong: #0f5488;
  --danger: #b33838;
  --success: #1f8a5d;
  --warning: #b06d1a;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 10px;
  --shadow-soft: 0 10px 30px rgba(15, 32, 49, 0.08);
  --shadow-strong: 0 24px 60px rgba(11, 27, 43, 0.2);
}

body {
  margin: 0;
  font-family: "Bahnschrift", "Segoe UI Variable", "Trebuchet MS", sans-serif;
  background:
    radial-gradient(circle at 8% 8%, rgba(26, 111, 176, 0.2), transparent 32%),
    radial-gradient(circle at 86% 4%, rgba(176, 109, 26, 0.12), transparent 28%),
    linear-gradient(175deg, #f7fbff 0%, #eef4fa 48%, #eaf1f8 100%);
  color: var(--text-strong);
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid transparent;
  background: linear-gradient(180deg, var(--primary), var(--primary-strong));
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-weight: 600;
  letter-spacing: 0.1px;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 180ms ease, filter 180ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(26, 111, 176, 0.25);
  filter: brightness(1.02);
}

button.secondary {
  background: #fff;
  color: var(--text-strong);
  border-color: var(--line);
}

button.ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--line);
}

button.danger {
  background: linear-gradient(180deg, #c34747, #9e3131);
}

input,
select,
textarea {
  width: 100%;
  margin-top: 6px;
  border: 1px solid #c9d8e6;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: #fff;
  color: var(--text-strong);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(26, 111, 176, 0.18);
  border-color: #8bb7da;
}

textarea {
  resize: vertical;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
  position: relative;
}

.sidebar {
  background: linear-gradient(190deg, var(--bg-deep) 0%, var(--bg-mid) 100%);
  color: #eef5fc;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow-strong);
  z-index: 1;
}

.brand {
  padding: 4px 8px 10px;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.35px;
}

.brand .muted {
  margin-top: 6px;
  color: rgba(226, 238, 249, 0.76);
}

.sidebar nav {
  display: grid;
  gap: 6px;
}

.nav-link {
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  color: rgba(235, 244, 252, 0.88);
  border: 1px solid transparent;
  transition: background-color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.nav-link:hover {
  transform: translateX(2px);
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.12);
}

.nav-link.active {
  background: linear-gradient(180deg, rgba(35, 118, 184, 0.44), rgba(28, 95, 150, 0.44));
  border-color: rgba(165, 210, 245, 0.35);
  color: #fff;
}

.sidebar-foot {
  margin-top: auto;
}

.content {
  padding: 28px;
  max-width: 1240px;
  width: 100%;
}

.page-intro {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin-bottom: 16px;
}

.page-header {
  margin-bottom: 20px;
}

.page-header h2 {
  margin: 0;
  font-size: clamp(26px, 3vw, 34px);
  letter-spacing: 0.2px;
}

.subtle {
  margin-top: 8px;
  color: var(--text-muted);
}

.card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-tint) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-soft);
  animation: cardEnter 380ms ease both;
}

.grid.two-col {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 18px;
}

.grid.two-col.tight {
  grid-template-columns: minmax(260px, 340px) 1fr;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  background: #fff;
}

.stat .label {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.stat .value {
  font-size: 24px;
  font-weight: 700;
}

.list-item {
  border: 1px solid #dce7f1;
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  background: #fff;
  transition: border-color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

.list-item:hover {
  border-color: #b8d3e8;
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(17, 34, 52, 0.08);
}

.list-item a {
  display: grid;
  gap: 6px;
  padding: 12px;
}

.item-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.list-item span {
  color: var(--text-muted);
  font-size: 12px;
  word-break: break-all;
}

.list-item.selected {
  background: #f1f8ff;
  border-color: #a8cae6;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.15px;
  border: 1px solid transparent;
}

.badge.online,
.badge.allowed {
  background: #e9f8f0;
  color: #146b46;
  border-color: #bde9d1;
}

.badge.offline,
.badge.blocked {
  background: #fff0f0;
  color: #a02d2d;
  border-color: #efc4c4;
}

.badge.neutral {
  background: #eef5fb;
  color: #27577f;
  border-color: #cfe0ef;
}

.stack-form,
.stack-block {
  display: grid;
  gap: 14px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin: 14px 0 16px;
}

.meta {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 10px 12px;
}

.meta .key {
  margin: 0 0 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.meta .val {
  margin: 0;
  font-size: 14px;
  color: var(--text-strong);
  word-break: break-word;
}

.narrow {
  max-width: 540px;
}

.code-card {
  margin-top: 16px;
  background: linear-gradient(145deg, #fff3d7, #ffe8bd);
  border: 1px solid #efcf8b;
  border-radius: var(--radius-md);
  padding: 18px;
}

.code-card h3 {
  margin: 0 0 8px;
  font-size: clamp(30px, 4vw, 40px);
  letter-spacing: 3px;
}

.message {
  color: #1f5463;
  background: #eaf5ff;
  border: 1px solid #c5ddf0;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-top: 10px;
}

.message.error {
  color: #8b2d2d;
  background: #fff0f0;
  border-color: #efc4c4;
}

.muted {
  color: var(--text-muted);
}

.toolbar {
  margin-bottom: 14px;
}

.selector-form {
  display: flex;
  gap: 12px;
  align-items: end;
}

.selector-form label {
  flex: 1;
}

.section-title {
  margin: 0 0 8px;
  font-size: 18px;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid #e8eef5;
  vertical-align: middle;
}

th {
  background: #f3f8fd;
  color: #334f67;
  font-weight: 700;
  font-size: 13px;
}

tbody tr:hover {
  background: #f8fbff;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 14% 20%, rgba(24, 108, 173, 0.26), transparent 34%),
    radial-gradient(circle at 84% 20%, rgba(176, 109, 26, 0.22), transparent 32%),
    linear-gradient(165deg, #eff6ff 0%, #e7f0f9 45%, #dce8f3 100%);
}

.auth-card {
  width: min(460px, calc(100vw - 32px));
  background: linear-gradient(180deg, #ffffff 0%, #f7fbff 100%);
  border: 1px solid #d5e2ee;
  border-radius: 22px;
  padding: 30px;
  box-shadow: 0 24px 60px rgba(16, 38, 58, 0.18);
  animation: cardEnter 500ms ease both;
}

.auth-card h1 {
  margin: 0;
}

.auth-tag {
  display: inline-block;
  margin-bottom: 12px;
  background: #ecf5fe;
  color: #225a87;
  border: 1px solid #cae0f3;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.auth-note {
  margin: 8px 0 18px;
  color: var(--text-muted);
}

.actions {
  display: flex;
  gap: 10px;
}

.actions > * {
  flex: 1;
}

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: none;
  }

  .page-intro {
    flex-direction: column;
    align-items: flex-start;
  }

  .grid.two-col {
    grid-template-columns: 1fr;
  }

  .split {
    grid-template-columns: 1fr;
  }

  .selector-form {
    flex-direction: column;
    align-items: stretch;
  }
}

/* Responsive table helpers - prevent overflowing parent and wrap long package names */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-responsive table {
  width: 100%;
  border-collapse: collapse;
}

/* Constrain the package name column and allow long package strings to wrap */
.package-name {
  max-width: 46ch;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Make action buttons slightly smaller so they don't force column width */
table td form button {
  padding: 6px 10px;
  font-size: 13px;
}

@media (max-width: 700px) {
  .package-name { max-width: 34ch; }
  table th, table td { padding: 10px 8px; }
  button { padding: 8px 12px; }
}

/* Users page tweaks: give username cell some breathing room and space reset fields */
.username-cell {
  padding-right: 14px;
  min-width: 160px;
}

/* Horizontal reset form inside table row */
.reset-form {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap; /* allow inputs to wrap to next line on narrow screens */
}

/* Allow inline password inputs to size from flex instead of forcing 100% width */
.reset-form input[type="password"] {
  width: auto; /* let flex sizing work */
  flex: 1 1 180px; /* grow/shrink with a reasonable base width */
  min-width: 120px;
}

/* Ensure the 'You' badge doesn't push layout too far but remains separated */
.username-cell .badge {
  margin-left: 8px;
}

/* Column sizing for users table - let reset column be flexible but bounded */
.col-reset { width: 1%; /* shrink-to-fit but allow content */ }
.col-action { width: 120px; }

@media (max-width: 900px) {
  /* On small screens stack the reset form inputs vertically to avoid overflow */
  .reset-form { gap: 8px; }
  .reset-form input[type="password"] { flex-basis: 100%; }
  .col-action { width: 100px; }
}

/* ── Exception-requests page ─────────────────────────────────────────────── */
.form-inline { display: inline; }

.meta-small {
  display: block;
  font-size: 0.75rem;
}

/* Modal overlay */
.review-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.review-overlay.open { display: flex; }

/* Modal dialog */
.review-dialog {
  background: var(--surface, #fff);
  border-radius: 8px;
  padding: 2rem;
  min-width: 320px;
  max-width: 480px;
  width: 90%;
}

.review-dialog h3 { margin-top: 0; }

.review-label {
  display: block;
  margin-bottom: .5rem;
}

.review-textarea {
  width: 100%;
  margin-top: .25rem;
  box-sizing: border-box;
}

.review-actions {
  display: flex;
  gap: .5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}
/* Conflict row: device overrode management intent */
.row-conflict {
  background: #fff8f0 !important;
  border-left: 3px solid var(--warning);
}

.row-conflict td:first-child {
  padding-left: 9px; /* compensate for 3px border */
}

:root {
  --color-danger: var(--danger);
}

.totp-qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px;
  margin: 14px 0 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.totp-manual-key {
  margin: 0;
  font-size: 13px;
  word-break: break-all;
  text-align: center;
}

.auth-logout-form {
  margin-top: 12px;
}

.inline-reset-2fa {
  margin-left: 8px;
}

.badge.warning {
  background: #fff6e5;
  color: #8a5300;
  border-color: #f0d095;
  margin-left: 6px;
}

.cert-banner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 18px;
  border-radius: var(--radius-md);
  background: #fff8e6;
  border: 1px solid #f0cf85;
  color: #6b4300;
}

.cert-banner.expired {
  background: #fff0f0;
  border-color: #efc4c4;
  color: #8e1e1e;
}

.cert-banner-sub {
  margin: 4px 0 0;
  font-size: 13px;
}

.cert-banner-link {
  padding: 6px 12px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid currentColor;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
}

.cert-renewal-card {
  margin-top: 20px;
}

.cert-steps {
  margin: 12px 0 0;
  padding-left: 20px;
  display: grid;
  gap: 12px;
  font-size: 14px;
}

.cert-cmd {
  margin: 6px 0 0;
  padding: 8px 12px;
  border-radius: 6px;
  background: #0f172a;
  color: #e2e8f0;
  font-size: 13px;
  overflow-x: auto;
}
