/* =========================================================
   DESIGN TOKENS
   ========================================================= */
:root {
  /* Palette — slate base with indigo accent */
  --bg:            #f4f6fb;
  --bg-elevated:   #ffffff;
  --bg-muted:      #eef1f7;
  --surface:       #ffffff;
  --surface-alt:   #f7f9fc;
  --border:        #e3e8f0;
  --border-strong: #cbd3e1;

  --text:          #0f172a;
  --text-muted:    #475569;
  --text-soft:     #64748b;
  --text-invert:   #ffffff;

  --primary:       #4f46e5;       /* indigo-600 */
  --primary-hover: #4338ca;
  --primary-soft:  #eef2ff;
  --primary-ring:  rgba(79, 70, 229, .25);

  --success:       #10b981;
  --success-soft:  #d1fae5;
  --danger:        #e11d48;
  --danger-hover:  #be123c;
  --danger-soft:   #ffe4e6;
  --warning:       #f59e0b;
  --warning-soft:  #fef3c7;

  /* Typography */
  --font-sans: "Inter Tight", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-full: 999px;

  /* Shadows — soft, layered */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-sm: 0 2px 6px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md: 0 6px 16px rgba(15, 23, 42, .08), 0 2px 4px rgba(15, 23, 42, .04);
  --shadow-lg: 0 18px 40px rgba(15, 23, 42, .12), 0 4px 10px rgba(15, 23, 42, .06);
  --shadow-ring: 0 0 0 4px var(--primary-ring);

  /* Spacing scale */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px;
  --s-4: 16px; --s-5: 20px; --s-6: 24px;
  --s-8: 32px; --s-10: 40px;

  /* Motion */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --t-fast: 140ms;
  --t-med:  240ms;
}

/* =========================================================
   IMPORT FONTS
   ========================================================= */
@import url('https://fonts.googleapis.com/css2?family=Inter+Tight:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* =========================================================
   BASE
   ========================================================= */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--font-sans);
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  background: var(--bg);
  background-image:
    radial-gradient(circle at 0% 0%, rgba(79, 70, 229, .06), transparent 40%),
    radial-gradient(circle at 100% 0%, rgba(16, 185, 129, .04), transparent 35%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding-top: 64px;
  letter-spacing: -0.005em;
}

.wrapper {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.content {
  flex: 1;
  padding: var(--s-6);
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* Headings */
h1, h2, h3 {
  text-align: center;
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.02em;
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }

/* Default link */
a {
  color: var(--primary);
  text-decoration: none;
  border-radius: var(--r-sm);
  transition: color var(--t-fast) var(--ease);
}
a:hover { color: var(--primary-hover); }

/* Focus-visible for keyboard accessibility (WCAG 2.4.7) */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[contenteditable="true"]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* =========================================================
   ACCESS DENIED & ERROR / WARNING STATES
   ========================================================= */
.warning {
  color: var(--danger);
  background: var(--warning-soft);
  border: 1px solid var(--warning);
  padding: var(--s-3) var(--s-4);
  border-radius: var(--r-md);
  font-size: 14px;
  margin: var(--s-4) auto;
  max-width: 700px;
  text-align: center;
}

/* Empty / loading states inside tables */
.empty-state {
  text-align: center;
  padding: var(--s-8) var(--s-4);
  color: var(--text-soft);
  font-size: 14px;
  font-style: italic;
}
.empty-state.error {
  color: var(--danger);
  font-style: normal;
}

/* =========================================================
   NAVBAR
   ========================================================= */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 64px;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-xs);
  z-index: 1000;
}

.navbar-left {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin-left: var(--s-6);
}

.user-initial {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-radius: var(--r-full);
  text-transform: uppercase;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, .2);
}

.navbar-right {
  margin-right: var(--s-6);
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.navbar h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text) !important;
  letter-spacing: -0.01em;
}

.navbar a {
  color: var(--text-muted);
  text-decoration: none;
  margin-left: var(--s-5);
  font-weight: 500;
  font-size: 14px;
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  transition: all var(--t-fast) var(--ease);
}
.navbar a:hover {
  color: var(--primary);
  background: var(--primary-soft);
}

