/* 學生平台 — 桌面殼層與共用元件（tokens.css 須先載入） */

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

.portal-body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--sw-font-family);
  color: var(--sw-text);
  background: var(--sw-bg-app);
}

.portal-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, #e0f2fe 0%, #f8fafc 50%, #ede9fe 100%);
}

/* Firefox／部分瀏覽器：.display:flex/grid 會蓋過 UA 的 [hidden]，導致登入後畫面不切換 */
.portal-login[hidden],
.portal-app[hidden] {
  display: none !important;
}

.portal-login__card {
  width: 100%;
  max-width: 400px;
  background: var(--sw-surface);
  border-radius: 16px;
  padding: 1.75rem;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.1);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.portal-login__brand {
  text-align: center;
  margin-bottom: 0.5rem;
}

.portal-login__logo-img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: 16px;
  display: block;
  margin: 0 auto;
  box-shadow: 0 8px 20px rgba(2, 132, 199, 0.2);
}

.portal-login__brand h1 {
  margin: 0.65rem 0 0.25rem;
  font-size: 1.5rem;
  color: var(--sw-primary-deep);
}

.portal-login__brand p,
.portal-login__hint {
  margin: 0;
  color: var(--sw-text-subtle);
  font-size: 0.875rem;
}

.portal-login__hint a {
  color: var(--sw-primary-dark);
}

.portal-fg {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--sw-text-muted);
}

.portal-fg input,
.portal-fg select,
.portal-fg textarea,
.portal-sidebar__student select {
  font: inherit;
  font-weight: 400;
  color: var(--sw-text);
  border: 1px solid var(--sw-border-strong);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  background: var(--sw-surface);
}

.portal-fg textarea {
  min-height: 100px;
  resize: vertical;
}

.portal-btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 0.75rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  text-decoration: none;
}

.portal-btn:focus-visible,
.portal-nav__item:focus-visible,
.portal-icon-btn:focus-visible,
.portal-bottom-nav__item:focus-visible,
.portal-card:focus-visible {
  outline: 2px solid var(--sw-primary);
  outline-offset: 2px;
}

.portal-btn--primary {
  background: var(--sw-gradient-btn);
  color: #fff;
}

.portal-btn--success {
  background: linear-gradient(135deg, #16a34a, #15803d);
  color: #fff;
}

.portal-btn--ghost {
  background: transparent;
  color: var(--sw-text-muted);
  border: 1px solid var(--sw-border);
}

.portal-btn--block {
  width: 100%;
}

.portal-btn--sm {
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  border-radius: 8px;
}

.portal-error {
  color: #b91c1c;
  font-size: 0.9rem;
  min-height: 1.25rem;
  margin: 0;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  background: #fef2f2;
  border: 1px solid #fecaca;
}

.portal-error:empty {
  display: none;
}

.portal-app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.portal-sidebar {
  background: var(--sw-surface);
  border-right: 1px solid var(--sw-border);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.portal-sidebar__brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.25rem 0.5rem;
}

.portal-sidebar__logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 10px;
  flex-shrink: 0;
  background: var(--sw-surface);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
}

.portal-sidebar__brand strong {
  display: block;
  color: var(--sw-primary-deep);
}

.portal-sidebar__brand small {
  color: var(--sw-text-subtle);
  font-size: 0.75rem;
}

.portal-chip--club {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.portal-chip--club img {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  object-fit: contain;
}

.portal-welcome {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 14px;
  background: linear-gradient(120deg, rgba(14, 165, 233, 0.12), rgba(248, 250, 252, 0.9));
  border: 1px solid var(--sw-border);
}

.portal-welcome__logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: contain;
  flex-shrink: 0;
}

.portal-welcome__club {
  display: block;
  color: var(--sw-primary-deep);
  font-size: 1rem;
}

.portal-welcome__hello {
  margin: 0.15rem 0 0;
  color: var(--sw-text-muted);
  font-size: 0.875rem;
}

.portal-sidebar__student {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--sw-text-muted);
  font-weight: 600;
}

