:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #657187;
  --line: #dce3ee;
  --brand: #0f766e;
  --brand-strong: #115e59;
  --accent: #f59e0b;
  --ok: #059669;
  --danger: #b91c1c;
  --shadow: 0 16px 42px rgba(23, 32, 51, .09);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: min(410px, 100%);
  display: grid;
  gap: 16px;
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.brand-mark {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--brand);
  border-radius: 8px;
  font-weight: 800;
}
.brand-mark.small {
  width: 38px;
  height: 38px;
  font-size: 14px;
}
h1, h2, p { margin: 0; }
p { color: var(--muted); }
label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
input, select {
  width: 100%;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}
input:focus, select:focus {
  outline: 3px solid rgba(15, 118, 110, .15);
  border-color: var(--brand);
}
.primary, .ghost, .danger {
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 800;
}
.primary {
  color: #fff;
  background: var(--brand);
}
.primary:hover { background: var(--brand-strong); }
.ghost {
  color: var(--brand);
  background: #eef8f7;
  border-color: #cce7e4;
}
.danger {
  color: var(--danger);
  background: #fff1f1;
  border-color: #ffd4d4;
}
.link-button {
  color: var(--brand);
  background: transparent;
  border: 0;
  font-weight: 800;
}
.error {
  display: none;
  padding: 10px;
  color: var(--danger);
  background: #fff1f1;
  border-radius: 6px;
  font-size: 13px;
}
.error.show { display: block; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
}
#category-nav {
  display: grid;
  gap: 8px;
}
#category-nav button {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 10px 12px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  text-align: left;
}
#category-nav button.active, #category-nav button:hover {
  color: var(--ink);
  background: #eef3f8;
}
.edit-toggle {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  margin-top: auto;
}
.edit-toggle input { width: auto; }

.content {
  padding: 28px;
  display: grid;
  align-content: start;
  gap: 22px;
}
.topbar, .controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar h1 { font-size: 32px; }
.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.stats article {
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(23, 32, 51, .05);
}
.stats strong {
  display: block;
  font-size: 28px;
}
.stats span { color: var(--muted); }
.controls input { flex: 1 1 280px; }
.controls select { width: auto; min-width: 210px; }
.controls button.active {
  color: #fff;
  background: var(--brand);
}
.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.card {
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(23, 32, 51, .05);
}
.cover {
  height: 130px;
  background: linear-gradient(135deg, #d7f2ee, #e8ecff);
}
.cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.card-body {
  display: grid;
  gap: 12px;
  padding: 16px;
}
.card h2 {
  font-size: 18px;
  line-height: 1.25;
}
.meta {
  color: var(--muted);
  font-size: 13px;
}
.badge-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.badge {
  padding: 4px 8px;
  color: var(--brand);
  background: #eef8f7;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}
.badge.warn {
  color: #92400e;
  background: #fff7ed;
}
.bar {
  height: 8px;
  background: #e5eaf2;
  border-radius: 999px;
  overflow: hidden;
}
.bar span {
  display: block;
  height: 100%;
  background: var(--ok);
}
.card-actions {
  display: none;
  gap: 8px;
}
body.editing .card-actions { display: flex; }
.empty {
  padding: 42px;
  text-align: center;
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 8px;
}
dialog {
  width: min(680px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(23, 32, 51, .45); }
#course-form {
  padding: 22px;
  display: grid;
  gap: 18px;
}
.dialog-head, .dialog-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.icon {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: #eef3f8;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.wide { grid-column: 1 / -1; }

@media (max-width: 920px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  #category-nav { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .grid, .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 620px) {
  .content, .sidebar { padding: 18px; }
  .grid, .stats, .form-grid { grid-template-columns: 1fr; }
}
