/* Prevent layout shift from scrollbar appearing/disappearing */
html {
  overflow-y: scroll;
}

/* Modern Design System - Professional & Intuitive */
:root {
  /* Core Palette - HSL for better manipulation */
  --hue-primary: 210;
  /* Blue */
  --hue-accent: 170;
  /* Teal */
  --hue-success: 150;
  --hue-warning: 40;
  --hue-danger: 350;

  /* Light Theme Variables */
  --bg-color: #f4f6f9;
  --surface-color: #ffffff;
  --surface-hover: #f8f9fa;
  --text-primary: #1a202c;
  --text-secondary: #4a5568;
  --text-tertiary: #5a6a7f;

  --primary-color: hsl(var(--hue-primary), 90%, 50%);
  --primary-hover: hsl(var(--hue-primary), 90%, 45%);
  --primary-light: hsl(var(--hue-primary), 90%, 96%);

  --accent-color: hsl(var(--hue-accent), 80%, 45%);
  --success-color: hsl(var(--hue-success), 70%, 45%);
  --warning-color: hsl(var(--hue-warning), 80%, 45%);
  --danger-color: hsl(var(--hue-danger), 80%, 55%);

  /* Ranking Medal Colors */
  --medal-gold: #fbbf24;
  --medal-silver: #94a3b8;
  --medal-bronze: #b45309;

  --border-color: #e2e8f0;
  --border-hover: #cbd5e0;

  /* Glassmorphism */
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(255, 255, 255, 0.6);
  --glass-blur: 16px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;

  /* Typography */
  --font-sans: 'Alibaba PuHuiTi', 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Mono', monospace;

  /* Spacing Scale (4px grid) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Font Size Scale */
  --text-xs: 0.72rem;
  --text-sm: 0.82rem;
  --text-base: 0.92rem;
  --text-md: 1rem;
  --text-lg: 1.1rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 2rem;

  /* Font Weight */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* Z-Index Scale */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-navbar: 999;
  --z-modal: 1000;
  --z-toast: 3000;
  --z-tooltip: 3200;
  --z-overlay: 3300;

  /* Container Widths */
  --container-xs: 480px;
  --container-sm: 640px;
  --container-md: 780px;
  --container-lg: 960px;
  --container-xl: 1100px;
  --container-2xl: 1280px;

  /* Transition */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s ease;
  --transition-slow: 0.3s ease;
}

/* Global Reset & Base */
body,
body.pushable {
  background-color: var(--bg-color) !important;
  background-image:
    radial-gradient(at 40% 20%, hsla(210, 100%, 96%, 1) 0px, transparent 50%),
    radial-gradient(at 80% 0%, hsla(189, 100%, 96%, 1) 0px, transparent 50%),
    radial-gradient(at 0% 50%, hsla(341, 100%, 96%, 1) 0px, transparent 50%) !important;
  background-attachment: fixed !important;
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.6;
  transition: background-color 0.3s ease, color 0.3s ease;
  margin: 0;
  min-height: 100vh;
}

a {
  color: var(--primary-color);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: var(--primary-hover);
}

.black-link {
  color: var(--text-primary) !important;
}

.black-link:hover {
  color: var(--primary-color) !important;
}

/* Glassmorphism Utility */
.glass {
  background: var(--glass-bg) !important;
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  will-change: backdrop-filter;
  border: 1px solid var(--glass-border) !important;
  box-shadow: var(--shadow-lg) !important;
}

/* Sticky Header Override */
.ui.fixed.menu {
  position: sticky !important;
  top: 0;
  width: 100%;
  z-index: 1000;
}

/* Dropdown Fix */
#user_dropdown .menu {
  margin-top: 0 !important;
  padding-top: 0.5rem;
  /* Semantic UI handles show/hide state */
}

