/* ============================================================================
   PT SANTANI AGRO LESTARI - UNIFIED PORTAL & DOCUMENT STUDIO STYLESHEET
   Visual Direction: Executive Modern | Merah SAL, Putih, Abu-abu Profesional
   ============================================================================ */

:root {
  --sal-red: #ee0000;
  --sal-red-btn: #c80000;
  --sal-red-dark: #a30000;
  --sal-red-soft: #fff0f0;
  --sal-red-border: #fca5a5;
  --sal-white: #ffffff;
  --sal-bg: #f4f6f9;
  --sal-surface: #ffffff;
  --sal-subtle: #f8fafc;
  --sal-border: #dbe2ea;
  --sal-border-strong: #94a3b8;
  --sal-ink: #0f172a;
  --sal-ink-secondary: #334155;
  --sal-ink-muted: #475569;
  --sal-success-bg: #ecfdf5;
  --sal-success-ink: #065f46;
  --sal-warn-bg: #fffbeb;
  --sal-warn-ink: #92400e;
  --sal-danger-bg: #fef2f2;
  --sal-danger-ink: #991b1b;
  --sal-info-bg: #eff6ff;
  --sal-info-ink: #1e40af;

  --sidebar-width: 264px;
  --sidebar-width-mini: 76px;
  --topbar-height: 64px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 6px 18px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 14px 32px rgba(15, 23, 42, 0.14);
  --ease-smooth: cubic-bezier(0.16, 1, 0.3, 1);
  --font-sans: "Inter", "Segoe UI", Arial, Helvetica, sans-serif;
  --font-mono: "JetBrains Mono", "Consolas", monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--sal-ink);
  background: var(--sal-bg);
  overflow-x: hidden;
}

button, a[href], summary, select, input[type="checkbox"], input[type="radio"], label[for] {
  cursor: pointer;
}

button:disabled, input:disabled, select:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

