@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  /* High-Contrast Minimal Palette */
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --text-main: #0A0A0B;
  --text-muted: #666666;
  --border: #E5E5E5;
  --border-hover: #111111;
  
  --primary: #000000;
  --primary-hover: #333333;
  --primary-text: #FFFFFF;
  
  --danger: #E03131;
  --danger-hover: #C92A2A;
  --success: #087F5B;
  
  --shadow-sm: 0 2px 4px rgba(0,0,0,0.03);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.05);
  --shadow-float: 0 24px 48px rgba(0,0,0,0.08);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  
  --font-sans: 'Outfit', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --transition: 0.25s cubic-bezier(0.2, 0, 0, 1);
}

body.dark-mode {
  --bg: #0F172A;
  --surface: #1E293B;
  --text-main: #F8FAFC;
  --text-muted: #94A3B8;
  --border: #334155;
  --border-hover: #475569;
  --primary: #3B82F6;
  --primary-hover: #60A5FA;
  --primary-text: #FFFFFF;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-main);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Typography ─────────────────────────────────────────── */
h1 {
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin-bottom: 2rem;
}
h2 {
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: -0.02em;
  margin-bottom: 1.5rem;
}
h3 {
  font-size: 1rem;
  font-weight: 500;
}

/* ── Mobile Header & Nav ────────────────────────────────── */
.mobile-header {
  display: none;
}
.mobile-overlay {
  display: none;
}

nav {
  background: #0F172A;
  width: 260px;
  flex-shrink: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 2rem 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid #1E293B;
}
nav strong {
  display: block;
  font-size: 1.1rem;
  font-weight: 600;
  color: #F8FAFC;
  letter-spacing: -0.02em;
  padding: 0 0.75rem;
  margin-bottom: 2.5rem;
}
nav a {
  color: #94A3B8;
  text-decoration: none;
  font-weight: 500;
  display: block;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.25rem;
  font-size: 0.95rem;
  transition: all var(--transition);
}
nav a:hover {
  background: #1E293B;
  color: #F8FAFC;
}
nav a.active {
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 500;
}
nav .logout {
  margin-top: 0.5rem;
  text-align: left;
  width: 100%;
  background: transparent;
  color: #94A3B8;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  cursor: pointer;
  border: none;
}
nav .logout:hover {
  background: #1E293B;
  color: #F8FAFC;
}
.nav-spacer {
  flex: 1;
}
.nav-user {
  padding: 1rem 0.75rem;
  border-top: 1px solid #1E293B;
  margin-top: 1rem;
}
.nav-user-name {
  font-size: 0.9rem;
  color: #F8FAFC;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-user-role {
  font-size: 0.75rem;
  color: #94A3B8;
  margin-top: 0.2rem;
}

@media (max-width: 768px) {
  body {
    flex-direction: column;
  }
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 40;
  }
  .mobile-brand {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
  }
  .mobile-menu-btn {
    background: transparent;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
  }
  nav {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    z-index: 50;
    transition: transform var(--transition);
  }
  body.nav-open nav {
    transform: translateX(280px);
  }
  .mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(2px);
    z-index: 45;
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
  }
  body.nav-open .mobile-overlay {
    opacity: 1;
    pointer-events: auto;
  }
  .container {
    padding: 1.5rem 1rem !important;
  }
}

/* ── Layout ─────────────────────────────────────────────── */
.main-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
}
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 3rem 2rem;
}

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.5rem;
  transition: box-shadow var(--transition);
}
.card:hover {
  box-shadow: var(--shadow-md);
}

/* ── Table ──────────────────────────────────────────────── */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 600px;
}
th {
  background: var(--surface);
  font-weight: 500;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 10;
}
td {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
  transition: background var(--transition);
}
.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
tr:last-child td {
  border-bottom: none;
}
tr:hover td {
  background: var(--bg);
}
.table-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* ── Empty state ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
}
.empty-state p {
  font-size: 0.95rem;
  margin-top: 0.75rem;
}

/* ── Buttons ────────────────────────────────────────────── */
.flex-nowrap {
  flex-wrap: nowrap !important;
}
.btn-icon {
  padding: 0.4rem;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  cursor: pointer;
}
.btn-icon:hover {
  background: var(--bg);
  color: var(--text-main);
  border-color: var(--border-hover);
}
.btn-icon.btn-danger {
  color: var(--danger);
  border-color: var(--danger);
}
.btn-icon.btn-danger:hover {
  background: var(--danger);
  color: white;
}
.btn-icon.btn-secondary {
  color: var(--primary);
  border-color: var(--primary);
}
.btn-icon.btn-secondary:hover {
  background: var(--primary);
  color: white;
}
body.dark-mode .btn-icon.btn-secondary {
  color: var(--text-main);
  border-color: var(--border);
}
body.dark-mode .btn-icon.btn-secondary:hover {
  background: var(--border-hover);
}
button, .btn {
  cursor: pointer;
  padding: 0.6rem 1.2rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  font-family: inherit;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  text-decoration: none;
}
button:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
}
.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.btn-primary:active {
  transform: translateY(0);
}
.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover {
  background: var(--danger-hover);
}
.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}
button:disabled, .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}
button:not(.btn-primary):not(.btn-danger):not(.logout):not(.mobile-menu-btn):not(.active) {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-main);
}
button:not(.btn-primary):not(.btn-danger):not(.logout):not(.mobile-menu-btn):not(.active):hover {
  background: var(--bg);
  border-color: var(--border-hover);
}

