:root {
  --color-primary: #1e40af;
  --color-primary-light: #3b82f6;
  --color-primary-dark: #1e3a8a;
  --color-sidebar-bg: #0f172a;
  --color-sidebar-hover: #1e293b;
  --color-sidebar-active: #1e40af;
  --color-sidebar-text: #e2e8f0;
  --color-sidebar-text-muted: #94a3b8;
  --color-main-bg: #f8fafc;
  --color-card-bg: #ffffff;
  --color-card-border: #e2e8f0;
  --color-text-primary: #0f172a;
  --color-text-secondary: #475569;
  --color-text-muted: #64748b;
  --color-success: #16a34a;
  --color-success-bg: #dcfce7;
  --color-warning: #ca8a04;
  --color-warning-bg: #fef9c3;
  --color-danger: #dc2626;
  --color-danger-bg: #fee2e2;
  --color-info: #2563eb;
  --color-info-bg: #dbeafe;
  --color-border: #e2e8f0;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --sidebar-width: 260px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text-primary);
  background-color: var(--color-main-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Only the content containers scroll — the page itself must never
     overflow horizontally on mobile. */
  overflow-x: hidden;
  max-width: 100vw;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input {
  font-family: inherit;
  font-size: inherit;
}

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

/* ===== Login Page ===== */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #1e40af 100%);
  padding: 1rem;
}

.login-card {
  background: var(--color-card-bg);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}

.login-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.login-brand-logo {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
  border-radius: var(--radius-lg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 1rem;
}

.login-brand h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text-primary);
}

.login-brand p {
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

/* ===== Form ===== */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
}

.form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  color: var(--color-text-primary);
  background: white;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgb(30 64 175 / 0.1);
}

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

.form-error {
  color: var(--color-danger);
  font-size: 0.875rem;
  margin-top: 0.5rem;
  background: var(--color-danger-bg);
  padding: 0.75rem;
  border-radius: var(--radius-md);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  font-size: 0.9375rem;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

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

.btn-primary:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

.btn-secondary {
  background: #f1f5f9;
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-block {
  width: 100%;
}

/* ===== Sidebar Layout ===== */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--color-sidebar-bg);
  color: var(--color-sidebar-text);
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  z-index: 50;
  overflow: hidden;
  transform: translateX(-100%);
  transition: transform 0.2s ease;
}

.layout.nav-open .sidebar {
  transform: translateX(0);
}

/* Click-catcher backdrop for the mobile drawer (layout-level sibling of the
   aside). Hidden on desktop — the sidebar there is a persistent panel, and
   tapping content must never collapse it. */
.sidebar-overlay {
  display: none;
}

.sidebar-brand {
  padding: 1.5rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
}

.sidebar-brand-logo {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 18px;
  flex-shrink: 0;
}

.sidebar-brand-name {
  font-size: 1.125rem;
  font-weight: 700;
  color: white;
}

.sidebar-brand-sub {
  font-size: 0.75rem;
  color: var(--color-sidebar-text-muted);
  margin-top: 0.125rem;
}

/* Explicit close affordance inside the drawer (mobile); the header
   hamburger sits beneath the open drawer so this is the visible exit. */
.sidebar-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--color-sidebar-text-muted);
  font-size: 1.5rem;
  line-height: 1;
  border-radius: var(--radius-md);
  cursor: pointer;
}

.sidebar-close:hover {
  background: var(--color-sidebar-hover);
  color: white;
}

@media (max-width: 1024px) {
  .sidebar-close {
    display: flex;
  }
}

.sidebar-nav {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem 0.75rem;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

.sidebar-nav::-webkit-scrollbar {
  width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 3px;
}

.sidebar-nav-section {
  margin-bottom: 1.5rem;
}

.sidebar-nav-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-sidebar-text-muted);
  padding: 0 0.75rem;
  margin-bottom: 0.5rem;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.125rem;
  border-radius: var(--radius-md);
  color: var(--color-sidebar-text);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s ease;
  cursor: pointer;
}