/* Bridge to prevent menu closing */
#user_dropdown .menu::before {
  content: '';
  position: absolute;
  top: -0.5rem;
  left: 0;
  width: 100%;
  height: 0.5rem;
  background: transparent;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(10px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes scaleIn {
  from {
    transform: scale(0.95);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

.animate-fade-in {
  animation: fadeIn 0.4s ease-out forwards;
}

.animate-slide-up {
  animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.animate-scale-in {
  animation: scaleIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Semantic UI Overrides - The "Professional" Look */

/* Containers */
.ui.container {
  width: 100%;
  max-width: 1200px !important;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Headers */
.ui.header {
  color: var(--text-primary) !important;
  font-family: var(--font-sans);
  font-weight: 700;
  letter-spacing: -0.025em;
}

/* Segments & Cards */
.ui.segment,
.ui.card,
.ui.cards>.card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-lg);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.ui.segment:hover,
.ui.card:hover,
.ui.cards>.card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-md);
}

.ui.card:hover,
.ui.cards>.card:hover {
  transform: translateY(-2px);
}

/* Menus */
.ui.menu {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
}

.ui.menu .item {
  color: var(--text-secondary);
  font-weight: 500;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
}

.ui.menu .item>i.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* .ui.menu .item:hover {
  color: var(--text-primary);
  background: var(--surface-hover);
} */

.ui.menu .active.item {
  color: var(--primary-color) !important;
  background: var(--primary-light) !important;
  font-weight: 600;
}

/* Buttons */
.ui.button {
  border-radius: var(--radius-md);
  font-weight: 600;
  font-family: var(--font-sans);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: var(--shadow-xs);
}

.ui.primary.button {
  background-color: var(--primary-color);
  color: #ffffff;
}

.ui.primary.button:hover {
  background-color: var(--primary-hover);
  box-shadow: 0 4px 12px hsla(var(--hue-primary), 90%, 50%, 0.3);
  transform: translateY(-1px);
}

/* Inputs */
.ui.input input {
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--surface-color);
  color: var(--text-primary);
  padding: 0.75em 1em;
  transition: all 0.2s ease;
}

.ui.input input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Tables */
.ui.table {
  background: var(--surface-color);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: none;
}

.ui.table thead th {
  background: var(--surface-hover);
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  padding: 1em;
}

.ui.table tbody td {
  border-top: 1px solid var(--border-color);
  padding: 1em;
}

body>.pusher,
body.pushable>.pusher {
  background: transparent !important;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.main-layout {
  flex: 1 0 auto;
}

.main-content {
  height: 100%;
}

.ui.search {
  position: relative !important;
  z-index: 3000 !important;
  overflow: visible !important;
}

.ui.search.focus,
.ui.search.active {
  z-index: 3200 !important;
}

.ui.search .results {
  z-index: 3300 !important;
}

.ui.segment,
.ui.search,
.ui.input,
.ui.icon.input {
  overflow: visible;
}


/* Code Blocks */
pre {
  background: var(--surface-hover);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25em;
  font-family: var(--font-mono);
  font-size: 0.9em;
  overflow-x: auto;
}

code {
  font-family: var(--font-mono);
  background: rgba(0, 0, 0, 0.05);
  padding: 0.2em 0.4em;
  border-radius: 4px;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-hover);
  border-radius: 5px;
  border: 2px solid var(--bg-color);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

/* Status Colors */
.status.accepted {
  color: hsl(var(--hue-success), 70%, 45%) !important;
}

.status.wrong_answer {
  color: hsl(var(--hue-danger), 80%, 55%) !important;
}

.status.time_limit_exceeded {
  color: hsl(var(--hue-warning), 80%, 45%) !important;
}

.status.memory_limit_exceeded {
  color: #CD5C5C !important;
}

.status.output_limit_exceeded {
  color: #00008B !important;
}

.status.runtime_error {
  color: #8b5cf6 !important;
}

.status.system_error {
  color: #551a8b !important;
}

.status.compile_error {
  color: #ef4444 !important;
}

.status.waiting,
.status.queuing,
.status.running,
.status.judging,
.status.compiling {
  color: var(--text-tertiary) !important;
}

.status.pending {
  color: #87CEEB !important;
}

.status.no_testdata,
.status.cancelled {
  color: var(--text-tertiary) !important;
}

.status.unknown {
  color: #000000 !important;
}

/* User Hover Card */
.user-hover-card {
  position: fixed;
  display: none;
  min-width: 280px;
  max-width: 340px;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-xl);
  border-radius: var(--radius-lg);
  padding: 16px;
  z-index: 1000;
  animation: scaleIn 0.2s ease-out;
}

.user-hover-card .uhc-header {
  display: flex;
  align-items: center;
  margin-bottom: 12px;
}

.user-hover-card .uhc-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  margin-right: 12px;
  object-fit: cover;
  border: 2px solid var(--surface-color);
  box-shadow: var(--shadow-sm);
}

.user-hover-card .uhc-name {
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.1em;
}

.user-hover-card .uhc-stats {
  color: var(--text-secondary);
  font-size: 0.9em;
  line-height: 1.5;
}

/* Utilities */
.padding {
  padding: 0 1em;
}

/* ═══════════════════════════════════════════════════
   Page Card — Unified content wrapper
   ═══════════════════════════════════════════════════ */
.page-card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.page-card-flush {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.page-card-flush > .ui.table {
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  margin: 0 !important;
}

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

.page-card-header-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.page-card-header-title > i.icon {
  margin: 0 !important;
  font-size: 1em;
  color: var(--text-tertiary);
}

.page-card-body {
  padding: 1.5rem;
}

/* ═══════════════════════════════════════════════════
   Data Metric Cards
   ═══════════════════════════════════════════════════ */
.metric-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.metric-card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  text-align: center;
  transition: border-color 0.2s;
}

.metric-card:hover {
  border-color: var(--border-hover);
}

.metric-card-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}

