/**
 * IMATH Abacus Competition Portal - Admin Panel Styles
 * Fully Responsive, Keyboard Navigable, Drawer & Modal System
 */

:root {
  --admin-sidebar-width: 260px;
  --admin-sidebar-collapsed-width: 72px;
  --admin-topbar-height: 64px;
  --admin-bg: #f1f5f9;
  --admin-surface: #ffffff;
  --admin-border: #e2e8f0;
  --admin-text: #0f172a;
  --admin-text-muted: #64748b;
  --admin-primary: #1d2071;
  --admin-secondary: #2aa64b;
  --admin-danger: #dc2626;
  --admin-warning: #d97706;
}

body.admin-body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background-color: var(--admin-bg);
  color: var(--admin-text);
  display: flex;
  min-height: 100vh;
}

/* ==========================================================================
   ADMIN SIDEBAR DRAWER (Hover Slide-Out, Icon-Only Collapsed, 100% Responsive)
   ========================================================================== */
.admin-sidebar {
  width: 72px;
  background: #0b1035;
  color: #e2e8f0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 1050;
  transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.28s ease;
  overflow-x: hidden;
  overflow-y: auto;
  white-space: nowrap;
}

.admin-sidebar:hover,
.admin-sidebar.open {
  width: 270px;
  box-shadow: 6px 0 28px rgba(0, 0, 0, 0.45);
}

.sidebar-header {
  height: var(--admin-topbar-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #ffffff;
  font-weight: 700;
  font-size: 1.1rem;
  text-decoration: none;
}

.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: rgba(42, 166, 75, 0.15);
  color: #2aa64b;
  font-weight: 800;
  flex-shrink: 0;
}

.brand-icon img {
  height: 32px;
  width: auto;
}

.brand-badge {
  font-size: 1.1rem;
  font-weight: 800;
  color: #2aa64b;
  letter-spacing: -0.5px;
}

.brand-text {
  opacity: 0;
  transform: translateX(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
}

.admin-sidebar:hover .brand-text,
.admin-sidebar.open .brand-text {
  opacity: 1;
  transform: translateX(0);
}

.sidebar-menu {
  list-style: none;
  padding: 12px 8px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 0 auto;
}

.sidebar-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #64748b;
  padding: 10px 14px 4px 14px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.admin-sidebar:hover .sidebar-label,
.admin-sidebar.open .sidebar-label {
  opacity: 1;
}

.sidebar-item {
  position: relative;
}

.sidebar-item > a {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  color: #94a3b8;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  transition: background-color 0.2s, color 0.2s;
  overflow: hidden;
}

.sidebar-item-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: #94a3b8;
  transition: color 0.2s;
}

.sidebar-item a:hover .sidebar-item-icon,
.sidebar-item.active a .sidebar-item-icon {
  color: #ffffff;
}

.sidebar-item-text {
  margin-left: 14px;
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
  font-weight: 500;
}

.admin-sidebar:hover .sidebar-item-text,
.admin-sidebar.open .sidebar-item-text {
  opacity: 1;
  transform: translateX(0);
}

