:root {
  --bg: #f4f7fb;
  --bg-gradient-start: #dbeafe;
  --bg-elevated: #ffffff;
  --text-main: #0f172a;
  --text-muted: #6b7a90;
  --accent: #3a7bd5;
  --accent-soft: rgba(58, 123, 213, 0.1);
  --border-soft: #d6deed;
  --input-bg: rgba(255, 255, 255, 0.9);
  --danger: #da3b3b;
  --radius-lg: 18px;
  --shadow-soft: 0 18px 40px rgba(15, 35, 75, 0.08);
}

html[data-theme="dark"] {
  --bg: #050819;
  --bg-gradient-start: #0f172a;
  --bg-elevated: #0b1224;
  --text-main: #e5edff;
  --text-muted: #94a3b8;
  --accent: #6db6ff;
  --accent-soft: rgba(109, 182, 255, 0.16);
  --border-soft: #1f273a;
  --input-bg: rgba(255, 255, 255, 0.06);
  --danger: #f87171;
  --shadow-soft: 0 18px 40px rgba(0, 0, 0, 0.55);
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Poppins", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: radial-gradient(circle at top left, var(--bg-gradient-start) 0, var(--bg) 45%);
  color: var(--text-main);
  overflow-x: hidden;
}
* {
  scrollbar-color: var(--border-soft) var(--bg-elevated);
  scrollbar-width: thin;
}
*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
*::-webkit-scrollbar-track {
  background: var(--bg-elevated);
  border-radius: 10px;
}
*::-webkit-scrollbar-thumb {
  background: var(--border-soft);
  border-radius: 10px;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}
button, input, select, textarea {
  font-family: inherit;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-elevated);
  backdrop-filter: blur(14px);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.06);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-box {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #22c1c3);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.25);
}
.logo-box img {
  width: 80%;
  height: 80%;
  object-fit: contain;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.app-name {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.app-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-main {
  flex: 1;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 16px;
  padding: 16px 18px;
}

.sidebar {
  background: linear-gradient(160deg, var(--bg-elevated), rgba(255, 255, 255, 0.02));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 14px;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.nav-item {
  border: none;
  background: transparent;
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.18s ease, color 0.18s ease, transform 0.05s ease;
}

.nav-item i {
  width: 18px;
}

.nav-item:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-item.active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.25);
  transform: translateY(-1px);
}
.nav-item-admin {
  border: 1px solid rgba(34, 197, 94, 0.6);
}
.nav-item-admin.active {
  background: #22c55e;
  box-shadow: 0 6px 14px rgba(34, 197, 94, 0.25);
}

.content {
  background: linear-gradient(145deg, var(--bg-elevated), rgba(255, 255, 255, 0.04));
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-center {
  text-align: center;
  margin: auto;
}

.primary-button {
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #ffffff;
  padding: 8px 18px;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.25);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.12s ease, filter 0.12s ease;
}

.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(37, 99, 235, 0.25);
}

.primary-button:active {
  transform: translateY(0);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.2);
}

.icon-button {
  border: none;
  background: var(--accent-soft);
  border-radius: 999px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.1s ease;
}

.icon-button:hover {
  background: rgba(15, 23, 42, 0.06);
  box-shadow: 0 6px 12px rgba(37, 99, 235, 0.18);
}

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
}
.avatar-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
}
.avatar-circle img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}
.user-name {
  font-size: 13px;
  color: var(--text-main);
}

.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}
.link-tile {
  display: flex;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text-main);
  background: var(--input-bg);
  align-items: flex-start;
  transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.1s ease;
}
.link-tile:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
  border-color: var(--accent);
}
.link-tile i {
  color: var(--accent);
  margin-top: 4px;
}
.link-title {
  font-weight: 600;
}
.link-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.card {
  background: var(--bg-elevated);
  border-radius: 16px;
  border: 1px solid var(--border-soft);
  padding: 14px 16px;
  box-shadow: var(--shadow-soft);
}

.cubs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
}

.section-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.cubs-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.select {
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  padding: 6px 10px;
  font-size: 13px;
  background: var(--input-bg);
}

.cubs-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cub-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px 150px auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: var(--input-bg);
}

.cub-name {
  font-weight: 500;
}

.cub-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.cub-star {
  font-size: 13px;
}

