/* ============================================================================
   SMART TEACHER PWA — App Styles
   ============================================================================ */

/* --- iOS Safari: prevent auto-zoom on focus for inputs < 16px --- */
@supports (-webkit-touch-callout: none) {
  input, select, textarea, button {
    font-size: 16px !important;
  }
}

/* Also prevent zoom via viewport on all mobile */
input, select, textarea {
  font-size: max(16px, 1em);
  -webkit-text-size-adjust: 100%;
}

/* --- Login Page --- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--color-bg-secondary);
  padding: var(--space-4);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-card__logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin-bottom: var(--space-8);
}

.login-card__logo-icon {
  width: 48px;
  height: 48px;
  background: var(--color-primary-600);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-neutral-0);
}

.login-card__logo-icon svg {
  width: 28px;
  height: 28px;
}

.login-card__logo-text {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--color-text);
}

.login-card__form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.login-card__error {
  color: var(--color-danger-600);
  font-size: var(--text-sm);
  background: var(--color-danger-50);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  display: none;
}

.login-card__error.visible {
  display: block;
}

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  z-index: var(--z-sidebar);
  transform: translateX(-100%);
  transition: transform var(--duration-slow) var(--ease-default);
  overflow-y: auto;
}

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

@media (min-width: 1024px) {
  .sidebar {
    transform: translateX(0);
  }
}

.sidebar__header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  min-height: var(--header-height);
  border-bottom: 1px solid var(--color-divider);
}

.sidebar__logo-icon {
  width: 36px;
  height: 36px;
  background: var(--color-primary-600);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--color-neutral-0);
}

.sidebar__logo-icon svg {
  width: 20px;
  height: 20px;
}

.sidebar__logo-text {
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  color: var(--color-text);
}

.sidebar__nav {
  flex: 1;
  padding: var(--space-3) var(--space-3);
}

.sidebar__nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2-5) var(--space-3);
  border-radius: var(--radius-lg);
  color: var(--color-text-secondary);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  cursor: pointer;
  transition: background-color var(--duration-normal) var(--ease-default),
              color var(--duration-normal) var(--ease-default);
  text-decoration: none;
  margin-bottom: var(--space-0-5);
  min-height: var(--touch-target-min);
}

.sidebar__nav-item:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text);
  text-decoration: none;
}

.sidebar__nav-item--active {
  background: var(--color-primary-50);
  color: var(--color-primary-700);
}

.sidebar__nav-item--active:hover {
  background: var(--color-primary-100);
  color: var(--color-primary-700);
}

.sidebar__nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* --- Page containers --- */
.page-toolbar {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

@media (min-width: 480px) {
  .page-toolbar {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
  }
}

.page-toolbar__search {
  flex: 1;
  min-width: 200px;
}

.page-toolbar__filter {
  min-width: 160px;
}

/* --- Empty state --- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-4);
  text-align: center;
  color: var(--color-text-tertiary);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-4);
  opacity: 0.4;
}

.empty-state__text {
  font-size: var(--text-md);
  margin-bottom: var(--space-2);
}

.empty-state__hint {
  font-size: var(--text-sm);
}

/* --- Loading spinner --- */
.spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-12);
}

.spinner::after {
  content: '';
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary-600);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Toast container --- */
.toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: 380px;
  width: calc(100% - var(--space-8));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s var(--ease-out);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

.toast--success {
  border-left: 3px solid var(--color-success-500);
}

.toast--error {
  border-left: 3px solid var(--color-danger-500);
}

.toast--info {
  border-left: 3px solid var(--color-primary-500);
}

.toast__icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  margin-top: 1px;
}

.toast--success .toast__icon { color: var(--color-success-500); }
.toast--error .toast__icon { color: var(--color-danger-500); }
.toast--info .toast__icon { color: var(--color-primary-500); }

.toast__text {
  flex: 1;
}

