/* ==================== AKM COMPONENT DESIGN SYSTEM ====================
 * Design tokens + reusable primitives for the modernization roadmap
 * (docs/MODERNIZATION_PLAN.md §26). Purely additive — existing pages'
 * styles are untouched; new pages (contacts/soa/import-export/reports)
 * and the nav shell opt into these classes.
 * Brand: theme #0760a8, Montserrat (already loaded by index.html/dashboard.html).
 */

:root {
  --akm-primary: #0760a8;
  --akm-primary-dark: #054d87;
  --akm-primary-light: #eaf2fb;
  --akm-success: #1e8e5a;
  --akm-success-bg: #e8f6ef;
  --akm-warning: #b45309;
  --akm-warning-bg: #fff7ed;
  --akm-danger: #c0362c;
  --akm-danger-bg: #fdecea;
  --akm-text: #212121;
  --akm-text-muted: #6e6e6e;
  --akm-border: #e2e5ea;
  --akm-bg: #f7f9fc;
  --akm-surface: #ffffff;
  --akm-radius: 8px;
  --akm-radius-sm: 4px;
  --akm-shadow: 0 2px 8px rgba(7, 96, 168, 0.08);
  --akm-shadow-hover: 0 4px 14px rgba(7, 96, 168, 0.14);
  --akm-space-1: 4px;
  --akm-space-2: 8px;
  --akm-space-3: 12px;
  --akm-space-4: 16px;
  --akm-space-5: 24px;
  --akm-space-6: 32px;
  --akm-font: 'Montserrat', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ── Page shell ─────────────────────────────────────────────────────────── */
.akm-page {
  font-family: var(--akm-font);
  color: var(--akm-text);
  background: var(--akm-bg);
  min-height: 100vh;
}

.akm-page__body {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--akm-space-5) var(--akm-space-4) var(--akm-space-6);
}

.akm-page__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--akm-space-3);
  margin-bottom: var(--akm-space-5);
  flex-wrap: wrap;
}

.akm-page__title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--akm-primary);
  margin: 0;
}

.akm-page__subtitle {
  font-size: 0.85rem;
  color: var(--akm-text-muted);
  margin: 2px 0 0;
}

/* ── Cards ──────────────────────────────────────────────────────────────── */
.akm-card {
  background: var(--akm-surface);
  border: 1px solid var(--akm-border);
  border-radius: var(--akm-radius);
  box-shadow: var(--akm-shadow);
  padding: var(--akm-space-4);
}

.akm-card + .akm-card {
  margin-top: var(--akm-space-4);
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.akm-btn {
  font-family: var(--akm-font);
  font-weight: 600;
  font-size: 0.85rem;
  border-radius: var(--akm-radius-sm);
  border: 1px solid transparent;
  padding: 9px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
  line-height: 1.2;
}
.akm-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.akm-btn--primary { background: var(--akm-primary); color: #fff; }
.akm-btn--primary:hover:not(:disabled) { background: var(--akm-primary-dark); box-shadow: var(--akm-shadow-hover); }

.akm-btn--secondary { background: var(--akm-surface); color: var(--akm-primary); border-color: var(--akm-primary); }
.akm-btn--secondary:hover:not(:disabled) { background: var(--akm-primary-light); }

.akm-btn--danger { background: var(--akm-danger); color: #fff; }
.akm-btn--danger:hover:not(:disabled) { background: #a02c24; }

.akm-btn--ghost { background: transparent; color: var(--akm-text-muted); border-color: var(--akm-border); }
.akm-btn--ghost:hover:not(:disabled) { background: var(--akm-bg); }

.akm-btn--sm { padding: 5px 10px; font-size: 0.78rem; }

/* ── Form fields ────────────────────────────────────────────────────────── */
.akm-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--akm-space-3); }
.akm-field label { font-size: 0.78rem; font-weight: 700; color: var(--akm-text-muted); text-transform: uppercase; letter-spacing: 0.02em; }
.akm-field input, .akm-field select, .akm-field textarea {
  font-family: var(--akm-font);
  font-size: 0.9rem;
  padding: 9px 11px;
  border: 1px solid var(--akm-border);
  border-radius: var(--akm-radius-sm);
  background: var(--akm-surface);
  color: var(--akm-text);
}
.akm-field input:focus, .akm-field select:focus, .akm-field textarea:focus {
  outline: none;
  border-color: var(--akm-primary);
  box-shadow: 0 0 0 3px var(--akm-primary-light);
}
.akm-field--error input, .akm-field--error select { border-color: var(--akm-danger); }
.akm-field__hint { font-size: 0.75rem; color: var(--akm-text-muted); }
.akm-field__error { font-size: 0.75rem; color: var(--akm-danger); }

.akm-form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--akm-space-3); }

