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

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.05), 0 4px 6px -4px rgb(0 0 0 / 0.05);
  --radius: 10px;
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 15px;
  background: var(--bg);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.topbar-inner {
  max-width: 1560px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0.8rem 1.5rem;
}

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  background: linear-gradient(135deg, var(--primary) 0%, #a855f7 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-decoration: none;
  letter-spacing: -0.02em;
}

.mainnav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
  flex-wrap: nowrap;
}

.mainnav a,
.nav-dropdown-toggle {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.3rem 0.45rem;
  border-radius: 8px;
  font-size: 0.72rem;
  font-weight: 500;
  transition: var(--transition);
}

.mainnav a:hover,
.nav-dropdown-toggle:hover {
  background: var(--bg);
  color: var(--text-main);
}

.mainnav a.active,
.nav-dropdown-toggle.active {
  background: #eef2ff;
  color: var(--primary-hover);
  font-weight: 600;
}

.nav-item-stacked {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 44px;
  text-align: center;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
}

.nav-item-stacked .nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 20px;
  color: currentColor;
}

.nav-item-stacked .nav-label {
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.1;
  white-space: nowrap;
  letter-spacing: -0.01em;
}

.nav-item-stacked.active .nav-icon {
  color: var(--primary);
}

/* Navigation Dropdown for Server Admin */
.nav-dropdown {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 210px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0.4rem;
  z-index: 100;
  margin-top: 0.25rem;
}

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu,
.nav-dropdown-menu.show {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.nav-dropdown-menu a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.85rem;
  border-radius: 6px;
  color: var(--text-main);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  transition: var(--transition);
}

.nav-dropdown-menu a:hover {
  background: #f1f5f9;
  color: var(--primary-hover);
}

.nav-dropdown-menu a.active {
  background: #eef2ff;
  color: var(--primary-hover);
  font-weight: 600;
}


.userbox {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  margin-left: auto;
}

.user-profile-wrap {
  display: inline-flex;
  align-items: center;
}

.user-profile-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  background: transparent;
  border: 1px solid transparent;
  padding: 0.25rem 0.6rem 0.25rem 0.35rem;
  border-radius: 9999px;
  cursor: pointer;
  color: var(--text-main, #0f172a);
  text-decoration: none;
  font-family: inherit;
  transition: all 0.15s ease;
}

.user-profile-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.08);
}

.user-avatar-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary, #4f46e5) 0%, #7c3aed 100%);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.user-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.user-first-name {
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-main, #0f172a);
  letter-spacing: -0.01em;
}

.logout-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--text-muted, #64748b);
  transition: all 0.15s ease;
  text-decoration: none;
  border: 1px solid transparent;
}

.logout-icon-btn:hover {
  color: #dc2626;
  background: var(--danger-bg, #fee2e2);
  border-color: rgba(220, 38, 38, 0.15);
  transform: translateY(-1px);
}

.userbox .who {
  color: var(--text-muted);
  font-weight: 500;
}

.userbox .logout {
  color: var(--danger-text);
  text-decoration: none;
  font-weight: 600;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  transition: var(--transition);
}

.userbox .logout:hover {
  background: var(--danger-bg);
}


.page {
  max-width: 1560px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  flex: 1;
  width: 100%;
  animation: fadeIn 0.4s ease-out;
}

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

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 1rem;
  letter-spacing: -0.02em;
  color: #0f172a;
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 1rem;
  color: #1e293b;
}