.portal-nav {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.portal-nav__item {
  appearance: none;
  border: none;
  background: transparent;
  text-align: left;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  font: inherit;
  color: var(--sw-text-muted);
  cursor: pointer;
}

.portal-nav__item.is-active,
.portal-nav__item:hover {
  background: #e0f2fe;
  color: var(--sw-primary-deep);
  font-weight: 600;
}

.portal-sidebar__logout {
  margin-top: auto;
}

.portal-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.portal-topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: var(--sw-gradient-hdr);
  border-bottom: 1px solid var(--sw-border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.portal-topbar h2 {
  margin: 0;
  font-size: 1.15rem;
  color: var(--sw-primary-deep);
  flex: 1;
}

.portal-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: #ede9fe;
  color: #5b21b6;
  font-size: 0.8rem;
  font-weight: 600;
}

.portal-icon-btn {
  appearance: none;
  border: 1px solid var(--sw-border);
  background: var(--sw-surface);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.portal-status {
  padding: 0 1.25rem;
  min-height: 0;
}

.portal-status:not(:empty) {
  padding-top: 0.75rem;
}

.portal-status__msg {
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  font-size: 0.875rem;
}

.portal-status__msg--ok {
  background: var(--sw-status-ok-bg);
  color: var(--sw-status-ok-text);
  border: 1px solid var(--sw-status-ok-border);
}

.portal-status__msg--err {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.portal-status__msg--warn {
  background: var(--sw-status-warn-bg);
  color: var(--sw-status-warn-text);
  border: 1px solid var(--sw-status-warn-border);
}

.portal-content {
  padding: 1.25rem;
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
}

.portal-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.portal-card {
  background: var(--sw-surface);
  border: 1px solid var(--sw-border);
  border-radius: 14px;
  padding: 1rem 1.1rem;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.04);
}

.portal-card--click {
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.portal-card--click:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(2, 132, 199, 0.12);
}

.portal-card__label {
  font-size: 0.75rem;
  color: var(--sw-text-subtle);
  margin: 0 0 0.35rem;
}

.portal-card__title {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  color: var(--sw-text);
}

.portal-card__meta {
  margin: 0;
  font-size: 0.875rem;
  color: var(--sw-text-muted);
}

.portal-tag {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #ede9fe;
  color: #6d28d9;
}

.portal-tag--ok {
  background: #dcfce7;
  color: #166534;
}

.portal-tag--warn {
  background: #fef3c7;
  color: #92400e;
}

.portal-tag--danger {
  background: #fee2e2;
  color: #991b1b;
}

.portal-section {
  margin-top: 1.25rem;
}

.portal-section h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  color: var(--sw-primary-deep);
}

.portal-cal {
  background: var(--sw-surface);
  border-radius: 14px;
  border: 1px solid var(--sw-border);
  overflow: hidden;
}

.portal-cal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  background: var(--sw-primary-deep);
  color: #fff;
}

.portal-cal__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--sw-border);
  padding: 1px;
}

.portal-cal__dow,
.portal-cal__cell {
  background: var(--sw-surface);
  text-align: center;
  padding: 0.55rem 0.2rem;
  font-size: 0.8rem;
  min-height: 42px;
}

.portal-cal__dow {
  font-weight: 600;
  color: var(--sw-text-subtle);
  background: var(--sw-surface-muted);
}

.portal-cal__cell {
  border: none;
  cursor: default;
  position: relative;
}

.portal-cal__cell--muted {
  color: #cbd5e1;
}

.portal-cal__cell--today {
  box-shadow: inset 0 0 0 2px var(--sw-primary);
  font-weight: 700;
}

.portal-cal__cell--has {
  cursor: pointer;
}

.portal-cal__cell--selected {
  outline: 2px solid var(--sw-primary);
  outline-offset: -2px;
  background: rgba(14, 165, 233, 0.18);
}

.portal-card.is-selected {
  border-color: var(--sw-primary);
  box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.25);
}

.portal-skeleton {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.25rem 0 1rem;
}

.portal-skeleton__line,
.portal-skeleton__card {
  border-radius: 12px;
  background: linear-gradient(90deg, #e2e8f0 0%, #f8fafc 50%, #e2e8f0 100%);
  background-size: 200% 100%;
  animation: portal-skeleton-shimmer 1.2s ease-in-out infinite;
}

.portal-skeleton__line {
  height: 0.9rem;
  width: 55%;
}

.portal-skeleton__line--lg {
  height: 1.25rem;
  width: 70%;
}

.portal-skeleton__card {
  height: 6.5rem;
  width: 100%;
}

@keyframes portal-skeleton-shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

.portal-cal__dot {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #f97316;
  margin: 0.2rem auto 0;
}

.portal-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.portal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 1rem;
}

