/* MT Exam Studio — layout.css (app shell: header / sidebar / preview) */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ===== Header — white surface, subtle border, calm nav ===== */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  height: var(--header-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 30;
}

/* Logo wordmark */
.app-header .logo {
  display: flex;
  align-items: baseline;
  gap: 4px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: .5px;
  white-space: nowrap;
  min-width: 0;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
}
.app-header .logo .logo-mt { color: var(--color-primary-deep); }
.app-header .logo .logo-exam { color: var(--color-primary); }

/* Primary navigation */
.header-nav {
  display: flex;
  gap: 6px;
  align-items: center;
}
.header-nav .nav-link {
  padding: 7px 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: .84rem;
  color: var(--color-text-muted);
  text-decoration: none;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.header-nav .nav-link:hover { background: var(--color-primary-soft); color: var(--color-primary-dark); }
.header-nav .nav-link.active {
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  box-shadow: inset 0 -2px 0 var(--color-primary);
}

.app-header .spacer { flex: 1; }
.app-header .header-actions { display: flex; gap: 6px; align-items: center; min-width: 0; }

/* Desktop: keep the nav centered in the header bar */
@media (min-width: 901px) {
  .app-header .header-nav {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
  }
}

/* Hamburger menu icon (CSS-based) */
.hamburger {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  position: relative;
}
.hamburger::before, .hamburger::after {
  content: '';
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background: currentColor;
}
.hamburger::before { top: -6px; }
.hamburger::after { top: 6px; }

/* Icon buttons (subtle) */
.app-header .icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--color-text-muted);
  font-size: .9rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--duration-fast) var(--ease), color var(--duration-fast) var(--ease);
}
.app-header .icon-btn:hover { background: var(--color-primary-soft); color: var(--color-primary-dark); }
.app-header .icon-btn:active { transform: translateY(1px); }

/* Icon button image sizing */
.app-header .icon-btn .btn-icon {
  display: block;
  width: 84%;
  height: auto;
  object-fit: contain;
}

/* Desktop: header action buttons show text labels, not icon images */
.app-header .header-actions .icon-btn:not(.nav-toggle) {
  width: auto;
  padding: 0 10px;
  gap: 6px;
  font-size: .8rem;
  font-weight: 600;
}
.app-header .header-actions .icon-btn:not(.nav-toggle) .btn-icon { display: none; }
.app-header .header-actions .icon-btn:not(.nav-toggle) .btn-label { display: inline; }

/* Language chip */
.lang-chip {
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-primary-dark);
  border-radius: 20px;
  cursor: pointer;
  font-weight: 600;
  font-size: .75rem;
  transition: all var(--duration-fast) var(--ease);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}
.lang-chip:hover { background: var(--color-primary-soft); border-color: var(--color-primary); }

/* Header actions use calm secondary style */
.app-header .header-actions .btn.secondary {
  background: var(--color-surface);
  color: var(--color-primary-dark);
  border-color: var(--color-border-strong);
}
.app-header .header-actions .btn.sm {
  height: 32px;
  padding: 0 10px;
  font-size: .78rem;
  border-radius: 8px;
}

/* ===== Mobile header nav drawer ===== */
.app-header .nav-toggle { display: none; }
@media (max-width: 900px) {
  .app-header { padding: 0 16px; }
  .header-nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-card);
    padding: 8px 16px;
    z-index: 40;
  }
  .app-header.nav-open .header-nav { display: flex; }
  .header-nav .nav-link { padding: 12px 16px; border-radius: 12px; }
  .app-header .nav-toggle { display: inline-flex; }
  .app-header .header-actions { gap: 4px; }
  .app-header .icon-btn { width: 34px; height: 34px; }

  /* On mobile: show icon images, hide text labels */
  .app-header .header-actions .icon-btn:not(.nav-toggle) {
    width: 38px;
    padding: 0;
    gap: 0;
    font-size: 0;
    font-weight: 400;
  }
  .app-header .header-actions .icon-btn:not(.nav-toggle) .btn-icon { display: block; }
  .app-header .header-actions .icon-btn:not(.nav-toggle) .btn-label { display: none; }
}