/* Logout — now a POST form/button styled to look like the nav links */
.logout-form {
  display: inline;
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  box-shadow: none;
}
.logout-btn {
  width: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
  padding: var(--s-2) var(--s-3);
  margin-left: var(--s-5);
  border-radius: var(--r-md);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--t-fast) var(--ease);
}
.logout-btn:hover {
  color: var(--primary);
  background: var(--primary-soft);
}

/* =========================================================
   BUTTONS — top action buttons
   ========================================================= */
.button-section {
  display: flex;
  justify-content: center;
  gap: var(--s-3);
  margin: var(--s-8) auto;
  flex-wrap: wrap;
}

.button-section button {
  width: fit-content;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: all var(--t-fast) var(--ease);
  white-space: nowrap;
  letter-spacing: -0.005em;
}
.button-section button:hover {
  background: var(--primary);
  color: var(--text-invert);
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.button-section button:active { transform: translateY(0); }

/* =========================================================
   GENERIC BUTTON (default)
   ========================================================= */
button {
  width: 100%;
  padding: 10px 16px;
  background: var(--primary);
  color: var(--text-invert);
  border: 1px solid var(--primary);
  border-radius: var(--r-md);
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  font-size: 14px;
  transition: all var(--t-fast) var(--ease);
}
button:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
button:focus-visible {
  outline: none;
  box-shadow: var(--shadow-ring);
}
button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* =========================================================
   FORMS
   ========================================================= */
form {
  margin: var(--s-6) auto;
  padding: var(--s-6);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--r-lg);
}

form h3 { margin-bottom: var(--s-4); text-align: left; }

.form-group {
  display: flex;
  flex-direction: column;
}

.form-group label {
  font-weight: 500;
  margin-bottom: var(--s-2);
  font-size: 13px;
  color: var(--text-muted);
}

.form-submit { grid-column: span 2; }

label {
  display: block;
  font-weight: 500;
  margin-bottom: var(--s-2);
  font-size: 13px;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: var(--s-4);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="url"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-ring);
}

textarea {
  resize: vertical;
  min-height: 80px;
  font-family: inherit;
}

input::placeholder,
textarea::placeholder {
  color: var(--text-soft);
}

/* Password input wrapper (login + user management) */
.password-wrapper {
  position: relative;
  margin-bottom: var(--s-3);
}
.password-wrapper input {
  margin-bottom: 0;
  padding-right: 42px;
}
.toggle-password {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 8px;
  font-size: 15px;
  border-radius: var(--r-sm);
}
.toggle-password:hover {
  color: var(--primary);
  background: var(--primary-soft);
}
.password-hint {
  font-size: 12px;
  color: var(--text-soft);
  margin: 0 0 var(--s-3) 0;
}

/* =========================================================
   TABLES
   ========================================================= */
table {
  width: 95%;
  margin: var(--s-6) auto;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

th, td {
  padding: 14px 16px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 14px;
}

th {
  background: var(--surface-alt);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  font-weight: 600;
  border-bottom: 1px solid var(--border-strong);
}

tbody tr { transition: background-color var(--t-fast) var(--ease); }
tr:nth-child(even) { background-color: var(--surface-alt); }
tr:hover { background-color: var(--primary-soft); }
tbody tr:last-child td { border-bottom: none; }

td { color: var(--text); }

/* Cells using monospace for IDs/IPs/dates feel cleaner */
td.mono, td .mono { font-family: var(--font-mono); font-size: 13px; color: var(--text-muted); }

/* Editable cell visual hint */
td[contenteditable="true"],
td .edit,
td span[contenteditable="true"] {
  cursor: text;
  transition: background-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
  border-radius: var(--r-sm);
}
td[contenteditable="true"]:hover,
td .edit:hover,
td span[contenteditable="true"]:hover {
  background-color: var(--primary-soft);
}
td[contenteditable="true"]:focus,
td .edit:focus,
td span[contenteditable="true"]:focus {
  outline: none;
  background-color: var(--surface);
  box-shadow: 0 0 0 2px var(--primary);
}

td button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: 32px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  border-radius: var(--r-md);
  transition: all var(--t-fast) var(--ease);
  font-size: 14px;
  color: var(--primary);
  margin: 2px;
  text-decoration: none;
}
td button i { margin-right: 6px; }
td button:hover {
  background: var(--primary-soft);
  border-color: var(--border);
  color: var(--primary-hover);
}
td button:disabled {
  color: var(--text-soft);
  cursor: not-allowed;
  opacity: .5;
}