.metric-card-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.metric-card-value.status-accepted { color: var(--success-color); }
.metric-card-value.status-error { color: var(--danger-color); }
.metric-card-value.status-warning { color: var(--warning-color); }
.metric-card-value.status-waiting { color: var(--text-tertiary); }

/* ═══════════════════════════════════════════════════
   Unified Tab Navigation
   ═══════════════════════════════════════════════════ */
.tab-bar {
  border-bottom: 1px solid var(--border-color);
  padding: 0;
  margin-bottom: 1.5rem;
}

.tab-bar .tab-nav {
  display: flex;
  gap: 0;
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-x: auto;
}

.tab-bar .tab-nav a,
.tab-bar .tab-nav button {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.65rem 1.15rem;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
  cursor: pointer;
}

.tab-bar .tab-nav a:hover,
.tab-bar .tab-nav button:hover {
  color: var(--text-primary);
}

.tab-bar .tab-nav a.active,
.tab-bar .tab-nav button.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
  font-weight: 600;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

/* ═══════════════════════════════════════════════════
   Pro Card — unified card wrapper
   ═══════════════════════════════════════════════════ */
.pro-card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.pro-card > .ui.table {
  margin: 0 !important;
  border: none !important;
  box-shadow: none !important;
}

/* ═══════════════════════════════════════════════════
   Professional Table Alignment
   ═══════════════════════════════════════════════════ */
.ui.table.pro-table {
  border: none !important;
  box-shadow: none !important;
}

.ui.table.pro-table thead th {
  background: var(--surface-hover);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  padding: 1rem 1.25rem !important;
  border-bottom: 1px solid var(--border-color);
}

.ui.table.pro-table tbody td {
  padding: 0.85rem 1.25rem !important;
  border-top: 1px solid var(--border-color);
  font-size: 0.9rem;
}

.ui.table.pro-table tbody tr:hover {
  background: var(--surface-hover);
}

/* Add horizontal breathing room for tables inside flush containers */
.page-card-flush .ui.table.pro-table thead th:first-child,
.page-card-flush .ui.table.pro-table tbody td:first-child,
.ui.segment.glass .ui.table.pro-table thead th:first-child,
.ui.segment.glass .ui.table.pro-table tbody td:first-child {
  padding-left: 1.5rem !important;
}
.page-card-flush .ui.table.pro-table thead th:last-child,
.page-card-flush .ui.table.pro-table tbody td:last-child,
.ui.segment.glass .ui.table.pro-table thead th:last-child,
.ui.segment.glass .ui.table.pro-table tbody td:last-child {
  padding-right: 1.5rem !important;
}

/* Text alignment conventions */
.align-left { text-align: left !important; }
.align-right { text-align: right !important; }
.align-center { text-align: center !important; }

/* ═══════════════════════════════════════════════════
   Filter Bar — unified form area
   ═══════════════════════════════════════════════════ */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.filter-bar .ui.input input,
