/* ===== Design Tokens ===== */
:root {
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Dark Theme (default) */
  --bg-primary: #0a1210;
  --bg-secondary: #0f1a16;
  --bg-card: #142420;
  --bg-card-hover: #1b2f29;
  --bg-input: #1b2f29;

  --text-primary: #e8f5e9;
  --text-secondary: #a5c4ad;
  --text-muted: #6b8f72;

  --accent: #22c55e;
  --accent-hover: #4ade80;
  --accent-glow: rgba(34, 197, 94, 0.25);
  --accent-subtle: rgba(34, 197, 94, 0.1);
  --accent-gradient-end: #86efac;

  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, 0.12);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, 0.12);
  --info: #67e8f9;
  --info-bg: rgba(103, 232, 249, 0.12);

  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);

  --header-bg: rgba(10, 18, 16, 0.85);
  --toast-success-bg: #0e2a1b;
  --toast-error-bg: #2a1215;
  --select-arrow: %23a5c4ad;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  --transition: 0.2s ease;
}

/* ===== Light Theme ===== */
[data-theme="light"] {
  --bg-primary: #f0faf4;
  --bg-secondary: #dcfce7;
  --bg-card: #ffffff;
  --bg-card-hover: #f0fdf4;
  --bg-input: #f0fdf4;

  --text-primary: #052e16;
  --text-secondary: #3f6b4f;
  --text-muted: #86a990;

  --accent: #16a34a;
  --accent-hover: #15803d;
  --accent-glow: rgba(22, 163, 74, 0.2);
  --accent-subtle: rgba(22, 163, 74, 0.08);
  --accent-gradient-end: #4ade80;

  --success: #16a34a;
  --success-bg: rgba(22, 163, 74, 0.1);
  --warning: #ca8a04;
  --warning-bg: rgba(202, 138, 4, 0.1);
  --danger: #dc2626;
  --danger-bg: rgba(220, 38, 38, 0.1);
  --info: #0891b2;
  --info-bg: rgba(8, 145, 178, 0.1);

  --border: rgba(0, 50, 20, 0.08);
  --border-hover: rgba(0, 50, 20, 0.15);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.1);

  --header-bg: rgba(255, 255, 255, 0.9);
  --toast-success-bg: #ecfdf5;
  --toast-error-bg: #fef2f2;
  --select-arrow: %233f6b4f;
}

/* ===== Reset ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition:
    background 0.3s ease,
    color 0.3s ease;
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
  transition: background 0.3s ease;
}

.header-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  background: linear-gradient(
    135deg,
    var(--accent),
    var(--accent-gradient-end)
  );
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  color: white;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.logo-text h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.2;
}

.logo-text span {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box i {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  font-size: 0.8rem;
  pointer-events: none;
}

.search-box input {
  padding: 0.55rem 0.75rem 0.55rem 2.2rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.82rem;
  width: 240px;
  transition: var(--transition);
  font-family: var(--font);
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  width: 280px;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

/* ===== Main ===== */
main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ===== Stats Grid ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  border-radius: 0 4px 4px 0;
}

.stat-total::before {
  background: var(--accent);
}
.stat-avg::before {
  background: var(--info);
}
.stat-pass::before {
  background: var(--success);
}
.stat-fail::before {
  background: var(--danger);
}

.stat-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.stat-total .stat-icon {
  background: var(--accent-subtle);
  color: var(--accent-hover);
}
.stat-avg .stat-icon {
  background: var(--info-bg);
  color: var(--info);
}
.stat-pass .stat-icon {
  background: var(--success-bg);
  color: var(--success);
}
.stat-fail .stat-icon {
  background: var(--danger-bg);
  color: var(--danger);
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 2px;
}

/* ===== Content Grid ===== */
.content-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.card-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
}

.card-header h2 i {
  color: var(--accent);
  font-size: 0.9rem;
}

/* ===== Form ===== */
.form-card {
  position: sticky;
  top: 80px;
}