td a {
  color: var(--primary);
  font-weight: 500;
  text-decoration: none;
}
td a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.td-row {
  display: grid;
  grid-template-columns: auto 1fr;
}
.td-row span { text-align: right; }
.td-notes { width: 12vw; }

/* =========================================================
   STATUS BADGES
   ========================================================= */
.status-badge {
  padding: 4px 10px;
  border-radius: var(--r-full);
  font-weight: 500;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.01em;
}
/*.status-badge::before {*/
/*  content: '';*/
/*  width: 6px;*/
/*  height: 6px;*/
/*  border-radius: var(--r-full);*/
/*  background: currentColor;*/
/*}*/
.status-active {
  background: var(--success-soft);
  color: #047857;
}
.status-suspended {
  background: var(--danger-soft);
  color: #be123c;
}

/* "Active (cannot be suspended)" badge for superusers */
.badge-active {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--success-soft);
  color: #047857;
  border-radius: var(--r-full);
  font-size: 12px;
  font-weight: 500;
  font-style: italic;
}

/* =========================================================
   MODALS — shared
   ========================================================= */
.import-export-modal-overlay,
.assign-modal-overlay,
.add-server-modal-overlay,
#modalOverlay,
.history-modal-overlay,
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 999;
  animation: fadeIn var(--t-med) var(--ease);
}

/* Modal hidden state utility (replaces inline display:none) */
.modal-hidden { display: none; }
.modal-overlay-hidden { display: none; }

/* Generic modal-overlay wrapper used by user_manage.js password-reset modal */
.modal-overlay {
  display: none;
  justify-content: center;
  align-items: center;
}
.modal-overlay.modal-open { display: flex; }

.import-export-modal-content,
.assign-modal-content,
.add-server-modal-content,
#expiringServersList,
#historyModal,
.history-modal-content,
.modal-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-elevated);
  padding: var(--s-8);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  animation: scaleIn var(--t-med) var(--ease);
}

/* Generic centered dialog (password reset) */
.modal-dialog {
  width: 90%;
  max-width: 420px;
  position: relative;
  top: auto;
  left: auto;
  transform: none;
}
.modal-dialog h3 {
  margin: 0 0 var(--s-2) 0;
  text-align: left;
  font-size: 18px;
}
.modal-subtitle {
  color: var(--text-muted);
  margin: 0 0 var(--s-4) 0;
  font-size: 14px;
  text-align: left;
}
.modal-buttons {
  display: flex;
  gap: var(--s-3);
  justify-content: flex-end;
  margin-top: var(--s-4);
}
.btn-primary {
  width: auto;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: var(--r-md);
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  font-family: inherit;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
  width: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 10px 18px;
  border-radius: var(--r-md);
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  font-family: inherit;
}
.btn-secondary:hover {
  background: var(--bg-muted);
  border-color: var(--text-soft);
}

.import-export-modal-content {
  width: 60%;
  max-width: 800px;
  max-height: 90%;
  overflow-y: auto;
}
.assign-modal-content { width: 50%; max-width: 600px; }
.add-server-modal-content {
  width: 50%;
  max-width: 600px;
  max-height: 90%;
  overflow-y: auto;
}
#expiringServersList { width: fit-content; height: 75vh; overflow: auto; }
#historyModal,
.history-modal-content {
  width: fit-content;
  min-width: 480px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}

/* Close buttons (consistent across modals) */
.import-export-close-btn,
.assign-close-btn,
.add-server-close-btn,
.close-btn,
.history-close-btn,
#closeHistoryModal {
  width: 32px;
  height: 32px;
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--bg-muted);
  color: var(--text-muted);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  cursor: pointer;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast) var(--ease);
  box-shadow: none;
}
.import-export-close-btn:hover,
.assign-close-btn:hover,
.add-server-close-btn:hover,
.close-btn:hover,
.history-close-btn:hover,
#closeHistoryModal:hover {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger-soft);
  transform: scale(1.05);
}

