/* MICA Document Portal — design system
 *
 * Ported by hand from stitch_design/.../mica_document_portal/DESIGN.md.
 * No Tailwind, no icon font, no runtime CSS dependency: the only external
 * request is the Google Fonts stylesheet for Inter + Noto Sans JP.
 *
 * Layers, in order: tokens → base → primitives → components → layout →
 * responsive. Class names are stable contracts used by assets/render.js.
 */

/* ---------------------------------------------------------------- tokens - */
:root {
  /* brand */
  --primary: #001e40;
  --primary-container: #003366;
  --primary-hover: #002b5c;
  --on-primary: #ffffff;
  --secondary: #b6171e;

  /* surface tiers (DESIGN.md "Elevation & Depth") */
  --surface: #f7f9fc;                 /* level 0 — app background */
  --surface-container-lowest: #ffffff;/* level 1 — cards, rows, inputs */
  --surface-container: #eceef1;
  --surface-hover: #eef2ff;           /* row hover tint */

  /* text */
  --on-surface: #191c1e;
  --on-surface-variant: #43474f;
  --text-main: #1f2430;

  /* lines */
  --outline-variant: #c3c6d1;
  --border-muted: #e5e8ee;
  --input-border: #d7dae0;

  /* status */
  --status-approved: #2e7d32;
  --status-warning: #f57c00;
  --status-rejected: #d32f2f;
  --status-approved-bg: #e9f9ee;
  --status-warning-bg: #fff4e5;
  --status-rejected-bg: #fdeceb;
  --status-neutral-bg: #f1f3f6;

  --background-paper: #faf6ec;        /* document preview only */

  /* shape */
  --radius: 0.25rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;
  --radius-full: 9999px;

  /* spacing — strict 4/8 grid */
  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 16px;
  --sp-lg: 24px;
  --sp-xl: 32px;

  --sidebar-width: 320px;
  --appbar-height: 64px;
  --paper-max: 560px;

  --shadow-1: 0 4px 12px rgba(0, 51, 102, 0.08);
  --focus-ring: 0 0 0 2px rgba(0, 51, 102, 0.18);

  --font-display: Inter, system-ui, -apple-system, sans-serif;
  --font-body: 'Noto Sans JP', 'Hiragino Sans', system-ui, sans-serif;
}

/* ------------------------------------------------------------------ base - */
* { box-sizing: border-box; }

/* The pages toggle sections with .hidden = true. Without this, any element
   carrying its own display declaration ignores the attribute entirely. */
[hidden] { display: none !important; }

body {
  margin: 0;
  /* Long emails, filenames and URLs must break rather than widen the page.
     break-word only breaks a word that cannot fit, so normal text is untouched. */
  overflow-wrap: break-word;
  background: var(--surface);
  color: var(--on-surface);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { font-family: var(--font-display); margin: 0 0 var(--sp-sm); color: var(--on-surface); }
h1 { font-size: 32px; font-weight: 700; line-height: 1.2; }
h2 { font-size: 24px; font-weight: 600; line-height: 1.3; }
h3 { font-size: 18px; font-weight: 600; line-height: 1.4; }

p { margin: 0 0 var(--sp-sm); }
a { color: var(--primary-container); }

.muted { color: var(--on-surface-variant); }
.error { color: var(--status-rejected); }
.caption { font-size: 12px; line-height: 1.4; }
.caption-xs { font-size: 11px; line-height: 1.2; }
.label { font-size: 14px; font-weight: 500; line-height: 1.4; }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }

/* Cyrillic and Japanese both run long; never let a flex child refuse to shrink. */
.flex-min { min-width: 0; overflow-wrap: anywhere; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ------------------------------------------------------------ primitives - */
.card {
  background: var(--surface-container-lowest);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-lg);
  padding: var(--sp-md);
}
.card-flush { padding: 0; overflow: hidden; }

.section-header {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--on-surface-variant);
  margin: var(--sp-lg) 0 var(--sp-sm);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-sm);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 16px;
  font: inherit;
  font-weight: 500;
  line-height: 1.4;
  cursor: pointer;
  text-decoration: none;
}
.btn-sm { padding: 4px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--status-rejected); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(0.94); }
.btn-outline {
  background: var(--surface-container-lowest);
  color: var(--text-main);
  border-color: var(--border-muted);
}
.btn-outline:hover:not(:disabled) { border-color: var(--primary); background: var(--surface-hover); }
.btn-ghost { background: transparent; color: var(--primary-container); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
/* Every keyboard-focusable control shows focus, including checkboxes, the
   bottom navigation and the <label> that fronts a hidden file input. */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.visually-hidden:focus-visible + .btn,
.visually-hidden:focus + .btn { outline: 2px solid var(--primary); outline-offset: 2px; }

.input, input[type="text"], input[type="email"], input[type="tel"], input[type="date"], select, textarea {
  width: 100%;
  padding: 8px 12px;
  font: inherit;
  color: var(--on-surface);
  background: var(--surface-container-lowest);
  border: 1px solid var(--input-border);
  border-radius: var(--radius);
}
.input:focus, input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}
.field { display: block; margin-bottom: var(--sp-md); }
.field > .field-label {
  display: block;
  margin-bottom: var(--sp-sm);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
}
.field-hint { display: block; margin-top: var(--sp-xs); font-size: 12px; color: var(--on-surface-variant); }

