:root {
  --bg: #f4f7fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #edf3f8;
  --sidebar: #08131d;
  --sidebar-2: #0d1d2b;
  --text: #111827;
  --muted: #64748b;
  --line: #dce3ea;
  --primary: #0a6ed1;
  --primary-strong: #0759aa;
  --success: #15803d;
  --danger: #b42318;
  --shadow: 0 12px 30px rgba(15, 23, 42, .07);
  --radius: 14px;
}

html[data-theme="dark"] {
  --bg: #0b1118;
  --surface: #121b24;
  --surface-2: #17222e;
  --surface-3: #1d2a37;
  --sidebar: #071019;
  --sidebar-2: #0b1824;
  --text: #f8fafc;
  --muted: #94a3b8;
  --line: #263241;
  --primary: #3b82f6;
  --primary-strong: #60a5fa;
  --success: #4ade80;
  --danger: #f87171;
  --shadow: 0 16px 36px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
  color: #dbe7f3;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  padding: 0 8px 22px;
  border-bottom: 1px solid rgba(255,255,255,.09);
}

.brand-icon-frame, .favorite-icon, .app-icon {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.brand-icon-frame {
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  border-radius: 13px;
}

.brand > .brand-icon-frame,
.auth-brand > .brand-icon-frame {
  transform: translateY(-5px);
}

.brand-icon {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-icon-fallback {
  display: none;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  place-items: center;
  background: linear-gradient(145deg, #0a6ed1, #54b4ff);
  color: white;
  font-weight: 900;
}

.image-broken > img { display: none; }
.image-broken > .brand-icon-fallback,
.image-broken > .app-icon-fallback { display: grid; }

.brand-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.brand-copy strong {
  font-size: 20px;
  line-height: 1;
  letter-spacing: .02em;
  color: white;
}

.brand-copy > span {
  margin-top: 5px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .34em;
  color: white;
}

.brand-copy small {
  margin-top: 7px;
  color: #9fb3cc;
  font-size: 11px;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 22px;
}

.sidebar-nav a, .sidebar-footer > a {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 0 13px;
  border-radius: 10px;
  color: #b8c8d8;
  font-size: 14px;
  transition: .18s ease;
}

.menu-icon {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: #91a8bc;
}

.menu-label {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sidebar-nav a:hover, .sidebar-footer > a:hover {
  color: white;
  background: rgba(255,255,255,.06);
}

.sidebar-nav a.active, .sidebar-footer > a.active {
  color: white;
  background: #0a6ed1;
}

.sidebar-nav a.active .menu-icon, .sidebar-footer > a.active .menu-icon { color: white; }

.nav-label {
  margin: 24px 13px 7px;
  color: #70869a;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,.09);
}

.sidebar-user, .top-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sidebar-user {
  padding: 8px;
  border-radius: 10px;
  background: rgba(255,255,255,.04);
}

.avatar {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(59,130,246,.18);
  color: #93c5fd;
  font-size: 12px;
  font-weight: 800;
}

.sidebar-user div:last-child, .top-user div:last-child {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.sidebar-user strong, .top-user strong {
  overflow: hidden;
  font-size: 12px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sidebar-user small, .top-user small { color: var(--muted); font-size: 10px; }
.sidebar-user small { color: #8fa4b7; }

.logout-button {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 9px;
  background: transparent;
  color: #b8c8d8;
  cursor: pointer;
}

.logout-button:hover { color: white; border-color: rgba(255,255,255,.2); }

.page-column { min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 78px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 32px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.top-search {
  width: min(460px, 48vw);
  height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--muted);
}

.top-search input, .app-filter-input input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.search-icon,
.topbar-icon {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.search-icon {
  color: var(--muted);
}

.icon-button {
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.mobile-menu { display: none; }

.top-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding-left: 16px;
  border-left: 1px solid var(--line);
}

.top-user {
  margin-left: 0;
  padding-left: 0;
  border-left: 0;
}

.page-content { padding: 42px 36px 64px; }

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 34px;
}

.page-heading.compact { margin-bottom: 24px; }

.page-heading h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 45px);
  line-height: 1.08;
  letter-spacing: -.035em;
}

.page-heading.compact h1 { font-size: clamp(26px, 3vw, 36px); }

.page-heading p:not(.eyebrow) {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 16px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.dashboard-section { margin-top: 30px; }

.section-heading, .panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.section-heading { margin-bottom: 16px; }
.section-heading h2, .panel-heading h2 { margin: 0; font-size: 18px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.favorite-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.favorite-tile {
  min-width: 0;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(15,23,42,.03);
  transition: transform .18s ease, border-color .18s ease;
}

.favorite-tile:hover { transform: translateY(-2px); border-color: var(--accent); }

.favorite-icon, .app-icon {
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  color: var(--accent);
}

.favorite-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
}

.favorite-icon img, .app-icon img {
  width: 100%;
  height: 100%;
  padding: 6px;
  object-fit: contain;
}

.app-icon-fallback {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  font-size: 12px;
  font-weight: 900;
}

.favorite-icon:not(.image-broken) .app-icon-fallback,
.app-icon:not(.image-broken) img + .app-icon-fallback { display: none; }

.favorite-tile strong, .favorite-tile small {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.favorite-tile strong { font-size: 14px; }
.favorite-tile small { color: var(--muted); font-size: 11px; }
.favorite-tile > span:last-child { color: var(--muted); }

.external-note {
  margin: 18px 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.app-filter-input {
  width: min(280px, 100%);
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--muted);
}

.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.category-chips button {
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.category-chips button.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.app-card {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(15,23,42,.025);
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}

.app-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.app-card-link {
  min-height: 168px;
  display: flex;
  gap: 14px;
  padding: 22px 20px;
}

.app-card-disabled { cursor: not-allowed; opacity: .72; }

.app-icon {
  flex: 0 0 50px;
  width: 50px;
  height: 50px;
  border-radius: 13px;
}

.app-card-copy { min-width: 0; flex: 1; }

.app-card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.app-card h3 { margin: 1px 0 0; font-size: 16px; }
.external-arrow { color: var(--muted); }

.app-card p {
  min-height: 40px;
  margin: 8px 0 14px;
  color: var(--muted);
  font-size: 12px;
}

.status-pill {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 13%, transparent);
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
}

.favorite-form {
  position: absolute;
  right: 13px;
  bottom: 12px;
  z-index: 4;
}

.favorite-button {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 9px;
  background: var(--surface-2);
  color: #f59e0b;
  cursor: pointer;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 190px;
  padding: 30px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.empty-state.small { min-height: 100px; }
.empty-state strong { color: var(--text); }

.flash {
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 13px;
}

.flash-success { border-color: var(--success); color: var(--success); }
.flash-error { border-color: var(--danger); color: var(--danger); }

.panel {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 6px 20px rgba(15,23,42,.03);
}

.panel-heading {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.counter {
  display: inline-flex;
  min-width: 28px;
  justify-content: center;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(280px, .72fr) minmax(0, 1.28fr);
  gap: 18px;
  align-items: start;
}

.panel-wide { min-width: 0; }
.narrow-panel { max-width: 720px; }
.stack-form { display: grid; gap: 14px; }

.stack-form label, .inline-form label {
  display: grid;
  gap: 6px;
}

.stack-form label > span, .inline-form label > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
}

input, select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  outline: 0;
  background: var(--surface-2);
  color: var(--text);
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(10,110,209,.13);
}

.checkbox-row {
  grid-template-columns: auto 1fr !important;
  align-items: center;
}

.checkbox-row input {
  width: 17px;
  min-height: 17px;
  height: 17px;
}

.checkbox-row span {
  color: var(--text) !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 9px;
  font-weight: 800;
  cursor: pointer;
}

.button-primary { background: var(--primary); color: white; }
.button-primary:hover { background: var(--primary-strong); }
.button-secondary { border-color: var(--line); background: var(--surface); color: var(--text); }
.button-block { width: 100%; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }

th, td {
  padding: 13px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 12px;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
}

td strong, td small { display: block; }
td small { margin-top: 2px; color: var(--muted); }
.text-link { color: var(--primary); font-weight: 800; }

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.status-dot::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
}

.status-dot.on::before { background: #22c55e; }
.status-dot.off::before { background: #f59e0b; }

.inline-form {
  display: flex;
  align-items: end;
  gap: 12px;
  margin-bottom: 22px;
}

.inline-form label { width: min(430px, 100%); }

.assignment-form { display: grid; gap: 20px; }

.assignment-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.assignment-card {
  position: relative;
  min-height: 116px;
  display: flex;
  gap: 11px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  cursor: pointer;
}

.assignment-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.assignment-check {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: transparent;
}

.assignment-card input:checked + .assignment-check {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.assignment-copy { display: flex; min-width: 0; flex-direction: column; }
.assignment-copy strong { font-size: 13px; }
.assignment-copy small { margin-top: 4px; color: var(--muted); font-size: 11px; }
.assignment-copy em { margin-top: auto; color: var(--primary); font-size: 10px; font-style: normal; font-weight: 800; }

.auth-page { background: #071019; }

.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(380px, .9fr) minmax(420px, 1.1fr);
}

.auth-brand-panel {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: clamp(30px, 5vw, 72px);
  background:
    radial-gradient(circle at 20% 15%, rgba(59,130,246,.28), transparent 34%),
    linear-gradient(145deg, #06101a, #0b1e2e);
  color: white;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.auth-brand > div:last-child { display: flex; flex-direction: column; }
.auth-brand strong { font-size: 25px; line-height: 1; }
.auth-brand span { margin-top: 6px; font-size: 11px; font-weight: 900; letter-spacing: .34em; }
.auth-brand small { margin-top: 8px; color: #9fb3cc; font-size: 12px; }

.auth-message { max-width: 540px; padding-bottom: 7vh; }
.auth-message h1 { margin: 0; font-size: clamp(42px, 5vw, 72px); line-height: 1; letter-spacing: -.05em; }
.auth-message p { max-width: 440px; margin: 22px 0 0; color: #a8bfd2; font-size: 18px; }

.auth-form-panel {
  display: grid;
  place-items: center;
  padding: 30px;
  background: var(--bg);
}

.auth-card {
  width: min(440px, 100%);
  padding: clamp(26px, 4vw, 42px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.auth-card-heading { margin-bottom: 26px; }
.auth-card-heading h2 { margin: 0; font-size: 30px; }
.auth-card-heading > p:last-child { margin: 8px 0 0; color: var(--muted); }

.sidebar-backdrop { display: none; }

@media (max-width: 1120px) {
  .app-grid, .assignment-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .favorite-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-layout { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-105%);
    width: min(310px, 86vw);
    transition: transform .22s ease;
  }

  .sidebar-open .sidebar { transform: translateX(0); }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 25;
    background: rgba(0,0,0,.48);
  }

  .sidebar-open .sidebar-backdrop { display: block; }
  .mobile-menu { display: block; }
  .topbar { height: 68px; padding: 0 16px; }
  .top-search { width: auto; flex: 1; }
  .top-actions { gap: 8px; padding-left: 10px; }
  .top-user div:last-child { display: none; }
  .page-content { padding: 28px 18px 50px; }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand-panel { min-height: auto; padding: 26px; }
  .auth-message { display: none; }
  .auth-form-panel { min-height: calc(100vh - 110px); padding: 20px; }
}

@media (max-width: 620px) {
  .page-heading, .section-heading { flex-direction: column; align-items: stretch; }
  .app-filter-input { width: 100%; }
  .app-grid, .favorite-grid, .assignment-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .top-search { display: none; }
  .page-content { padding-inline: 14px; }
  .panel { padding: 17px; }
  .app-card-link { min-height: 148px; }
}