.sidebar-nav-item:hover {
  background: var(--color-sidebar-hover);
  color: white;
}

.sidebar-nav-item.active {
  background: var(--color-sidebar-active);
  color: white;
}

.sidebar-nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

/* ===== Multi-level (database-driven) menu groups ===== */
.sidebar-nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.65rem 0.75rem;
  margin-bottom: 0.125rem;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-sidebar-text);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sidebar-nav-group-toggle:hover {
  background: var(--color-sidebar-hover);
  color: white;
}

.sidebar-nav-group-toggle.has-active {
  color: white;
}

.sidebar-nav-group-toggle .sidebar-nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-nav-chevron {
  font-size: 0.7rem;
  transition: transform 0.15s ease;
  opacity: 0.7;
}

.sidebar-nav-group.open .sidebar-nav-chevron {
  transform: rotate(180deg);
}

.sidebar-nav-sub {
  display: none;
  margin: 0.125rem 0 0.375rem 0.9rem;
  padding-left: 0.5rem;
  border-left: 1px solid #1e293b;
}

.sidebar-nav-group.open .sidebar-nav-sub {
  display: block;
}

.sidebar-nav-item.sub-item {
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  font-weight: 400;
}

.sidebar-user {
  padding: 1rem 1.25rem;
  border-top: 1px solid #1e293b;
  flex-shrink: 0;
  background: var(--color-sidebar-bg);
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.sidebar-user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary-light), #60a5fa);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 0.9375rem;
  flex-shrink: 0;
}

.sidebar-user-email {
  font-size: 0.8125rem;
  font-weight: 500;
  color: white;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-role {
  font-size: 0.75rem;
  color: var(--color-sidebar-text-muted);
  margin-top: 0.125rem;
}

.sidebar-logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-sidebar-text-muted);
  transition: all 0.15s ease;
  background: transparent;
}

.sidebar-logout-btn:hover {
  background: #ef4444;
  color: white;
}

/* ===== Main Content ===== */
.main {
  flex: 1;
  min-width: 0;
  margin-left: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.2s ease;
  overflow-x: hidden;
}

.layout.nav-open .main {
  margin-left: var(--sidebar-width);
}

.main-header {
  background: white;
  border-bottom: 1px solid var(--color-border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.main-header-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text-primary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-content {
  flex: 1;
  min-width: 0;
  padding: 2rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: 0.25rem;
}

.page-subtitle {
  color: var(--color-text-muted);
  margin-bottom: 2rem;
}

/* ===== Cards ===== */
.card {
  background: var(--color-card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-card-border);
  overflow: hidden;
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

.card-body {
  padding: 1.5rem;
}

/* ===== Stat Grid ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-card-border);
  padding: 1.5rem;
}

.stat-card-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.025em;
  margin-bottom: 0.5rem;
}

.stat-card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: 1.1;
}

.stat-card-icon {
  float: right;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  margin-top: -0.25rem;
}

.stat-icon-blue {
  background: var(--color-info-bg);
  color: var(--color-info);
}

.stat-icon-green {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.stat-icon-yellow {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.stat-icon-purple {
  background: #f3e8ff;
  color: #9333ea;
}

.stat-icon-red {
  background: #fee2e2;
  color: #dc2626;
}

.live-dot {
  animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* ===== Tables ===== */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
}

.table th {
  text-align: left;
  padding: 0.875rem 1.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.table td {
  padding: 1rem 1.25rem;
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.table tbody tr:hover {
  background: #f8fafc;
}

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

/* ===== Filter bar (shared by all data tables) ===== */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
  max-width: 100%;
}

.filter-bar .form-group {
  flex: 1 1 150px;
  min-width: 140px;
  max-width: 100%;
  margin-bottom: 0;
}

.filter-bar .form-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.filter-bar input[type='date'] {
  min-height: 42px;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}

.pagination-info {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.pagination-buttons {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-wrap: wrap;
}

.pagination-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 0.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  background: white;
  border-radius: var(--radius-md);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  cursor: pointer;
}

.pagination-btn:hover:not(:disabled) {
  background: #f1f5f9;
  color: var(--color-text-primary);
}

.pagination-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}

.pagination-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  .pagination {
    flex-direction: column;
    align-items: stretch;
  }
  .pagination-buttons {
    justify-content: center;
  }
}

/* ===== Chips / Badges ===== */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
}