/* Import/Export columns */
.import-export-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-5);
}
.import-section,
.export-section {
  background: var(--surface-alt);
  padding: var(--s-5);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: none;
}
.import-section h4, .export-section h4 {
  margin-top: 0;
  margin-bottom: var(--s-3);
  font-weight: 600;
  font-size: 14px;
}

input[type="file"] { display: block; margin-bottom: var(--s-3); font-size: 13px; }

/* =========================================================
   FOOTER
   ========================================================= */
footer {
  background: var(--text);
  color: rgba(255, 255, 255, .7);
  text-align: center;
  padding: var(--s-5);
  font-size: 13px;
  width: 100%;
  margin-top: var(--s-10);
}
footer p { margin: 0; }
footer a {
  color: #a5b4fc;
  text-decoration: none;
  font-weight: 500;
}
footer a:hover { color: #c7d2fe; }

/* =========================================================
   PAGINATION (shared)
   ========================================================= */
#historyPagination button,
#expiringPagination button,
#pagination button,
.history-pagination button {
  width: fit-content;
  padding: 8px 14px;
  margin: 0 var(--s-1);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--t-fast) var(--ease);
}
#historyPagination button.active,
#expiringPagination button.active,
#pagination button.active,
.history-pagination button.active {
  background: var(--primary);
  color: var(--text-invert);
  border-color: var(--primary);
  font-weight: 600;
}
#historyPagination button:hover:not(:disabled),
#expiringPagination button:hover:not(:disabled),
#pagination button:hover:not(:disabled),
.history-pagination button:hover:not(:disabled) {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}
#pagination button:disabled,
#expiringPagination button:disabled,
#historyPagination button:disabled,
.history-pagination button:disabled {
  background: var(--bg-muted);
  color: var(--text-soft);
  cursor: not-allowed;
  border-color: var(--border);
  opacity: 1;
}
#pagination span,
.pagination-ellipsis {
  padding: 8px 6px;
  color: var(--text-soft);
  font-weight: 500;
  user-select: none;
}

#pagination,
.pagination {
  width: 80%;
  margin: var(--s-5) auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s-1);
  text-align: center;
}

.history-pagination {
  margin-top: var(--s-4);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s-1);
}

/* =========================================================
   POPUP NOTIFICATION (expiring server alert)
   ========================================================= */
.popup-notification,
#popupNotification {
  position: fixed;
  top: 84px;
  right: var(--s-5);
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  z-index: 998;
  animation: fadeIn var(--t-med) var(--ease);
}
.popup-notification h3,
#popupNotification h3 {
  margin: 0 0 var(--s-3) 0;
  text-align: left;
  font-size: 15px;
}
.popup-notification p,
#popupNotification p {
  margin: 0 0 var(--s-3) 0;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
}
.popup-notification button,
#popupNotification button {
  width: auto;
  margin: var(--s-2) var(--s-1) 0 0;
  padding: 8px 14px;
  border: none;
  background: var(--danger);
  color: #fff;
  cursor: pointer;
  border-radius: var(--r-md);
  font-size: 13px;
}
.popup-notification button:hover,
#popupNotification button:hover { background: var(--danger-hover); }

#viewExpiringServers {
  background: var(--primary) !important;
}
#viewExpiringServers:hover {
  background: var(--primary-hover) !important;
}

/* =========================================================
   MODAL TABLES (expiring / history)
   ========================================================= */