.sidebar-chevron {
  margin-left: auto;
  opacity: 0;
  display: flex;
  align-items: center;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.admin-sidebar:hover .sidebar-chevron,
.admin-sidebar.open .sidebar-chevron {
  opacity: 0.8;
}

.sidebar-item.active > a {
  background: var(--admin-secondary);
  color: #ffffff;
}

.sidebar-item a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.sidebar-submenu {
  list-style: none;
  padding: 0;
  margin: 0;
  display: none;
  flex-direction: column;
  gap: 2px;
  background: rgba(0, 0, 0, 0.28);
  border-radius: 6px;
  margin-top: 4px;
  overflow: hidden;
  transition: all 0.25s ease;
}

/* Submenu shows on hover over parent item OR when expanded/clicked, provided sidebar is hovered or open */
.admin-sidebar:hover .sidebar-item.has-submenu:hover > .sidebar-submenu,
.admin-sidebar:hover .sidebar-item.expanded > .sidebar-submenu,
.admin-sidebar:hover .sidebar-submenu.open,
.admin-sidebar.open .sidebar-item.has-submenu:hover > .sidebar-submenu,
.admin-sidebar.open .sidebar-item.expanded > .sidebar-submenu,
.admin-sidebar.open .sidebar-submenu.open {
  display: flex !important;
  padding: 6px 8px !important;
}

/* When sidebar is collapsed on desktop (not hovered and not open), keep submenus completely hidden */
.admin-sidebar:not(:hover):not(.open) .sidebar-submenu {
  display: none !important;
}

.sidebar-chevron svg {
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.admin-sidebar:hover .sidebar-item.has-submenu:hover .sidebar-chevron svg,
.admin-sidebar.open .sidebar-item.has-submenu:hover .sidebar-chevron svg,
.sidebar-item.expanded .sidebar-chevron svg {
  transform: rotate(180deg);
}

.sidebar-submenu a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
  color: #cbd5e1;
  text-decoration: none;
  transition: all 0.2s;
}

.sidebar-subitem-icon {
  display: flex;
  align-items: center;
  color: #64748b;
  flex-shrink: 0;
}

.sidebar-submenu a:hover,
.sidebar-submenu li.active a {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.sidebar-submenu li.active .sidebar-subitem-icon {
  color: #2aa64b;
}

.sidebar-footer-text {
  padding: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.75rem;
  color: #64748b;
  text-align: center;
  opacity: 0;
  transition: opacity 0.2s ease;
  white-space: nowrap;
}

.admin-sidebar:hover .sidebar-footer-text {
  opacity: 1;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  z-index: 1040;
}

/* ==========================================================================
   ADMIN MAIN CONTENT & TOPBAR
   ========================================================================== */
.admin-main {
  margin-left: 72px;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: margin-left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

.admin-topbar {
  height: var(--admin-topbar-height);
  background: var(--admin-surface);
  border-bottom: 1px solid var(--admin-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 1000;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 auto;
}

.topbar-toggle {
  background: none;
  border: 1px solid var(--admin-border);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--admin-text);
  flex-shrink: 0;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  color: var(--admin-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.breadcrumb-root {
  color: var(--admin-text-muted);
  text-decoration: none;
  flex-shrink: 0;
}

.breadcrumb-separator {
  color: #cbd5e1;
  flex-shrink: 0;
}

.breadcrumb-current {
  font-weight: 700;
  color: var(--admin-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.topbar-btn-site {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  white-space: nowrap;
  font-weight: 600;
}

.topbar-btn-logout {
  white-space: nowrap;
  font-weight: 600;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--admin-primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.user-info {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.2;
}

.user-role {
  font-size: 0.75rem;
  color: var(--admin-text-muted);
}

.admin-content {
  padding: 32px 28px;
  flex: 1 0 auto;
}

/* Dashboard Header & Grid Layout */
.dashboard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}

.dashboard-title {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--admin-primary);
  margin: 0 0 6px 0;
}

.dashboard-subtitle {
  color: var(--admin-text-muted);
  margin: 0;
  font-size: 0.95rem;
}

.dashboard-header-actions {
  display: flex;
  gap: 12px;
}

.dashboard-main-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 24px;
  align-items: start;
}

/* Reusable Admin Layout & Grid Components */
.admin-two-col-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 24px;
  align-items: start;
}

.admin-two-col-grid.grid-wide-left {
  grid-template-columns: 1.6fr 1fr;
}

.admin-two-col-grid.grid-equal {
  grid-template-columns: 1fr 1fr;
}

.admin-page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
}

.admin-page-header h1 {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--admin-primary);
  margin: 0 0 4px 0;
}

.admin-page-header p {
  color: var(--admin-text-muted);
  margin: 0;
  font-size: 0.92rem;
}

.admin-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.admin-form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.admin-filter-bar {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin: 0;
}

.admin-form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 24px;
}

/* ==========================================================================
   METRIC STATS CARDS
   ========================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  gap: 18px;
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.stat-icon.primary { background: #e0e7ff; color: #3730a3; }
.stat-icon.success { background: #dcfce7; color: #166534; }
.stat-icon.amber { background: #fef3c7; color: #92400e; }
.stat-icon.slate { background: #f1f5f9; color: #475569; }

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--admin-text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--admin-primary);
  line-height: 1.1;
}

.stat-note {
  font-size: 0.75rem;
  color: var(--admin-text-muted);
  margin-top: 4px;
}

/* ==========================================================================
   TABLES & CARDS
   ========================================================================== */
.table-card {
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  margin-bottom: 32px;
}

.table-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--admin-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.table-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--admin-primary);
  margin: 0;
}

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

.table-responsive .data-table {
  min-width: 520px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th {
  background: #f8fafc;
  padding: 12px 20px;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--admin-text-muted);
  border-bottom: 1px solid var(--admin-border);
}

.data-table td {
  padding: 16px 20px;
  border-bottom: 1px solid var(--admin-border);
  font-size: 0.92rem;
  vertical-align: middle;
}

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

/* Forms */
.form-card {
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 12px;
  padding: 32px;
  max-width: 900px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.form-group {
  margin-bottom: 24px;
}

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 8px;
  color: var(--admin-text);
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  font-size: 0.95rem;
  background-color: #ffffff;
  color: var(--admin-text);
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
  border-color: var(--admin-primary);
  box-shadow: 0 0 0 3px rgba(29, 32, 113, 0.15);
  outline: none;
}

