/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --haiilo-blue: #2563eb;
  --haiilo-blue-dark: #1d4ed8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --progress-bg: #e2e8f0;
  --progress-fill: #2563eb;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
}

#app {
  height: 100%;
  overflow-y: auto;
}

/* ── State views ── */
.state-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 200px;
  gap: 12px;
  color: var(--text-muted);
  padding: 24px;
  text-align: center;
}

.state-view.hidden, .hidden { display: none !important; }

.state-icon { font-size: 36px; }

/* Spinner */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--haiilo-blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Buttons ── */
.btn-primary, .btn-moodle {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}

.btn-primary {
  background: var(--haiilo-blue);
  color: #fff;
}
.btn-primary:hover { background: var(--haiilo-blue-dark); }

#retry-btn {
  background: transparent;
  border: 1px solid var(--border);
  padding: 7px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}
#retry-btn:hover { background: var(--border); }

/* ── Courses view ── */
#courses-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

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

.plugin-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.btn-moodle {
  background: transparent;
  color: var(--haiilo-blue);
  border: 1px solid var(--haiilo-blue);
  font-size: 12px;
  padding: 5px 10px;
}
.btn-moodle:hover { background: #eff6ff; }

/* ── Course grid ── */
#course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  padding: 16px;
  overflow-y: auto;
}

/* ── Course card ── */
.course-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  transition: transform .15s, box-shadow .15s;
}
.course-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(0,0,0,.12);
}

.course-thumbnail {
  height: 100px;
  background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.course-initial {
  font-size: 32px;
  font-weight: 700;
  color: rgba(255,255,255,.9);
  line-height: 1;
}

.course-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.course-category {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--haiilo-blue);
}

.course-name {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}

.course-summary {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
  margin-top: 2px;
}

/* ── Progress ── */
.progress-bar {
  margin-top: auto;
  padding-top: 10px;
  height: 6px;
  border-radius: 3px;
  background: var(--progress-bg);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--progress-fill);
  transition: width .3s;
}

.progress-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Responsive ── */
@media (max-width: 340px) {
  #course-grid { grid-template-columns: 1fr; }
}