.toast__close {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  cursor: pointer;
  color: var(--color-text-tertiary);
  background: none;
  border: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast__close:hover {
  color: var(--color-text);
}

.toast--removing {
  animation: toast-out 0.25s var(--ease-in) forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 0;
  animation: modal-overlay-in 0.2s var(--ease-out) forwards;
}

.modal-overlay--closing {
  animation: modal-overlay-out 0.2s var(--ease-in) forwards;
}

@keyframes modal-overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-overlay-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-2xl);
  transform: scale(0.95) translateY(10px);
  animation: modal-in 0.25s var(--ease-out) forwards;
}

.modal-overlay--closing .modal {
  animation: modal-out 0.2s var(--ease-in) forwards;
}

@keyframes modal-in {
  from { transform: scale(0.95) translateY(10px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes modal-out {
  from { transform: scale(1) translateY(0); opacity: 1; }
  to { transform: scale(0.95) translateY(10px); opacity: 0; }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-5) var(--space-3);
}

.modal__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  margin: 0;
}

.modal__close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-tertiary);
  cursor: pointer;
  background: none;
  border: none;
}

.modal__close:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text);
}

.modal__body {
  padding: var(--space-3) var(--space-5) var(--space-5);
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5) var(--space-5);
}

/* --- Context menu --- */
.context-menu {
  position: absolute;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-popover);
  min-width: 160px;
  padding: var(--space-1) 0;
  animation: context-menu-in 0.15s var(--ease-out);
}

@keyframes context-menu-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.context-menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2-5) var(--space-4);
  font-size: var(--text-sm);
  color: var(--color-text);
  cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-default);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.context-menu__item:hover {
  background: var(--color-bg-secondary);
}

.context-menu__item--danger {
  color: var(--color-danger-600);
}

.context-menu__item--danger:hover {
  background: var(--color-danger-50);
}

.context-menu__item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* --- File upload / drag zone --- */
.file-upload-zone {
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
  color: var(--color-text-tertiary);
  cursor: pointer;
  transition: border-color var(--duration-normal) var(--ease-default),
              background-color var(--duration-normal) var(--ease-default);
}

.file-upload-zone:hover,
.file-upload-zone--active {
  border-color: var(--color-primary-400);
  background: var(--color-primary-50);
  color: var(--color-primary-600);
}

.file-upload-zone svg {
  width: 32px;
  height: 32px;
  margin: 0 auto var(--space-2);
}

.file-upload-zone__text {
  font-size: var(--text-sm);
}

.file-upload-zone__hint {
  font-size: var(--text-xs);
  margin-top: var(--space-1);
}

/* --- File thumbnails --- */
.file-thumbnails {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.file-thumb {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--color-border);
  background: var(--color-bg-tertiary);
}

.file-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-thumb__remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  background: var(--color-danger-600);
  color: var(--color-neutral-0);
  border: none;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 0;
}

.file-thumb--doc {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-1);
}

.file-thumb--doc svg {
  width: 24px;
  height: 24px;
  margin-bottom: var(--space-1);
  color: var(--color-text-tertiary);
}

.file-thumb--doc span {
  font-size: 9px;
  color: var(--color-text-tertiary);
  text-align: center;
  word-break: break-all;
  line-height: 1.2;
  max-height: 28px;
  overflow: hidden;
}

/* --- Grade popup --- */
.grade-popup-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: var(--z-popover);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modal-overlay-in 0.15s var(--ease-out) forwards;
}

.grade-popup {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-5);
  box-shadow: var(--shadow-2xl);
  width: 280px;
  animation: modal-in 0.2s var(--ease-out) forwards;
}

.grade-popup__title {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-4);
  text-align: center;
}

.grade-popup__grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.grade-popup__btn {
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  background: var(--color-surface);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
}

.grade-popup__btn:hover {
  border-color: var(--color-primary-400);
  background: var(--color-primary-50);
  color: var(--color-primary-700);
}

.grade-popup__btn--active {
  border-color: var(--color-primary-600);
  background: var(--color-primary-600);
  color: var(--color-neutral-0);
}

