/* =============================================
   Censos Platform - Main Stylesheet
   Extracted from layout.php for performance
   ============================================= */

:root {
  --bg: #f7f8fb;
  --surface: rgba(255, 255, 255, .9);
  --card: #ffffff;
  --text: #0b1220;
  --muted: rgba(11, 18, 32, .62);
  --border: rgba(11, 18, 32, .10);

  --primary: #2563eb;
  /* blue 600 */
  --primary-ink: #ffffff;
  --primary-soft: rgba(37, 99, 235, .10);

  --danger: #e11d48;
  /* rose 600 */
  --danger-soft: rgba(225, 29, 72, .10);

  --shadow: 0 10px 30px rgba(11, 18, 32, .08);
  --shadow-soft: 0 6px 18px rgba(11, 18, 32, .06);

  --radius: 16px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 12% 0%, rgba(37, 99, 235, .12), transparent 60%),
    radial-gradient(900px 500px at 90% 10%, rgba(99, 102, 241, .10), transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  text-decoration: none;
}

.wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 18px 24px 42px;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 12px;
  z-index: 20;

  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;

  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.brand img {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(11, 18, 32, .06);
  background: #fff;
}

.brand .t {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand .t strong {
  font-size: 14px;
  letter-spacing: -0.02em;
}

.brand .t span {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}

.nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav a {
  font-size: 13px;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .7);
  color: rgba(11, 18, 32, .86);
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}

.nav a:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
  background: #fff;
}

.container {
  margin-top: 16px;
}

/* Typography */
h1 {
  margin: 0 0 10px;
  font-size: 22px;
  letter-spacing: -0.03em;
}

h2 {
  margin: 0 0 10px;
  font-size: 15px;
  color: rgba(11, 18, 32, .85);
  letter-spacing: -0.01em;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

/* Layout blocks */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 16px;
}

.grid {
  display: grid;
  gap: 14px;
}

@media(min-width: 920px) {
  .grid.two {
    grid-template-columns: 1fr 1fr;
  }
}

.row {
  display: grid;
  gap: 12px;
}

@media(min-width: 760px) {
  .row.two {
    grid-template-columns: 1fr 1fr;
  }

  .row.three {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .row.four {
    grid-template-columns: 1fr 1fr 1fr 1fr;
  }
}

/* Custom Checkbox */
.checkbox-container {
  display: block;
  position: relative;
  padding-left: 28px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  user-select: none;
  margin: 12px 0;
}

.checkbox-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 18px;
  width: 18px;
  background-color: #eee;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.checkbox-container:hover input~.checkmark {
  background-color: #ccc;
}

.checkbox-container input:checked~.checkmark {
  background-color: var(--primary);
  border-color: var(--primary);
}

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

.checkbox-container input:checked~.checkmark:after {
  display: block;
}

.checkbox-container .checkmark:after {
  left: 6px;
  top: 2px;
  width: 4px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Form */
label {
  display: block;
  margin: 10px 0 6px;
  font-size: 12px;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid rgba(11, 18, 32, .12);
  background: rgba(247, 248, 251, .55);
  color: rgba(11, 18, 32, .94);
  outline: none;
  transition: box-shadow .12s ease, border-color .12s ease, background .12s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(37, 99, 235, .45);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .12);
  background: #fff;
}

textarea {
  resize: vertical;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  line-height: 1;

  padding: 0 16px;
  height: 40px;

  border-radius: 10px;
  border: 1px solid rgba(11, 18, 32, .10);
  cursor: pointer;

  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.01em;

  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease, background .12s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Toolbar (Filters) */
.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(247, 248, 251, .3);
}

.toolbar .search-box {
  flex: 1;
  min-width: 200px;
  position: relative;
  display: flex;
  align-items: center;
}

.toolbar input,
.toolbar select {
  border: 1px solid rgba(11, 18, 32, .1);
  background: #fff;
  font-size: 13px;
  padding: 0 12px;
  height: 38px;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .03);
  display: flex;
  align-items: center;
}