#expiringTable,
#historyModal table,
.history-modal-content table,
.history-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: var(--s-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: none;
}
#expiringTable th,
#expiringTable td,
#historyModal th,
#historyModal td,
.history-table th,
.history-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
#expiringTable th,
#historyModal th,
.history-table th {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
#expiringTable tr:hover,
#historyModal tr:hover,
.history-table tr:hover { background: var(--primary-soft); }
#historyModal tr:nth-child(even),
.history-table tr:nth-child(even) { background: var(--surface-alt); }

#expiringPagination { margin-top: var(--s-5); text-align: center; }

/* =========================================================
   ANIMATIONS
   ========================================================= */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes scaleIn {
  from { transform: translate(-50%, -50%) scale(.96); opacity: 0; }
  to   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* Reduced motion preference (WCAG 2.3.3) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* =========================================================
   ASSIGN / ADD-SERVER MODAL FORMS
   ========================================================= */
.assign-modal-content h3,
.add-server-modal-content h3 {
  margin-top: 0;
  margin-bottom: var(--s-5);
  font-size: 18px;
  text-align: left;
}

.assign-modal-content input,
.add-server-modal-content input,
.add-server-modal-content textarea {
  width: 100%;
  padding: 10px 12px;
  margin-top: var(--s-2);
  margin-bottom: var(--s-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 14px;
}
.assign-modal-content input:focus,
.add-server-modal-content input:focus,
.add-server-modal-content textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-ring);
}

.assign-modal-content button {
  background: var(--primary);
  color: #fff;
  padding: 10px 18px;
  border: none;
  border-radius: var(--r-md);
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  transition: background var(--t-fast) var(--ease);
}
.assign-modal-content button:hover { background: var(--primary-hover); }

.two-column-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-4);
  align-items: start;
}
.two-column-form input,
.two-column-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  font-family: inherit;
}

.submit-btn {
  grid-column: span 2;
  background: var(--primary);
  color: #fff;
  padding: 12px 18px;
  border: none;
  border-radius: var(--r-md);
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  text-align: center;
  transition: background var(--t-fast) var(--ease);
}
.submit-btn:hover { background: var(--primary-hover); }
.submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* =========================================================
   SEARCH / FILTER FORM
   ========================================================= */
#searchFilterForm {
  width: 95%;
  margin: 0 auto var(--s-4) auto;
  padding: var(--s-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

.grid-container {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--s-3);
  margin-bottom: var(--s-2);
}

#searchFilterForm input[type="text"],
#searchFilterForm select,
#searchFilterForm button {
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-sizing: border-box;
  font-family: inherit;
  font-size: 14px;
  background: var(--surface);
  margin-bottom: 0;
}
#searchFilterForm input[type="text"]:focus,
#searchFilterForm select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-ring);
}

#searchFilterForm input[type="text"] { grid-column: span 4; }

#searchFilterForm button[type="submit"] {
  grid-column: span 1;
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  cursor: pointer;
  font-weight: 500;
  transition: background var(--t-fast) var(--ease);
}
#searchFilterForm button[type="submit"]:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

#clearFilters {
  grid-column: span 1;
  background: var(--surface);
  color: var(--danger);
  border-color: var(--border-strong);
}
#clearFilters:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger-hover);
}

/* =========================================================
   USER MANAGEMENT
   ========================================================= */
.user-management-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: var(--s-5);
  padding: var(--s-5);
}

.add-user-section,
.users-list-section {
  background: var(--surface);
  padding: var(--s-6);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.add-user-section { height: fit-content; }
.users-list-section { display: flex; flex-direction: column; overflow-y: auto; }

.users-list-section table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  flex-grow: 1;
  margin: 0;
  border: none;
  box-shadow: none;
}

.add-user-section form {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  box-shadow: none;
}

#addUserForm label,
.add-user-section label {
  display: block;
  margin-top: var(--s-3);
  margin-bottom: var(--s-1);
  font-weight: 500;
  font-size: 13px;
  color: var(--text-muted);
}
#addUserForm input,
#addUserForm select,
.add-user-section input,
.add-user-section select {
  width: 100%;
  padding: 10px 12px;
  margin-top: 0;
  margin-bottom: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  font-family: inherit;
  font-size: 14px;
}

#addUserButton {
  margin-top: var(--s-5);
  background: var(--primary);
  color: #fff;
  padding: 10px 18px;
  border: none;
  border-radius: var(--r-md);
  cursor: pointer;
  font-weight: 500;
  width: 100%;
}
#addUserButton:hover { background: var(--primary-hover); }
#addUserButton:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#usersTable th,
#usersTable td {
  padding: 12px 14px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
#usersTable th {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
}

.users-action-buttons {
  display: flex;
  justify-content: center;
  gap: var(--s-2);
}
.users-action-buttons button {
  width: 32px;
  height: 32px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 15px;
  color: var(--text-muted);
  border-radius: var(--r-md);
  transition: all var(--t-fast) var(--ease);
}
.users-action-buttons button:hover:not(:disabled) {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--border);
}
.users-action-buttons button:disabled {
  color: var(--text-soft);
  cursor: not-allowed;
  opacity: .5;
}

