/* ===================== VARIABLES ===================== */
:root {
  --primary: #2c3e50;
  --primary-light: #34495e;
  --accent: #3498db;
  --accent-hover: #2980b9;
  --success: #27ae60;
  --warning: #f39c12;
  --danger: #e74c3c;
  --danger-hover: #c0392b;
  --bg: #f5f6fa;
  --card-bg: #ffffff;
  --text: #2c3e50;
  --text-muted: #7f8c8d;
  --border: #dcdde1;
  --shadow: 0 2px 10px rgba(0,0,0,0.08);
  --shadow-lg: 0 5px 25px rgba(0,0,0,0.12);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: all 0.3s ease;
}

/* ===================== RESET ===================== */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { text-decoration: none; color: var(--accent); }
button { cursor: pointer; border: none; font-family: inherit; }
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
}

/* ===================== LOGIN PAGE ===================== */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
}

.login-card {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  overflow: hidden;
}

.login-header {
  background: var(--primary);
  color: white;
  padding: 30px;
  text-align: center;
}

.login-header h1 {
  font-size: 24px;
  margin-bottom: 5px;
}

.login-header p {
  opacity: 0.8;
  font-size: 14px;
}

.login-body {
  padding: 30px;
}

.login-tabs {
  display: flex;
  margin-bottom: 25px;
  border-bottom: 2px solid var(--border);
}

.login-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  background: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: var(--transition);
}

.login-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ===================== FORMS ===================== */
.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  transition: var(--transition);
  background: white;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.form-control::placeholder {
  color: #bdc3c7;
}

/* ===================== BUTTONS ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  transition: var(--transition);
  border: none;
}

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

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover { background: #229954; }

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

.btn-warning {
  background: var(--warning);
  color: white;
}
.btn-warning:hover { background: #e67e22; }

.btn-secondary {
  background: #95a5a6;
  color: white;
}
.btn-secondary:hover { background: #7f8c8d; }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:hover {
  background: var(--bg);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn-block { width: 100%; }

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

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

.sidebar {
  width: 260px;
  background: var(--primary);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
  font-size: 16px;
  margin-bottom: 4px;
}

.sidebar-header small {
  opacity: 0.7;
  font-size: 12px;
}

.sidebar-nav {
  flex: 1;
  padding: 15px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  transition: var(--transition);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255,255,255,0.1);
  color: white;
}

.nav-item i {
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 15px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.main-content {
  flex: 1;
  margin-left: 260px;
  padding: 25px;
  min-height: 100vh;
}

/* ===================== TOP BAR ===================== */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
}

.topbar h1 {
  font-size: 22px;
  color: var(--primary);
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--primary);
  cursor: pointer;
}

/* ===================== CARDS ===================== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.card-header h3 {
  font-size: 16px;
  color: var(--primary);
}

.card-body {
  padding: 22px;
}

/* Stats Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-bottom: 25px;
}

.stat-card {
  background: white;
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 15px;
}

.stat-icon {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: white;
}

.stat-icon.blue { background: linear-gradient(135deg, #3498db, #2980b9); }
.stat-icon.green { background: linear-gradient(135deg, #27ae60, #229954); }
.stat-icon.orange { background: linear-gradient(135deg, #f39c12, #e67e22); }
.stat-icon.red { background: linear-gradient(135deg, #e74c3c, #c0392b); }
.stat-icon.purple { background: linear-gradient(135deg, #9b59b6, #8e44ad); }

.stat-info h4 {
  font-size: 24px;
  line-height: 1;
  margin-bottom: 4px;
}

.stat-info p {
  font-size: 13px;
  color: var(--text-muted);
}

/* ===================== TABLE ===================== */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

thead th {
  background: var(--bg);
  padding: 12px 15px;
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  white-space: nowrap;
}