.toolbar input {
  padding-left: 36px;
  width: 100%;
}

.toolbar .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  opacity: .5;
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.toolbar .btn {
  height: 38px;
  border-radius: 8px;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}

.btn:active {
  transform: translateY(0px);
}

.btn.primary {
  background: linear-gradient(180deg, rgba(37, 99, 235, 1), rgba(29, 78, 216, 1));
  color: var(--primary-ink);
  border-color: rgba(37, 99, 235, .35);
}

.btn.secondary {
  background: rgba(255, 255, 255, .9);
  color: rgba(11, 18, 32, .92);
  border-color: rgba(11, 18, 32, .12);
}

.btn.danger {
  background: var(--danger-soft);
  color: rgba(225, 29, 72, .92);
  border-color: rgba(225, 29, 72, .22);
}

.btn.link {
  background: transparent;
  border-color: transparent;
  color: rgba(37, 99, 235, .95);
  padding: 8px 10px;
  border-radius: 10px;
}

.btn.link:hover {
  background: rgba(37, 99, 235, .08);
  box-shadow: none;
  transform: none;
}

/* Messages */
.msg {
  margin: 12px 0 0;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid rgba(11, 18, 32, .12);
  background: rgba(247, 248, 251, .75);
  color: rgba(11, 18, 32, .92);
}

.msg.ok {
  border-color: rgba(43, 212, 166, .30);
  background: rgba(43, 212, 166, .10);
}

.msg.err {
  border-color: rgba(225, 29, 72, .25);
  background: rgba(225, 29, 72, .08);
}

.msg.warn {
  border-color: rgba(245, 158, 11, .28);
  background: rgba(245, 158, 11, .10);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(11, 18, 32, .12);
  background: rgba(247, 248, 251, .7);
  font-size: 12px;
  color: rgba(11, 18, 32, .70);
  white-space: nowrap;
}

.badge.ok {
  border-color: rgba(43, 212, 166, .30);
  background: rgba(43, 212, 166, .12);
  color: rgba(22, 101, 52, 1);
}

.badge.err {
  border-color: rgba(225, 29, 72, .22);
  background: rgba(225, 29, 72, .10);
  color: rgba(153, 27, 27, 1);
}

.badge.warn {
  border-color: rgba(245, 158, 11, .25);
  background: rgba(245, 158, 11, .12);
  color: rgba(146, 64, 14, 1);
}

.badge.blue {
  border-color: rgba(37, 99, 235, .25);
  background: rgba(37, 99, 235, .10);
  color: rgba(30, 64, 175, 1);
}

.badge.purple {
  border-color: rgba(126, 34, 206, .25);
  background: rgba(126, 34, 206, .10);
  color: rgba(107, 33, 168, 1);
}

/* Tables: desktop table, mobile cards */
.table-wrap {
  margin-top: 12px;
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid rgba(11, 18, 32, .10);
  box-shadow: var(--shadow-soft);
  background: #fff;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 920px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid rgba(11, 18, 32, .06);
  vertical-align: top;
  text-align: left;
}

th {
  font-size: 12px;
  color: rgba(11, 18, 32, .62);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  background: rgba(247, 248, 251, .75);
  position: sticky;
  top: 0;
  z-index: 5;
}

tr:hover td {
  background: rgba(247, 248, 251, .55);
}

/* Mobile card table */
@media(max-width: 760px) {
  .table-wrap {
    border: none;
    background: transparent;
    box-shadow: none;
    overflow: visible;
  }

  table {
    min-width: 0;
    display: block;
    background: transparent;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    display: block;
    border: 1px solid rgba(11, 18, 32, .10);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow-soft);
    padding: 10px;
  }

  td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border: none;
    padding: 9px 4px;
  }

  td:before {
    content: attr(data-label);
    color: rgba(11, 18, 32, .55);
    font-size: 12px;
  }
}

.footer {
  margin-top: 18px;
  text-align: center;
  font-size: 12px;
  color: rgba(11, 18, 32, .48);
}

