/* ============================================================================
   STG ANALYTICS — Modals, Toasts, Forms, Responsive  (v2, light)
   ============================================================================ */

/* ─── Modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(16,18,24,0.42); backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 44px 16px; overflow-y: auto;
  opacity: 0; transition: opacity .18s;
}
.modal-overlay.open { opacity: 1; }
.modal {
  background: var(--surface-1); border-radius: var(--r-lg);
  box-shadow: var(--shadow-modal); width: 100%; max-width: 520px;
  margin: auto 0; transform: translateY(10px) scale(.985); transition: transform .22s var(--ease);
  border: 1px solid var(--border);
}
.modal-overlay.open .modal { transform: translateY(0) scale(1); }
.modal.wide { max-width: 760px; }
.modal.narrow { max-width: 420px; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 12px; }
.modal-title { font-size: 16px; font-weight: 660; color: var(--n-900); letter-spacing: -0.3px; }
.modal-desc { font-size: 13px; color: var(--n-500); margin-top: 3px; }
.modal-close { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; color: var(--n-400); font-size: 14px; flex-shrink: 0; transition: all .13s; }
.modal-close:hover { background: var(--n-100); color: var(--n-800); }
.modal-body { padding: 6px 22px 20px; max-height: calc(100vh - 220px); overflow-y: auto; }
.modal-footer { padding: 15px 22px 18px; display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid var(--border-subtle); }
.modal-footer.between { justify-content: space-between; }

/* ─── Forms ─────────────────────────────────────────────────────────── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--n-700); }
.field label .req { color: var(--neg); }
.field .hint { font-size: 11.5px; color: var(--n-400); }
.input, .select, .textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); background: var(--surface-1); font-size: 14px;
  color: var(--n-900); outline: none; transition: border .13s, box-shadow .13s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.input::placeholder, .textarea::placeholder { color: var(--n-300); }
.textarea { resize: vertical; min-height: 72px; line-height: 1.5; }
.input.error, .select.error { border-color: var(--neg); box-shadow: 0 0 0 3px var(--neg-tint); }
.field-error { font-size: 11.5px; color: var(--neg); font-weight: 500; }
.input-prefix { position: relative; }
.input-prefix .pfx { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--n-400); font-size: 13px; font-weight: 500; pointer-events: none; }
.input-prefix input { padding-left: 32px; }

/* ─── Toasts ────────────────────────────────────────────────────────── */
#toast-stack { position: fixed; bottom: 24px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 12px; min-width: 280px; max-width: 400px;
  background: var(--n-900); color: #fff; padding: 12px 15px; border-radius: var(--r-md);
  box-shadow: var(--shadow-pop); font-size: 13.5px; font-weight: 500;
  transform: translateX(120%); transition: transform .32s var(--ease); pointer-events: auto;
}
.toast.show { transform: translateX(0); }
.toast-icon { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 12px; flex-shrink: 0; }
.toast.success .toast-icon { background: var(--pos); color: #fff; }
.toast.error .toast-icon { background: var(--neg); color: #fff; }
.toast.info .toast-icon { background: var(--brand); color: #fff; }
.toast-msg { flex: 1; line-height: 1.35; }
.toast-close { color: rgba(255,255,255,0.55); font-size: 13px; cursor: pointer; }

/* ─── Confirm popover ───────────────────────────────────────────────── */
.confirm-pop {
  position: absolute; z-index: 1500; background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: var(--r-md); box-shadow: var(--shadow-pop); padding: 14px; width: 244px;
}
.confirm-pop p { font-size: 13px; color: var(--n-700); margin-bottom: 12px; line-height: 1.4; }
.confirm-pop .actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ─── Dropdown menu (config) ────────────────────────────────────────── */
.menu-pop {
  position: absolute; z-index: 1500; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-pop); padding: 6px; min-width: 232px;
}
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 9px 10px; border-radius: 7px; font-size: 13px; color: var(--n-700); font-weight: 500; transition: background .12s; }
.menu-item i { width: 16px; text-align: center; color: var(--n-400); font-size: 13px; }
.menu-item:hover { background: var(--n-75); color: var(--n-900); }
.menu-item:hover i { color: var(--n-600); }
.menu-item.danger { color: var(--neg); }
.menu-item.danger i { color: var(--neg); }
.menu-item.danger:hover { background: var(--neg-tint); }
.menu-sep { height: 1px; background: var(--border-subtle); margin: 5px 4px; }
.menu-label { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--n-400); padding: 8px 10px 4px; }

/* ─── Import dropzone ───────────────────────────────────────────────── */
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--r-md);
  padding: 28px; text-align: center; transition: all .18s; cursor: pointer; background: var(--surface-2);
}
.dropzone:hover, .dropzone.dragover { border-color: var(--brand); background: var(--brand-tint); }
.dropzone i { font-size: 24px; color: var(--n-300); margin-bottom: 10px; }
.dropzone.dragover i { color: var(--brand); }
.dropzone p { font-size: 13.5px; color: var(--n-700); font-weight: 500; }
.dropzone span { font-size: 12px; color: var(--n-400); }