/* Status select inside the users table */
#usersTable select {
  width: auto;
  min-width: 140px;
  padding: 6px 10px;
  margin: 0;
  font-size: 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
}
#usersTable select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--shadow-ring);
}
#usersTable select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* =========================================================
   AUDIT LOGS PAGE
   ========================================================= */
#auditLogsTable {
  width: 95%;
  margin: var(--s-5) auto;
}
#auditLogsTable th,
#auditLogsTable td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
#auditLogsTable th {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
#auditLogsTable tbody tr:nth-child(even) { background: var(--surface-alt); }

/* =========================================================
   TOAST
   ========================================================= */
.toast-container {
  position: fixed;
  bottom: var(--s-5);
  right: var(--s-5);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  animation: toastIn 5s forwards;
  border-left: 3px solid var(--primary);
  max-width: 400px;
  word-wrap: break-word;
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

/* Manual fade-out applied by JS before removal */
.toast-fade-out {
  opacity: 0 !important;
  transform: translateY(-10px) !important;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

@keyframes toastIn {
  0%   { opacity: 0; transform: translateY(20px); }
  10%  { opacity: 1; transform: translateY(0); }
  90%  { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(20px); }
}

/* =========================================================
   LOGIN PAGE (scoped overrides)
   ========================================================= */
.login-container {
  background: var(--surface);
  padding: var(--s-8);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  text-align: center;
  border: 1px solid var(--border);
}
.login-container h2 {
  text-align: center;
  margin-bottom: var(--s-5);
}
.login-icon {
  font-size: 44px;
  color: var(--primary);
  margin-bottom: var(--s-4);
}
.login-container form {
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  box-shadow: none;
  display: flex;
  flex-direction: column;
}
.login-container label {
  text-align: left;
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 768px) {
  body { padding-top: 56px; }

  .navbar {
    height: auto;
    flex-direction: column;
    gap: var(--s-2);
    padding: var(--s-3) 0;
  }
  .navbar-left, .navbar-right { margin: 0; }
  .navbar a, .logout-btn { margin-left: var(--s-2); }

  .button-section { flex-direction: column; gap: var(--s-3); }
  .button-section button { width: 80%; margin: 0 auto; }

  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tr {
    margin-bottom: var(--s-3);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface);
    overflow: hidden;
  }
  td {
    display: flex;
    justify-content: space-between;
    padding: 10px var(--s-3);
    text-align: right;
  }
  td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
  td button { width: 36px; height: 36px; }
  .td-notes { width: 100%; }

  form { width: 90%; }
  select { width: 50%; }

  #historyModal,
  .history-modal-content { width: 92%; min-width: 0; padding: var(--s-5); }

  .grid-container { grid-template-columns: 1fr; }
  #searchFilterForm input[type="text"],
  #searchFilterForm select,
  #searchFilterForm button {
    width: 100%;
    grid-column: span 1;
  }

  #pagination,
  .pagination { width: 95%; }

  #expiringServersList {
    width: 92%;
    height: 80%;
    max-height: 80vh;
    border-radius: var(--r-lg);
  }

  .popup-notification,
  #popupNotification {
    width: calc(100% - var(--s-8));
    right: var(--s-4);
    left: var(--s-4);
  }

  .modal-content {
    max-height: calc(100vh - 100px);
    overflow-y: auto;
  }

  .user-management-grid { grid-template-columns: 1fr; }
  .client-details { width: auto; }

  .two-column-form { grid-template-columns: 1fr; }
  .form-submit { grid-column: span 1; }

  .import-export-columns { grid-template-columns: 1fr; }
  .import-export-modal-content,
  .assign-modal-content,
  .add-server-modal-content { width: 92%; }

  .modal-buttons { flex-direction: column-reverse; }
  .modal-buttons button { width: 100%; }
}

/* =========================================================
   COMPACT SERVER TABLE - 6 COLUMN LAYOUT
   ========================================================= */
.compact-server-table {
  width: 98%;
  table-layout: fixed;
}

.compact-server-table th,
.compact-server-table td {
  vertical-align: top;
  text-align: left;
  padding: 14px 14px;
}