.grade-popup__btn--active:hover {
  background: var(--color-primary-700);
  border-color: var(--color-primary-700);
  color: var(--color-neutral-0);
}

.grade-popup__clear {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  background: var(--color-surface);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-default);
}

.grade-popup__clear:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text);
}

/* --- Detail page header --- */
.detail-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.detail-header__back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--color-text-secondary);
  font-size: var(--text-sm);
  cursor: pointer;
  background: none;
  border: none;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-md);
  transition: color var(--duration-fast), background var(--duration-fast);
}

.detail-header__back:hover {
  color: var(--color-text);
  background: var(--color-bg-tertiary);
}

.detail-header__back svg {
  width: 18px;
  height: 18px;
}

.detail-header__title {
  flex: 1;
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  margin: 0;
}

.detail-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* --- Info form (student/parent detail) --- */
.info-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  max-width: 500px;
}

.info-form__row {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.info-form__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-secondary);
}

/* --- Status tags --- */
.status-tag {
  display: inline-flex;
  align-items: center;
  padding: var(--space-0-5) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

.status-tag--new {
  background: var(--color-accent-100);
  color: var(--color-accent-700);
}

.status-tag--active {
  background: var(--color-success-100);
  color: var(--color-success-700);
}

.status-tag--completed {
  background: var(--color-success-100);
  color: var(--color-success-700);
}

.status-tag--pending {
  background: var(--color-warning-100);
  color: var(--color-warning-700);
}

.status-tag--draft {
  background: var(--color-neutral-100);
  color: var(--color-neutral-600);
}

.status-tag--sent {
  background: var(--color-primary-100);
  color: var(--color-primary-700);
}

.status-tag--reviewed {
  background: var(--color-success-100);
  color: var(--color-success-700);
}

/* --- Logs --- */
.logs-container {
  background: var(--color-neutral-900);
  color: var(--color-neutral-200);
  font-family: var(--font-family-mono);
  font-size: var(--text-xs);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  overflow: auto;
  max-height: 70vh;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-line--error {
  color: var(--color-danger-400);
}

.log-line--warning {
  color: var(--color-warning-400);
}

.log-line--info {
  color: var(--color-neutral-400);
}

/* --- Grades table --- */
.grades-table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

.grades-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.grades-table th,
.grades-table td {
  padding: var(--space-2) var(--space-3);
  text-align: center;
  border-bottom: 1px solid var(--color-divider);
  white-space: nowrap;
}

.grades-table th {
  background: var(--color-bg-secondary);
  font-weight: var(--weight-semibold);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  position: sticky;
  top: 0;
  z-index: 1;
}

.grades-table td:first-child,
.grades-table th:first-child {
  text-align: left;
  font-weight: var(--weight-medium);
}

.grades-table tbody tr:hover {
  background: var(--color-surface-hover);
}

.grades-table .grade-cell--high {
  color: var(--color-success-600);
  font-weight: var(--weight-semibold);
}

.grades-table .grade-cell--mid {
  color: var(--color-warning-600);
  font-weight: var(--weight-medium);
}

.grades-table .grade-cell--low {
  color: var(--color-danger-600);
  font-weight: var(--weight-medium);
}

/* --- Messages page --- */
.message-form {
  max-width: 600px;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.message-form__recipient-toggle {
  display: flex;
  gap: var(--space-2);
}

/* --- Misc --- */
.section-divider {
  height: 1px;
  background: var(--color-divider);
  margin: var(--space-6) 0;
}

.link {
  color: var(--color-primary-600);
  cursor: pointer;
  text-decoration: none;
  font-size: var(--text-sm);
}

.link:hover {
  text-decoration: underline;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--color-primary-100);
  color: var(--color-primary-700);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
  flex-shrink: 0;
}

.avatar--sm {
  width: 32px;
  height: 32px;
  font-size: var(--text-xs);
}

.avatar--lg {
  width: 56px;
  height: 56px;
  font-size: var(--text-md);
}