.chip-active {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.chip-suspended {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.chip-blocked {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.chip-pending {
  background: var(--color-info-bg);
  color: var(--color-info);
}

.chip-inactive {
  background: #f1f5f9;
  color: var(--color-text-muted);
}

.chip-completed {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.chip-missed {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.chip-in-progress {
  background: var(--color-info-bg);
  color: var(--color-info);
}

.chip-cancelled {
  background: #f1f5f9;
  color: var(--color-text-muted);
}

.chip-admin {
  background: #fef3c7;
  color: #92400e;
}

.chip-user {
  background: #dbeafe;
  color: #1e40af;
}

/* ===== Loading / Empty ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--color-text-muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 0.75rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--color-text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 0.25rem;
}

.empty-state-desc {
  font-size: 0.875rem;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  /* Keep aside-level .open working for the mobile drawer. */
  .layout.nav-open .sidebar {
    transform: translateX(0);
  }
  .main,
  .layout.nav-open .main {
    margin-left: 0;
  }
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .sidebar-overlay.visible {
    opacity: 1;
    pointer-events: auto;
  }
}

/* ===== Hamburger (sidebar toggle in the header) ===== */
.hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border: 1px solid var(--color-border);
  background: white;
  border-radius: var(--radius-md);
  font-size: 1.25rem;
  line-height: 1;
  color: var(--color-text-primary);
  cursor: pointer;
  transition: background 0.15s ease;
}

.hamburger:hover {
  background: var(--color-background);
}

/* ===== Modals / Dialogs ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: all 0.15s ease;
  font-size: 1.25rem;
  line-height: 1;
}

.modal-close:hover {
  background: #f1f5f9;
  color: var(--color-text-primary);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
}

.form-group-row {
  margin-bottom: 1.25rem;
}

.btn-danger {
  background: var(--color-danger);
  color: white;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8125rem;
  border-radius: var(--radius-sm);
}

.btn-icon {
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.btn-ghost:hover {
  background: #f1f5f9;
  color: var(--color-text-primary);
}

.action-cell {
  display: flex;
  gap: 0.375rem;
  align-items: center;
  white-space: nowrap;
}

.confirm-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  display: block;
}

.confirm-danger .confirm-icon { color: var(--color-danger); }

.textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-family: inherit;
  color: var(--color-text-primary);
  background: white;
  resize: vertical;
  min-height: 80px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgb(30 64 175 / 0.1);
}

.kv-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1rem;
}

.kv-label {
  color: var(--color-text-muted);
  font-size: 0.8125rem;
  font-weight: 500;
}

.kv-value {
  color: var(--color-text-primary);
  font-size: 0.875rem;
  word-break: break-word;
}

.section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin: 1.25rem 0 0.5rem 0;
}

.section-title:first-child { margin-top: 0; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0;
}

.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ===== Admin: Permission Summary Badges ===== */
.perm-summary {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  flex-wrap: wrap;
}

.perm-count {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--color-info-bg);
  color: var(--color-info);
  white-space: nowrap;
}

.perm-count.perm-full {
  background: #fef3c7;
  color: #92400e;
}

.perm-count.perm-none {
  background: #f1f5f9;
  color: var(--color-text-muted);
}

.module-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 500;
  background: #f1f5f9;
  color: var(--color-text-secondary);
}

.module-tag.granted {
  background: var(--color-success-bg);
  color: var(--color-success);
}

/* ===== Enterprise Permission Modal ===== */
.modal-lg {
  max-width: 880px !important;
}

.perm-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-bottom: 1.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

.perm-header-avatar {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--color-primary-light), #60a5fa);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.perm-header-meta {
  flex: 1;
  min-width: 0;
}

.perm-header-name {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: 0.15rem;
}