.cub-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.action-small {
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  background: var(--input-bg);
  padding: 4px 8px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.action-small i {
  color: inherit;
}
.action-small.danger {
  border-color: rgba(239, 68, 68, 0.6);
  color: #ef4444;
}

.input-control {
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  background: var(--input-bg);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-main);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.input-control.readonly {
  background: var(--bg-elevated);
  color: var(--text-muted);
  opacity: 0.9;
}

.input-control:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) calc(50% - 3px), calc(100% - 10px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
select.input-control,
select.select {
  background: var(--input-bg);
  color: var(--text-main);
}
option {
  background: var(--bg-elevated);
  color: var(--text-main);
}

.input-control::placeholder {
  color: var(--text-muted);
}

.form-row textarea {
  min-height: 110px;
  resize: vertical;
}

.form-row {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.form-row input,
.form-row select,
.form-row textarea {
  flex: 1;
  width: 100%;
  font-family: inherit;
}

.analysis-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.stat-pill {
  border-radius: 16px;
  padding: 10px 12px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.skills-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

.skills-table th,
.skills-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}

.skills-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
}

.skills-table img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.color-field {
  border-radius: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border-soft);
  background: var(--input-bg);
}
.color-field.red { background: rgba(239, 68, 68, 0.08); }
.color-field.yellow { background: rgba(234, 179, 8, 0.12); }
.color-field.green { background: rgba(34, 197, 94, 0.1); }
.color-field.blue { background: rgba(59, 130, 246, 0.1); }
.color-field.violet { background: rgba(139, 92, 246, 0.12); }
.stacked {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stacked .color-field {
  width: 100%;
}
.stacked textarea.input-control,
.stacked input.input-control {
  width: 100%;
}
.task-field .input-control {
  width: 100%;
}
.char-field textarea.input-control {
  min-height: 90px;
}

.progress-wrap {
  margin-top: 6px;
  background: var(--border-soft);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}
.progress-bar {
  height: 8px;
  background: var(--accent);
  width: 0%;
  transition: width 0.2s ease;
}

.trial-preview {
  display: none;
}
.trial-preview.active {
  display: block;
}
.trial-preview .color-field {
  font-size: 12px;
}
.trial-preview .color-field img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  display: inline-block;
}

.collapsible-card details {
  width: 100%;
}
.collapsible-card summary {
  cursor: pointer;
  padding: 4px 0;
}

/* Archive spacing */
#view-archive details {
  margin-bottom: 10px;
}
#view-archive details:last-of-type {
  margin-bottom: 0;
}

.app-footer {
  padding: 8px 20px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  border-top: 1px solid rgba(148, 163, 184, 0.3);
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 10px;
}
.chart-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 12px;
  box-shadow: var(--shadow-soft);
  min-height: 320px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chart-card canvas {
  width: 100% !important;
  height: 280px !important;
}
.donut-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.donut-card canvas {
  height: auto !important;
  aspect-ratio: 1 / 1;
  max-width: 260px;
  margin: 0 auto;
}

@media (max-width: 960px) {
  .app-main {
    grid-template-columns: 1fr;
    width: 100%;
  }
  .sidebar {
    order: 2;
    width: 100%;
  }
  .content {
    order: 1;
    width: 100%;
  }
}

/* Modal styles */
.modal-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-container.active {
  opacity: 1;
  pointer-events: all;
}

.modal-content {
  background: var(--bg-elevated);
  padding: 24px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  width: 90%;
  max-width: 800px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform 0.3s ease;
}

.modal-container.active .modal-content {
  transform: scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-header .section-title {
  font-size: 20px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-close:hover {
  color: var(--accent);
}

.grid-2-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.grid-5-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

.skill-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 8px;
}

.skill-tile {
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 8px;
  background: var(--input-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.skill-tile img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.skill-tile.selected {
  border-color: var(--accent);
  box-shadow: 0 8px 20px rgba(58, 123, 213, 0.18);
  transform: translateY(-2px);
}

.trial-checklist {
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--input-bg);
}

.checklist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.checklist-grid img {
  width: 32px;
  height: auto;
  object-fit: contain;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0;
  font-size: 14px;
}

.text-danger {
  color: var(--danger);
}
.text-accent {
  color: var(--accent);
}

.form-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 6px;
}

.table-responsive {
  overflow-x: auto;
}
.admin-card {
  border-color: rgba(34, 197, 94, 0.3);
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}
.admin-table th,
.admin-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}
.admin-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
}
.admin-actions {
  display: flex;
  gap: 6px;
}
.pill {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  text-transform: uppercase;
}
.pill-active { background: rgba(34, 197, 94, 0.15); color: #16a34a; }
.pill-suspended { background: rgba(234, 179, 8, 0.15); color: #b45309; }
.pill-deleted { background: rgba(239, 68, 68, 0.15); color: #dc2626; }
.admin-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}
.admin-chart {
  border-color: rgba(34, 197, 94, 0.2);
}
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

@media (max-width: 900px) {
  .app-header {
    flex-wrap: wrap;
    gap: 10px;
  }
  .header-right {
    width: 100%;
    justify-content: flex-end;
  }
  .cubs-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .cubs-toolbar {
    width: 100%;
    justify-content: space-between;
  }
}

@media (max-width: 720px) {
  .app-header {
    flex-wrap: nowrap;
    gap: 8px;
    overflow: hidden;
  }
  .logo-text {
    min-width: 0;
  }
  .header-right {
    flex-shrink: 1;
  }
  .user-badge {
    flex-shrink: 0;
  }
  .app-subtitle {
    display: none;
  }
  #userName {
    display: none;
  }
  #loginButton {
    font-size: 0;
    padding: 8px 12px;
    white-space: nowrap;
  }
  #loginButton i {
    font-size: 16px;
  }
  .app-header {
    padding: 12px 14px;
  }
  .content {
    padding: 12px 14px;
    overflow-x: hidden;
  }
  .cub-row {
    grid-template-columns: 1fr;
    align-items: flex-start;
  }
  .cub-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .checklist-grid {
    grid-template-columns: 1fr;
  }
  .analysis-grid {
    grid-template-columns: 1fr;
  }
  .admin-stats-grid {
    grid-template-columns: 1fr;
  }
  .skills-table th,
  .skills-table td {
    font-size: 12px;
  }
  .modal-content {
    max-width: 95%;
    padding: 18px;
  }
}