/* Utilities */
.stack {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.spacer {
  height: 12px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: #fff;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 14px;
  position: relative;
  overflow: hidden;
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0;
  flex-shrink: 0;
}

.stat-icon svg {
  width: 20px;
  height: 20px;
}

.stat-icon.blue {
  background: #eff6ff;
  color: #2563eb;
}

.stat-icon.green {
  background: #dcfce7;
  color: #166534;
}

.stat-icon.amber {
  background: #fef3c7;
  color: #d97706;
}

.stat-icon.purple {
  background: #f3e8ff;
  color: #7e22ce;
}

.stat-icon.red {
  background: #fee2e2;
  color: #e11d48;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

/* Compact Table Overrides */
th,
td {
  padding: 8px 12px;
  font-size: 13px;
}

.badge {
  padding: 2px 8px;
  font-size: 11px;
}

/* Page Layout Enhancements */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
}

.page-header h1 {
  margin: 0;
  font-size: 24px;
}

.page-header p {
  margin: 4px 0 0;
  font-size: 14px;
  opacity: .7;
}

/* Icons */
.icon {
  width: 20px;
  height: 20px;
  stroke-width: 1.5;
  stroke: currentColor;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn .icon {
  width: 18px;
  height: 18px;
}

/* Loading Spinner */
.btn.loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn.loading:after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid rgba(0, 0, 0, .15);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

.btn.primary.loading:after {
  border: 2px solid rgba(255, 255, 255, .3);
  border-top-color: #fff;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast-container.center {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  right: auto;
  bottom: auto;
  align-items: center;
}

.toast {
  pointer-events: auto;
  padding: 20px 24px;
  padding-right: 52px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .15);
  border: 1px solid rgba(11, 18, 32, .08);
  font-size: 16px;
  font-weight: 500;
  line-height: 1.6;
  color: var(--text);
  display: none;
  animation: slideIn .3s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  max-width: 450px;
  width: 100%;
}

.toast.show {
  display: block;
}

.toast.ok {
  border-left: 5px solid #2bd4a6;
}

.toast.err {
  border-left: 5px solid #e11d48;
}

.toast-close {
  position: absolute;
  top: 12px;
  right: 12px;
  opacity: .5;
  cursor: pointer;
  background: none;
  border: none;
  padding: 4px;
}

.toast-close:hover {
  opacity: 1;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Empty State */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  background: #fff;
  border-radius: var(--radius);
  border: 1px dashed rgba(11, 18, 32, .15);
  color: var(--muted);
}

.empty-icon {
  width: 48px;
  height: 48px;
  opacity: .4;
  margin-bottom: 12px;
}

/* Sticky Bulk Bar */
.sticky-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #fff;
  padding: 12px 20px;
  border-radius: 99px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .15), 0 0 0 1px rgba(0, 0, 0, .05);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all .3s cubic-bezier(0.16, 1, 0.3, 1);
  opacity: 0;
}

.sticky-bar.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Sortable Headers */
th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover {
  background: rgba(0, 0, 0, .03);
}

th.sortable:after {
  content: ' ↕';
  opacity: .3;
  font-size: 10px;
}

th.sortable.asc:after {
  content: ' ↑';
  opacity: 1;
}

th.sortable.desc:after {
  content: ' ↓';
  opacity: 1;
}

/* Visual Polish: Inputs */
input:focus,
select:focus,
textarea:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

/* Visual Polish: Badges (override) */
.badge {
  font-weight: 600;
  letter-spacing: -0.01em;
  padding: 4px 10px;
  border-radius: 6px;
  border: none;
}

.badge.ok {
  background: #dcfce7;
  color: #166534;
}

.badge.err {
  background: #fee2e2;
  color: #991b1b;
}

.badge.warn {
  background: #fef3c7;
  color: #92400e;
}

/* =============================================
   Global Loading Overlay
   ============================================= */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  z-index: 9999;
  backdrop-filter: blur(4px);
}