tbody td {
  padding: 12px 15px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

tbody tr:hover {
  background: rgba(52, 152, 219, 0.04);
}

.table-actions {
  display: flex;
  gap: 6px;
}

/* ===================== BADGES ===================== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-success { background: #e8f5e9; color: #27ae60; }
.badge-danger { background: #fce4ec; color: #e74c3c; }
.badge-warning { background: #fff3e0; color: #f39c12; }
.badge-info { background: #e3f2fd; color: #3498db; }

/* ===================== MODAL ===================== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 550px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.9);
  transition: var(--transition);
}

.modal-overlay.active .modal {
  transform: scale(1);
}

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

.modal-header h3 {
  font-size: 16px;
  color: var(--primary);
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  line-height: 1;
}

.modal-close:hover { color: var(--danger); }

.modal-body {
  padding: 22px;
}

.modal-footer {
  padding: 15px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ===================== SEARCH BAR ===================== */
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.search-bar .form-control {
  flex: 1;
  min-width: 200px;
}

/* ===================== ALERTS ===================== */
.alert {
  padding: 12px 18px;
  border-radius: var(--radius);
  margin-bottom: 15px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.alert-success { background: #e8f5e9; color: #27ae60; border-left: 4px solid #27ae60; }
.alert-danger { background: #fce4ec; color: #c0392b; border-left: 4px solid #e74c3c; }
.alert-warning { background: #fff3e0; color: #e67e22; border-left: 4px solid #f39c12; }
.alert-info { background: #e3f2fd; color: #2980b9; border-left: 4px solid #3498db; }

/* ===================== DUPLICATE CARD ===================== */
.duplicate-group {
  background: #fff3e0;
  border: 1px solid #f39c12;
  border-radius: var(--radius);
  padding: 15px;
  margin-bottom: 15px;
}

.duplicate-group h4 {
  color: var(--warning);
  margin-bottom: 10px;
  font-size: 14px;
}

.duplicate-item {
  background: white;
  padding: 10px 15px;
  border-radius: var(--radius);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.duplicate-item-info {
  flex: 1;
  min-width: 200px;
}

.duplicate-item-info strong {
  display: block;
  font-size: 14px;
}

.duplicate-item-info small {
  color: var(--text-muted);
  font-size: 12px;
}

/* ===================== LOG ENTRY ===================== */
.log-action {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg);
}

/* ===================== PASSWORD DISPLAY ===================== */
.password-display {
  background: var(--bg);
  padding: 12px 18px;
  border-radius: var(--radius);
  font-family: 'Courier New', monospace;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 0;
  word-break: break-all;
}

.copy-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.copy-btn:hover { background: var(--accent-hover); }

/* ===================== LDAP CONFIG BOX ===================== */
.ldap-config {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 15px;
  margin-top: 10px;
}

.ldap-config p {
  font-size: 13px;
  margin-bottom: 6px;
  display: flex;
  gap: 8px;
}

.ldap-config strong {
  min-width: 120px;
  display: inline-block;
}

.ldap-config code {
  background: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  word-break: break-all;
}

/* ===================== PAGINATION ===================== */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.pagination button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: white;
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.pagination button:hover:not(:disabled) {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.pagination button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.pagination button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ===================== TOAST ===================== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  padding: 14px 20px;
  border-radius: var(--radius);
  color: white;
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease;
  max-width: 400px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }
.toast-info { background: var(--accent); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ===================== EMPTY STATE ===================== */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 48px;
  margin-bottom: 15px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--text);
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 20px;
}

/* ===================== LOADING ===================== */
.loading {
  display: flex;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===================== TABS ===================== */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.tab {
  padding: 10px 20px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: var(--transition);
  cursor: pointer;
  white-space: nowrap;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab:hover:not(.active) {
  color: var(--text);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ===================== FORM ROW ===================== */
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

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

  .main-content {
    margin-left: 0;
    padding: 15px;
  }

  .menu-toggle {
    display: block;
  }

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

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

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

  .search-bar {
    flex-direction: column;
  }

  .search-bar .form-control {
    min-width: auto;
  }

  .modal {
    max-width: 100%;
    margin: 10px;
  }

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

  table {
    font-size: 13px;
  }

  thead th, tbody td {
    padding: 8px 10px;
  }

  .duplicate-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .btn-sm {
    padding: 5px 8px;
    font-size: 11px;
  }

  .stat-card {
    padding: 15px;
  }

  .stat-info h4 {
    font-size: 20px;
  }

  .card-body {
    padding: 15px;
  }

  .ldap-config p {
    flex-direction: column;
    gap: 2px;
  }

  .ldap-config strong {
    min-width: auto;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .login-body {
    padding: 20px;
  }

  .table-actions {
    flex-direction: column;
  }

  .pagination {
    gap: 3px;
  }

  .pagination button {
    padding: 6px 10px;
    font-size: 12px;
  }
}

/* ===================== OVERLAY FOR SIDEBAR (MOBILE) ===================== */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

.sidebar-overlay.active {
  display: block;
}

/* ===================== UTILITY ===================== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-10 { margin-top: 10px; }
.mt-20 { margin-top: 20px; }
.mb-10 { margin-bottom: 10px; }
.mb-20 { margin-bottom: 20px; }
.d-flex { display: flex; }
.gap-10 { gap: 10px; }
.flex-wrap { flex-wrap: wrap; }
.hidden { display: none !important; }
