:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #182033;
  --muted: #687289;
  --line: #e4e8f0;
  --primary: #b8822e;
  --primary-dark: #8f611f;
  --primary-soft: #fbf2df;
  --danger: #d3445b;
  --success: #167c55;
  --warning: #a46200;
  --shadow: 0 10px 30px rgba(28, 39, 69, .08);
  --radius: 18px;
}

html { color-scheme: light; }
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0c0e;
  --panel: #17191c;
  --ink: #f5f5f2;
  --muted: #a7abb4;
  --line: #30333a;
  --primary: #d3a44d;
  --primary-dark: #e1b762;
  --primary-soft: #2b251a;
  --shadow: 0 12px 34px rgba(0, 0, 0, .32);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.theme-switcher {
  position: fixed;
  top: 14px;
  right: 20px;
  z-index: 90;
  display: flex;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.theme-switcher button {
  min-height: 30px;
  padding: 5px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}
.theme-switcher button[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary); }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  background: #10100f;
  color: #f8f8ff;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 5px 9px 25px; }
.brand-logo {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border: 1px solid rgba(224, 180, 92, .45);
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 8px 20px rgba(184, 130, 46, .25);
}
.brand span:last-child { display: flex; flex-direction: column; line-height: 1.2; }
.brand strong { font-size: 17px; }
.brand small { margin-top: 4px; color: #999db5; font-size: 10px; letter-spacing: .03em; }
.sidebar nav { display: grid; gap: 5px; }
.nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: #b7bbcf;
  cursor: pointer;
  text-align: left;
  transition: .18s ease;
}
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,.09); color: white; }
.nav-link span { width: 22px; text-align: center; font-size: 20px; }
.nav-badge { margin-left: auto; min-width: 23px; padding: 2px 7px; border-radius: 99px; background: #ff677c; color: white; font-size: 11px; text-align: center; }
.sidebar-bottom { margin-top: auto; padding-top: 25px; }
.profile-chip { display: flex; align-items: center; gap: 10px; padding: 12px 9px; border-top: 1px solid rgba(255,255,255,.1); }
.profile-text { min-width: 0; display: flex; flex-direction: column; }
.profile-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.profile-text small { color: #999db5; font-size: 11px; }
.avatar { display: grid; place-items: center; flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; background: #b8822e; color: white; font-weight: 800; }
.avatar.large { width: 44px; height: 44px; }
.logout { font-size: 13px; }

.app-main { margin-left: 248px; min-height: 100vh; max-width: calc(100% - 248px); overflow-x: hidden; }
.mobile-header { display: none; }
.page-shell { width: min(1180px, calc(100% - 56px)); margin: 0 auto; padding: 45px 0 70px; }
.narrow-shell { width: min(760px, calc(100% - 56px)); }
.page-heading { margin-bottom: 30px; }
.page-heading h1 { margin: 4px 0 4px; font-size: clamp(27px, 3vw, 38px); line-height: 1.15; letter-spacing: -.04em; }
.page-heading p { margin: 0; }
.split-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 22px; }
.eyebrow { color: var(--primary); font-size: 11px; font-weight: 850; letter-spacing: .14em; }
.muted { color: var(--muted); }
.optional { color: #949bad; font-size: 11px; font-weight: 500; }
.back-link { display: inline-block; margin-bottom: 24px; color: var(--muted); font-size: 14px; font-weight: 700; }
.back-link:hover { color: var(--primary); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  font-weight: 750;
  font-size: 13px;
  transition: transform .15s ease, background .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button.primary { background: var(--primary); color: white; box-shadow: 0 7px 18px rgba(184,130,46,.24); }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { border-color: var(--line); background: white; color: var(--ink); }
.button.danger { background: var(--danger); color: white; }
.button.light { background: white; color: #775018; }
.button.ghost-light { border-color: rgba(255,255,255,.4); color: white; }
.button.small { min-height: 34px; padding: 6px 11px; font-size: 12px; }
.full-button { width: 100%; }

.flash-stack { position: fixed; top: 20px; right: 22px; z-index: 100; display: grid; gap: 8px; width: min(390px, calc(100% - 36px)); }
.flash { padding: 13px 16px; border: 1px solid var(--line); border-left: 4px solid var(--primary); border-radius: 11px; background: white; box-shadow: var(--shadow); font-size: 13px; font-weight: 650; }
.flash.success { border-left-color: var(--success); }
.flash.error { border-left-color: var(--danger); }
.flash.warning { border-left-color: var(--warning); }

.notice-card { display: flex; align-items: center; gap: 14px; margin-bottom: 34px; padding: 18px 20px; border: 1px solid #ead3a7; border-radius: 15px; background: var(--primary-soft); color: #6d4917; }
.notice-card:hover { border-color: #d2aa62; }
.notice-card span:nth-child(2) { display: flex; flex: 1; flex-direction: column; }
.notice-card small { color: #8f7244; }
.notice-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; background: white; font-size: 22px; }

.section-heading { display: flex; align-items: end; justify-content: space-between; margin: 28px 0 15px; }
.section-heading h2 { margin: 0; font-size: 19px; letter-spacing: -.02em; }
.section-heading p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.section-heading > a { color: var(--primary); font-size: 13px; font-weight: 750; }
.recent-heading { margin-top: 40px; }

.course-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 17px; }
.course-card { position: relative; min-width: 0; min-height: 205px; padding: 23px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: 0 4px 15px rgba(28,39,69,.035); transition: transform .18s ease, box-shadow .18s ease; }
.course-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.course-accent { position: absolute; inset: 0 0 auto; height: 5px; background: var(--card-color); }
.course-card-top { display: flex; justify-content: space-between; align-items: center; }
.course-code { color: var(--card-color); font-size: 10px; font-weight: 900; letter-spacing: .12em; }
.arrow { color: #a7adba; font-size: 20px; }
.course-card h3 { margin: 25px 0 7px; font-size: 19px; }
.course-card p { min-height: 44px; margin: 0 0 18px; overflow: hidden; color: var(--muted); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.course-card small { color: #8a92a5; font-size: 11px; font-weight: 700; }
.color-blue { --card-color: #4e73e7; }
.color-violet { --card-color: #8a5ce5; }
.color-green { --card-color: #2d9d73; }
.color-orange { --card-color: #e58a32; }
.color-red { --card-color: #df5266; }
.color-teal { --card-color: #1d9aa3; }

.content-list { overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: white; }
.content-row { display: flex; align-items: center; gap: 13px; min-width: 0; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.content-row:last-child { border-bottom: 0; }
.content-row:hover { background: #fafbfe; }
.type-icon { display: grid; place-items: center; flex: 0 0 auto; width: 37px; height: 37px; border-radius: 10px; background: color-mix(in srgb, var(--card-color) 12%, white); color: var(--card-color); font-weight: 900; }
.content-main { min-width: 0; display: flex; flex: 1; flex-direction: column; }
.content-main strong, .content-main small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content-main strong { font-size: 13px; }
.content-main small, .content-row time { color: var(--muted); font-size: 11px; }

.empty-state { display: grid; justify-items: center; padding: 55px 25px; border: 1px dashed #cbd1dd; border-radius: var(--radius); background: rgba(255,255,255,.6); text-align: center; }
.empty-state > span { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 15px; background: var(--primary-soft); color: var(--primary); font-size: 25px; font-weight: 900; }
.empty-state h3, .empty-state h1 { margin: 14px 0 2px; }
.empty-state p { max-width: 530px; margin: 0 0 17px; color: var(--muted); }
.empty-inline { padding: 22px; border: 1px dashed var(--line); border-radius: 13px; color: var(--muted); text-align: center; }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: white; box-shadow: 0 4px 18px rgba(28,39,69,.035); }
.form-panel { padding: 27px; }
.stack-form { display: grid; gap: 18px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: grid; gap: 7px; color: #353d51; font-size: 12px; font-weight: 750; }
input, textarea, select {
  min-width: 0;
  width: 100%;
  border: 1px solid #d8dde7;
  border-radius: 10px;
  outline: none;
  background: #fff;
  color: var(--ink);
  font-weight: 500;
}
input, select { min-height: 43px; padding: 9px 11px; }
textarea { padding: 11px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: #d2a253; box-shadow: 0 0 0 3px rgba(184,130,46,.13); }
fieldset { margin: 0; padding: 0; border: 0; }
legend { margin-bottom: 8px; color: #353d51; font-size: 12px; font-weight: 750; }
.color-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.color-choice { display: flex; grid-template: none; align-items: center; gap: 6px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; font-size: 11px; }
.color-choice input { width: auto; min-height: 0; margin: 0; }
.color-choice span { width: 13px; height: 13px; border-radius: 50%; background: var(--swatch); }
.color-choice.blue { --swatch: #4e73e7; }.color-choice.violet { --swatch: #8a5ce5; }.color-choice.green { --swatch: #2d9d73; }.color-choice.orange { --swatch: #e58a32; }.color-choice.red { --swatch: #df5266; }.color-choice.teal { --swatch: #1d9aa3; }
.current-file { margin-top: -2px; color: var(--muted); font-weight: 500; }

.course-hero { position: relative; display: flex; align-items: end; justify-content: space-between; gap: 25px; min-height: 225px; padding: 40px; overflow: hidden; border-radius: 22px; background: linear-gradient(135deg, color-mix(in srgb, var(--card-color) 95%, #1c2550), color-mix(in srgb, var(--card-color) 65%, #151c40)); color: white; box-shadow: 0 15px 35px color-mix(in srgb, var(--card-color) 22%, transparent); }
.course-hero .eyebrow { color: rgba(255,255,255,.8); }
.course-hero h1 { margin: 5px 0 8px; font-size: clamp(29px, 4vw, 44px); line-height: 1.1; letter-spacing: -.04em; }
.course-hero p:last-child { max-width: 650px; margin: 0; color: rgba(255,255,255,.82); }
.hero-accent { position: absolute; width: 200px; height: 200px; right: -55px; top: -90px; border: 45px solid rgba(255,255,255,.09); border-radius: 50%; }
.hero-actions { z-index: 1; display: flex; flex: 0 0 auto; gap: 9px; }

.material-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.material-card { min-width: 0; padding: 21px; border: 1px solid var(--line); border-radius: 15px; background: white; }
.material-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.material-meta time { color: var(--muted); font-size: 10px; }
.kind, .role-pill { display: inline-flex; padding: 4px 8px; border-radius: 99px; background: #eef0f6; color: #535c70; font-size: 9px; font-weight: 900; letter-spacing: .06em; text-transform: uppercase; }
.kind-study_guide { background: #f1eaff; color: #7441c1; }.kind-summary { background: #e8f5ff; color: #2771a8; }.kind-assignment { background: #fff1df; color: #aa641d; }.kind-announcement { background: #ffe8ec; color: #bc4053; }
.material-card h3 { margin: 17px 0 8px; font-size: 17px; }
.material-body { margin: 0; color: #555f75; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.resource-links { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 17px; }
.resource-button { padding: 7px 10px; border-radius: 8px; background: var(--primary-soft); color: #76501c; font-size: 11px; font-weight: 750; overflow-wrap: anywhere; }
.material-card footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; padding-top: 12px; border-top: 1px solid var(--line); }
.material-card footer > small { color: var(--muted); font-size: 10px; }
.card-actions { display: flex; gap: 10px; font-size: 11px; font-weight: 750; }
.card-actions form { display: inline; }
.card-actions button { padding: 0; border: 0; background: none; cursor: pointer; font: inherit; }
.text-danger { color: var(--danger); }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-top: 45px; padding: 20px; border: 1px solid #f0c8cf; border-radius: 14px; background: #fff9fa; }
.danger-zone p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.request-list, .user-list { display: grid; gap: 10px; }
.request-card, .user-card { display: flex; align-items: center; gap: 13px; min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: white; }
.request-card > div:nth-child(2), .user-identity span:last-child { min-width: 0; display: flex; flex: 1; flex-direction: column; }
.request-card p { margin: 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.request-card small, .user-card small { color: #8b93a5; font-size: 10px; overflow-wrap: anywhere; }
.request-actions { display: flex; margin-left: auto; gap: 7px; }
.create-user-panel { margin: 35px 0; padding: 25px; }
.create-user-panel h2 { margin: 2px 0; }
.create-user-panel > div { margin-bottom: 18px; }
.compact-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.align-end { align-self: end; }
.user-card { justify-content: space-between; }
.user-identity { display: flex; align-items: center; gap: 12px; min-width: 0; }
.role-pill.owner { background: var(--primary-soft); color: var(--primary); }
.user-controls { display: flex; align-items: center; gap: 8px; }
.inline-controls { display: flex; align-items: center; gap: 7px; }
.inline-controls select { width: 105px; }
.check-label { display: flex; grid-template: none; align-items: center; gap: 5px; white-space: nowrap; }
.check-label input { width: auto; min-height: 0; }
details { position: relative; }
summary { padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; list-style: none; font-size: 12px; font-weight: 750; }
.details-menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: 10; display: grid; gap: 12px; width: 245px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: white; box-shadow: var(--shadow); }
.details-menu form { display: grid; gap: 7px; }

.table-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; background: white; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { padding: 13px 15px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #fafbfe; color: var(--muted); font-size: 10px; letter-spacing: .07em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }

.auth-page { background: radial-gradient(circle at top left, #f9edcf, transparent 42%), linear-gradient(145deg, #f8f9fc, #edece8); }
.auth-main { display: grid; place-items: center; min-height: 100vh; padding: 35px 18px; }
.auth-card { width: min(430px, 100%); padding: 35px; border: 1px solid rgba(222,226,237,.9); border-radius: 22px; background: rgba(255,255,255,.94); box-shadow: 0 24px 70px rgba(35,44,80,.12); }
.wide-auth { width: min(650px, 100%); }
.auth-logo-image { display: block; width: 104px; height: 104px; margin: 0 auto 25px; border: 2px solid #d5a64e; border-radius: 50%; object-fit: cover; box-shadow: 0 12px 28px rgba(26,20,10,.18); }
.mobile-logo { width: 31px; height: 31px; border: 1px solid #c99a46; border-radius: 50%; object-fit: cover; }
.auth-card h1 { margin: 3px 0 7px; font-size: 27px; letter-spacing: -.035em; }
.auth-card > .muted { margin: 0 0 24px; font-size: 13px; }
.auth-divider { display: flex; align-items: center; gap: 10px; margin: 22px 0 15px; color: #9ba2b2; font-size: 10px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.auth-footer { margin: 20px 0 0; text-align: center; font-size: 12px; font-weight: 700; }
.auth-footer a { color: var(--primary); }
.message-state { margin-top: 15vh; }

html[data-theme="dark"] body,
html[data-theme="dark"] .app-main { background: var(--bg); color: var(--ink); }
html[data-theme="dark"] .panel,
html[data-theme="dark"] .course-card,
html[data-theme="dark"] .content-list,
html[data-theme="dark"] .material-card,
html[data-theme="dark"] .request-card,
html[data-theme="dark"] .user-card,
html[data-theme="dark"] .table-wrap,
html[data-theme="dark"] .button.secondary,
html[data-theme="dark"] .notice-icon,
html[data-theme="dark"] .details-menu,
html[data-theme="dark"] .flash,
html[data-theme="dark"] .auth-card,
html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] select,
html[data-theme="dark"] summary,
html[data-theme="dark"] .color-choice,
html[data-theme="dark"] .icon-button {
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
}
html[data-theme="dark"] .auth-page {
  background: radial-gradient(circle at top left, #332713, transparent 42%), linear-gradient(145deg, #0b0c0e, #121315);
}
html[data-theme="dark"] .mobile-header { border-color: var(--line); background: rgba(23, 25, 28, .95); color: var(--ink); }
html[data-theme="dark"] .content-row:hover,
html[data-theme="dark"] th { background: #1f2125; }
html[data-theme="dark"] label,
html[data-theme="dark"] legend { color: #e6e6e2; }
html[data-theme="dark"] .material-body { color: #c4c7ce; }
html[data-theme="dark"] .empty-state { border-color: #3a3d44; background: rgba(23, 25, 28, .72); }
html[data-theme="dark"] .empty-inline { border-color: var(--line); }
html[data-theme="dark"] .notice-card { border-color: #5c4928; background: #282116; color: #e3bd72; }
html[data-theme="dark"] .notice-card small { color: #bd9e64; }
html[data-theme="dark"] .danger-zone { border-color: #63323a; background: #241719; }
html[data-theme="dark"] .auth-divider::before,
html[data-theme="dark"] .auth-divider::after { background: var(--line); }
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #777c86; }

@media (max-width: 1020px) {
  .course-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .compact-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .course-hero { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); box-shadow: 12px 0 35px rgba(8,10,24,.25); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .app-main { margin-left: 0; max-width: 100%; padding-top: 56px; }
  .mobile-header { position: fixed; inset: 0 0 auto; z-index: 40; display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 16px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.95); backdrop-filter: blur(10px); }
  .icon-button { width: 37px; height: 37px; border: 1px solid var(--line); border-radius: 9px; background: white; cursor: pointer; }
  html[data-theme="dark"] .mobile-header { background: rgba(23, 25, 28, .95); }
  html[data-theme="dark"] .icon-button { background: var(--panel); color: var(--ink); }
  .theme-switcher { top: 9px; right: 12px; box-shadow: none; }
  .page-shell, .narrow-shell { width: min(100% - 30px, 1180px); padding-top: 27px; }
  .split-heading { align-items: flex-start; flex-direction: column; }
  .user-card { align-items: flex-start; flex-direction: column; }
  .user-controls { width: 100%; justify-content: space-between; }
}

@media (max-width: 620px) {
  .course-grid, .material-grid, .form-grid, .compact-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .auth-card { padding: 26px 21px; }
  .course-hero { min-height: 0; padding: 28px 23px; }
  .hero-actions { width: 100%; flex-wrap: wrap; }
  .hero-actions .button { flex: 1; }
  .danger-zone, .request-card { align-items: flex-start; flex-direction: column; }
  .request-actions { width: 100%; margin-left: 0; }
  .request-actions form, .request-actions button { flex: 1; }
  .user-controls, .inline-controls { align-items: stretch; flex-direction: column; }
  .inline-controls select { width: 100%; }
  .user-controls details { align-self: flex-start; }
  .details-menu { position: fixed; inset: auto 15px 20px; width: auto; }
  .content-row time { display: none; }
  .flash-stack { top: 65px; right: 18px; }
  .theme-switcher button { padding-inline: 8px; }
  .theme-switcher button span { display: none; }
  .mobile-header strong { max-width: 155px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