.student-form {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

label i {
  font-size: 0.7rem;
  color: var(--text-muted);
}

input,
select {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-family: var(--font);
  transition: var(--transition);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

input::placeholder {
  color: var(--text-muted);
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='var(--select-arrow)' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 2rem;
}

select option {
  background: var(--bg-card);
  color: var(--text-primary);
}

.btn-submit {
  width: 100%;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(
    135deg,
    var(--accent),
    var(--accent-gradient-end)
  );
  color: white;
  font-weight: 600;
  font-size: 0.85rem;
  font-family: var(--font);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.btn-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--accent-glow);
  filter: brightness(1.1);
}

.btn-submit:active {
  transform: translateY(0);
}

/* ===== Table ===== */
.table-card .card-header {
  background: var(--bg-card);
}

.controls {
  display: flex;
  gap: 0.5rem;
}

.select-wrapper select {
  min-width: 110px;
  font-size: 0.8rem;
  padding: 0.45rem 2rem 0.45rem 0.7rem;
}

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

thead {
  background: var(--bg-secondary);
}

th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--bg-card-hover);
}

td {
  padding: 0.8rem 1rem;
  vertical-align: middle;
  color: var(--text-secondary);
  white-space: nowrap;
}

td:first-child {
  color: var(--text-primary);
  font-weight: 500;
}

/* ===== Status Badge ===== */
.status {
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  letter-spacing: 0.02em;
}

.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.status-passed {
  background: var(--success-bg);
  color: var(--success);
}

.status-passed::before {
  background: var(--success);
}

.status-failed {
  background: var(--danger-bg);
  color: var(--danger);
}

.status-failed::before {
  background: var(--danger);
}

.status-average {
  background: var(--warning-bg);
  color: var(--warning);
}

.status-average::before {
  background: var(--warning);
}

/* Grade bar */
.grade-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.grade-bar {
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  width: 60px;
}

.grade-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.5s ease;
}

.grade-bar-fill.grade-high {
  background: var(--success);
}

.grade-bar-fill.grade-mid {
  background: var(--warning);
}

.grade-bar-fill.grade-low {
  background: var(--danger);
}

/* ===== Delete Button ===== */
.action-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--danger-bg);
  color: var(--danger);
  cursor: pointer;
  font-size: 0.8rem;
  transition: var(--transition);
  display: inline-grid;
  place-items: center;
}

.action-btn:hover {
  background: var(--danger);
  color: white;
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* ===== Empty State ===== */
.no-records td {
  padding: 3rem 1rem;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 2.5rem;
  color: var(--border-hover);
  margin-bottom: 0.25rem;
}

.empty-state p {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.empty-state span {
  font-size: 0.8rem;
}

/* ===== Error Styling ===== */
.error {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15) !important;
}

.error-message {
  color: var(--danger);
  font-size: 0.72rem;
  display: none;
  margin-top: 2px;
  font-weight: 500;
}

/* ===== Toast Notifications ===== */
.toast-container {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.8rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  font-family: var(--font);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 260px;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.35s ease forwards;
  border: 1px solid var(--border);
}

.toast-success {
  background: var(--toast-success-bg);
  color: var(--success);
  border-color: rgba(34, 197, 94, 0.2);
}

.toast-error {
  background: var(--toast-error-bg);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.2);
}

.toast-out {
  animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(40px);
  }
}

/* ===== Row animations ===== */
@keyframes rowSlideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

tbody tr:not(.no-records) {
  animation: rowSlideIn 0.3s ease forwards;
}

/* ===== Responsive ===== */

/* --- Large Desktop (1440px+) --- */
@media (min-width: 1440px) {
  main {
    max-width: 1440px;
    padding: 2rem 3rem;
  }

  .header-inner {
    max-width: 1440px;
  }

  .stats-grid {
    gap: 1.25rem;
  }

  .content-grid {
    grid-template-columns: 380px 1fr;
    gap: 2rem;
  }

  .stat-value {
    font-size: 1.75rem;
  }
}

/* --- Small Desktop / Laptop (1025px – 1279px) --- */
@media (max-width: 1279px) {
  main {
    padding: 1.25rem;
  }

  .content-grid {
    grid-template-columns: 320px 1fr;
    gap: 1.25rem;
  }

  .search-box input {
    width: 200px;
  }

  .search-box input:focus {
    width: 240px;
  }
}

