:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --border: #e6e2d8;
  --text: #211f1a;
  --text-muted: #6f6a60;
  --brand: #0d9488;
  --brand-dark: #0f6f66;
  --brand-tint: #e6f5f3;

  --status-active-bg: #e8f7ef;
  --status-active-text: #157a4d;
  --status-expiring-bg: #fdf3e2;
  --status-expiring-text: #9a6400;
  --status-expired-bg: #fbeaea;
  --status-expired-text: #b02a2a;
  --status-pending-bg: #eef0f2;
  --status-pending-text: #52606d;
  --status-revoked-bg: #efeceb;
  --status-revoked-text: #4a4540;

  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(33, 31, 26, 0.06);
  --shadow-md: 0 6px 20px rgba(33, 31, 26, 0.08);

  --font-display: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.5;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

a {
  color: var(--brand-dark);
  text-decoration: none;
}

/* Shell layout */

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: #171615;
  color: #e9e6df;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 28px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 15px;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15.5px;
  color: #fff;
}

.brand-name small {
  display: block;
  font-size: 10.5px;
  font-weight: 600;
  color: #a39d90;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 1px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-link {
  padding: 9px 12px;
  border-radius: 8px;
  color: #c9c4ba;
  font-size: 13.5px;
  font-weight: 600;
}

.nav-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-link.active {
  background: var(--brand);
  color: #fff;
}

.logout-form {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 14px;
  margin-top: 14px;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
}

.user-name {
  font-size: 13px;
  color: #a39d90;
  font-weight: 600;
}

.link-button {
  background: none;
  border: none;
  color: #a39d90;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.link-button:hover {
  color: #fff;
}

.main {
  flex: 1;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 26px 36px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.content {
  padding: 28px 36px 60px;
}

.messages {
  padding: 14px 36px 0;
}

.message {
  background: var(--status-active-bg);
  color: var(--status-active-text);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 8px;
}

/* Guest (login) page */

.guest-card .brand-name {
  color: var(--text);
}

.guest-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 16px;
}

.guest-card {
  /* A fixed 340px overflows a phone narrower than ~396px once padding is
     added (common on smaller Android devices) - cap at what's actually
     available instead of a flat width. */
  width: min(340px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 32px 28px;
}

.guest-card .brand {
  padding: 0 0 24px;
  justify-content: center;
}

.guest-card h2 {
  font-size: 17px;
  text-align: center;
  margin-bottom: 20px;
}

/* Stat cards */

.stat-grid {
  display: grid;
  /* Auto-fit reflows the column count to whatever actually fits, instead
     of a hardcoded 5-across that gets crushed on anything narrower than
     a desktop - this needs no separate breakpoint overrides at all. */
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow-sm);
}

.stat-card .stat-value {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 26px;
  font-variant-numeric: tabular-nums;
}

.stat-card .stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 4px;
}

.stat-card.accent .stat-value {
  color: var(--brand-dark);
}

/* Cards / sections */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  /* Lets any table inside scroll horizontally on its own rather than
     overflowing the page - no per-template wrapper needed, every
     existing .panel > table benefits automatically. */
  overflow-x: auto;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-header h3 {
  font-size: 15px;
}

/* Tables */

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 11px 20px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 13px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: #fbfaf7;
}

.mono {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 12.5px;
  letter-spacing: 0.02em;
}

.text-muted {
  color: var(--text-muted);
}

/* Badges */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 11.5px;
  font-weight: 700;
}

.badge-active { background: var(--status-active-bg); color: var(--status-active-text); }
.badge-expiring_soon { background: var(--status-expiring-bg); color: var(--status-expiring-text); }
.badge-expired { background: var(--status-expired-bg); color: var(--status-expired-text); }
.badge-pending { background: var(--status-pending-bg); color: var(--status-pending-text); }
.badge-revoked { background: var(--status-revoked-bg); color: var(--status-revoked-text); }

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: var(--font-body);
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-dark);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  border-color: #c9c4ba;
}

.btn-danger {
  background: #fff;
  color: var(--status-expired-text);
  border-color: #f0c9c9;
}

.btn-danger:hover {
  background: var(--status-expired-bg);
}

.btn-alert {
  background: var(--status-expiring-bg);
  color: var(--status-expiring-text);
  border-color: #f3dfb0;
}

.btn-alert:hover {
  background: #fbead0;
}

.btn-block {
  width: 100%;
}

/* Forms */

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  font-family: var(--font-body);
  background: var(--surface);
  color: var(--text);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
}

.field .errorlist {
  list-style: none;
  padding: 0;
  margin: 6px 0 0;
  color: var(--status-expired-text);
  font-size: 12.5px;
}

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  max-width: 480px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* Misc */

.page-actions {
  display: flex;
  gap: 10px;
}

.search-bar {
  margin-bottom: 18px;
}

.search-bar input {
  width: 280px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 100px;
  font-size: 13.5px;
  font-family: var(--font-body);
}

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 20px;
}

.kv-list {
  padding: 18px 20px;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}

.kv-row:last-child {
  border-bottom: none;
}

.kv-row .k {
  color: var(--text-muted);
  font-weight: 600;
}

.license-key-display {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: var(--brand-tint);
  color: var(--brand-dark);
  padding: 12px 16px;
  border-radius: 8px;
  display: inline-block;
}

.pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 20px;
}

/* Side drawer (forms, confirmations) */

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(23, 22, 21, 0.35);
  z-index: 40;
  display: flex;
  justify-content: flex-end;
  animation: drawer-fade-in 0.18s ease-out;
}