@media (max-width: 640px) {
  .app-header { gap: 10px; }
  .lang-chip {
    height: 30px;
    padding: 0 10px;
    font-size: .75rem;
  }
  .app-header .btn { height: 32px; padding: 0 12px; font-size: .8rem; }
}

/* ===== App body ===== */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar: slim section-list column, hidden on mobile, static on desktop */
.app-sidebar {
  display: none;
  flex-shrink: 0;
  width: 280px;
  max-width: 280px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}
@media (min-width: 1024px) {
  .app-sidebar { display: block; }
}

.app-main {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

#previewArea {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-bottom: 32px;
}

#paperPreview {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.sidebar-section {
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 14px;
  margin-bottom: 14px;
}
.sidebar-section:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.sidebar-section h3 {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--color-text-muted);
  margin-bottom: 10px;
}

/* Section card (sidebar) — single compact row */
.section-card .section-card-row1 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-card .section-card-row1 .input { flex: 1; min-width: 0; }

.section-card .section-del {
  flex-shrink: 0;
  min-width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  color: var(--color-text-muted);
  font-size: .9rem;
  line-height: 1;
}
.section-card .section-del:hover {
  background: var(--color-error-bg);
  color: var(--color-error);
}

/* Drag & drop reordering */
.section-card[draggable="true"] { cursor: grab; }
.section-card[draggable="true"]:active { cursor: grabbing; }
.section-card.section-card-dragging { opacity: .5; border-style: dashed; }
.section-card.section-card-dragover {
  border: 2px solid var(--color-primary);
  box-shadow: var(--shadow-focus);
}

/* Disabled buttons — clear "not clickable" styling */
.btn:disabled,
.btn[disabled],
.btn.btn-disabled {
  opacity: .45;
  cursor: not-allowed;
  filter: none;
}
.btn:disabled:hover,
.btn[disabled]:hover,
.btn.btn-disabled:hover { background: inherit; }

/* ===== Top bar inside main — document title + save status ===== */
.main-topbar {
  width: 100%;
  max-width: var(--container-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.main-topbar .doc-title {
  font-size: 1.15rem;
  font-weight: 700;
  min-width: 0;
  flex: 1;
}
.main-topbar .doc-title input {
  border: 0;
  border-bottom: 1px dashed var(--color-border);
  background: transparent;
  font-weight: 700;
  font-size: 1.15rem;
  padding: 2px 4px;
  width: 100%;
  min-width: 140px;
  color: var(--color-heading);
}
.main-topbar .doc-title input:focus { outline: none; border-bottom-color: var(--color-primary); }
.main-topbar .doc-title input::placeholder { color: var(--color-text-muted); }

/* Save / draft status indicator (tiny, next to title) */
.save-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  font-weight: 600;
  color: var(--color-text-muted);
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--color-primary-pale);
  white-space: nowrap;
}
.save-status .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.save-status.saved { color: var(--color-ok); background: var(--color-ok-bg); }
.save-status.saved .dot { background: var(--color-ok); }
.save-status.saving { color: var(--color-warn); background: var(--color-warn-bg); }
.save-status.saving .dot { background: var(--color-warn-fill); }
.save-status.unsaved { color: var(--color-text-muted); }
.save-status.unsaved .dot { background: var(--color-border-strong); }

/* Count / marks badges */
.main-topbar .mt-row .badge {
  font-size: .78rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--color-primary-pale);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

/* Primary actions row in the top bar */
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Status strip (validation summary) */
.status-strip {
  width: 100%;
  max-width: var(--container-sm);
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  padding: 6px 12px;
  border-radius: var(--radius);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  font-size: .78rem;
  line-height: 1.3;
}
.status-strip.has-details {
  cursor: pointer;
  user-select: none;
  transition: background var(--duration-fast) var(--ease);
}
.status-strip.has-details:hover { background: var(--color-primary-pale); }
.status-strip.has-details:active { background: var(--color-border); }
.status-strip .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--color-ok); display: inline-block; flex-shrink: 0; }
.status-strip.has-warnings .pulse { background: var(--color-warn-fill); }
.status-strip.has-errors .pulse { background: var(--color-error-fill); }
.status-strip #statusText {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-strip .status-chevron {
  flex-shrink: 0;
  color: var(--color-text-muted);
  font-size: .75rem;
}
.status-review-badge {
  flex-shrink: 0;
  background: var(--color-warn-bg);
  color: var(--color-warn);
  border: 1px solid var(--color-warn-fill);
  border-radius: 20px;
  padding: 1px 8px;
  font-size: .7rem;
  font-weight: 700;
  white-space: nowrap;
}