/* ── Badges ─────────────────────────────────────────────────────────────── */
.akm-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.akm-badge--success { background: var(--akm-success-bg); color: var(--akm-success); }
.akm-badge--warning { background: var(--akm-warning-bg); color: var(--akm-warning); }
.akm-badge--danger  { background: var(--akm-danger-bg);  color: var(--akm-danger); }
.akm-badge--neutral { background: var(--akm-bg); color: var(--akm-text-muted); }

/* ── Table wrapper ──────────────────────────────────────────────────────── */
.akm-table-wrap { overflow-x: auto; border: 1px solid var(--akm-border); border-radius: var(--akm-radius); background: var(--akm-surface); }
.akm-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; min-width: 560px; }
.akm-table th {
  background: var(--akm-primary-light);
  color: var(--akm-primary-dark);
  text-align: left;
  font-weight: 700;
  padding: 10px 12px;
  border-bottom: 1px solid var(--akm-border);
  white-space: nowrap;
}
.akm-table td { padding: 10px 12px; border-bottom: 1px solid var(--akm-border); vertical-align: middle; }
.akm-table tbody tr:hover { background: var(--akm-bg); }
.akm-table tbody tr:last-child td { border-bottom: none; }

/* ── Empty / loading states ─────────────────────────────────────────────── */
.akm-empty { text-align: center; padding: var(--akm-space-6) var(--akm-space-4); color: var(--akm-text-muted); }
.akm-empty__icon { font-size: 2rem; margin-bottom: var(--akm-space-2); }