.filter-bar .ui.selection.dropdown {
  border: 1px solid var(--border-color) !important;
  border-radius: var(--radius-md) !important;
  font-size: 0.88rem;
  padding: 0.6em 0.9em;
}

.filter-bar .ui.input input:focus,
.filter-bar .ui.selection.dropdown.active {
  border-color: var(--primary-color) !important;
  box-shadow: 0 0 0 2px var(--primary-light) !important;
}

.filter-bar label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ═══════════════════════════════════════════════════
   Ghost / Outline Buttons
   ═══════════════════════════════════════════════════ */
.ui.button.ghost {
  background: transparent !important;
  border: 1px solid var(--border-color) !important;
  color: var(--text-secondary) !important;
  box-shadow: none !important;
}

.ui.button.ghost:hover {
  background: var(--surface-hover) !important;
  border-color: var(--border-hover) !important;
  color: var(--text-primary) !important;
}

.ui.button.ghost.danger:hover {
  background: hsl(var(--hue-danger), 80%, 97%) !important;
  border-color: var(--danger-color) !important;
  color: var(--danger-color) !important;
}

.ui.button.ghost.primary:hover {
  background: var(--primary-light) !important;
  border-color: var(--primary-color) !important;
  color: var(--primary-color) !important;
}

/* ═══════════════════════════════════════════════════
   Compact Form Layout (for edit pages)
   ═══════════════════════════════════════════════════ */
.form-compact {
  max-width: 720px;
  margin: 0 auto;
}

.form-compact .field > label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.form-compact .field > input,
.form-compact .field > textarea,
.form-compact .field > select {
  border-radius: var(--radius-md);
}

.form-compact .field > small {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-tertiary);
}

/* ═══════════════════════════════════════════════════
   Unified Tag / Label Styles
   ═══════════════════════════════════════════════════ */
.ui.label.tag-label {
  border-radius: 4px !important;
  padding: 0.25em 0.6em !important;
  font-weight: 600 !important;
  font-size: 0.75em !important;
  letter-spacing: 0.01em !important;
  border: 1px solid transparent !important;
}

/* ═══════════════════════════════════════════════════
   Slim Progress Bars (for submission detail)
   ═══════════════════════════════════════════════════ */
.resource-bar-slim .resource-bar-track {
  height: 5px;
  border-radius: 3px;
}

.resource-bar-slim .resource-bar-label {
  font-size: 0.78rem;
  margin-bottom: 6px;
}

/* ═══════════════════════════════════════════════════
   Reply / Comment Input Box
   ═══════════════════════════════════════════════════ */
.reply-form-pro .field textarea {
  border: 1.5px solid var(--border-color) !important;
  border-radius: var(--radius-md) !important;
  padding: 1em !important;
  font-size: 0.9rem;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 100px;
}

.reply-form-pro .field textarea:focus {
  border-color: var(--primary-color) !important;
  box-shadow: 0 0 0 3px var(--primary-light) !important;
  outline: none;
}

.reply-form-pro .reply-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.75rem;
}

/* ═══════════════════════════════════════════════════
   User Profile - Left/Right Layout
   ═══════════════════════════════════════════════════ */
.profile-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.5rem;
  align-items: start;
}

.profile-sidebar .profile-avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--border-color);
  display: block;
  margin: 0 auto 1rem;
}