/* ── Inputs ─────────────────────────────────────────────── */
input, select, textarea {
  font-family: inherit;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  width: 100%;
  outline: none;
  background: var(--surface);
  color: var(--text-main);
  transition: border-color var(--transition), box-shadow var(--transition);
}
input::placeholder {
  color: var(--text-muted);
  opacity: 0.6;
}
input:hover, select:hover, textarea:hover {
  border-color: var(--border-hover);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}
input[type="checkbox"] {
  width: auto;
  padding: 0;
  cursor: pointer;
  accent-color: var(--primary);
}
input[type="number"], .font-mono {
  font-family: var(--font-mono);
}

/* ── Filters ────────────────────────────────────────────── */
.filters {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  align-items: flex-end;
}
.filters label {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 500;
}
.filters .field {
  min-width: 150px;
  flex: 1;
}
.filters input, .filters select {
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
.filters button {
  height: 38px;
  padding: 0 1rem;
}

/* ── Errors ─────────────────────────────────────────────── */
.error-msg, #error, #errorPwd, #slError {
  color: var(--danger);
  margin-top: 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
  background: #FEF2F2;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--danger);
  display: none;
}

/* ── Badges ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.badge-green  { background: #E6FCF5; color: #087F5B; border: 1px solid #C3FAE8; }
.badge-red    { background: #FFF5F5; color: #E03131; border: 1px solid #FFC9C9; }
.badge-yellow { background: #FFF9DB; color: #E67700; border: 1px solid #FFEC99; }
.badge-gray   { background: #F8F9FA; color: #495057; border: 1px solid #E9ECEF; }
.badge-blue   { background: #E7F5FF; color: #1864AB; border: 1px solid #D0EBFF; }
.badge-purple { background: #F3F0FF; color: #5F3DC4; border: 1px solid #E5DBFF; }

/* ── Pagination ─────────────────────────────────────────── */
.pagination {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.pagination button {
  background: var(--surface);
  border: 1px solid var(--border);
  min-width: 2.25rem;
  height: 2.25rem;
  padding: 0 0.5rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.pagination button:hover {
  background: var(--bg);
  border-color: var(--border-hover);
}
.pagination button.active {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}
.pagination-info {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-left: 0.75rem;
}

/* ── Forms ──────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1.25rem;
}
.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-main);
  font-weight: 500;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
@media (max-width: 640px) {
  .grid-2 {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

/* ── Login ──────────────────────────────────────────────── */
.login-wrap {
  flex: 1;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1rem;
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 3rem 2.5rem;
  box-shadow: var(--shadow-float);
  border: 1px solid var(--border);
}
.login-card h1 {
  margin-bottom: 0.5rem;
  font-size: 2rem;
  text-align: center;
}
.login-card p {
  text-align: center;
  margin-bottom: 2.5rem !important;
}

/* ── UI Components: Skeleton, Toast, Drawer ─────────────── */

/* Skeleton Loader */
.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-text {
  height: 1rem;
  margin-bottom: 0.5rem;
  width: 100%;
}
.skeleton-text:last-child {
  margin-bottom: 0;
}
.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 100;
}
.toast {
  background: var(--surface);
  color: var(--text-main);
  padding: 1rem 1.5rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-float);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.95rem;
  font-weight: 500;
  animation: slideInUp 0.3s cubic-bezier(0.2, 0, 0, 1) forwards;
  max-width: 350px;
}
.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--danger); }
@keyframes slideInUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Slide-over Drawer */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 450px;
  background: var(--surface);
  box-shadow: -10px 0 30px rgba(0,0,0,0.1);
  z-index: 210;
  transform: translateX(100%);
  transition: transform var(--transition);
  display: flex;
  flex-direction: column;
}
.drawer.open {
  transform: translateX(0);
}
.drawer-header {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-header h2 {
  margin: 0;
  font-size: 1.25rem;
}
.drawer-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
}
.drawer-close:hover {
  color: var(--text-main);
  background: none;
  border: none;
}
.drawer-content {
  padding: 2rem;
  overflow-y: auto;
  flex: 1;
}