:focus-visible {
  outline: 3px solid rgba(200, 0, 0, 0.45);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.hidden {
  display: none !important;
}

/* ============================================================================
   PORTAL SHELL: TOPBAR + COLLAPSIBLE SIDEBAR + MAIN CONTENT
   ============================================================================ */
.portal-shell {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

.portal-sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: var(--sal-white);
  border-right: 1px solid var(--sal-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 40;
  transition: width 0.24s var(--ease-smooth), flex-basis 0.24s var(--ease-smooth), transform 0.24s var(--ease-smooth);
}

.portal-shell.sidebar-collapsed .portal-sidebar {
  width: var(--sidebar-width-mini);
  flex-basis: var(--sidebar-width-mini);
}

.sidebar-brand {
  height: var(--topbar-height);
  padding: 0 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--sal-border);
  background: linear-gradient(135deg, #c80000 0%, #990000 100%);
  color: var(--sal-white);
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--sal-red);
  border: 2px solid rgba(255, 255, 255, 0.9);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.5px;
  color: var(--sal-white);
}

.brand-text {
  min-width: 0;
  overflow: hidden;
}

.brand-text strong {
  display: block;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  letter-spacing: 0.2px;
}

.brand-text span {
  display: block;
  font-size: 11px;
  color: #ffe4e6;
  white-space: nowrap;
}

.portal-shell.sidebar-collapsed .brand-text,
.portal-shell.sidebar-collapsed .nav-label,
.portal-shell.sidebar-collapsed .nav-section-caption,
.portal-shell.sidebar-collapsed .sidebar-user-meta {
  display: none;
}

.sidebar-nav {
  flex: 1;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-section-caption {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--sal-ink-muted);
  padding: 8px 12px 4px;
}

.sidebar-nav-btn {
  width: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--sal-ink-secondary);
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.portal-shell.sidebar-collapsed .sidebar-nav-btn {
  justify-content: center;
  padding: 10px;
}

.sidebar-nav-btn svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-nav-btn:hover {
  background: var(--sal-red-soft);
  color: var(--sal-red-dark);
}

.sidebar-nav-btn.active {
  background: var(--sal-red-btn);
  color: var(--sal-white);
  font-weight: 700;
  box-shadow: 0 3px 10px rgba(200, 0, 0, 0.22);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--sal-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: var(--sal-subtle);
  border: 1px solid var(--sal-border);
}

.user-avatar-chip {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--sal-red-btn);
  color: var(--sal-white);
  font-size: 13px;
  font-weight: 800;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.sidebar-user-meta {
  min-width: 0;
  flex: 1;
}

.sidebar-user-meta strong {
  display: block;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-meta span {
  display: block;
  font-size: 11px;
  color: var(--sal-ink-muted);
  text-transform: uppercase;
  font-weight: 700;
}

.portal-main-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.portal-topbar {
  height: var(--topbar-height);
  background: var(--sal-white);
  border-bottom: 1px solid var(--sal-border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-title-group h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  color: var(--sal-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-title-group p {
  margin: 0;
  font-size: 12px;
  color: var(--sal-ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  min-width: 40px;
  min-height: 40px;
  padding: 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--sal-border);
  background: var(--sal-white);
  color: var(--sal-ink-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.icon-btn:hover {
  background: var(--sal-subtle);
  border-color: var(--sal-border-strong);
}

.mobile-only-btn {
  display: none;
}

.portal-content {
  flex: 1;
  padding: 20px;
  min-width: 0;
}

.portal-view {
  display: none;
}

.portal-view.active {
  display: block;
  animation: viewEnter 0.22s var(--ease-smooth);
}

@keyframes viewEnter {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .portal-view.active, .portal-sidebar {
    animation: none !important;
    transition: none !important;
  }
}

/* ============================================================================
   BUTTONS, INPUTS, CARDS, BADGES, SKELETONS & STATES
   ============================================================================ */
.btn {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
  text-decoration: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-sm {
  min-height: 36px;
  padding: 6px 11px;
  font-size: 12.5px;
}

.btn-primary {
  background: var(--sal-red-btn);
  color: var(--sal-white);
  border-color: var(--sal-red-btn);
}

.btn-primary:hover:not(:disabled) {
  background: var(--sal-red-dark);
}

.btn-secondary {
  background: var(--sal-white);
  color: var(--sal-ink);
  border-color: var(--sal-border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--sal-subtle);
}

.btn-danger {
  background: #b91c1c;
  color: var(--sal-white);
}

.btn-danger:hover:not(:disabled) {
  background: #991b1b;
}

.btn-success {
  background: #047857;
  color: var(--sal-white);
}

.btn-success:hover:not(:disabled) {
  background: #065f46;
}

.card {
  background: var(--sal-surface);
  border: 1px solid var(--sal-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 18px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--sal-border);
  flex-wrap: wrap;
}

.card-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 800;
  color: var(--sal-ink);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-field label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--sal-ink-secondary);
}

.input, .select, .textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--sal-border-strong);
  background: var(--sal-white);
  color: var(--sal-ink);
  font-size: 13.5px;
  font-family: inherit;
}

.textarea {
  min-height: 110px;
  resize: vertical;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-success { background: var(--sal-success-bg); color: var(--sal-success-ink); border: 1px solid #a7f3d0; }
.badge-warn { background: var(--sal-warn-bg); color: var(--sal-warn-ink); border: 1px solid #fde68a; }
.badge-danger { background: var(--sal-danger-bg); color: var(--sal-danger-ink); border: 1px solid #fecaca; }
.badge-info { background: var(--sal-info-bg); color: var(--sal-info-ink); border: 1px solid #bfdbfe; }
.badge-neutral { background: #f1f5f9; color: #334155; border: 1px solid #cbd5e1; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card {
  background: var(--sal-white);
  border: 1px solid var(--sal-border);
  border-radius: var(--radius-md);
  padding: 16px;
}

.kpi-card.accent {
  border-color: var(--sal-red-border);
  background: linear-gradient(180deg, #fff5f5 0%, #ffffff 100%);
}

.kpi-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--sal-ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 900;
  color: var(--sal-ink);
  margin-top: 4px;
}

.kpi-card.accent .kpi-value {
  color: var(--sal-red-dark);
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--sal-border);
  border-radius: var(--radius-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.data-table th, .data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--sal-border);
  vertical-align: middle;
}

.data-table th {
  background: var(--sal-subtle);
  color: var(--sal-ink-secondary);
  font-weight: 800;
  font-size: 12px;
  text-transform: uppercase;
}

.data-table tbody tr:hover {
  background: #fafafa;
}

.skeleton {
  height: 16px;
  border-radius: 6px;
  background: linear-gradient(90deg, #e2e8f0 25%, #f1f5f9 50%, #e2e8f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.state-box {
  padding: 28px 18px;
  text-align: center;
  border: 1px dashed var(--sal-border-strong);
  border-radius: var(--radius-md);
  background: var(--sal-subtle);
  color: var(--sal-ink-secondary);
}

.state-box strong {
  display: block;
  font-size: 15px;
  color: var(--sal-ink);
  margin-bottom: 4px;
}

.state-box.error {
  background: var(--sal-danger-bg);
  border-color: var(--sal-red-border);
  color: var(--sal-danger-ink);
}

/* ============================================================================
   DOCUMENT STUDIO WORKSPACE
   ============================================================================ */
.studio-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.studio-tab-btn {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--sal-border-strong);
  background: var(--sal-white);
  color: var(--sal-ink-secondary);
  font-size: 13px;
  font-weight: 700;
}

.studio-tab-btn.active {
  background: var(--sal-red-btn);
  color: var(--sal-white);
  border-color: var(--sal-red-btn);
}

.dropzone {
  border: 2px dashed var(--sal-border-strong);
  border-radius: var(--radius-md);
  padding: 28px 18px;
  text-align: center;
  background: var(--sal-subtle);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone.dragover {
  border-color: var(--sal-red-btn);
  background: var(--sal-red-soft);
}

.studio-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.preview-frame {
  border: 1px solid var(--sal-border);
  border-radius: var(--radius-sm);
  background: #f1f5f9;
  min-height: 360px;
  max-height: 540px;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12px;
}

.preview-frame img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.progress-bar-track {
  width: 100%;
  height: 10px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--sal-red-btn);
  transition: width 0.25s ease;
}

.rte-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  background: var(--sal-subtle);
  border: 1px solid var(--sal-border-strong);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.rte-surface {
  min-height: 280px;
  padding: 16px;
  border: 1px solid var(--sal-border-strong);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: var(--sal-white);
  outline: none;
  overflow-y: auto;
}

.a4-doc-preview {
  background: var(--sal-white);
  border: 1px solid #cbd5e1;
  box-shadow: var(--shadow-md);
  padding: 24px 28px;
  min-height: 460px;
  font-family: Arial, Helvetica, sans-serif;
  color: #0f172a;
}

.sal-kop-banner {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding-bottom: 10px;
  margin-bottom: 14px;
  border-bottom: 3px solid var(--sal-red);
}

/* ============================================================================
   AI ASSISTANT CHAT
   ============================================================================ */
.assistant-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
}

.chat-stream {
  min-height: 320px;
  max-height: 480px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  background: var(--sal-subtle);
  border: 1px solid var(--sal-border);
  border-radius: var(--radius-sm);
}

.chat-msg {
  max-width: 88%;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13.5px;
  white-space: pre-wrap;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--sal-red-btn);
  color: var(--sal-white);
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--sal-white);
  border: 1px solid var(--sal-border);
  color: var(--sal-ink);
}

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0;
}

.prompt-chip {
  min-height: 34px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--sal-border-strong);
  background: var(--sal-white);
  color: var(--sal-ink-secondary);
  font-size: 12px;
  font-weight: 600;
}

.prompt-chip:hover {
  background: var(--sal-red-soft);
  border-color: var(--sal-red-btn);
  color: var(--sal-red-dark);
}

/* ============================================================================
   TOASTS & MODALS
   ============================================================================ */
.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}

.toast-item {
  background: #0f172a;
  color: var(--sal-white);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--sal-red);
  font-size: 13px;
}

.toast-item.success { border-left-color: #10b981; }
.toast-item.error { border-left-color: #ef4444; }
.toast-item.warn { border-left-color: #f59e0b; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 80;
}

.modal-box {
  background: var(--sal-white);
  border-radius: var(--radius-md);
  border: 1px solid var(--sal-border);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-box-head {
  padding: 14px 18px;
  background: var(--sal-red-btn);
  color: var(--sal-white);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-box-body {
  padding: 18px;
  overflow-y: auto;
}

/* ============================================================================
   CASH ADVANCE MODULE (100% PRESERVED + INTEGRATED INSIDE PORTAL)
   ============================================================================ */
.ca-toolbar {
  background: #ffffff;
  border: 1px solid var(--sal-border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.ca-mode-group {
  display: inline-flex;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--sal-border);
  gap: 4px;
}

.ca-mode-btn {
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 6px;
  border: none;
  font-size: 12.5px;
  font-weight: 700;
  background: transparent;
  color: #334155;
}

.ca-mode-btn.active-mode {
  background: var(--sal-red-btn);
  color: #ffffff;
}

.ca-workspace {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.ca-form-panel {
  width: 440px;
  flex: 0 0 440px;
  background: #ffffff;
  border: 1px solid var(--sal-border);
  border-radius: var(--radius-md);
  padding: 16px;
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  font-size: 12.5px;
}

.ca-preview-panel {
  flex: 1;
  min-width: 0;
  background: #e2e8f0;
  border-radius: var(--radius-md);
  padding: 18px;
  overflow-x: auto;
  display: flex;
  justify-content: center;
}

.ca-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.ca-col-span-2 {
  grid-column: span 2;
}

.ca-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 12.5px;
  background: #ffffff;
  color: #0f172a;
}

.ca-row-card {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #f8fafc;
  padding: 6px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  margin-bottom: 6px;
}

.ca-dropdown-wrap {
  position: relative;
  display: inline-block;
}

.ca-dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 6px;
  width: 220px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 45;
}

.ca-dropdown-menu button,
.ca-dropdown-menu label {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 12.5px;
  color: #0f172a;
  text-align: left;
}

.ca-dropdown-menu button:hover,
.ca-dropdown-menu label:hover {
  background: #f1f5f9;
}

/* A4 Cash Advance Sheet Exact Styling */
.a4-sheet {
  width: 210mm;
  max-width: 210mm;
  background: #ffffff;
  padding: 22px;
  box-shadow: var(--shadow-md);
  color: #000000;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  font-family: Arial, Helvetica, sans-serif;
}

.form-border-solid {
  border: 1.5px solid #0f172a !important;
}

.table-bordered {
  width: 100%;
  border-collapse: collapse;
}

.table-bordered th,
.table-bordered td {
  border: 1.2px solid #0f172a !important;
  padding: 4px 6px;
}

.font-mono {
  font-family: var(--font-mono);
}

.ca-signers-grid {
  display: grid;
  gap: 12px;
  padding-top: 8px;
  border-top: 2px solid #000000;
  text-align: center;
  font-size: 8.5pt;
}

.ca-signers-1 { grid-template-columns: repeat(1, 1fr); }
.ca-signers-2 { grid-template-columns: repeat(2, 1fr); }
.ca-signers-3 { grid-template-columns: repeat(3, 1fr); }
.ca-signers-4 { grid-template-columns: repeat(4, 1fr); }

/* ============================================================================
   RESPONSIVE BREAKPOINTS (TABLET & SMARTPHONE)
   ============================================================================ */
.sidebar-backdrop {
  display: none;
}

@media (max-width: 1120px) {
  .ca-workspace {
    flex-direction: column;
  }
  .ca-form-panel {
    width: 100%;
    flex: none;
    max-height: none;
  }
  .ca-preview-panel {
    width: 100%;
    justify-content: flex-start;
  }
  .studio-split,
  .assistant-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .mobile-only-btn {
    display: inline-flex;
  }
  .desktop-only-btn {
    display: none;
  }
  .portal-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
    z-index: 60;
  }
  .portal-shell.mobile-drawer-open .portal-sidebar {
    transform: translateX(0);
  }
  .portal-shell.mobile-drawer-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 55;
  }
  .portal-content {
    padding: 14px;
  }
}

@media (max-width: 600px) {
  .ca-grid-2 {
    grid-template-columns: 1fr;
  }
  .ca-col-span-2 {
    grid-column: span 1;
  }
  .portal-topbar {
    padding: 0 12px;
  }
  .topbar-actions .btn span.hide-xs {
    display: none;
  }
}

/* ============================================================================
   PRINT RULES: 1 HALAMAN CETAK A4 PORTRAIT FOR CASH ADVANCE
   ============================================================================ */
@page {
  size: A4 portrait;
  margin: 8mm 10mm 6mm 10mm;
}

@media print {
  html, body {
    width: 210mm !important;
    height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    color: #000000 !important;
    overflow: hidden !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .no-print,
  .portal-sidebar,
  .portal-topbar,
  .sidebar-backdrop,
  .toast-stack,
  .modal-overlay,
  .portal-view:not(#view-cash-advance) {
    display: none !important;
  }

  .portal-shell,
  .portal-main-wrap,
  .portal-content,
  #view-cash-advance,
  .ca-workspace,
  .ca-preview-panel {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #ffffff !important;
    border: none !important;
    width: 100% !important;
    overflow: visible !important;
  }

  .a4-sheet {
    box-shadow: none !important;
    border: none !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 279mm !important;
    max-height: 279mm !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    page-break-after: avoid !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    overflow: hidden !important;
  }
}