.flash {
  padding: 1rem 1.2rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.flash-success { background: var(--success-bg); color: var(--success-text); border: 1px solid #bbf7d0; }
.flash-error { background: var(--danger-bg); color: var(--danger-text); border: 1px solid #fecaca; }
.flash-info { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card-header {
  padding: 1rem 1.5rem;
  background: #fafafa;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.95rem;
  color: #334155;
}

.card-body {
  padding: 1.5rem;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  border-radius: 6px;
  gap: 0.35rem;
  line-height: 1.4;
}

.btn-icon {
  padding: 0.35rem;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  padding: 1rem 1.25rem;
  border-bottom: 2px solid var(--border);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #f8fafc;
}

tbody td {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: #334155;
}

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

tr:hover td {
  background: #f8fafc;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  line-height: 1.5;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
  color: #fff;
  box-shadow: 0 2px 4px rgba(99, 102, 241, 0.2);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 6px rgba(99, 102, 241, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-ghost {
  background: #fff;
  color: var(--text-muted);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.btn-ghost:hover {
  background: var(--bg);
  color: var(--text-main);
  border-color: #cbd5e1;
}

.btn-danger {
  background: #ef4444;
  color: #fff;
}

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

.btn-link {
  background: transparent;
  border: none;
  color: var(--primary);
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  font-size: inherit;
  transition: var(--transition);
}
.btn-link:hover {
  text-decoration: underline;
  color: var(--primary-hover);
}

.actions a, .actions form {
  margin-right: 0.75rem;
  color: var(--primary);
  font-weight: 500;
  text-decoration: none;
  transition: var(--transition);
}
.actions a:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

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

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  color: #334155;
}

input[type="text"], input[type="email"], input[type="password"], input[type="date"], select, textarea, .form-control {
  display: block;
  width: 100%;
  padding: 0.6rem 0.8rem;
  font-size: 0.95rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: var(--text-main);
  transition: var(--transition);
  font-family: inherit;
  box-shadow: var(--shadow-sm);
}

input:focus, select:focus, textarea:focus, .form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

select {
  appearance: auto;
  cursor: pointer;
}

textarea {
  resize: vertical;
}

.inline-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}
.inline-row .form-group, .inline-row .card {
  flex: 1;
  min-width: 0;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-success { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.badge-danger { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
.badge-active { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.badge-inactive { background: #f1f5f9; color: #64748b; border: 1px solid #e2e8f0; }

/* Utilities */
.text-muted { color: var(--text-muted); font-size: 0.85rem; }
.mt-1 { margin-top: 1rem; }
.mt-2 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 1rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.action-bar { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }

.footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--bg);
  margin-top: auto;
}


/* ==========================================================================
   Login & Password Reset Layout (Desktop & Mobile Centering)
   ========================================================================== */

body.login-center {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1.5rem;
  margin: 0;
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
  padding: 2.5rem 2rem;
  margin: auto;
  animation: fadeIn 0.3s ease-out;
}

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

.login-brand .brand {
  font-size: 1.5rem;
}

.login-card h1 {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 1.5rem;
  text-align: center;
}

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

.login-card .form-group label {
  display: block;
  font-weight: 500;
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
  color: var(--text-main);
}

.pw-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.pw-wrap input {
  padding-right: 2.75rem !important;
  width: 100%;
}

.pw-toggle {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.15rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  line-height: 1;
  transition: var(--transition);
}

.pw-toggle:hover {
  color: var(--text-main);
}

.login-help {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.88rem;
}

.login-help a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.login-help a:hover {
  text-decoration: underline;
}

.reset-info {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  text-align: center;
}

.cli-hint {
  margin-top: 1.5rem;
  padding: 0.75rem 1rem;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.cli-hint code {
  display: block;
  margin-top: 0.4rem;
  padding: 0.3rem 0.5rem;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.75rem;
  color: var(--text-main);
  overflow-x: auto;
}

/* Mobile Navigation Button (Desktop: Hidden) */
.topbar-brand-group {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.mobile-nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-main);
  cursor: pointer;
  transition: var(--transition);
  padding: 0;
  flex-shrink: 0;
}
.mobile-nav-toggle:hover,
.mobile-nav-toggle.is-active {
  background: #e2e8f0;
  color: var(--primary);
}

/* === Mobile Layout Media Queries === */
@media (max-width: 768px) {
  /* Page container */
  .page {
    padding: 0.85rem 0.5rem;
  }

  /* Prevent iOS Safari auto-zoom on text focus by enforcing >= 16px */
  input[type="text"],
  input[type="search"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="url"],
  select,
  textarea {
    font-size: 16px !important;
  }

  /* Topbar & Navigation Drawer */
  .topbar-inner {
    padding: 0.55rem 0.75rem;
    gap: 0.4rem;
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .mobile-nav-toggle {
    display: inline-flex !important;
  }

  .mainnav {
    display: none;
    flex-direction: column;
    width: 100%;
    order: 10;
    background: #ffffff;
    border-top: 1px solid var(--border);
    padding: 0.65rem 0.25rem;
    gap: 0.35rem;
    box-shadow: var(--shadow-md);
    border-radius: 0 0 10px 10px;
  }

  .mainnav.show {
    display: flex;
  }

  .mainnav a,
  .mainnav .nav-item-stacked {
    padding: 0.65rem 0.85rem;
    font-size: 0.95rem;
    min-height: 44px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 0.75rem;
    border-radius: 8px;
    width: 100%;
    text-align: left;
  }

  .mainnav .nav-item-stacked .nav-label {
    font-size: 0.95rem;
    margin-top: 0;
  }

  .nav-dropdown {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .nav-dropdown-toggle {
    width: 100%;
    justify-content: space-between;
    min-height: 44px;
    padding: 0.65rem 0.85rem;
    flex-direction: row !important;
  }

  .nav-dropdown-menu {
    position: static;
    box-shadow: none;
    border: none;
    background: var(--bg);
    margin: 0.25rem 0 0 0.5rem;
    padding: 0.35rem;
    border-radius: 6px;
    display: none;
  }

  .nav-dropdown-menu.show {
    display: flex;
  }

  /* Userbox & language switcher */
  .userbox {
    margin-left: auto;
    gap: 0.45rem;
    font-size: 0.82rem;
  }

  .userbox .who {
    max-width: 90px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .userbox .logout {
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
  }
}
