/* public/app.css — app-shell + view layout. Values come from tokens.css; DESIGN_CONTRACT compliant. */

:root { --rail-w: 240px; --header-h: 56px; }

html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font-sans); }

/* ---------- Header (fixed top) ---------- */
.app-header {
  position: fixed; top: 0; left: 0; right: 0; height: var(--header-h); z-index: var(--z-nav);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--page-pad-x); background: var(--bg); border-bottom: 1px solid var(--border);
}
.app-header .wordmark { font-family: var(--font-display); font-size: var(--h3-size);
  font-weight: var(--wordmark-weight); letter-spacing: 2px; text-transform: uppercase; color: var(--text);
  white-space: nowrap; }
.app-header .wordmark span { color: var(--text2); }

/* Language pill — EN｜JP segmented (mirrors assort-os-v10 .lang-toggle) */
.lang-toggle { display: inline-flex; align-items: center; gap: var(--space-1);
  height: 36px; padding: 3px 4px 3px 7px; border: 1px solid var(--border);
  border-radius: var(--radius-full); background: var(--white); box-sizing: border-box; flex-shrink: 0; }
.lang-toggle svg { width: 16px; height: 16px; color: var(--text2); flex-shrink: 0; }
.lang-seg { display: flex; background: var(--surface-tint); border-radius: var(--radius-full); overflow: hidden; }
.lang-seg button { border: 0; background: transparent; font-family: inherit; font-size: 13px; font-weight: 700;
  color: var(--text2); padding: 6px 8px; cursor: pointer; border-radius: var(--radius-full); }
.lang-seg button.on { background: var(--text); color: var(--white); }

/* Circular profile / sign-out avatar (mirrors assort-os-v10 .header-avatar-circle) */
.header-avatar-circle { width: 36px; height: 36px; border: 0; border-radius: var(--radius-full);
  background: var(--avatar-bg); display: inline-flex; align-items: center; justify-content: center;
  font-size: var(--caption-size); font-weight: 700; color: var(--text-mid); cursor: pointer; flex-shrink: 0; }

/* ---------- Main outlet ---------- */
.app-main { max-width: var(--app-max-w); margin: 0 auto;
  padding-top: calc(var(--header-h) + var(--space-5)); padding-bottom: calc(var(--nav-h) + var(--space-5)); }
.page-title { margin: 0 var(--gutter) var(--space-5); }
.section-label { margin: var(--space-7) var(--gutter) var(--space-3); }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; height: var(--nav-h); z-index: var(--z-nav);
  display: flex; background: var(--white); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0); }
.bottom-nav button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: var(--tap-target); border: none; background: none; cursor: pointer;
  color: var(--text2); font-size: 10px; font-weight: var(--h3-weight); }
.bottom-nav button[aria-current="page"] { color: var(--blue); }
.bottom-nav svg { width: 24px; height: 24px; }

/* ---------- Side rail (desktop) ---------- */
.side-nav { display: none; }
@media (min-width: 768px) {
  .bottom-nav { display: none; }
  .side-nav { display: flex; flex-direction: column; gap: var(--space-1);
    position: fixed; top: var(--header-h); bottom: 0; left: 0; width: var(--rail-w);
    padding: var(--space-7) var(--space-5); border-right: 1px solid var(--border); background: var(--bg); }
  .side-nav button { display: flex; align-items: center; gap: var(--space-5); min-height: var(--tap-target);
    padding: 0 var(--space-5); border: none; background: none; cursor: pointer; border-radius: var(--radius-lg);
    color: var(--text-mid); font-size: var(--body-size); font-weight: var(--h3-weight); text-align: left; }
  .side-nav button[aria-current="page"] { background: var(--blue-tint); color: var(--blue-ink); }
  .side-nav svg { width: 20px; height: 20px; }
  .app-main { max-width: 900px; margin-left: var(--rail-w); margin-right: auto; padding-bottom: var(--space-12); }
}