.profile-sidebar .profile-name {
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.profile-sidebar .profile-role {
  text-align: center;
  margin-bottom: 1rem;
}

.profile-sidebar .profile-info-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.profile-sidebar .profile-info-list li {
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.88rem;
  color: var(--text-secondary);
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.profile-sidebar .profile-info-list li:last-child {
  border-bottom: none;
}

.profile-sidebar .profile-info-list li i.icon {
  color: var(--text-tertiary);
  width: 18px;
  flex-shrink: 0;
  margin-top: 2px;
}

.profile-sidebar .profile-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.profile-sidebar .profile-stat {
  text-align: center;
}

.profile-sidebar .profile-stat-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.profile-sidebar .profile-stat-label {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

@media (max-width: 991px) {
  .profile-layout {
    grid-template-columns: 1fr;
  }
  .profile-sidebar .profile-avatar {
    width: 80px;
    height: 80px;
  }
}

.font-content {
  font-family: var(--font-sans);
  background-color: transparent !important;
  font-size: 14px;
  line-height: 1.6;
}

.font-content {
  color-scheme: light;
  --color-fg-default: var(--text-primary);
  --color-canvas-default: transparent;
  --color-border-default: var(--border-color);
  --color-border-muted: var(--border-color);
  --color-accent-fg: var(--primary-color);
  --color-canvas-subtle: var(--surface-hover);
  --color-neutral-muted: rgba(0, 0, 0, 0.05);
  --color-fg-muted: var(--text-secondary);
  --color-fg-subtle: var(--text-tertiary);
}

.markdown-edit {
  font-family: var(--font-mono);
}

/* Responsive */
/* ═══════════════════════════════════════════════════
   Toast Notification System
   ═══════════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: min(420px, calc(100vw - 40px));
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-sans);
  font-size: 0.92em;
  line-height: 1.5;
  color: var(--text-primary);
  animation: toast-slide-in 0.35s cubic-bezier(0.21, 1.02, 0.73, 1) forwards;
  word-break: break-word;
  overflow: hidden;
}

.toast.toast-exiting {
  animation: toast-slide-out 0.28s cubic-bezier(0.06, 0.71, 0.55, 1) forwards;
}

.toast-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 1px;
}

.toast-icon svg {
  width: 20px;
  height: 20px;
}

.toast-body {
  flex: 1;
  min-width: 0;
}

.toast-title {
  font-weight: 600;
  font-size: 0.95em;
  margin-bottom: 2px;
}

.toast-message {
  color: var(--text-secondary);
  font-size: 0.9em;
}

.toast-close {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  margin: -2px -4px 0 0;
  color: var(--text-tertiary);
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}

.toast-close:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.toast-close svg {
  width: 16px;
  height: 16px;
}

.toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  animation: toast-progress linear forwards;
}

/* Toast types */
.toast-error {
  border-left: 4px solid var(--danger-color);
}

.toast-error .toast-icon svg {
  color: var(--danger-color);
}

.toast-error .toast-title {
  color: var(--danger-color);
}

.toast-error .toast-progress {
  background: var(--danger-color);
}

.toast-success {
  border-left: 4px solid var(--success-color);
}

.toast-success .toast-icon svg {
  color: var(--success-color);
}

.toast-success .toast-title {
  color: var(--success-color);
}

.toast-success .toast-progress {
  background: var(--success-color);
}

.toast-warning {
  border-left: 4px solid var(--warning-color);
}

.toast-warning .toast-icon svg {
  color: var(--warning-color);
}

.toast-warning .toast-title {
  color: var(--warning-color);
}

.toast-warning .toast-progress {
  background: var(--warning-color);
}

.toast-info {
  border-left: 4px solid var(--primary-color);
}

.toast-info .toast-icon svg {
  color: var(--primary-color);
}

.toast-info .toast-title {
  color: var(--primary-color);
}

.toast-info .toast-progress {
  background: var(--primary-color);
}

@keyframes toast-slide-in {
  from {
    opacity: 0;
    transform: translateX(40px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
}

@keyframes toast-slide-out {
  from {
    opacity: 1;
    transform: translateX(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateX(40px) scale(0.96);
  }
}

@keyframes toast-progress {
  from { width: 100%; }
  to { width: 0%; }
}

/* ═══════════════════════════════════════════════════
   Custom Confirm Dialog
   ═══════════════════════════════════════════════════ */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  animation: confirm-fade-in 0.2s ease forwards;
}

.confirm-overlay.confirm-exiting {
  animation: confirm-fade-out 0.2s ease forwards;
}

.confirm-dialog {
  background: var(--surface-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: 28px 32px 24px;
  max-width: 400px;
  width: calc(100vw - 40px);
  text-align: center;
  animation: confirm-scale-in 0.25s cubic-bezier(0.21, 1.02, 0.73, 1) forwards;
}

.confirm-exiting .confirm-dialog {
  animation: confirm-scale-out 0.2s ease forwards;
}

.confirm-icon {
  margin: 0 auto 12px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: hsl(var(--hue-warning), 80%, 95%);
}

.confirm-icon svg {
  width: 28px;
  height: 28px;
  color: var(--warning-color);
}

.confirm-title {
  font-weight: 600;
  font-size: 1.1em;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.confirm-message {
  color: var(--text-secondary);
  font-size: 0.92em;
  line-height: 1.5;
  margin-bottom: 22px;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.confirm-btn {
  padding: 9px 24px;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: 0.92em;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
}

.confirm-btn:active {
  transform: scale(0.97);
}

.confirm-cancel {
  background: var(--surface-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.confirm-cancel:hover {
  background: var(--border-color);
  color: var(--text-primary);
}

.confirm-ok {
  background: var(--danger-color);
  color: #fff;
}

.confirm-ok:hover {
  filter: brightness(1.08);
  box-shadow: 0 4px 12px hsla(var(--hue-danger), 80%, 55%, 0.3);
}

@keyframes confirm-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes confirm-fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes confirm-scale-in {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes confirm-scale-out {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.9); }
}

/* ═══════════════════════════════════════════════════
   Resource Usage Bars
   ═══════════════════════════════════════════════════ */
.resource-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-bottom: 4px;
  color: var(--text-secondary);
}

.resource-bar-label span:last-child {
  font-family: var(--font-mono);
}

.resource-bar-track {
  height: 6px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.resource-bar-fill {
  height: 100%;
  min-width: 0;
  border-radius: 3px;
  transition: width 0.8s ease-out, background-color 0.8s ease-out;
}

.resource-bar-fill.bar-ok {
  background-color: var(--success-color);
}

.resource-bar-fill.bar-warn {
  background-color: var(--warning-color);
}

.resource-bar-fill.bar-danger {
  background-color: var(--danger-color);
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE / MOBILE ADAPTATION
   Breakpoints:
     <= 991px  — tablet & below (hide desktop nav)
     <= 767px  — mobile (stack grids, shrink padding)
     <= 480px  — small phone (tighten everything)
   ═══════════════════════════════════════════════════ */

/* ---------- Utility classes ---------- */
.mobile-only     { display: none !important; }
.hide-mobile     { }  /* visible by default */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- Tablet & below (<=991px) ---------- */
@media (max-width: 991px) {
  .ui.container {
    padding: 0 1rem;
  }

  .ui.menu {
    overflow-x: auto;
  }

  #menu_toggle {
    display: flex !important;
  }

  .item.computer.only {
    display: none !important;
  }

  .mobile-only  { display: block !important; }
  .hide-mobile  { display: none !important; }

  /* Semantic UI grids — force stacking */
  .ui.grid > .row > .five.wide.column,
  .ui.grid > .row > .eleven.wide.column,
  .ui.grid > .row > .eight.wide.column,
  .ui.grid > .row > .four.wide.column {
    width: 100% !important;
  }

  /* Tables must scroll, not squish */
  .ui.table:not(.unstackable) {
    display: block;
  }
  table.ui.table:not(.unstackable) {
    width: 100%;
    min-width: 0;
  }
  .ui.segment > table.ui.table,
  .ui.segment.glass > table.ui.table {
    display: table;  /* keep table layout inside scroll container */
  }

  /* Multi-column fields → stack */
  .ui.form .two.fields,
  .ui.form .three.fields,
  .ui.form .four.fields {
    flex-direction: column;
  }
  .ui.form .two.fields > .field,
  .ui.form .three.fields > .field,
  .ui.form .four.fields > .field {
    width: 100% !important;
    margin-bottom: 1em;
  }

  /* Admin statistics — 2 cols on tablet */
  .ui.statistics .statistic {
    width: calc(50% - 2em) !important;
  }

  /* Admin grid layout — stack sidebar */
  .ui.grid > .three.wide.column,
  .ui.grid > .thirteen.wide.column {
    width: 100% !important;
  }
  .ui.vertical.tabular.menu {
    flex-direction: row !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    height: auto !important;
  }
  .ui.vertical.tabular.menu .item {
    white-space: nowrap;
  }

  /* Inline form fields wrap */
  .ui.form .inline.fields {
    flex-wrap: wrap;
    white-space: normal !important;
    gap: 0.5rem;
  }

  /* User hover card — limit width */
  .user-hover-card {
    max-width: min(340px, calc(100vw - 24px)) !important;
    min-width: auto !important;
  }
}

/* ═══════════════════ Utility Classes ═══════════════════ */
.u-text-center { text-align: center; }
.u-text-left { text-align: left; }
.u-text-right { text-align: right; }
.u-text-mono { font-family: var(--font-mono); }
.u-text-sm { font-size: var(--text-sm); }
.u-text-xs { font-size: var(--text-xs); }
.u-text-muted { color: var(--text-tertiary); }
.u-text-secondary { color: var(--text-secondary); }
.u-fw-500 { font-weight: var(--font-medium); }
.u-fw-600 { font-weight: var(--font-semibold); }
.u-fw-700 { font-weight: var(--font-bold); }
.u-mx-auto { margin-left: auto; margin-right: auto; }
.u-mt-2 { margin-top: var(--space-2); }
.u-mt-4 { margin-top: var(--space-4); }
.u-mt-6 { margin-top: var(--space-6); }
.u-mb-2 { margin-bottom: var(--space-2); }
.u-mb-4 { margin-bottom: var(--space-4); }
.u-mb-6 { margin-bottom: var(--space-6); }
.u-flex { display: flex; }
.u-flex-col { display: flex; flex-direction: column; }
.u-items-center { align-items: center; }
.u-justify-between { justify-content: space-between; }
.u-gap-2 { gap: var(--space-2); }
.u-gap-3 { gap: var(--space-3); }
.u-gap-4 { gap: var(--space-4); }

/* Container Width Utilities */
.container-narrow { max-width: var(--container-sm); margin-left: auto; margin-right: auto; }
.container-medium { max-width: var(--container-md); margin-left: auto; margin-right: auto; }
.container-wide { max-width: var(--container-lg); margin-left: auto; margin-right: auto; }
.container-xl { max-width: var(--container-xl); margin-left: auto; margin-right: auto; }

/* Empty State Component */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-tertiary);
}
.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}
.empty-state-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}
.empty-state-desc {
  font-size: var(--text-sm);
}

/* Form Card Component (auth pages) */
.form-card {
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  padding: var(--space-8);
  max-width: var(--container-sm);
  margin: var(--space-8) auto;
}

/* Status Badge Component */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.status-badge.is-success { background: hsla(var(--hue-success), 70%, 45%, 0.1); color: var(--success-color); }
.status-badge.is-danger { background: hsla(var(--hue-danger), 80%, 55%, 0.1); color: var(--danger-color); }
.status-badge.is-warning { background: hsla(var(--hue-warning), 80%, 45%, 0.1); color: var(--warning-color); }
.status-badge.is-info { background: hsla(var(--hue-primary), 90%, 50%, 0.1); color: var(--primary-color); }

/* ---------- Mobile (<=767px) ---------- */
@media (max-width: 767px) {
  html {
    font-size: 15px;
  }

  .glass {
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .ui.container {
    padding: 0 0.75rem;
  }

  .padding {
    padding: 0 0.5em;
  }

  /* Header nav bar height reduction */
  .ui.fixed.borderless.menu.glass {
    height: 56px !important;
  }
  .main-layout {
    margin-top: 20px !important;
  }

  /* Segments / cards — reduce padding */
  .ui.segment {
    padding: 1rem !important;
  }
  .ui.segment.glass {
    padding: 1rem !important;
  }

  /* Buttons — prevent overflow */
  .ui.buttons {
    flex-wrap: wrap;
  }
  .ui.button {
    font-size: 0.9rem !important;
  }
  .ui.huge.button {
    font-size: 1.1rem !important;
    padding: 0.8em 1.5em !important;
  }

  /* Tables — ensure horizontal scroll for data-heavy tables */
  .table-responsive {
    margin: 0 -0.5rem;
    padding: 0 0.5rem;
  }
  .ui.table thead th {
    padding: 0.75em 0.5em;
    font-size: 0.7rem;
  }
  .ui.table tbody td {
    padding: 0.75em 0.5em;
    font-size: 0.85rem;
  }

  /* Semantic UI grid — full-width columns */
  .ui.grid:not(.unstackable) > .row > .column,
  .ui.grid:not(.unstackable) > .column:not(.row) {
    width: 100% !important;
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }
  .ui.grid > .row {
    flex-direction: column;
  }
  .ui.stackable.grid > .column,
  .ui.stackable.grid > .row > .column {
    width: 100% !important;
  }

  /* Fix input widths in forms */
  .ui.form input[type="text"],
  .ui.form input[type="email"],
  .ui.form input[type="password"],
  .ui.form select,
  .ui.form textarea,
  .ui.selection.dropdown {
    max-width: 100%;
  }
  .ui.form .inline.fields .field input {
    width: auto !important;
    min-width: 60px;
  }
  .ui.form .inline.fields label {
    font-size: 1em !important;
    margin-right: 4px !important;
  }

  /* Modal popups — make full-ish width */
  .ui.modal {
    width: 92vw !important;
    margin: 0 auto !important;
  }
  .ui.basic.modal {
    max-width: 92vw !important;
  }

  /* Confirm dialog */
  .confirm-dialog {
    padding: 20px 18px 18px;
    max-width: calc(100vw - 24px);
  }

  /* Toast — full width */
  .toast-container {
    right: 8px;
    left: 8px;
    max-width: none;
  }

  /* User avatar card */
  .user-hover-card {
    max-width: min(300px, calc(100vw - 16px)) !important;
    min-width: auto !important;
  }

  /* Footer */
  .ui.vertical.footer.segment {
    padding: 2rem 0 !important;
  }
  .ui.vertical.footer.segment .ui.container {
    font-size: 0.9em;
  }
  .ui.vertical.footer.segment span {
    display: block;
    margin: 0.3rem 0;
  }

  /* Dropdown menus within hover-style dropdowns */
  .ui.simple.dropdown > .menu {
    min-width: 180px;
  }

  /* Pre/code blocks — ensure scrollable */
  pre {
    max-width: 100%;
    overflow-x: auto;
    padding: 1em;
    font-size: 0.82em;
  }
  code {
    word-break: break-word;
  }

  /* Chart legend */
  .chart-legend li {
    width: 100%;
  }

  /* Admin statistics — single column on mobile */
  .ui.statistics .statistic {
    width: 100% !important;
  }

  /* Admin editor — responsive height */
  #editor.editor {
    height: 350px !important;
  }

  /* Article comments — float fix */
  .ui.comments .ui.dividing.header span[style*="float"] {
    float: none !important;
    display: block;
    margin-top: 0.5em;
  }
}

/* ---------- Small phone (<=480px) ---------- */
@media (max-width: 480px) {
  html {
    font-size: 14px;
  }

  .ui.container {
    padding: 0 0.5rem;
  }

  .padding {
    padding: 0 0.25em;
  }

  .ui.segment {
    padding: 0.75rem !important;
    border-radius: var(--radius-md) !important;
  }

  .ui.table thead th {
    padding: 0.5em 0.35em;
    font-size: 0.65rem;
  }
  .ui.table tbody td {
    padding: 0.5em 0.35em;
    font-size: 0.8rem;
  }

  /* Header items */
  .ui.fixed.borderless.menu.glass {
    height: 48px !important;
  }
  .ui.fixed.borderless.menu.glass .header.item img {
    max-height: 28px !important;
  }
  .ui.fixed.borderless.menu.glass .header.item span {
    font-size: 1em !important;
  }

  /* User dropdown — keep compact */
  #user_dropdown img.avatar {
    width: 24px !important;
    height: 24px !important;
  }
  #user_dropdown > span:not(.__avatar_dot) {
    display: none;
  }
  #user_dropdown > i.dropdown.icon {
    margin-left: 2px !important;
  }

  /* Login & auth pages */
  .ui.segment.glass[style*="padding: 2.5rem"] {
    padding: 1.25rem !important;
  }

  /* Confirm & modal */
  .confirm-dialog {
    padding: 16px 14px 14px;
  }
  .confirm-actions {
    flex-direction: column;
    gap: 8px;
  }
  .confirm-btn {
    width: 100%;
  }

  /* Sidebar menu items */
  #mobile_sidebar .item {
    padding: 0.85em 1em !important;
    font-size: 0.95em;
  }
}