/* YAS Employee Portal — mobile-first LIFF styles. Neutral palette, one
   accent colour, tap targets >= 44px, safe-area padding for LINE's in-app
   browser. */

:root {
  --bg: #f4f2ec;
  --card: #ffffff;
  --text: #232323;
  --muted: #6b6b6b;
  --line: #e2ddd2;
  --accent: #0e6b4d;
  --accent-dark: #0a523c;
  --danger: #b3261e;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Thai", "Sarabun", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

/* Elements with display set in CSS ignore the hidden attribute otherwise. */
[hidden] {
  display: none !important;
}

.app-name {
  font-weight: 700;
  margin-inline-start: auto;
  color: var(--accent);
}

.home-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  padding: 10px 4px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.close-btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  min-height: 44px;
  padding: 0 16px;
  font: inherit;
  cursor: pointer;
}

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

h1 {
  font-size: 1.35rem;
  margin: 0 0 12px;
}

h2 {
  font-size: 1.1rem;
  margin: 20px 0 8px;
}

p {
  margin: 0 0 12px;
}

.muted {
  color: var(--muted);
}

.center {
  text-align: center;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:active {
  background: var(--accent-dark);
}

.btn-secondary {
  background: var(--card);
  border-color: var(--line);
  color: var(--text);
}

.btn-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.link-secondary {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Home tiles */

.tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 104px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 1.05rem;
  text-align: center;
  padding: 12px;
}

.tile:active {
  border-color: var(--accent);
}

.tile-disabled {
  color: var(--muted);
  background: #faf9f6;
}

.tile svg {
  color: var(--accent);
}

/* Lists */

.row-link {
  display: block;
  color: inherit;
  text-decoration: none;
  padding: 14px 16px;
  min-height: 44px;
}

.row-link:active {
  background: #faf9f6;
}

.row-title {
  font-weight: 500;
  margin-bottom: 4px;
}

.row-meta {
  color: var(--muted);
  font-size: 0.85rem;
}

.row-excerpt {
  color: var(--muted);
  font-size: 0.92rem;
  margin-top: 4px;
}

.badge {
  display: inline-block;
  font-size: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 10px;
  margin-inline-start: 8px;
  color: var(--muted);
}

/* Forms */

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-weight: 500;
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  font: inherit;
  background: var(--card);
  color: var(--text);
}

.field textarea {
  padding: 12px;
  resize: vertical;
}

/* Standalone label styled like .field label (for checkbox groups). */

.field-label {
  font-weight: 500;
  margin: 0 0 6px;
}

.hint {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 6px 0 0;
}

p.hint {
  margin-bottom: 12px;
}

.counter {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: end;
  margin: 4px 0 0;
}

.preview-line {
  background: #eef4f0;
  border: 1px solid #cfddd4;
  border-radius: var(--radius);
  padding: 10px 14px;
}

/* Checkbox rows (roles, audience, toggles). */

.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 6px 0;
  cursor: pointer;
}

.check-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  accent-color: var(--accent);
}

.check-row input[type="checkbox"]:disabled + span {
  color: var(--muted);
}

/* Tabs (status filter, kind filter, lookups). */

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
}

.tab {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  white-space: nowrap;
  padding: 0 12px;
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}

/* Danger button, busy and disabled states. */

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn:disabled {
  opacity: 0.65;
  cursor: default;
}

.btn-busy {
  opacity: 0.75;
}

/* Badges and per-row action areas. */

.badge-danger {
  border-color: #e5b3ae;
  color: var(--danger);
}

.row-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 16px 14px;
}

.row-actions .btn {
  min-height: 44px;
}

/* Error box with a fix checklist (R2 key problems). */

.error-box {
  background: #fdf0ef;
  border: 1px solid #e5b3ae;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-top: 12px;
}

.error-box p {
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}

.check-list {
  margin: 0;
  padding-inline-start: 20px;
  font-size: 0.92rem;
}

.check-list li {
  margin-bottom: 4px;
}

/* In-page confirm modal (replaces native confirm()). */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(35, 35, 35, 0.55);
}

.modal-box {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
}

.modal-title {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.modal-message {
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.modal-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.field-error {
  color: var(--danger);
  font-size: 0.88rem;
  margin: 6px 0 0;
}

.form-note {
  background: #fdf6e4;
  border: 1px solid #e8d9a8;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

.success-note {
  background: #e9f5ee;
  border: 1px solid #bfe3cf;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

/* Article body: preserve line breaks, content is always textContent. */

.article-body {
  white-space: pre-line;
  overflow-wrap: anywhere;
}

/* Definition rows (profile) */

.def-row {
  display: flex;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.def-row:last-child {
  border-bottom: none;
}

.def-label {
  flex: 0 0 110px;
  color: var(--muted);
}

.def-value {
  flex: 1;
  overflow-wrap: anywhere;
}

/* Document viewer */

.page-indicator {
  position: sticky;
  top: 56px;
  z-index: 5;
  text-align: center;
  margin-bottom: 12px;
}

.page-indicator span {
  display: inline-block;
  background: rgba(35, 35, 35, 0.85);
  color: #fff;
  font-size: 0.85rem;
  border-radius: 999px;
  padding: 4px 14px;
}

.page-slot {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 12px;
  overflow: hidden;
  min-height: 120px;
}

.page-slot canvas {
  display: block;
  width: 100%;
  height: auto;
}

.page-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  min-height: 120px;
}

/* Video viewer */

.video-wrap {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

.video-wrap video {
  display: block;
  width: 100%;
  max-height: 70vh;
}

.watermark-video {
  position: absolute;
  pointer-events: none;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 0.8rem;
  border-radius: 6px;
  padding: 4px 10px;
  max-width: 88%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Loading spinner */

.loading {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
}

.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto 12px;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }
}

/* T8 nits bundled with T9. */

.advanced-details {
  margin-bottom: 16px;
}

/* Visually-hidden file inputs stay activatable through their label
   button; display:none would break label activation. */
input[type="file"].file-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
}

/* label.btn file pickers sit inside .field, whose label rule sets
   display:block — that would undo the .btn flex layout (and its
   vertical centering), so restore the plain secondary-button look. */
.field label.btn {
  display: inline-flex;
  margin-bottom: 0;
}

/* T9 requests + certificate print. */

.badge-ok {
  border-color: #bfe3d2;
  color: var(--accent);
}

/* Superseded issues stay visible but marked (T9 Decision 7). */
.card.superseded {
  opacity: 0.72;
}

.superseded-note {
  color: var(--danger);
}

.attach-box {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.print-wrap {
  overflow-x: auto;
}

.print-sheet {
  margin: 0 auto;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
}

@page {
  size: A4;
  margin: 0;
}

@media print {
  .topbar,
  .no-print {
    display: none !important;
  }
  body {
    background: #ffffff;
  }
  .view {
    max-width: none;
    margin: 0;
    padding: 0;
  }
  .print-wrap {
    overflow: visible;
  }
  .print-sheet {
    margin: 0;
    box-shadow: none;
  }
  /* The seal placeholder keeps its space on paper, but its dashed
     border and text stay on screen only (!important beats the inline
     print-sheet styles). */
  .cert-seal {
    border-color: transparent !important;
    color: transparent !important;
  }
}
