/* ===== Design Tokens (from existing portal) ===== */
:root {
  --primary: #714B67;
  --primary-light: #8F6B82;
  --primary-dark: #5A3A52;
  --secondary: #00A09D;
  --accent: #017E84;
  --bg: #F8F9FA;
  --card-bg: #FFFFFF;
  --text: #212529;
  --text-muted: #6C757D;
  --border: #DEE2E6;
  --success: #28A745;
  --warning: #FFC107;
  --danger: #DC3545;
  --info: #17A2B8;
  --radius: 8px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

/* ===== Header / Navbar ===== */
.header {
  background: #ffffff;
  color: var(--text);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 2px solid var(--primary);
}
.header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
}
.header h1 a {
  color: inherit;
  text-decoration: none;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.header-actions .user-name {
  font-size: 0.9rem;
  color: var(--text-muted);
}
.header-actions a {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: color 0.2s;
}
.header-actions a:hover { color: var(--secondary); }

/* Dark header variant (viewer page) */
.header.header-dark {
  background: var(--primary);
  color: #ffffff;
  border-bottom: 1px solid rgba(255,255,255,0.3);
}
.header.header-dark h1 { color: #ffffff; }
.header.header-dark .header-actions .user-name { color: rgba(255,255,255,0.7); }
.header.header-dark .header-actions a { color: rgba(255,255,255,0.9); }
.header.header-dark .header-actions a:hover { color: #ffffff; }

/* ===== Hero header (login, register, portal) ===== */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 50%, var(--secondary) 100%);
  color: white;
  padding: 3rem 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2rem;
}
.hero-content {
  text-align: left;
}
.hero h1 {
  font-size: 2rem;
  font-weight: 300;
  margin-bottom: 0.25rem;
}
.hero h1 span {
  font-weight: 700;
}
.hero p {
  font-size: 1.1rem;
  opacity: 0.9;
  margin-bottom: 0.75rem;
}
.hero-tags {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.hero-tag {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  padding: 0.3rem 0.75rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

/* ===== Container ===== */
.container {
  max-width: 900px;
  margin: 2rem auto;
  padding: 0 1rem;
}
.container-narrow {
  max-width: 440px;
  margin: 2rem auto;
  padding: 0 1rem;
}
.container-wide {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1rem;
}

/* ===== Cards ===== */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.card-centered {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

/* Module card grid (matches existing portal design) */
.module-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
}
.module-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.2s, transform 0.2s;
  display: block;
  cursor: pointer;
}
.module-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transform: translateY(-2px);
}
.module-card h2 {
  font-size: 1.15rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
}
.module-card p {
  font-size: 0.9rem;
  color: var(--text-muted);
}
.badge {
  display: inline-block;
  background: var(--secondary);
  color: white;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  margin-top: 0.75rem;
}
.badge-role {
  background: var(--primary);
}
.badge-pending { background: var(--warning); color: var(--text); }
.badge-accepted { background: var(--success); }
.badge-expired { background: var(--text-muted); }
.badge-revoked { background: var(--danger); }

/* ===== Forms ===== */
.form-group {
  margin-bottom: 1.25rem;
  text-align: left;
}
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.35rem;
}
.form-control {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
  transition: border-color 0.2s;
  font-family: inherit;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(113, 75, 103, 0.15);
}
select.form-control {
  appearance: auto;
}

/* ===== Buttons ===== */
.btn {
  display: inline-block;
  padding: 0.65rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background 0.2s, opacity 0.2s;
  font-family: inherit;
}
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}
.btn-secondary {
  background: var(--secondary);
  color: white;
}
.btn-secondary:hover:not(:disabled) {
  background: var(--accent);
}
.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover:not(:disabled) {
  background: #c82333;
}
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover:not(:disabled) {
  background: var(--primary);
  color: white;
}
.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}
.btn-block {
  display: block;
  width: 100%;
}

/* ===== Alerts ===== */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}
.alert-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}
.alert-info {
  background: #d1ecf1;
  color: #0c5460;
  border: 1px solid #bee5eb;
}

/* ===== Tables ===== */
.table-wrapper {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--text-muted);
  background: #f1f3f5;
}
tr:hover td {
  background: #f8f9fa;
}