/* ---------- Loading / empty / error states (rule 13) ---------- */
.skeleton { background: var(--fill-tint); border-radius: var(--radius); animation: pulse 1.2s ease-in-out infinite; }
.skeleton-row { height: 64px; margin: 0 var(--gutter) 10px; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }
.state-block { margin: var(--space-12) var(--gutter); text-align: center; color: var(--text2); }
.state-block .state-icon { display: inline-flex; width: 48px; height: 48px; align-items: center; justify-content: center;
  border-radius: var(--radius-full); background: var(--surface-tint); color: var(--text2); margin-bottom: var(--space-5); }
.state-block svg { width: 24px; height: 24px; }
.state-block .state-title { color: var(--text); font-size: var(--h3-size); font-weight: var(--h3-weight); margin-bottom: var(--space-2); }
.state-block.error .state-icon { color: var(--red); background: var(--red-tint); }

/* ---------- Reference placeholder well (metadata-only; no photos yet) ---------- */
.thumb-well { display: flex; align-items: center; justify-content: center; aspect-ratio: 4/3;
  background: var(--fill-tint); border-radius: var(--radius-md); color: var(--text3); }
.thumb-well svg { width: 28px; height: 28px; }

/* ---------- Difficulty stars ---------- */
.stars { display: inline-flex; gap: 2px; color: var(--yellow); }
.stars svg { width: 14px; height: 14px; }
.stars .empty { color: var(--text3); }

/* ---------- Reference grid (widens on desktop) ---------- */
.ref-grid { display: grid; grid-template-columns: 1fr; gap: 10px; margin: 0 var(--gutter); }
@media (min-width: 768px) { .ref-grid { grid-template-columns: repeat(3, 1fr); } }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap-target); padding: 0 var(--space-7); border-radius: var(--radius-lg);
  border: 1px solid var(--border); background: var(--white); color: var(--text); font-weight: var(--h3-weight); cursor: pointer; }
.btn-primary { background: var(--blue); border-color: var(--blue); color: var(--white); }
.btn svg { width: 18px; height: 18px; }
.btn-block { width: calc(100% - 2 * var(--gutter)); margin: var(--space-3) var(--gutter); }

/* ---------- Sheet (bottom sheet / modal) ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: var(--z-sheet); background: rgba(0,0,0,.25);
  display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: var(--app-max-w); background: var(--white); border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow-lg); padding: var(--space-7) var(--gutter) calc(var(--space-9) + env(safe-area-inset-bottom, 0)); }
@media (min-width: 768px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: var(--radius); } }
.sheet h2 { margin: 0 0 var(--space-5); }
.field { margin-bottom: var(--space-5); }
.field label { display: block; font-size: var(--caption-size); font-weight: var(--h3-weight); color: var(--text2); margin-bottom: var(--space-2); }
.field input, .field select, .field textarea { width: 100%; min-height: var(--tap-target); padding: 0 var(--space-5);
  border: 1px solid var(--border-input); border-radius: var(--radius-sm); background: var(--white);
  color: var(--text); font-family: var(--font-sans); font-size: var(--body-size); }

/* ---------- Toast ---------- */
.toast-host { position: fixed; left: 0; right: 0; bottom: calc(var(--nav-h) + var(--space-5)); z-index: var(--z-toast);
  display: flex; flex-direction: column; align-items: center; gap: var(--space-2); pointer-events: none; }
.toast { background: var(--text); color: var(--white); padding: var(--space-3) var(--space-7); border-radius: var(--radius-xl);
  font-size: var(--body-sm-size); box-shadow: var(--shadow-lg); }
.toast.error { background: var(--red); }
@media (min-width: 768px) {
  .toast-host { bottom: var(--space-9); }
}

/* ---------- List rows / cards reuse .card from tokens.css ---------- */
.row { display: flex; align-items: center; gap: var(--space-5); }
.row .grow { flex: 1; min-width: 0; }
.row .muted { color: var(--text2); font-size: var(--caption-size); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: var(--tap-target); height: var(--tap-target);
  border: none; background: none; color: var(--text2); cursor: pointer; border-radius: var(--radius-sm); }
.tabnum { font-variant-numeric: tabular-nums lining-nums; }