/* --- Tablet landscape & small laptop (769px – 1024px) --- */
@media (max-width: 1024px) {
  .content-grid {
    grid-template-columns: 1fr;
  }

  .form-card {
    position: static;
  }

  /* Make form horizontal on tablet */
  .student-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
  }

  .student-form .form-row {
    grid-column: 1 / -1;
  }

  .student-form .btn-submit {
    grid-column: 1 / -1;
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
  }

  .stat-card {
    padding: 1rem;
    gap: 0.75rem;
  }

  .stat-icon {
    width: 38px;
    height: 38px;
    font-size: 1rem;
  }

  .stat-value {
    font-size: 1.3rem;
  }

  .stat-label {
    font-size: 0.7rem;
  }
}

/* --- Tablet portrait (641px – 768px) --- */
@media (max-width: 768px) {
  .header-inner {
    padding: 0.65rem 1rem;
  }

  .logo-icon {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  .logo-text h1 {
    font-size: 1.05rem;
  }

  .logo-text span {
    font-size: 0.62rem;
  }

  .search-box input {
    width: 180px;
    font-size: 0.8rem;
  }

  .search-box input:focus {
    width: 200px;
  }

  main {
    padding: 1rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
  }

  .student-form {
    grid-template-columns: 1fr;
  }

  .card-header {
    padding: 0.85rem 1rem;
  }

  .card-header h2 {
    font-size: 0.9rem;
  }

  .controls {
    width: 100%;
  }

  .controls .select-wrapper {
    flex: 1;
  }

  .controls .select-wrapper select {
    width: 100%;
    min-width: unset;
  }

  /* Table adjustments */
  th,
  td {
    padding: 0.65rem 0.6rem;
    font-size: 0.78rem;
  }

  .grade-bar {
    width: 50px;
  }

  .toast-container {
    left: 1rem;
    right: 1rem;
  }

  .toast {
    min-width: unset;
    width: 100%;
  }
}

/* --- Mobile landscape / large mobile (481px – 640px) --- */
@media (max-width: 640px) {
  .header-inner {
    flex-direction: column;
    gap: 0.6rem;
    padding: 0.6rem 0.75rem;
  }

  .header-inner .logo {
    width: 100%;
  }

  .header-actions {
    width: 100%;
    gap: 0.5rem;
  }

  .search-box {
    flex: 1;
  }

  .search-box input {
    width: 100%;
  }

  .search-box input:focus {
    width: 100%;
  }

  .theme-toggle {
    width: 36px;
    height: 36px;
    font-size: 0.9rem;
  }

  main {
    padding: 0.75rem;
  }

  .stat-card {
    padding: 0.85rem;
    gap: 0.6rem;
  }

  .stat-icon {
    width: 36px;
    height: 36px;
    font-size: 0.9rem;
  }

  .stat-value {
    font-size: 1.15rem;
  }

  .card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
    padding: 0.85rem;
  }

  .student-form {
    padding: 1rem;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  /* Switch table to card layout on mobile */
  .table-wrapper table,
  .table-wrapper thead,
  .table-wrapper tbody,
  .table-wrapper th,
  .table-wrapper td,
  .table-wrapper tr {
    display: block;
  }

  .table-wrapper thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  .table-wrapper tbody tr {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 0.75rem;
    padding: 1rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem 1rem;
    position: relative;
  }

  .table-wrapper tbody tr:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-sm);
  }

  .table-wrapper tbody tr:last-child {
    margin-bottom: 0;
  }

  .table-wrapper td {
    padding: 0.2rem 0;
    white-space: normal;
    border-bottom: none;
    font-size: 0.82rem;
  }

  .table-wrapper td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
  }

  /* Name spans full width */
  .table-wrapper td:nth-child(1) {
    grid-column: 1 / -1;
    font-size: 0.95rem;
    font-weight: 600;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.15rem;
  }

  /* Action button positioned top-right */
  .table-wrapper td:nth-child(7) {
    position: absolute;
    top: 0.85rem;
    right: 0.85rem;
    padding: 0;
  }

  .table-wrapper td:nth-child(7)::before {
    display: none;
  }

  /* Empty state full width */
  .table-wrapper .no-records {
    grid-template-columns: 1fr;
    border: none;
    background: none;
  }

  .table-wrapper .no-records td {
    grid-column: 1 / -1;
  }

  .table-wrapper .no-records td::before {
    display: none;
  }

  .grade-bar {
    width: 100%;
    max-width: 100px;
  }

  .action-btn {
    width: 36px;
    height: 36px;
    font-size: 0.85rem;
  }

  .empty-state i {
    font-size: 2rem;
  }

  .empty-state p {
    font-size: 0.85rem;
  }

  .empty-state span {
    font-size: 0.75rem;
  }
}