.import-stat-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 16px; }
.import-stat { border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px; text-align: center; }
.import-stat .n { font-size: 24px; font-weight: 680; letter-spacing: -0.5px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.import-stat .l { font-size: 11.5px; color: var(--n-400); margin-top: 2px; }
.import-log { max-height: 200px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--r-md); }
.import-log-row { padding: 8px 12px; font-size: 12px; border-bottom: 1px solid var(--border-subtle); display: flex; gap: 8px; }
.import-log-row:last-child { border-bottom: none; }
.import-log-row .ln { font-weight: 700; font-size: 10px; padding: 1px 6px; border-radius: 4px; flex-shrink: 0; height: fit-content; }
.import-log-row.err .ln { background: var(--neg-tint); color: var(--neg); }
.import-log-row.warn .ln { background: var(--warn-tint); color: var(--warn); }

/* ─── Mobile bottom nav (hidden on desktop) ─────────────────────────── */
.mobile-nav { display: none; }
.sidebar-scrim { display: none; }

/* ============================================================================
   RESPONSIVE
   ============================================================================ */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2,1fr); }
  .grid-3 { grid-template-columns: 1fr 1fr; }
  .metrics.cols-4 { grid-template-columns: repeat(2,1fr); }
  .metrics.cols-4 .metric:nth-child(2) { border-right: none; }
  .metrics.cols-4 .metric:nth-child(1), .metrics.cols-4 .metric:nth-child(2) { border-bottom: 1px solid var(--border-subtle); }
}

@media (max-width: 900px) {
  .hamburger { display: grid; }
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); box-shadow: var(--shadow-modal); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 45; opacity: 0; transition: opacity .3s; }
  .sidebar-scrim.open { display: block; opacity: 1; }
  .page { padding: 22px 18px 96px; }
  .topbar { padding: 0 16px; }
}

@media (max-width: 720px) {
  .grid-2, .grid-3, .col-span-2 { grid-template-columns: 1fr; grid-column: auto; }
  .metrics.cols-4, .metrics.cols-3, .metrics.cols-2 { grid-template-columns: 1fr 1fr; }
  .metric { border-bottom: 1px solid var(--border-subtle); }
  .metrics.cols-4 .metric:nth-child(odd), .metrics.cols-2 .metric:nth-child(odd) { border-right: 1px solid var(--border-subtle); }
  .metrics.cols-4 .metric:nth-child(even) { border-right: none; }
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; border-radius: var(--r-lg) var(--r-lg) 0 0; margin: 0; max-height: 92vh; overflow-y: auto; }
  .modal.wide, .modal.narrow { max-width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  #toast-stack { left: 12px; right: 12px; bottom: 12px; }
  .toast { min-width: 0; max-width: 100%; }
  .topbar-sub { display: none; }
  .period-select { max-width: 104px; font-size: 13px; }

  /* Mobile: stack tables into cards */
  .data-table.responsive-cards thead { display: none; }
  .data-table.responsive-cards, .data-table.responsive-cards tbody, .data-table.responsive-cards tr, .data-table.responsive-cards td { display: block; width: 100%; }
  .data-table.responsive-cards tr {
    border: 1px solid var(--border); border-radius: var(--r-md); margin-bottom: 10px;
    padding: 4px 4px; background: var(--surface-1);
  }
  .data-table.responsive-cards td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 8px 14px; border-bottom: 1px solid var(--border-subtle); text-align: right !important;
  }
  .data-table.responsive-cards td:last-child { border-bottom: none; }
  .data-table.responsive-cards td::before {
    content: attr(data-label); font-size: 11px; font-weight: 600; color: var(--n-400);
    text-transform: uppercase; letter-spacing: 0.03em; text-align: left; flex-shrink: 0;
  }
  .data-table.responsive-cards td.cell-actions { justify-content: flex-end; }
  .data-table.responsive-cards td.cell-actions::before { display: none; }
  .data-table.responsive-cards tfoot, .data-table.responsive-cards tfoot tr, .data-table.responsive-cards tfoot td { display: block; }
  .data-table.responsive-cards tfoot td { background: var(--surface-2); border-radius: var(--r-md); }

  /* Mobile bottom nav */
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: 58px;
    background: rgba(255,255,255,0.92); backdrop-filter: blur(8px);
    border-top: 1px solid var(--border); z-index: 40;
    padding: 5px 4px calc(5px + env(safe-area-inset-bottom, 0)); justify-content: space-around;
  }
  .mobile-nav-item { display: flex; flex-direction: column; align-items: center; gap: 3px; flex: 1; color: var(--n-400); font-size: 10px; font-weight: 550; padding: 4px 0; border-radius: 8px; }
  .mobile-nav-item i { font-size: 16px; }
  .mobile-nav-item.active { color: var(--brand); }
  .content { padding-bottom: 58px; }
}

@media (max-width: 420px) {
  .section-title { font-size: 18px; }
}

@media print { .sidebar, .topbar, .mobile-nav { display: none !important; } }