.compact-server-table th:nth-child(1),
.compact-server-table td:nth-child(1) {
  width: 24%;
}

.compact-server-table th:nth-child(2),
.compact-server-table td:nth-child(2) {
  width: 26%;
}

.compact-server-table th:nth-child(3),
.compact-server-table td:nth-child(3) {
  width: 16%;
}

.compact-server-table th:nth-child(4),
.compact-server-table td:nth-child(4) {
  width: 12%;
}

.compact-server-table th:nth-child(5),
.compact-server-table td:nth-child(5) {
  width: 10%;
}

.compact-server-table th:nth-child(6),
.compact-server-table td:nth-child(6) {
  width: 12%;
}

.compact-server-table .td-row {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  margin-bottom: 7px;
  line-height: 1.4;
}

.compact-server-table td:first-child .td-row:first-child span {
  white-space: nowrap;
  font-size: 15px;
  font-weight: 700;
}

/* Prevent unnecessary line breaks */
.compact-server-table .td-row span,
.compact-server-table .td-row a {
  word-break: normal;
  overflow-wrap: anywhere;
}

/* Specs column */
.compact-server-table td:nth-child(2) .td-row {
  grid-template-columns: 72px minmax(0, 1fr);
}

/* Server info column */
.compact-server-table td:nth-child(1) .td-row {
  grid-template-columns: 78px minmax(0, 1fr);
}

.compact-server-table .td-row:last-child {
  margin-bottom: 0;
}

.compact-server-table .td-row label {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  white-space: nowrap;
}

.compact-server-table .td-row span,
.compact-server-table .td-row a {
  min-width: 0;
  text-align: left;
  word-break: break-word;
  font-size: 13px;
  color: var(--text);
}

.compact-server-table .td-row a {
  color: var(--primary);
  font-weight: 600;
}

.compact-server-table .status-badge {
  padding: 5px 10px;
  border-radius: var(--r-full);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.compact-server-table .status-badge.assigned {
  background: var(--success-soft);
  color: #047857;
}

.compact-server-table .status-badge.unassigned {
  background: var(--warning-soft);
  color: #92400e;
}

.compact-server-table .action-column {
  text-align: center;
}

.compact-server-table .action-btn {
  width: 100%;
  min-height: 34px;
  margin: 0 0 7px 0;
  padding: 8px 10px;
  justify-content: center;
  border-radius: var(--r-md);
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
}

.compact-server-table .action-btn:last-child {
  margin-bottom: 0;
}

.compact-server-table .action-btn.success {
  background: var(--success-soft);
  color: #047857;
}

.compact-server-table .action-btn.warning {
  background: var(--warning-soft);
  color: #92400e;
}

.compact-server-table .action-btn.neutral {
  background: var(--primary-soft);
  color: var(--primary);
}

.compact-server-table .action-btn.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.compact-server-table .action-btn:hover {
  filter: brightness(0.97);
  border-color: var(--border);
}

.compact-server-table .td-notes {
  width: auto;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
  word-break: break-word;
  text-align: left;
  font-size: 13px;
}

.compact-server-table .edit {
  outline: none;
  border-radius: var(--r-sm);
  padding: 2px 4px;
}

.compact-server-table .edit:hover {
  background: var(--primary-soft);
}

.compact-server-table .edit:focus {
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--primary);
}

/* Tablet */
@media (max-width: 1200px) {
  .compact-server-table {
    width: 100%;
  }

  .compact-server-table th,
  .compact-server-table td {
    padding: 12px 10px;
  }

  .compact-server-table .td-row {
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 6px;
  }

  .compact-server-table .td-row label,
  .compact-server-table .td-row span,
  .compact-server-table .td-row a {
    font-size: 12px;
  }

  .compact-server-table .action-btn {
    font-size: 11px;
    padding: 7px 8px;
  }
}