.loading-overlay .spinner {
  width: 48px;
  height: 48px;
  border: 5px solid #e2e8f0;
  border-top-color: #2563eb;
  border-radius: 50%;
  animation: spin 0.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.loading-overlay p {
  color: var(--text);
  font-size: 14px;
  margin: 0;
}

/* =============================================
   Structure Popover (index.php)
   ============================================= */
.struct-badge-container {
  display: flex;
  align-items: center;
  gap: 6px;
}

.struct-main {
  color: var(--text);
  font-weight: 500;
}

.struct-more-badge {
  background: #eff6ff;
  color: #2563eb;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  cursor: help;
  border: 1px solid #dbeafe;
  position: relative;
  transition: all 0.2s;
}

.struct-more-badge:hover {
  background: #dbeafe;
}

.struct-popover {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  background: white;
  border: 1px solid #e2e8f0;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  padding: 12px;
  border-radius: 8px;
  z-index: 100;
  min-width: 220px;
  transition: all 0.2s;
  text-align: left;
}

.struct-more-badge:hover .struct-popover {
  visibility: visible;
  opacity: 1;
  transform: translateX(-50%) translateY(-5px);
}

.struct-popover.pop-down {
  bottom: auto;
  top: 100%;
  transform: translateX(-50%) translateY(10px);
}

.struct-more-badge:hover .struct-popover.pop-down {
  transform: translateX(-50%) translateY(5px);
}

.struct-popover-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #f1f5f9;
}

.struct-popover-item:last-child {
  border-bottom: none;
}

.struct-type-label {
  font-size: 10px;
  text-transform: uppercase;
  color: #94a3b8;
  font-weight: 600;
  display: block;
  margin-bottom: 2px;
}

.struct-name-label {
  font-size: 12px;
  color: #1e293b;
  font-weight: 500;
}

/* =============================================
   Modal Overlay & Content
   ============================================= */
.modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: modalFadeIn 0.2s ease;
  padding: 20px;
}

.modal[style*="display: flex"],
.modal[style*="display:flex"] {
  display: flex !important;
}