/* Status details popup */
.status-detail-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 55vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.status-detail-list li {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-alt, var(--color-bg));
  border: 1px solid var(--color-border);
  line-height: 1.45;
}
.status-detail-list li.status-detail-error { border-left: 3px solid var(--color-error); }
.status-detail-list li.status-detail-warning { border-left: 3px solid var(--color-warn-fill); }
.status-detail-list li.status-detail-info { border-left: 3px solid var(--color-primary); }
.status-detail-list li.navigable {
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease), transform .1s var(--ease);
}
.status-detail-list li.navigable:hover { background: var(--color-primary-soft); }
.status-detail-list li.navigable:active { transform: scale(.99); }

/* ===== Tablet / mobile ===== */
@media (max-width: 900px) {
  .app-main {
    overflow-y: auto;
    width: 100%;
    padding: 16px;
  }
}

/* ===== Small phones ===== */
@media (max-width: 480px) {
  .app-header {
    gap: 6px;
    padding: 0 10px;
  }
  .app-header .logo { font-size: 1.2rem; letter-spacing: 1px; }
  .app-header .icon-btn { width: 32px; height: 32px; }
  .app-header .header-actions .btn { height: 32px; padding: 0 10px; font-size: .78rem; }
  .app-main { padding: 12px; }
  .main-topbar { gap: 8px; }
}

/* ===== Footer — compact ===== */
.app-footer {
  width: 100%;
  max-width: var(--container-sm);
  margin-top: auto;
  margin-bottom: 8px;
  padding: 20px 20px 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
}
.app-footer-brand {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 100%;
}
.app-footer-logo {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: .5px;
}
.app-footer-logo .logo-mt { color: var(--color-primary-deep); }
.app-footer-logo .logo-exam { color: var(--color-primary); }
.app-footer-tagline { margin: 0; font-size: .86rem; font-weight: 600; color: var(--color-text); line-height: 1.5; }
.app-footer-feedback {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: .8rem;
  line-height: 1.5;
  text-decoration: none;
  color: var(--color-primary-dark);
  font-weight: 600;
  transition: color var(--duration-fast) var(--ease);
}
.app-footer-feedback:hover { color: var(--color-primary); }
.app-footer-feedback img { width: 14px; height: 14px; vertical-align: middle; margin-right: 3px; }
.app-footer-links {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: .8rem;
}
.app-footer-links a {
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: 600;
}
.app-footer-links a:hover { color: var(--color-primary-dark); text-decoration: underline; }
.app-footer-btn {
  background: none;
  border: 0;
  color: var(--color-primary-dark);
  font-weight: 600;
  font-size: .8rem;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 8px;
  transition: all var(--duration-fast) var(--ease);
}
.app-footer-btn:hover { background: var(--color-primary-soft); color: var(--color-primary); }
.app-footer-legal {
  flex: 1 1 100%;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}
.app-footer-legal p { margin: 0; font-size: .74rem; line-height: 1.5; color: var(--color-text-muted); }
.app-footer-privacy { opacity: .85; }

@media (min-width: 601px) {
  .app-footer { display: grid; grid-template-columns: 1fr auto; gap: 12px 24px; padding: 24px 24px 20px; }
  .app-footer-brand { grid-column: 1; grid-row: 1 / 3; }
  .app-footer-links { grid-column: 2; grid-row: 1; justify-self: end; }
  .app-footer-legal { grid-column: 1 / -1; grid-row: 2; }
}

@media (max-width: 600px) {
  .app-footer { padding: 16px 14px; }
  .app-footer-links { flex-wrap: wrap; }
}