/* --- Small mobile (≤480px) --- */
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .stat-card {
    padding: 0.75rem;
    gap: 0.5rem;
  }

  .stat-icon {
    width: 32px;
    height: 32px;
    font-size: 0.85rem;
  }

  .stat-value {
    font-size: 1.05rem;
  }

  .stat-label {
    font-size: 0.65rem;
  }

  .logo-icon {
    width: 34px;
    height: 34px;
    font-size: 0.95rem;
  }

  .logo-text h1 {
    font-size: 1rem;
  }

  .student-form {
    padding: 0.85rem;
    gap: 0.85rem;
  }

  label {
    font-size: 0.75rem;
  }

  input,
  select {
    padding: 0.55rem 0.75rem;
    font-size: 0.82rem;
  }

  .btn-submit {
    padding: 0.65rem;
    font-size: 0.82rem;
  }

  .card-header h2 {
    font-size: 0.85rem;
  }

  .table-wrapper tbody tr {
    padding: 0.85rem;
    gap: 0.4rem 0.75rem;
  }

  .table-wrapper td {
    font-size: 0.78rem;
  }

  .table-wrapper td:nth-child(1) {
    font-size: 0.88rem;
  }

  .table-wrapper td::before {
    font-size: 0.62rem;
  }

  .toast-container {
    top: 0.75rem;
    left: 0.75rem;
    right: 0.75rem;
  }

  .toast {
    padding: 0.65rem 1rem;
    font-size: 0.78rem;
  }
}

/* --- Extra small mobile (≤360px) --- */
@media (max-width: 360px) {
  main {
    padding: 0.5rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .stat-card {
    flex-direction: row;
    padding: 0.7rem;
  }

  .table-wrapper tbody tr {
    grid-template-columns: 1fr;
    padding: 0.75rem;
  }

  .table-wrapper td:nth-child(7) {
    position: static;
    margin-top: 0.35rem;
  }

  .table-wrapper td:nth-child(7)::before {
    display: block;
  }

  .header-inner {
    padding: 0.5rem;
  }

  .search-box input {
    font-size: 0.78rem;
    padding: 0.5rem 0.6rem 0.5rem 2rem;
  }
}

/* ===== Touch-friendly adjustments ===== */
@media (hover: none) and (pointer: coarse) {
  .action-btn {
    width: 40px;
    height: 40px;
  }

  .btn-submit {
    padding: 0.8rem 1rem;
    font-size: 0.88rem;
  }

  input,
  select {
    padding: 0.7rem 0.85rem;
    font-size: 0.88rem;
  }

  .select-wrapper select {
    padding: 0.55rem 2rem 0.55rem 0.7rem;
  }

  .theme-toggle {
    width: 42px;
    height: 42px;
  }

  .stat-card:hover {
    transform: none;
  }

  .btn-submit:hover {
    transform: none;
  }

  .action-btn:hover {
    transform: none;
  }
}

/* ===== Theme Toggle Button ===== */
.theme-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1rem;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-subtle);
  transform: rotate(15deg);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Smooth transitions for theme-sensitive elements */
.card,
.stat-card,
.search-box input,
input,
select,
.action-btn,
.toast {
  transition:
    background 0.3s ease,
    border-color 0.3s ease,
    color 0.3s ease,
    box-shadow 0.2s ease,
    transform 0.2s ease;
}