.modal-content {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.05);
  padding: 24px;
  max-width: 500px;
  width: 100%;
  animation: modalSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-content h3 {
  margin: 0 0 16px 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.modal-content p {
  margin: 0 0 24px 0;
  line-height: 1.6;
  color: var(--muted);
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* =============================================
   Utility Classes (to replace inline styles)
   ============================================= */
.badge-pill {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  background: rgba(0, 0, 0, .03);
  border-radius: 6px;
  display: inline-block;
}

.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.flex-center {
  display: flex;
  justify-content: center;
  align-items: center;
}

.flex-wrap {
  flex-wrap: wrap;
}

.gap-12 {
  gap: 12px;
}

.gap-8 {
  gap: 8px;
}

.card-section {
  flex: 1;
  background: var(--bg);
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.form-section {
  background: var(--bg);
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 12px;
}

.mb-12 {
  margin-bottom: 12px;
}

.mt-12 {
  margin-top: 12px;
}

.text-muted {
  color: var(--muted);
}

.text-sm {
  font-size: 12px;
}

.text-xs {
  font-size: 11px;
}

.font-semibold {
  font-weight: 600;
}

.rounded {
  border-radius: 6px;
}

/* Input error states */
.input.error,
select.error,
textarea.error {
  border-color: var(--danger);
  background: rgba(225, 29, 72, .05);
}

.error-message {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
  display: block;
}

/* Button loading state */
.btn.loading {
  opacity: 0.7;
  cursor: not-allowed;
  pointer-events: none;
}

.btn.loading::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* =============================================
   Mobile Responsive Improvements
   ============================================= */

/* Nav toggle button — hidden on desktop */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,.7);
  cursor: pointer;
  color: var(--text);
  flex-shrink: 0;
  transition: background .15s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
}

.nav-toggle:hover {
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.nav-toggle-icon { display: flex; align-items: center; justify-content: center; }
.nav-toggle-icon.close { display: none; }
.nav-toggle[aria-expanded="true"] .nav-toggle-icon.open { display: none; }
.nav-toggle[aria-expanded="true"] .nav-toggle-icon.close { display: flex; }

/* User badge in nav */
.nav-user-badge {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  background: rgba(0,0,0,.03);
  border-radius: 6px;
}

@media (max-width: 768px) {
  /* Show hamburger on mobile */
  .nav-toggle {
    display: flex;
  }

  /* Topbar: keep brand + hamburger in a row */
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
    top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
  }

  /* Brand: smaller on mobile */
  .brand {
    min-width: 0;
    flex: 1;
    gap: 10px;
  }

  .brand img {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .brand .t strong {
    font-size: 13px;
  }

  .brand .t span {
    font-size: 11px;
  }

  /* Nav: hidden by default on mobile, full-width dropdown */
  .nav {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
  }

  .nav.open {
    display: flex;
  }

  .nav a {
    width: 100%;
    text-align: center;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
  }

  .nav-user-badge {
    text-align: center;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 13px;
  }

  /* Wrap */
  .wrap {
    padding: 0 12px 32px;
  }

  .container {
    margin-top: 12px;
  }

  /* Page header: stack vertically */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
  }

  .page-header h1 {
    font-size: 20px;
  }

  /* Stats grid: 2 columns on mobile */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
  }

  .stat-card {
    padding: 12px;
    gap: 10px;
  }

  .stat-icon {
    width: 36px;
    height: 36px;
  }

  .stat-icon svg {
    width: 16px;
    height: 16px;
  }

  .stat-value {
    font-size: 18px;
  }

  .stat-label {
    font-size: 11px;
  }

  /* Cards */
  .card {
    padding: 12px;
    border-radius: 12px;
  }

  /* Filter forms */
  .filter-form {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .filter-form input[type="text"],
  .filter-form select,
  .filter-form .btn {
    width: 100% !important;
  }

  .filter-form .search-box {
    min-width: 0 !important;
  }

  /* Details/Legend */
  details summary {
    font-size: 12px !important;
    padding: 10px 14px !important;
  }

  /* Toolbar */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar select,
  .toolbar .search-box {
    width: 100% !important;
  }

  .toolbar .btn {
    width: 100%;
    justify-content: center;
  }

  .stack {
    flex-direction: column;
    gap: 8px;
  }

  table {
    font-size: 13px;
  }

  th,
  td {
    padding: 8px 6px;
  }

  /* Footer */
  .footer {
    font-size: 11px;
    padding: 0 8px;
  }

  /* Toast */
  .toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
  }

  .toast {
    max-width: 100%;
    font-size: 14px;
    padding: 14px 16px;
    padding-right: 40px;
  }
}

@media (max-width: 480px) {
  /* Very small screens: single column stats */
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  /* Member cards: single column */
  .member-list {
    grid-template-columns: 1fr !important;
  }

  h1 {
    font-size: 18px;
  }
}

@media (max-width: 600px) {
  .modal {
    margin: 16px;
    max-height: 90vh;
    overflow-y: auto;
    max-width: calc(100% - 32px) !important;
  }

  .flex-between {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .card-section {
    padding: 12px;
  }
}

/* =============================================
   Progressive Enhancement: Backdrop Filter
   ============================================= */
.loading-overlay {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

@supports (backdrop-filter: blur(4px)) {
  .loading-overlay {
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }
}

/* =============================================
   Global Navigation Progress Bar (YouTube/GitHub style)
   ============================================= */
#nav-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: linear-gradient(90deg, #2563eb 0%, #3b82f6 50%, #60a5fa 100%);
  z-index: 99999;
  pointer-events: none;
  transition: width 0.2s ease-out, opacity 0.3s ease;
  box-shadow: 0 0 10px rgba(37, 99, 235, 0.5);
}

#nav-progress.active {
  opacity: 1;
}

#nav-progress.done {
  width: 100% !important;
  opacity: 0;
  transition: width 0.1s ease-out, opacity 0.4s ease 0.1s;
}

@keyframes progress-trickle {
  0% {
    width: var(--progress-start);
  }

  100% {
    width: var(--progress-end);
  }
}