/* ── Modal / dialog (lightweight, used by warn-on-create etc.) ─────────── */
.akm-dialog-overlay {
  position: fixed; inset: 0; background: rgba(20, 30, 45, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 4000; padding: var(--akm-space-4);
  /* Fallback scroller: the dialog caps its own height, but if a browser refuses
     the percentage max-height the overlay still scrolls instead of clipping. */
  overflow-y: auto;
}
.akm-dialog {
  --akm-dialog-pad: var(--akm-space-5);
  /* There is no global border-box reset here, and content-box would let the
     padding push the dialog past max-height: 100% (its own height cap). */
  box-sizing: border-box;
  background: var(--akm-surface); border-radius: var(--akm-radius);
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
  max-width: 480px; width: 100%; padding: var(--akm-dialog-pad);
  /* A tall dialog (the merge dialog on a phone, and inside the dashboard's
     short iframe) must scroll itself — centred overflow is unreachable. */
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.akm-dialog h3 { margin: 0 0 var(--akm-space-2); color: var(--akm-primary); font-size: 1.1rem; }
.akm-dialog__actions {
  display: flex; justify-content: flex-end; gap: var(--akm-space-2);
  /* Pinned to the bottom of the scroll box so Cancel / Confirm stay reachable
     without scrolling to the end of a long dialog. */
  position: sticky; bottom: calc(-1 * var(--akm-dialog-pad));
  margin: var(--akm-space-4) calc(-1 * var(--akm-dialog-pad)) calc(-1 * var(--akm-dialog-pad));
  padding: var(--akm-space-3) var(--akm-dialog-pad);
  background: var(--akm-surface);
  border-top: 1px solid var(--akm-border);
}

/* Merge dialog field rows (contacts page) — one row per field, the two
   candidate values side by side. */
.merge-row {
  display: grid; grid-template-columns: 70px 1fr 1fr; gap: 10px;
  align-items: center; padding: 8px 0; border-bottom: 1px solid var(--akm-border);
}
.merge-row__label { font-size: 0.85rem; font-weight: 700; }
.merge-row__opt {
  display: flex; gap: 6px; align-items: center;
  font-size: 0.85rem; cursor: pointer;
}
.merge-row__opt input { flex: 0 0 auto; }

/* ── Responsive breakpoints ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .akm-page__body { padding: var(--akm-space-4) var(--akm-space-3) var(--akm-space-5); }
  .akm-form-row { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .akm-page__title { font-size: 1.2rem; }
  .akm-page__body { padding: var(--akm-space-3) var(--akm-space-2) var(--akm-space-4); }
  .akm-btn { width: 100%; justify-content: center; min-height: 44px; font-size: 0.9rem; }
  .akm-btn--sm { width: auto; min-height: auto; }
  .akm-dialog { --akm-dialog-pad: var(--akm-space-4); max-width: 90vw; }
  .akm-field input, .akm-field textarea { font-size: 1.05rem; }
  /* Narrow screens: the field name gets its own line so the two values keep
     the full width and stop wrapping into four-line columns. */
  .merge-row { grid-template-columns: 1fr 1fr; gap: 6px 10px; }
  .merge-row__label {
    grid-column: 1 / -1;
    font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em;
    color: var(--akm-text-muted);
  }
}

/* ==================== NAVIGATION SHELL (feature-flagged: navShell) ==================== */
.akm-nav {
  background: var(--akm-primary);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 var(--akm-space-4);
  overflow-x: auto;
  font-family: var(--akm-font);
}
.akm-nav__brand {
  color: #fff;
  font-weight: 800;
  font-size: 0.95rem;
  padding: 12px var(--akm-space-4) 12px 0;
  white-space: nowrap;
  text-decoration: none;
}
.akm-nav__link {
  color: rgba(255,255,255,0.82);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 14px 12px;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  transition: all 0.15s ease;
}
.akm-nav__link:hover { color: #fff; background: rgba(255,255,255,0.08); }
.akm-nav__link--active { color: #fff; border-bottom-color: #fff; }

@media (max-width: 700px) {
  .akm-nav__link { padding: 12px 8px; font-size: 0.76rem; }
  .akm-nav__brand { display: none; }
}

/* ==================== EMBEDDED (inside dashboard content shell) ==================== */
/* When a section page is shown inside the dashboard iframe, hide its own page
   header/back button and shared nav so only the section content is visible. */
.embedded #akm-nav-root { display: none !important; }
.embedded .akm-page__body > .akm-page__header { display: none !important; }
.embedded .akm-page__body { padding: 16px !important; }
.embedded #auth-loading { background: #fff !important; }

/* ==================== SOA — search + company cards ==================== */
.soa-search-wrap { position: relative; margin-bottom: 16px; }
.soa-search-wrap input {
  width: 100%;
  padding: 12px 16px 12px 42px;
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
  background: #fff;
}
.soa-search-wrap input:focus {
  outline: none;
  border-color: #0760a8;
  box-shadow: 0 0 0 3px rgba(7,96,168,0.1);
}
.soa-search-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 16px; color: #9ca3af;
}
.soa-company-list { display: grid; gap: 10px; }
.soa-company-card {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 12px;
  padding: 14px 16px; transition: box-shadow .2s, border-color .2s;
}
.soa-company-card:hover { border-color: #0760a8; box-shadow: 0 2px 10px rgba(0,0,0,0.06); }
.soa-company-name { font-weight: 700; font-size: 15px; color: #1f2937; }
.soa-company-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: #6b7280; margin-top: 4px; flex-wrap: wrap;
}
.soa-badge { padding: 2px 8px; border-radius: 999px; font-weight: 600; font-size: 11.5px; }
.soa-badge--due { background: #fdecea; color: #d32f2f; }
.soa-badge--clear { background: #e7f6ec; color: #1a7f37; }
.soa-company-actions { display: flex; gap: 8px; flex-shrink: 0; }
@media (max-width: 640px) {
  .soa-company-card { flex-direction: column; align-items: stretch; }
  .soa-company-actions { justify-content: flex-end; }
}

/* ==================== MOBILE / EMBEDDED OVERFLOW GUARD ====================
   No global box-sizing reset exists, so inputs with width:100% + padding were
   spilling past their card and causing left-right scroll on phones and inside
   the dashboard content iframe (SOA search, Import/Export file + PIN fields). */
.akm-page__body { overflow-x: hidden; }
.akm-card, .akm-field { min-width: 0; box-sizing: border-box; max-width: 100%; }
.akm-field input, .akm-field select, .akm-field textarea,
.soa-search-wrap input {
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
}
input[type="file"] { max-width: 100%; }
.akm-form-row { flex-wrap: wrap; }