textarea.form-control {
  min-height: 120px;
  resize: vertical;
}

.form-hint {
  font-size: 0.8rem;
  color: var(--admin-text-muted);
  margin-top: 6px;
}

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

/* Drag & Drop Reorder List */
.reorder-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.reorder-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--admin-surface);
  border: 1px solid var(--admin-border);
  border-radius: 8px;
  cursor: grab;
  user-select: none;
}

.reorder-item:active {
  cursor: grabbing;
  background: #f8fafc;
}

.reorder-handle {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
}

/* ==========================================================================
   ADMIN RESPONSIVE
   ========================================================================== */
@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .dashboard-main-grid,
  .admin-two-col-grid,
  .admin-two-col-grid.grid-wide-left,
  .admin-two-col-grid.grid-equal {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

@media (max-width: 768px) {
  .admin-sidebar {
    width: 270px !important;
    transform: translateX(-100%);
    box-shadow: none;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .admin-sidebar.open {
    transform: translateX(0);
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.6);
  }
  .admin-sidebar .brand-text,
  .admin-sidebar .sidebar-label,
  .admin-sidebar .sidebar-item-text,
  .admin-sidebar .sidebar-chevron,
  .admin-sidebar .sidebar-footer-text {
    opacity: 1 !important;
    transform: none !important;
  }
  .admin-sidebar.open .sidebar-item.expanded > .sidebar-submenu,
  .admin-sidebar.open .sidebar-submenu.open {
    display: flex !important;
    padding: 6px 8px;
  }
  .sidebar-backdrop.open {
    display: block;
  }
  .admin-main {
    margin-left: 0 !important;
  }
  .admin-topbar {
    height: 58px;
    padding: 0 12px;
  }
  .topbar-right {
    gap: 8px;
  }
  .topbar-btn-site .topbar-btn-text {
    display: none;
  }
  .topbar-btn-site {
    padding: 6px 10px;
    font-size: 0.85rem;
  }
  .user-info {
    display: none;
  }
  .user-avatar {
    width: 32px;
    height: 32px;
    font-size: 0.82rem;
  }
  .topbar-btn-logout {
    padding: 6px 10px;
    font-size: 0.82rem;
  }
  .admin-content {
    padding: 20px 14px;
  }
  .admin-page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    margin-bottom: 20px;
  }
  .admin-page-header h1 {
    font-size: 1.45rem;
  }
  .admin-page-header .btn {
    width: 100%;
    text-align: center;
    justify-content: center;
  }
  .admin-form-actions {
    flex-direction: column;
    align-items: stretch;
  }
  .admin-form-actions .btn {
    width: 100%;
    text-align: center;
    justify-content: center;
  }
  .admin-form-grid-2 {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .admin-filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .admin-filter-bar > div {
    width: 100% !important;
    min-width: 100% !important;
  }
  .admin-filter-bar button,
  .admin-filter-bar a {
    flex: 1 1 auto;
    text-align: center;
    justify-content: center;
  }
  .admin-kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .dashboard-header {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    margin-bottom: 20px;
  }
  .dashboard-title {
    font-size: 1.5rem;
  }
  .dashboard-header-actions {
    width: 100%;
  }
  .dashboard-header-actions .btn {
    flex: 1 1 auto;
    text-align: center;
    justify-content: center;
  }
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 14px;
    margin-bottom: 24px;
  }
  .stat-card {
    padding: 18px 16px;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
  .form-card {
    padding: 22px 18px;
  }
}

@media (max-width: 480px) {
  .admin-topbar {
    padding: 0 10px;
  }
  .breadcrumb-root,
  .breadcrumb-separator {
    display: none;
  }
  .breadcrumb-current {
    font-size: 0.95rem;
    max-width: 130px;
  }
  .topbar-btn-logout .logout-text {
    display: none;
  }
  .topbar-btn-logout .logout-icon {
    display: inline-block !important;
  }
  .topbar-btn-logout {
    padding: 6px 8px;
  }
  .admin-content {
    padding: 16px 10px;
  }
  .admin-kpi-grid {
    grid-template-columns: 1fr;
  }
  .stat-card {
    padding: 16px 14px;
    gap: 12px;
  }
  .stat-icon {
    width: 44px;
    height: 44px;
    font-size: 20px;
  }
  .stat-value {
    font-size: 1.5rem;
  }
  .table-header {
    padding: 14px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .table-title {
    font-size: 1.05rem;
  }
  .form-card {
    padding: 18px 14px;
  }
}