.portal-empty {
  text-align: center;
  color: var(--sw-text-subtle);
  padding: 2rem 1rem;
}

.portal-progress-bars {
  display: grid;
  gap: 0.65rem;
}

.portal-progress-row {
  display: grid;
  grid-template-columns: 72px 1fr 2rem;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.875rem;
}

.portal-progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--sw-surface-subtle);
  overflow: hidden;
}

.portal-progress-fill {
  height: 100%;
  background: var(--sw-primary);
  border-radius: 999px;
}

.portal-bottom-nav {
  display: none;
}

.portal-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.portal-modal[hidden] {
  display: none !important;
}

.portal-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.portal-modal__sheet {
  position: relative;
  width: min(560px, 100%);
  max-height: min(90vh, 720px);
  overflow: auto;
  background: var(--sw-surface);
  border-radius: 16px 16px 0 0;
  z-index: 1;
}

.portal-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--sw-border);
  position: sticky;
  top: 0;
  background: var(--sw-surface);
}

.portal-modal__head h3 {
  margin: 0;
  font-size: 1.05rem;
}

.portal-modal__body {
  padding: 1rem;
}

.portal-kv {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 0.45rem 0.75rem;
  font-size: 0.9rem;
  margin: 0 0 1rem;
}

.portal-kv dt {
  color: var(--sw-text-subtle);
}

.portal-kv dd {
  margin: 0;
  color: var(--sw-text);
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media (min-width: 769px) {
  .portal-modal {
    align-items: center;
  }
  .portal-modal__sheet {
    border-radius: 16px;
  }
}

.portal-skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.5rem 0.75rem;
  background: var(--sw-surface);
  color: var(--sw-primary-deep);
  border-radius: 0 0 8px 0;
}

.portal-skip:focus {
  left: 0;
}

.portal-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.portal-login__hint--firefox {
  margin: 0;
  color: var(--sw-text-subtle);
  font-size: 0.8rem;
}

.portal-topbar__student {
  display: none;
  margin: 0;
}

.portal-topbar__student select {
  font: inherit;
  font-size: 0.85rem;
  max-width: 9.5rem;
  border: 1px solid var(--sw-border-strong);
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  background: var(--sw-surface);
  color: var(--sw-text);
}

.portal-todo-link {
  appearance: none;
  border: none;
  background: transparent;
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--sw-border);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.portal-todo-link:last-child {
  border-bottom: none;
}

.portal-todo-link:hover,
.portal-todo-link:focus-visible {
  color: var(--sw-primary-dark);
}

.portal-todo-link__count {
  font-weight: 700;
  color: var(--sw-primary-deep);
}

.portal-msg-tabs {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--sw-bg-app);
  padding: 0.35rem 0;
}

.portal-msg-tabs__btn {
  appearance: none;
  border: 1px solid var(--sw-border);
  background: var(--sw-surface);
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--sw-text-muted);
}

.portal-msg-tabs__btn.is-active {
  background: var(--sw-primary);
  border-color: var(--sw-primary);
  color: #fff;
  font-weight: 600;
}

.portal-msg-panel[hidden] {
  display: none !important;
}

.portal-thread {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.portal-thread__bubble {
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  background: #f1f5f9;
  border: 1px solid var(--sw-border);
}

.portal-thread__bubble--staff {
  background: #eff6ff;
  border-color: #bfdbfe;
}

.portal-thread__meta {
  margin: 0 0 0.35rem;
  font-size: 0.75rem;
  color: var(--sw-text-subtle);
}

.portal-thread__body {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.5;
}

.portal-error-retry {
  margin-top: 0.75rem;
}

.portal-body.portal-modal-open {
  overflow: hidden;
}

@media (prefers-reduced-motion: reduce) {
  .portal-card--click:hover {
    transform: none;
  }

  .portal-skeleton__line,
  .portal-skeleton__card {
    animation: none;
  }
}