/* Mobile - convert each table row into clean stacked card */
@media (max-width: 768px) {
  .compact-server-table,
  .compact-server-table thead,
  .compact-server-table tbody,
  .compact-server-table th,
  .compact-server-table td,
  .compact-server-table tr {
    display: block;
    width: 100%;
  }

  .compact-server-table {
    width: 95%;
    border: none;
    background: transparent;
    box-shadow: none;
    margin-top: var(--s-4);
  }

  .compact-server-table thead {
    display: none;
  }

  .compact-server-table tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--s-4);
    overflow: hidden;
  }

  .compact-server-table tr:nth-child(even) {
    background: var(--surface);
  }

  .compact-server-table tr:hover {
    background: var(--surface);
  }

  .compact-server-table td {
    display: block;
    width: 100% !important;
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
  }

  .compact-server-table td:last-child {
    border-bottom: none;
  }

  .compact-server-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 8px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.07em;
  }

  .compact-server-table .td-row {
    display: grid;
    grid-template-columns: 95px minmax(0, 1fr);
    gap: 8px;
    margin-bottom: 8px;
  }

  .compact-server-table .td-row label {
    font-size: 12px;
  }

  .compact-server-table .td-row span,
  .compact-server-table .td-row a {
    font-size: 13px;
  }

  .compact-server-table .action-column {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .compact-server-table .action-btn {
    width: 100%;
    margin: 0;
    min-height: 38px;
  }

  .compact-server-table .td-notes {
    max-height: 160px;
  }
}

/* Small mobile */
@media (max-width: 420px) {
  .compact-server-table {
    width: 100%;
  }

  .compact-server-table .td-row {
    grid-template-columns: 1fr;
    gap: 3px;
  }

  .compact-server-table .td-row label {
    color: var(--text-soft);
  }
}

/* =========================================================
   NOTES PREVIEW
   ========================================================= */
.td-notes-wrapper {
  min-width: 0;
}

.td-notes-preview {
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  word-break: break-word;
  margin-bottom: 10px;
  max-height: 130px;
  overflow: hidden;
}

.td-notes-preview {
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
  position: relative;
  min-height: 120px;
}

.view-notes-btn {
  width: 100%;
  min-height: 34px;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 12px;
  font-weight: 700;
}

.view-notes-btn:hover {
  background: var(--primary);
  color: #fff;
}

/* =========================================================
   NOTES MODAL
   ========================================================= */
.notes-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(4px);
  z-index: 9998;
}

.notes-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  width: 700px;
  max-width: 95%;
  max-height: 85vh;
  overflow: auto;
  transform: translate(-50%, -50%);
  background: var(--surface);
  border-radius: var(--r-xl);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  z-index: 9999;
}

.notes-modal h3 {
  margin-top: 0;
  margin-bottom: 20px;
  text-align: left;
}

.notes-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: var(--bg-muted);
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-size: 20px;
  padding: 0;
}

.notes-modal-close:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.notes-modal-textarea {
  width: 100%;
  min-height: 320px;
  resize: vertical;
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 20px;
}

.notes-modal-footer {
  display: flex;
  justify-content: flex-end;
}

.notes-save-btn {
  width: auto;
  min-width: 140px;
}

/* Mobile */
@media (max-width: 768px) {
  .notes-modal {
    width: 95%;
    padding: 18px;
  }

  .notes-modal-textarea {
    min-height: 240px;
  }
}

/* =========================================================
   EDITABLE FIELD BORDER
   ========================================================= */
.edit,
td[contenteditable="true"],
span[contenteditable="true"],
div[contenteditable="true"] {
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 3px 6px;
  min-height: 24px;
  transition:
    border-color var(--t-fast) var(--ease),
    background-color var(--t-fast) var(--ease),
    box-shadow var(--t-fast) var(--ease);
}

/* Hover */
.edit:hover,
td[contenteditable="true"]:hover,
span[contenteditable="true"]:hover,
div[contenteditable="true"]:hover {
  border-color: #d7deea;
  background: #fafbff;
}

/* Focus / Editing */
.edit:focus,
td[contenteditable="true"]:focus,
span[contenteditable="true"]:focus,
div[contenteditable="true"]:focus {
  outline: none;
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.12);
}

/* Empty editable fields */
.edit:empty::before,
td[contenteditable="true"]:empty::before,
span[contenteditable="true"]:empty::before,
div[contenteditable="true"]:empty::before {
  content: "—";
  color: var(--text-soft);
}

.status-client-wrap {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}

.client-status-link {
  text-decoration: none;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.client-status-link:hover {
  text-decoration: none;
  filter: brightness(0.95);
}