/* ===== Loading spinner ===== */
.spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.loading-center {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 3rem;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal {
  background: white;
  border-radius: var(--radius);
  padding: 2rem;
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal h2 {
  margin-bottom: 1.5rem;
  font-size: 1.25rem;
  color: var(--primary);
}
.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* ===== Admin layout ===== */
.admin-layout {
  display: flex;
  min-height: calc(100vh - 56px);
}
.admin-sidebar {
  width: 220px;
  background: white;
  border-right: 1px solid var(--border);
  padding: 1rem 0;
  flex-shrink: 0;
}
.admin-sidebar nav {
  display: flex;
  flex-direction: column;
}
.admin-sidebar a {
  display: block;
  padding: 0.65rem 1.25rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  transition: background 0.15s;
}
.admin-sidebar a:hover,
.admin-sidebar a.active {
  background: #f1f3f5;
  color: var(--primary);
}
.admin-sidebar a.active {
  border-left: 3px solid var(--primary);
  font-weight: 500;
}
.admin-sidebar .sidebar-back {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.admin-content {
  flex: 1;
  padding: 1.5rem 2rem;
  overflow-x: auto;
}
.admin-content h2 {
  font-size: 1.35rem;
  margin-bottom: 1rem;
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.toolbar-filters {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.toolbar-filters select {
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 4px;
}

/* ===== Checkbox list (module access) ===== */
.checkbox-list {
  list-style: none;
}
.checkbox-list li {
  padding: 0.5rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.checkbox-list input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

/* ===== Copy link ===== */
.copy-link {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.copy-link input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #f8f9fa;
  font-family: monospace;
}

/* ===== Viewer ===== */
.viewer-container {
  position: relative;
  height: calc(100vh - 56px);
  height: calc(100dvh - 56px);
  overflow: hidden;
}
.viewer-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: none;
}

/* ===== Links ===== */
.link {
  color: var(--primary);
  text-decoration: none;
  cursor: pointer;
}
.link:hover {
  text-decoration: underline;
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ===== Utilities ===== */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.hidden { display: none; }

/* ===== Classification pills (admin module edit) ===== */
.classification-section {
  margin-top: 1.5rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}
.classification-section h4 {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 1rem;
}
.classification-group {
  margin-bottom: 1rem;
}
.classification-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
}
.classification-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.classification-pill {
  display: inline-block;
  padding: 0.25rem 0.65rem;
  font-size: 0.8rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.classification-pill:hover {
  border-color: var(--primary-light);
}
.classification-pill.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ===== Portal filter bar ===== */
.portal-filters-wrapper {
  margin-bottom: 1.5rem;
}
.filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.filter-toggle:hover {
  border-color: var(--primary-light);
  color: var(--primary);
}
.filter-toggle .filter-chevron {
  transition: transform 0.2s;
}
.filter-toggle.open .filter-chevron {
  transform: rotate(180deg);
}
.filter-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
  background: var(--secondary);
  border-radius: 10px;
}
.portal-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: flex-start;
  margin-top: 0.75rem;
  padding: 1rem 1.25rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-group label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.3rem;
  letter-spacing: 0.3px;
}
.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.filter-pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  font-size: 0.78rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}
.filter-pill:hover {
  border-color: var(--primary-light);
  color: var(--text);
}
.filter-pill.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.filter-clear {
  align-self: flex-end;
  margin-left: auto;
  padding: 0.2rem 0.7rem;
  font-size: 0.75rem;
  color: var(--danger);
  background: none;
  border: 1px solid var(--danger);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-clear:hover {
  background: var(--danger);
  color: white;
}

/* Module card classification badges */
.module-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.5rem;
}
.module-card-tag {
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  background: #f1f3f5;
  color: var(--text-muted);
}

/* ===== Classification admin items editor ===== */
.classification-items-editor {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  background: #fafafa;
}
.classification-item-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.classification-item-row input {
  flex: 1;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.classification-item-row .btn-remove-item {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.2rem 0.4rem;
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .module-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .hero { padding: 2rem 1rem; flex-direction: column; text-align: center; }
  .hero-content { text-align: center; }
  .hero-tags { justify-content: center; }
  .hero h1 { font-size: 1.5rem; }
  .module-grid { grid-template-columns: 1fr; }
  .admin-layout { flex-direction: column; }
  .admin-sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .admin-sidebar nav { flex-direction: row; overflow-x: auto; }
  .admin-sidebar a { white-space: nowrap; }
  .admin-content { padding: 1rem; }
  .header { flex-wrap: wrap; gap: 0.5rem; }
}