/* status pills — 11px bold, pill shape (DESIGN.md "Status Chips") */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-xs);
  border-radius: var(--radius-full);
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.5;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-approved { background: var(--status-approved-bg); color: var(--status-approved); }
.badge-review   { background: var(--status-warning-bg);  color: var(--status-warning); }
.badge-rejected { background: var(--status-rejected-bg); color: var(--status-rejected); }
.badge-draft    { background: var(--status-warning-bg);  color: var(--status-warning); }
.badge-none     { background: var(--status-neutral-bg);  color: var(--on-surface-variant); }

/* count chips — circular, one per real status we actually hold */
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 700;
}
.chip-approved { background: var(--status-approved-bg); color: var(--status-approved); }
.chip-review   { background: var(--status-warning-bg);  color: var(--status-warning); }
.chip-rejected { background: var(--status-rejected-bg); color: var(--status-rejected); }
.chip-none     { background: var(--status-neutral-bg);  color: var(--on-surface-variant); }
.chip-group { display: inline-flex; gap: var(--sp-xs); }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: var(--radius-full);
  background: var(--primary-container);
  color: var(--on-primary);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}
.avatar-lg { width: 48px; height: 48px; flex-basis: 48px; font-size: 16px; }

.icon { width: 20px; height: 20px; flex: 0 0 auto; display: inline-block; vertical-align: -4px; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }

.progress-track { height: 4px; background: #f5f6f8; border-radius: var(--radius-full); overflow: hidden; }
.progress-fill { height: 4px; background: var(--status-approved); border-radius: var(--radius-full); }
.progress-fill.is-low { background: var(--status-warning); }

.divider { height: 1px; background: var(--border-muted); border: 0; margin: var(--sp-md) 0; }

.empty-state {
  padding: var(--sp-xl) var(--sp-md);
  text-align: center;
  color: var(--on-surface-variant);
}

/* ------------------------------------------------------------- components - */
table { width: 100%; border-collapse: collapse; background: var(--surface-container-lowest); }
th, td { text-align: left; padding: 12px var(--sp-md); border-bottom: 1px solid var(--border-muted); }
th {
  font-size: 12px;
  font-weight: 500;
  color: var(--on-surface-variant);
  background: var(--surface);
  text-transform: none;
  white-space: nowrap;
}
tbody tr:hover { background: var(--surface-hover); }
.table-wrap {
  background: var(--surface-container-lowest);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}
.table-foot {
  padding: 12px var(--sp-md);
  font-size: 12px;
  color: var(--on-surface-variant);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-sm);
}

/* document status card — the workhorse of the student portal */
.doc-card {
  background: var(--surface-container-lowest);
  border: 1px solid var(--border-muted);
  border-left: 4px solid var(--border-muted);
  border-radius: var(--radius-lg);
  padding: var(--sp-md);
  margin-bottom: var(--sp-md);
}
.doc-card-rejected { border-left-color: var(--status-rejected); }
.doc-card-pending  { border-left-color: var(--status-warning); }
.doc-card-approved { border-left-color: var(--status-approved); }
.doc-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-sm); }
.doc-card-title { font-weight: 700; }
.doc-note {
  margin-top: var(--sp-sm);
  padding: var(--sp-sm) 12px;
  border-radius: var(--radius);
  font-size: 13px;
}
.doc-note-rejected { background: var(--status-rejected-bg); color: #8c1d18; }
.doc-note-pending  { background: var(--status-warning-bg);  color: #7a4a00; }

/* compact row form for already-settled documents */
.doc-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-sm) var(--sp-md);
  padding: 12px var(--sp-md);
  border-bottom: 1px solid var(--border-muted);
  background: var(--surface-container-lowest);
}
.doc-row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-sm); flex: 0 0 auto; }
.doc-row:last-child { border-bottom: 0; }
.doc-row:hover { background: var(--surface-hover); }

.dropzone {
  border: 2px dashed var(--primary);
  border-radius: var(--radius-lg);
  padding: var(--sp-md);
  text-align: center;
  background: #f5f7ff;
}
.dropzone-icon {
  width: 56px; height: 56px;
  margin: 0 auto var(--sp-sm);
  display: grid; place-items: center;
  border-radius: var(--radius-lg);
  background: var(--primary);
  color: var(--on-primary);
}