.drawer-panel {
  position: relative;
  z-index: 1;
  width: 440px;
  max-width: 92vw;
  height: 100vh;
  background: var(--surface);
  box-shadow: -8px 0 32px rgba(23, 22, 21, 0.18);
  display: flex;
  flex-direction: column;
  animation: drawer-slide-in 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 26px;
  border-bottom: 1px solid var(--border);
}

.drawer-header h2 {
  font-size: 17px;
}

.drawer-close {
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
}

.drawer-close:hover {
  background: var(--bg);
  color: var(--text);
}

.drawer-body {
  padding: 24px 26px;
  overflow-y: auto;
  min-height: 0;
}

.drawer-footer {
  display: flex;
  gap: 10px;
  padding: 18px 26px;
  border-top: 1px solid var(--border);
}

.drawer-footer .btn {
  flex: 1;
}

@keyframes drawer-fade-in {
  from { background: rgba(23, 22, 21, 0); }
  to { background: rgba(23, 22, 21, 0.35); }
}

@keyframes drawer-slide-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .drawer-overlay, .drawer-panel {
    animation: none;
  }
}

/* Consequence list (used in confirmation drawers) */

.drawer-summary {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 20px;
}

.drawer-summary .key-line {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.drawer-summary .sub-line {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 3px;
}

.consequence-heading {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: 0 0 12px;
}

.consequence-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.consequence-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  font-size: 13.5px;
  line-height: 1.5;
}

.consequence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 5px;
}

.consequence-dot.danger { background: var(--status-expired-text); }
.consequence-dot.muted { background: var(--text-muted); }
.consequence-dot.accent { background: var(--brand); }

/* OTP / activation pages */

.guest-subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
  margin: -12px 0 20px;
}

.otp-input {
  text-align: center;
  font-family: "Courier New", monospace;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 12px;
  padding-left: 12px !important;
}

.guest-links {
  text-align: center;
  margin-top: 16px;
  font-size: 13px;
}

.guest-links button {
  background: none;
  border: none;
  color: var(--brand-dark);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-size: 13px;
}

.guest-links button:hover {
  text-decoration: underline;
}

.guest-links a {
  color: var(--text-muted);
}

/* In-table row actions (e.g. the Users list) - distinct from
   .link-button above, which is tuned for the dark sidebar; on this
   table's light background that same white hover color is invisible. */

.row-action {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: none;
}

.row-action:hover {
  color: var(--brand-dark);
}

.row-action-item {
  display: inline-block;
}

/* Separator only appears before an item that has a visible item before
   it - sibling selector means rows with different action combinations
   (pending vs active vs disabled vs self) never need the template to
   track "is this the last one shown" by hand. */
.row-action-item + .row-action-item::before {
  content: "|";
  margin: 0 8px;
  color: var(--border);
}

/* Role / staff-status badges - distinct "role-"/"staff-" prefixes, not
   reusing the bare license-status badge names (badge-pending etc. above
   already mean something different there - a shared name here would
   silently repaint those too). */

.badge-role-full_access { background: var(--status-active-bg); color: var(--status-active-text); }
.badge-role-view_only { background: var(--status-pending-bg); color: var(--status-pending-text); }
.badge-staff-pending { background: var(--status-expiring-bg); color: var(--status-expiring-text); }
.badge-staff-active { background: var(--status-active-bg); color: var(--status-active-text); }
.badge-staff-disabled { background: var(--status-revoked-bg); color: var(--status-revoked-text); }

/* ==========================================================================
   Responsive
   ========================================================================== */

/* Tablet and down - the fixed 232px sidebar stops making sense once it's
   competing with the content for real width, so it becomes a compact
   horizontal bar instead of a full-height rail. */
@media (max-width: 768px) {
  .shell {
    flex-direction: column;
    min-height: auto;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 10px 14px;
    overflow-x: auto;
  }

  .brand {
    padding: 0;
    flex-shrink: 0;
  }

  .nav {
    flex-direction: row;
    flex: initial;
    gap: 2px;
    overflow-x: auto;
  }

  .nav-link {
    white-space: nowrap;
    padding: 7px 10px;
    font-size: 12.5px;
  }

  .logout-form {
    border-top: none;
    margin: 0 0 0 auto;
    padding: 0;
    flex-shrink: 0;
  }

  .user-row {
    padding: 0;
    gap: 10px;
  }

  /* The username label is the first thing worth dropping for space - the
     Sign out action itself still needs to stay reachable. */
  .user-name {
    display: none;
  }

  .topbar {
    padding: 16px 18px;
    flex-wrap: wrap;
    gap: 10px;
  }

  .topbar h1 {
    font-size: 18px;
  }

  .content {
    padding: 18px 16px 40px;
  }

  .messages {
    padding: 12px 16px 0;
  }

  .page-actions {
    flex-wrap: wrap;
  }

  /* Two-column layouts (customer detail's licenses+contact panels) stack
     - side by side at this width leaves each column too narrow to be
     useful rather than actually saving space. */
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .search-bar input {
    width: 100%;
  }

  .drawer-panel {
    width: 100%;
    max-width: 100vw;
  }

  .drawer-header,
  .drawer-body,
  .drawer-footer {
    padding-left: 18px;
    padding-right: 18px;
  }
}

/* Phones specifically - tighten further where even the tablet sizing is
   still cramped. */
@media (max-width: 420px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-card {
    padding: 14px 14px 12px;
  }

  .stat-card .stat-value {
    font-size: 22px;
  }

  th, td {
    padding: 10px 14px;
  }

  .guest-card {
    padding: 24px 20px;
  }

  .otp-input {
    font-size: 22px;
    letter-spacing: 8px;
  }

  .drawer-footer {
    flex-direction: column;
  }
}