/* ---------- Chips ---------- */
.chip { display: inline-flex; align-items: center; min-height: 24px; padding: 0 var(--space-3); border-radius: var(--radius-xl); background: var(--fill-tint); color: var(--text-mid); font-size: var(--caption-size); font-weight: var(--h3-weight); }
.chip-broadcast { background: var(--blue-tint); color: var(--blue-ink); }
.chip-open { background: var(--green-tint); color: var(--green-ink); }
.chip-pass { background: var(--green-tint); color: var(--green-ink); }
.chip-fail { background: var(--red-tint); color: var(--red); }

/* ---------- Muted text (standalone — also appears as .row .muted above) ---------- */
.muted { color: var(--text2); font-size: var(--caption-size); }

/* ---------- Weight utilities ---------- */
.semibold { font-weight: var(--h3-weight); }

/* --- auth: login screen + header actions --- */
.header-actions { display: inline-flex; align-items: center; gap: var(--space-3); }
.login-card {
  max-width: var(--app-max-w); margin: 0 auto; padding: var(--space-7) var(--space-5);
  display: flex; flex-direction: column; align-items: center; gap: var(--space-5); text-align: center;
}
.login-mark { font-weight: var(--h1-weight); letter-spacing: .04em; font-size: var(--h3-size); color: var(--text); }
.login-mark-edu { color: var(--blue); }
.login-tagline { color: var(--text2); }
.gis-button { display: flex; justify-content: center; min-height: var(--tap-target); }
.login-error { color: var(--red); font-size: var(--caption-size); }

/* ---------- Shared photo uploader tile (references + submissions) ---------- */
.photo-slot { position: relative; aspect-ratio: 4/3; border-radius: var(--radius-md);
  background: var(--fill-tint); border: 1px solid var(--border); overflow: hidden; cursor: pointer; }
.photo-slot[data-disabled="true"] { cursor: default; }
.photo-slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-slot-ph { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--text3); }
.photo-slot-ph svg { width: 28px; height: 28px; }
.photo-slot-label { position: absolute; left: var(--space-3); bottom: var(--space-2); z-index: 2;
  color: var(--white); font-size: var(--caption-size); font-weight: var(--h3-weight); text-shadow: 0 1px 3px rgba(0,0,0,.55); }
.photo-slot-overlay { position: absolute; top: var(--space-2); right: var(--space-2); z-index: 2;
  display: flex; align-items: center; justify-content: center; }
.photo-slot-overlay svg { width: 16px; height: 16px; }
.photo-slot[data-state="uploading"] .photo-slot-overlay { background: rgba(0,0,0,.45); border-radius: var(--radius-full); padding: 4px; }
.photo-slot[data-state="done"] .photo-slot-overlay { color: var(--white); background: var(--green); border-radius: var(--radius-full); padding: 2px; }
.photo-slot[data-state="error"] .photo-slot-overlay { color: var(--white); background: var(--red); border-radius: var(--radius-full); padding: 2px; }
.photo-slot-x { position: absolute; top: var(--space-2); left: var(--space-2); z-index: 3; padding: 0;
  display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px;
  border: none; border-radius: var(--radius-full); background: rgba(0,0,0,.55); color: var(--white); cursor: pointer; }
.photo-slot-x svg { width: 16px; height: 16px; }
/* spinner = CSS motion (design contract: never an emoji/icon for a spinner) */
.spinner { width: 18px; height: 18px; border: 2px solid var(--white); border-top-color: transparent;
  border-radius: var(--radius-full); animation: edu-spin .7s linear infinite; }
@keyframes edu-spin { to { transform: rotate(360deg); } }

/* ---------- Admin "View as" role-preview dropdown ---------- */
.viewas-select { height: var(--tap-target); padding: 0 var(--space-3); border: 1px solid var(--border);
  border-radius: var(--radius-md); background: var(--white); color: var(--text); font: inherit;
  font-size: var(--caption-size); cursor: pointer; }

/* ---------- Admin role-preview banner ---------- */
.view-banner { display: flex; align-items: center; gap: var(--space-2); margin: 0 var(--gutter) var(--space-3);
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-md);
  background: var(--blue-tint); color: var(--blue-ink); font-size: var(--caption-size); }
.view-banner svg { width: 16px; height: 16px; }
.btn[disabled] { opacity: .5; cursor: default; }
