/*
 * app.css — shared components (v1.2 Phase 22, UIK-01).
 * tokens.css holds values (colours, sizes, spacing); this file holds components
 * built from them. Load after tokens.css. Every selector here is either
 * namespaced (.app-*, .page-header) or a global accessibility rule, so adding
 * the file to a page cannot restyle that page's existing markup.
 */

:root {
  --app-ink: #1d2a22;
  --app-muted: #5b6660;
  --app-surface: #ffffff;
  --app-line: #dfe5e1;
  --app-success: #1f7a43;
  --app-danger: #b42318;
  --app-warning: #9a5b00;
  --app-info: var(--cu-green, #00421c);
  --app-shadow: 0 12px 32px -14px rgba(0, 33, 14, 0.45), 0 2px 6px rgba(0, 33, 14, 0.08);
  --app-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ---- Focus: one visible ring for keyboard users, everywhere (VIS-03) ---- */
:focus-visible {
  outline: 3px solid var(--cu-gold, #eab676);
  outline-offset: 2px;
}
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
  outline: 3px solid var(--cu-gold, #eab676);
  outline-offset: 2px;
  box-shadow: none;
}

/* ---- Page header -------------------------------------------------------- */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-sm, 8px) var(--space-md, 16px);
  margin: var(--space-sm, 8px) 0 var(--space-lg, 24px);
  padding-bottom: var(--space-sm, 8px);
  border-bottom: 1px solid var(--app-line);
}
.page-header-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--cu-green, #00421c);
}
.page-header-title::after {
  content: "";
  display: block;
  width: 48px;
  height: 3px;
  margin-top: 6px;
  border-radius: 2px;
  background: var(--cu-gold, #eab676);
}
.page-header-title .text-en {
  display: block;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--app-muted);
}
.page-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm, 8px);
}

/* ---- Notes (Ui::alert) -------------------------------------------------- */
.app-note {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: var(--space-md, 16px);
  padding: 12px 14px;
  border: 1px solid var(--app-line);
  border-left: 5px solid var(--app-tone, var(--app-info));
  border-radius: var(--radius-md, 8px);
  background: var(--app-surface);
  color: var(--app-ink);
}
.app-note > .bi { color: var(--app-tone, var(--app-info)); font-size: 1.15rem; line-height: 1.3; }
.app-note .text-en { display: block; }
.app-note-success { --app-tone: var(--app-success); background: #f3faf5; }
.app-note-danger { --app-tone: var(--app-danger); background: #fdf4f3; }
.app-note-warning { --app-tone: var(--app-warning); background: #fffaf0; }
.app-note-info { --app-tone: var(--app-info); }

/* ---- Toasts (App.toast) ------------------------------------------------- */
.app-toasts {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1090;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(400px, calc(100vw - 32px));
  pointer-events: none;
}
#app-toasts-alert { top: auto; bottom: 16px; }
.app-toast {
  --app-tone: var(--app-info);
  position: relative;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px 40px 14px 14px;
  border-radius: var(--radius-lg, 10px);
  border-left: 6px solid var(--app-tone);
  background: var(--app-surface);
  color: var(--app-ink);
  box-shadow: var(--app-shadow);
  font-size: var(--text-base, 14px);
  line-height: 1.4;
  pointer-events: auto;
  animation: app-toast-in 260ms var(--app-ease) both;
}
.app-toast-success { --app-tone: var(--app-success); }
.app-toast-danger { --app-tone: var(--app-danger); }
.app-toast-warning { --app-tone: var(--app-warning); }
.app-toast-icon { color: var(--app-tone); font-size: 1.25rem; line-height: 1.1; }
.app-toast-body { min-width: 0; overflow-wrap: anywhere; }
.app-toast-close { position: absolute; top: 12px; right: 12px; transform: scale(0.8); }
.app-toast-leaving { animation: app-toast-out 200ms ease-in both; }
.app-msg-tr,
.app-msg-line { display: block; }
.app-toast .text-en,
.app-dialog .text-en { display: block; margin-top: 2px; font-size: var(--text-sm, 12px); color: var(--app-muted); }

@keyframes app-toast-in {
  from { opacity: 0; transform: translateX(24px); }
  to { opacity: 1; transform: none; }
}
@keyframes app-toast-out {
  to { opacity: 0; transform: translateX(24px); }
}

/* ---- Dialogs (App.confirm / App.prompt) -------------------------------- */
.app-dialog .modal-content {
  border: 0;
  border-top: 6px solid var(--cu-green, #00421c);
  border-radius: 12px;
  box-shadow: var(--app-shadow);
}
.app-dialog-danger .modal-content { border-top-color: var(--app-danger); }
.app-dialog .modal-header { border-bottom: 0; padding-bottom: 0; align-items: flex-start; }
.app-dialog .modal-title {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--cu-green, #00421c);
}
.app-dialog-danger .modal-title { color: var(--app-danger); }
.app-dialog .modal-title .bi { font-size: 1.3rem; line-height: 1.1; }
.app-dialog-message { color: var(--app-ink); font-size: var(--text-base, 14px); line-height: 1.5; }
.app-dialog-message .text-en { margin-top: 6px; }
.app-dialog-input { margin-top: 12px; }
.app-dialog-counter { text-align: right; }
.app-dialog .modal-footer { border-top: 0; padding-top: 0; gap: 8px; }
/* Brand primary inside kit dialogs only; site-wide button colours are VIS work (Phase 27). */
.app-dialog .btn-primary {
  --bs-btn-bg: var(--cu-green, #00421c);
  --bs-btn-border-color: var(--cu-green, #00421c);
  --bs-btn-hover-bg: var(--cu-green-dark, #003318);
  --bs-btn-hover-border-color: var(--cu-green-dark, #003318);
  --bs-btn-active-bg: var(--cu-green-dark, #003318);
  --bs-btn-active-border-color: var(--cu-green-dark, #003318);
  --bs-btn-disabled-bg: var(--cu-green, #00421c);
  --bs-btn-disabled-border-color: var(--cu-green, #00421c);
}
.app-dialog .modal-footer .btn { min-height: 44px; min-width: 112px; }
.app-dialog .modal-footer .btn .text-en { margin-top: 0; font-size: 11px; color: inherit; opacity: 0.85; }

/* ---- Busy buttons (App.busy / data-loading) ---------------------------- */
.app-spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  margin-right: 0.45em;
  vertical-align: -0.15em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: app-spin 0.7s linear infinite;
}
.app-busy { cursor: progress; }
@keyframes app-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .app-toast,
  .app-toast-leaving { animation: none; }
  .app-spinner { animation-duration: 2s; }
}

@media (max-width: 575.98px) {
  .app-toasts { top: auto; bottom: 12px; right: 12px; left: 12px; width: auto; }
  #app-toasts-alert { bottom: auto; top: 12px; }
  .page-header-title { font-size: 1.2rem; }
}