/* the registration-first pipeline, shown as an explicit journey */
.pipeline { display: flex; flex-wrap: wrap; gap: var(--sp-xs); align-items: center; margin: var(--sp-sm) 0; }
.pipeline-step {
  display: inline-flex; align-items: center; gap: var(--sp-xs);
  padding: 2px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-muted);
  background: var(--surface-container-lowest);
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  color: var(--on-surface-variant);
}
.pipeline-step.is-done    { background: var(--status-approved-bg); color: var(--status-approved); border-color: transparent; }
.pipeline-step.is-current { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.pipeline-sep { color: var(--outline-variant); font-size: 11px; }

.paper {
  background: var(--background-paper);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  padding: var(--sp-md);
  max-width: var(--paper-max);
}

.notice {
  padding: var(--sp-sm) 12px;
  border-radius: var(--radius);
  border-left: 4px solid var(--status-warning);
  background: var(--status-warning-bg);
  color: #7a4a00;
  font-size: 13px;
}
.notice-info { border-left-color: var(--primary-container); background: var(--surface-hover); color: var(--text-main); }

/* ----------------------------------------------------------------- layout - */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--surface-container-lowest);
  border-right: 1px solid var(--border-muted);
  padding: var(--sp-lg);
  display: flex;
  flex-direction: column;
}
.sidebar-brand { font-family: var(--font-display); font-size: 22px; font-weight: 700; color: var(--primary); line-height: 1.2; }
.sidebar-nav { margin-top: var(--sp-lg); display: flex; flex-direction: column; gap: var(--sp-xs); flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--on-surface-variant);
  text-decoration: none;
  font-weight: 500;
}
.nav-item:hover { background: var(--surface-hover); }
.nav-item.is-active { color: var(--primary); background: var(--surface-hover); box-shadow: inset 2px 0 0 var(--primary); }
.sidebar-foot { display: flex; align-items: center; gap: var(--sp-sm); padding-top: var(--sp-md); border-top: 1px solid var(--border-muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.appbar {
  height: var(--appbar-height);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  padding: 0 var(--sp-lg);
  background: var(--surface-container-lowest);
  border-bottom: 1px solid var(--border-muted);
}
.appbar-title { font-family: var(--font-display); font-weight: 700; color: var(--primary); font-size: 18px; }
.appbar-spacer { flex: 1; }
.content { padding: var(--sp-lg); flex: 1; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: var(--sp-md); align-items: flex-end;
  background: var(--surface-container-lowest);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-lg);
  padding: var(--sp-md);
  margin-bottom: var(--sp-lg);
}
.toolbar .field { margin-bottom: 0; }

.search { position: relative; display: flex; align-items: center; }
.search .icon { position: absolute; left: 10px; color: var(--on-surface-variant); pointer-events: none; }
.search input { padding-left: 36px; }

/* Source and draft side by side on desktop, sequential on mobile. */
.translate-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--sp-lg); align-items: start; }
.attest {
  display: flex; gap: var(--sp-sm); align-items: flex-start;
  padding: 10px 0; border-bottom: 1px solid var(--border-muted);
}
.attest:last-of-type { border-bottom: 0; }
.attest input { margin-top: 4px; flex: 0 0 auto; width: 18px; height: 18px; }

.workspace { display: grid; grid-template-columns: 340px minmax(0, 1fr) 300px; gap: var(--sp-lg); align-items: start; }
.stack { display: flex; flex-direction: column; gap: var(--sp-md); }
.row { display: flex; align-items: center; gap: var(--sp-sm); min-width: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-sm); }

/* mobile shell */
.mobile-shell { max-width: 640px; margin: 0 auto; padding: var(--sp-md) var(--sp-md) 96px; }
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  max-width: 100vw;
  display: flex;
  background: var(--surface-container-lowest);
  border-top: 1px solid var(--border-muted);
  padding: var(--sp-sm);
  gap: var(--sp-sm);
  z-index: 10;
}
.bottom-nav-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: var(--sp-sm);
  border: 0; border-radius: var(--radius-md);
  background: transparent;
  font: inherit; font-size: 12px;
  color: var(--on-surface-variant);
  cursor: pointer;
}
.bottom-nav-item.is-active { background: var(--primary); color: var(--on-primary); }

pre { white-space: pre-wrap; word-break: break-word; font-family: var(--font-body); margin: 0; }

/* ------------------------------------------------------------- responsive - */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .translate-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-basis: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border-muted);
    padding: var(--sp-md);
  }
  .sidebar-nav { flex-direction: row; overflow-x: auto; }
  .sidebar-foot { border-top: 0; padding-top: var(--sp-sm); }
  .content, .appbar { padding: var(--sp-md); }
  .appbar { height: auto; padding-top: var(--sp-sm); padding-bottom: var(--sp-sm); }
  h1 { font-size: 24px; }
  h2 { font-size: 20px; }
  .toolbar { flex-direction: column; align-items: stretch; }
}
