:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --radius: 10px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body {
  max-width: 100%;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* Auth Overlay */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

.auth-card {
  background: var(--surface);
  padding: 2rem;
  border-radius: var(--radius);
  width: 100%;
  max-width: 390px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.auth-logo-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #dbeafe;
  color: var(--primary);
  font-weight: 800;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 0.75rem;
}

.auth-card h2 {
  margin-bottom: 0.35rem;
}

.auth-card p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 1.1rem;
}

.auth-card input {
  width: 100%;
  margin-bottom: 0.85rem;
}

.error-text {
  color: var(--danger) !important;
  margin-top: 0.75rem;
  font-weight: 500;
}

.hint-text {
  font-size: 0.8rem !important;
  margin-top: 0.75rem;
  margin-bottom: 0 !important;
}

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.85rem;
}

.topbar-title-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.topbar h1 {
  font-size: 1.2rem;
}

.badge {
  background: var(--success-bg);
  color: var(--success);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  display: inline-block;
}

.user-pill {
  background: #e0e7ff;
  color: #3730a3;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  display: inline-block;
}

.pill-tag {
  background: #f1f5f9;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Layout */
.container {
  max-width: 1150px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.card-header-clean {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.65rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.card-header-clean h3 {
  font-size: 1.02rem;
  margin: 0;
}

.muted-small {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.9rem;
}

.control-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.control-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.grid-two {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
}

.stacked-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

input, select {
  padding: 0.58rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  background: #fff;
  width: 100%;
}

.control-group input,
.control-group select {
  width: auto;
  flex: 1;
  min-width: 130px;
}

input:focus, select:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

/* Logo Upload Preview */
.logo-upload-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-preview {
  max-height: 64px;
  max-width: 160px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
  background: #f8fafc;
}

/* Buttons */
.btn {
  padding: 0.55rem 0.95rem;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
  white-space: nowrap;
  text-align: center;
}

.full-width { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

/* Stats */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.stat-label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.stat-box.present .stat-value { color: var(--success); }
.stat-box.absent .stat-value { color: var(--danger); }

/* Category Section & Table */
.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.75rem;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.category-actions {
  display: flex;
  gap: 0.5rem;
}

.responsive-table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 0.7rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
}

.status-toggle {
  display: inline-flex;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.status-btn {
  padding: 0.35rem 0.85rem;
  border: none;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
}

.status-btn.active-present {
  background: var(--success);
  color: #fff;
}

.status-btn.active-absent {
  background: var(--danger);
  color: #fff;
}

.delete-link {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
}

.delete-link:hover {
  color: var(--danger);
  text-decoration: underline;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}

/* Setup Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 900;
}

.modal-box {
  background: var(--bg);
  border-radius: var(--radius);
  width: 100%;
  max-width: 820px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 35px -5px rgba(0, 0, 0, 0.35);
}

.modal-header {
  background: var(--surface);
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}

.modal-header h2 {
  font-size: 1.1rem;
}

.modal-body {
  padding: 1.25rem;
}

.modal-subcard {
  margin-bottom: 0;
}

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

/* Mobile Overrides */
@media (max-width: 680px) {
  .topbar {
    padding: 0.85rem 1rem;
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.45rem;
  }

  .control-bar, .control-group {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .control-group input, .control-group select, .control-group .btn {
    width: 100%;
    min-width: 0;
  }

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

  .category-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.65rem;
  }

  .category-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
  }

  .category-actions .btn {
    padding: 0.45rem 0.3rem;
    font-size: 0.75rem;
  }

  .mobile-card-table,
  .mobile-card-table thead,
  .mobile-card-table tbody,
  .mobile-card-table th,
  .mobile-card-table td,
  .mobile-card-table tr {
    display: block;
    width: 100%;
  }

  .mobile-card-table thead { display: none; }

  .mobile-card-table tbody tr {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 0.65rem;
    background: #f8fafc;
  }

  .mobile-card-table tbody td {
    border: none;
    padding: 0.25rem 0;
    text-align: left !important;
  }

  .mobile-card-table tbody td:first-child { display: none; }

  .status-toggle {
    display: flex;
    width: 100%;
    margin-top: 0.4rem;
  }

  .status-btn {
    flex: 1;
    padding: 0.55rem;
    font-size: 0.85rem;
  }
}