.perm-header-email {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  margin-bottom: 0.5rem;
  word-break: break-word;
}

.perm-header-chips {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.perm-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 720px) {
  .perm-stats { grid-template-columns: repeat(2, 1fr); }
}

.perm-stat-card {
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.875rem 1rem;
  text-align: center;
}

.perm-stat-card .val {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-text-primary);
  line-height: 1.1;
}

.perm-stat-card .lbl {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.25rem;
  font-weight: 600;
}

.perm-stat-card.green .val { color: var(--color-success); }
.perm-stat-card.blue  .val { color: var(--color-info); }
.perm-stat-card.amber .val { color: var(--color-warning); }
.perm-stat-card.red   .val { color: var(--color-danger); }

.perm-module-section {
  background: white;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
  overflow: hidden;
}

.perm-module-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.125rem;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  border-bottom: 1px solid var(--color-border);
}

.perm-module-title {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-weight: 700;
  color: var(--color-text-primary);
  font-size: 0.9375rem;
}

.perm-module-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--color-primary);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
}

.perm-module-progress {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-weight: 600;
  margin-left: 0.25rem;
}

.perm-module-progress-bar {
  width: 120px;
  height: 6px;
  background: #e2e8f0;
  border-radius: 9999px;
  overflow: hidden;
  margin-left: 0.75rem;
}

.perm-module-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary-light), var(--color-primary));
  border-radius: 9999px;
  transition: width 0.3s ease;
}

.perm-module-actions {
  display: flex;
  gap: 0.375rem;
}

.bulk-btn {
  padding: 0.3rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: white;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.bulk-btn:hover { background: #f1f5f9; color: var(--color-text-primary); }
.bulk-btn.grant:hover { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success-bg); }
.bulk-btn.revoke:hover { background: var(--color-danger-bg); color: var(--color-danger); border-color: var(--color-danger-bg); }
.bulk-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.perm-rows {
  padding: 0.5rem 0;
}

.perm-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 1.125rem;
  transition: background 0.1s ease;
}

.perm-row:hover { background: #f8fafc; }

.perm-row + .perm-row { border-top: 1px solid #f1f5f9; }

.perm-check-wrap {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.perm-check-wrap input {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--color-primary);
}

.perm-info {
  flex: 1;
  min-width: 0;
}

.perm-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-primary);
  letter-spacing: -0.01em;
}

.perm-name {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.perm-status-pill {
  flex-shrink: 0;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
}

.perm-status-pill.on {
  background: var(--color-success-bg);
  color: var(--color-success);
}
.perm-status-pill.off {
  background: #f1f5f9;
  color: var(--color-text-muted);
}

.perm-lock-banner {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border: 1px solid #fcd34d;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  color: #78350f;
  font-size: 0.875rem;
  line-height: 1.5;
}

.perm-lock-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
  line-height: 1.2;
}

.perm-footer-summary {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  color: var(--color-text-secondary);
  font-size: 0.8125rem;
}

/* ========== Visitor / Gate Passes + Verifier ========== */
.pass-code-display {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  padding: 1.5rem 1rem;
  background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 50%, #2563eb 100%);
  border-radius: var(--radius-lg);
  color: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 800;
  font-size: 2.75rem;
  letter-spacing: 0.75rem;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  border: 2px solid #3b82f6;
  box-shadow: 0 10px 25px -5px rgba(37, 99, 235, 0.35), 0 8px 10px -6px rgba(37, 99, 235, 0.2);
  user-select: all;
}
.pass-type-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
}
.pass-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0 1.5rem;
}
.pass-kpi {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 0.875rem 1rem;
}
.pass-kpi-label {
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}
.pass-kpi-value {
  color: var(--color-text-primary);
  font-size: 0.95rem;
  font-weight: 600;
}

/* Verifier */
.verifier-card {
  max-width: 680px;
  margin: 0 auto;
}
.verifier-inputs {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.625rem;
  margin: 1.5rem 0 1rem;
}
.verifier-digit {
  aspect-ratio: 1 / 1;
  text-align: center;
  font-family: ui-monospace, monospace;
  font-size: 2rem;
  font-weight: 800;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #fff;
  transition: all 0.15s;
  color: var(--color-text-primary);
}
.verifier-digit:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
  background: #eff6ff;
}
.verifier-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.625rem;
  margin-top: 0.75rem;
}
.verify-result {
  margin-top: 1.5rem;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  border-left-width: 4px;
  border-left-style: solid;
  background: #fff;
  border: 1px solid var(--color-border);
}
.verify-result-success {
  border-left-color: var(--color-success);
  background: linear-gradient(90deg, rgba(16,185,129,0.08) 0%, rgba(255,255,255,0) 100%);
}
.verify-result-fail {
  border-left-color: var(--color-danger);
  background: linear-gradient(90deg, rgba(239,68,68,0.08) 0%, rgba(255,255,255,0) 100%);
}
.verify-result-title {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 0.5rem;
}
.verify-result-title.success { color: #047857; }
.verify-result-title.fail { color: #991b1b; }

/* Visitors & gate entries tabs */
.sub-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  background: #f1f5f9;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
}
.sub-tab {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text-secondary);
  font-weight: 500;
  font-size: 0.875rem;
  border: none;
  background: transparent;
  transition: all 0.15s;
}
.sub-tab.active {
  background: #fff;
  color: var(--color-primary);
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

/* filter bar */
.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.625rem;
  margin-bottom: 1rem;
}

/* status badges for visitor pass */
.badge-pass {
  display: inline-flex;
  align-items: center;
  padding: 0.1875rem 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.badge-pass.ACTIVE { background: #dcfce7; color: #166534; }
.badge-pass.USED { background: #dbeafe; color: #1e40af; }
.badge-pass.EXPIRED { background: #f1f5f9; color: #334155; }
.badge-pass.CANCELLED { background: #fee2e2; color: #991b1b; }
.badge-pass.REVOKED { background: #fef3c7; color: #92400e; }
.badge-pass.DRAFT { background: #f3e8ff; color: #581c87; }

.verified-pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.15rem 0.5rem; font-size: 0.7rem; font-weight: 600; border-radius: 999px;
}
.verified-pill.ok { background: #dcfce7; color: #166534; }
.verified-pill.no { background: #fee2e2; color: #991b1b; }

@media (max-width: 640px) {
  .main-content {
    padding: 1rem;
  }
  .main-header {
    padding: 0.875rem 1rem;
  }
  .login-card {
    padding: 1.5rem;
  }
  .card-body {
    padding: 1rem;
  }
  .card-header {
    padding: 1rem;
  }
  .table th,
  .table td {
    padding: 0.75rem 1rem;
  }
  .stat-card {
    padding: 1rem;
  }
  .stat-card-value {
    font-size: 1.5rem;
  }
  .modal { max-height: 95vh; }
  .modal-body { padding: 1rem; }
  .modal-header, .modal-footer { padding: 1rem; }
}

/* ===== Page header row (action bar used by Visitors / Gate pages) ===== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-header-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text-primary);
}
.page-header-subtitle {
  margin: 0.25rem 0 0;
  color: var(--color-text-secondary);
  font-size: 0.875rem;
  max-width: 640px;
}
.page-header-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* ===== Toast notifications ===== */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 380px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-lg);
  color: #fff;
  font-size: 0.875rem;
  font-weight: 500;
  background: var(--color-success);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.25s ease;
}
.toast-error { background: var(--color-danger); }
.toast-info { background: var(--color-info); }
.toast-hide {
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.toast-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6875rem;
  flex-shrink: 0;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Misc missing helpers ===== */
.modal-footer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  width: 100%;
  flex-wrap: wrap;
}
.card-subtitle {
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
  margin-top: 2px;
  font-weight: 400;
}
.row-actions {
  display: flex;
  gap: 0.375rem;
  align-items: center;
}
.actions-nowrap {
  white-space: nowrap;
}
.input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  color: var(--color-text-primary);
  background: white;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgb(30 64 175 / 0.1);
}
