/* Chronologie Form JO — UI system V10.
   Antarmuka menggunakan Montserrat dan basis #E6D8A8.
   Canvas/template PDF tidak dipengaruhi stylesheet ini. */
:root {
  --brand-50: #fbf8ed;
  --brand-100: #f5efd7;
  --brand-300: #e6d8a8;
  --brand-500: #b79c45;
  --brand-700: #756020;
  --surface: #ffffff;
  --surface-muted: #f8f6ef;
  --surface-warm: #fcf9ee;
  --surface-dark: #2e2a20;
  --text-primary: #2e2a20;
  --text-secondary: #625d50;
  --text-muted: #787164;
  --border: #dcd6c7;
  --border-strong: #bfb49b;
  --success: #17633a;
  --success-bg: #e8f6ed;
  --warning: #745b00;
  --warning-bg: #fff5c7;
  --danger: #9b2727;
  --danger-bg: #fff0f0;
  --info: #315376;
  --info-bg: #edf3fa;
  --focus: rgba(183, 156, 69, .34);
  --shadow-sm: 0 2px 8px rgba(57, 49, 25, .06);
  --shadow-md: 0 12px 34px rgba(57, 49, 25, .11);
  --shadow-lg: 0 24px 70px rgba(45, 38, 18, .19);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --header-height: 64px;
  --context-height: 70px;
  --content-max: 1560px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 0;
  color: var(--text-primary);
  background:
    radial-gradient(circle at 8% -8%, rgba(230, 216, 168, .52), transparent 34rem),
    #f4f1e8;
  font-family: "Montserrat", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}
body.no-scroll { overflow: hidden; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .56; }
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
[hidden] { display: none !important; }
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(22px, 2vw, 28px); line-height: 1.22; font-weight: 700; letter-spacing: -.025em; }
h2 { margin-bottom: 0; font-size: 17px; line-height: 1.4; font-weight: 700; letter-spacing: -.015em; }
h3 { font-size: 14px; line-height: 1.45; }
.eyebrow { margin: 0 0 4px; color: var(--text-muted); font-size: 11px; line-height: 1.45; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.eyebrow.dark { color: var(--brand-700); }
.required-symbol { color: var(--danger); font-style: normal; }

/* Loading and login */
.loading-screen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  padding: 24px;
  color: var(--text-primary);
  background: var(--brand-50);
  text-align: center;
}
.loading-screen strong { font-size: 16px; }
.loading-screen span { color: var(--text-secondary); font-size: 13px; }
.loading-mark,
.brand-monogram {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 8px;
  border: 1px solid rgba(255,255,255,.25);
  border-radius: 50%;
  color: var(--brand-300);
  background: var(--surface-dark);
  font-family: Georgia, serif;
  font-size: 27px;
  line-height: 1;
  box-shadow: var(--shadow-md);
}
.brand-monogram.small { width: 38px; height: 38px; margin: 0; font-size: 20px; box-shadow: none; }
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 14% 0%, rgba(230,216,168,.82), transparent 36rem),
    var(--brand-50);
}
.login-card {
  width: min(500px, 100%);
  padding: clamp(24px, 4vw, 36px);
  border: 1px solid #d2c79f;
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,.96);
  box-shadow: var(--shadow-lg);
}
.login-brand { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 28px; }
.login-brand .brand-monogram { flex: 0 0 auto; }
.login-brand h1 { font-size: 28px; }
.login-brand p:last-child { margin: 7px 0 0; color: var(--text-secondary); font-size: 13px; line-height: 1.6; }
.login-card form { display: grid; gap: 16px; }
.login-submit { width: 100%; min-height: 46px; margin-top: 2px; }
.login-footer { display: grid; gap: 4px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); color: var(--text-muted); font-size: 12px; }
.password-field {
  position: relative;
  display: flex;
  align-items: stretch;
  width: 100%;
  min-height: 46px;
  overflow: hidden;
  border: 1px solid #d2cab5;
  border-radius: var(--radius-sm);
  background: #fffefa;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.password-field:hover { border-color: #b9aa79; }
.password-field:focus-within { border-color: var(--brand-500); box-shadow: 0 0 0 3px var(--focus); }
.password-field input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  border: 0 !important;
  border-radius: 0 !important;
  padding: 9px 12px !important;
  background: transparent !important;
  box-shadow: none !important;
  outline: 0 !important;
}
.password-field .password-toggle {
  position: static;
  flex: 0 0 auto;
  min-width: 102px;
  min-height: 44px !important;
  border: 0;
  border-left: 1px solid var(--border);
  border-radius: 0;
  padding: 9px 13px;
  color: #403a2b;
  background: #fff;
  transform: none;
  font-size: 12px;
}
.password-field .password-toggle:hover { background: var(--brand-50); transform: none; }
.password-field:has(input[aria-invalid="true"]) { border-color: #cf7070; box-shadow: 0 0 0 3px rgba(183,57,57,.13); }
.inline-notice { margin: -6px 0 0; color: var(--warning); font-size: 12px; font-weight: 600; }
.form-error { margin: 0; padding: 11px 12px; border: 1px solid #ddb1b1; border-radius: var(--radius-sm); color: #851f1f; background: var(--danger-bg); font-size: 12px; }

/* Buttons */
.btn,
.icon-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 13px;
  line-height: 20px;
  font-weight: 600;
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease, box-shadow .16s ease;
}
.btn:hover:not(:disabled), .icon-button:hover:not(:disabled) { transform: translateY(-1px); }
.btn-primary { color: #fffdf8; background: var(--surface-dark); border-color: var(--surface-dark); box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: #18160f; }
.btn-accent { color: var(--surface-dark); background: var(--brand-300); border-color: #c8b873; }
.btn-accent:hover:not(:disabled) { background: #dacb96; }
.btn-secondary { color: #403a2b; background: var(--surface); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--brand-50); border-color: #a99b79; }
.btn-ghost { color: var(--brand-100); background: transparent; border-color: rgba(255,255,255,.24); }
.btn-ghost:hover:not(:disabled) { color: #fff; background: rgba(255,255,255,.09); }
.btn.danger, .icon-button.danger { color: var(--danger); border-color: #dfabab; background: var(--danger-bg); }
.btn.compact, .icon-button.compact { min-height: 36px; padding: 7px 11px; font-size: 12px; }
.icon-button { padding-inline: 10px; color: var(--text-primary); background: var(--surface); border-color: var(--border); }

/* Header */
.app-shell { min-height: 100vh; }
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  min-height: var(--header-height);
  display: grid;
  grid-template-columns: minmax(220px, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: 24px;
  padding: 10px clamp(16px, 2vw, 28px);
  color: #fff;
  background: var(--surface-dark);
  border-bottom: 1px solid rgba(255,255,255,.09);
  box-shadow: 0 5px 22px rgba(31,27,17,.18);
}
.app-brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.app-brand > div:last-child { display: grid; min-width: 0; }
.app-brand strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-brand span { color: #cfc7ad; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.view-tabs { display: flex; justify-content: center; align-items: center; gap: 3px; min-width: 0; }
.view-tab {
  min-height: 40px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: #d4cdb8;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.view-tab:hover { color: #fff; background: rgba(255,255,255,.08); }
.view-tab.active { color: var(--surface-dark); background: var(--brand-300); }
.count-badge { display: inline-grid; place-items: center; min-width: 21px; height: 21px; margin-left: 5px; padding: 0 6px; border-radius: 999px; color: var(--surface-dark); background: var(--brand-100); font-size: 10px; font-weight: 700; }
.view-tab.active .count-badge { background: #fff; }
.header-user-row { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.current-user { display: grid; justify-items: end; min-width: 0; line-height: 1.3; }
.current-user strong { max-width: 180px; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.current-user span { margin-top: 2px; color: var(--brand-300); font-size: 11px; font-weight: 700; letter-spacing: .05em; }

/* Context bar */
.record-context {
  position: sticky;
  top: var(--header-height);
  z-index: 90;
  min-height: var(--context-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px clamp(16px, 2vw, 28px);
  border-bottom: 1px solid #cfc5a3;
  background: rgba(255,253,248,.96);
  box-shadow: 0 4px 14px rgba(66,56,28,.07);
  backdrop-filter: blur(14px);
}
.record-summary { min-width: 0; display: flex; align-items: center; gap: 12px; }
.record-summary > div { min-width: 0; display: grid; }
.record-summary > div strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.record-summary > div span { max-width: 560px; color: var(--text-secondary); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.revision-chip { display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto; padding: 5px 8px; border: 1px solid var(--border); border-radius: 999px; color: var(--text-secondary); background: var(--surface); font-size: 11px; }
.context-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex: 0 0 auto; }
.action-menu { position: relative; }
.menu-trigger { min-width: 40px; letter-spacing: .1em; }
.menu-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 130;
  min-width: 210px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}
.menu-popover button { width: 100%; min-height: 40px; border: 0; border-radius: 7px; padding: 9px 10px; color: var(--text-primary); background: transparent; text-align: left; font-size: 12px; font-weight: 600; }
.menu-popover button:hover { background: var(--surface-muted); }
.menu-popover button.danger { color: var(--danger); }
.preview-mobile-trigger { display: none; }

/* Status */
.status-badge { display: inline-flex; align-items: center; justify-content: center; min-height: 27px; padding: 4px 9px; border: 1px solid transparent; border-radius: 999px; font-size: 11px; line-height: 16px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.status-badge.small { min-height: 24px; padding: 3px 8px; font-size: 11px; }
.status-unsaved, .status-archived { color: #5f5845; background: #f0ead7; border-color: #d9cfad; }
.status-draft { color: var(--success); background: var(--success-bg); border-color: #8fcca3; }
.status-finalized { color: var(--success); background: var(--success-bg); border-color: #8fcca3; }
.status-void { color: var(--danger); background: #ffe8e8; border-color: #dfa1a1; }
.status-revised { color: var(--info); background: var(--info-bg); border-color: #a5b9d4; }

/* Form layout */
.workspace { min-height: calc(100vh - var(--header-height) - var(--context-height)); display: grid; grid-template-columns: minmax(680px, 52%) minmax(480px, 48%); }
.form-area { min-width: 0; display: grid; grid-template-columns: 170px minmax(0, 1fr); align-items: start; }
.section-nav {
  position: sticky;
  top: calc(var(--header-height) + var(--context-height) + 18px);
  max-height: calc(100vh - var(--header-height) - var(--context-height) - 36px);
  overflow: auto;
  display: grid;
  gap: 4px;
  margin: 22px 0 22px 18px;
  padding: 14px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255,255,255,.84);
  box-shadow: var(--shadow-sm);
}
.section-nav > p { margin: 0 8px 6px; color: var(--text-muted); font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.section-nav button { display: grid; grid-template-columns: 26px minmax(0,1fr); align-items: center; gap: 0 8px; min-height: 50px; border: 0; border-radius: 8px; padding: 7px 8px; color: var(--text-secondary); background: transparent; text-align: left; }
.section-nav button:hover, .section-nav button.active { color: var(--text-primary); background: var(--brand-100); }
.section-nav button > span { grid-row: 1 / 3; display: grid; place-items: center; width: 26px; height: 26px; border: 1px solid var(--border-strong); border-radius: 8px; font-size: 10px; font-weight: 700; }
.section-nav button strong { font-size: 11px; line-height: 1.3; }
.section-nav button i { font-style: normal; color: var(--text-muted); font-size: 9px; line-height: 1.35; }
.section-nav button.is-complete i { color: var(--success); }
.form-panel { min-width: 0; padding: 22px clamp(16px, 2vw, 24px) 48px 16px; }
.form-intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 18px; padding: 4px 2px; }
.form-intro p:last-child { margin: 6px 0 0; color: var(--text-secondary); font-size: 12px; }
.completion-meter { width: 170px; flex: 0 0 auto; }
.completion-meter > span { display: flex; justify-content: flex-end; gap: 4px; color: var(--text-secondary); font-size: 11px; }
.completion-meter > span strong { color: var(--text-primary); font-size: 13px; }
.completion-meter > div { height: 6px; margin-top: 6px; overflow: hidden; border-radius: 999px; background: #e4dfd1; }
.completion-meter i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--brand-500); transition: width .2s ease; }
.section-card { scroll-margin-top: calc(var(--header-height) + var(--context-height) + 18px); margin-bottom: 14px; border: 1px solid var(--border); border-radius: var(--radius-md); background: rgba(255,255,255,.96); box-shadow: var(--shadow-sm); }
.section-heading { min-height: 68px; display: grid; grid-template-columns: 36px minmax(0,1fr) auto; align-items: start; gap: 12px; padding: 16px 18px; }
.section-heading .step { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid #c5b77f; border-radius: 9px; color: var(--surface-dark); background: var(--brand-300); font-size: 11px; font-weight: 700; }
.section-heading h2 { font-size: 16px; }
.section-heading p { margin: 3px 0 0; color: var(--text-secondary); font-size: 12px; line-height: 1.5; }
.section-toggle { min-height: 34px; border: 0; border-radius: 7px; padding: 6px 8px; color: var(--text-secondary); background: transparent; font-size: 11px; font-weight: 600; }
.section-toggle:hover { color: var(--text-primary); background: var(--surface-muted); }
.section-body { padding: 0 18px 18px; border-top: 1px solid #ece8dd; }
.section-card.is-collapsed .section-body { display: none; }
.section-card.is-collapsed .section-heading { min-height: 62px; align-items: center; }

/* Fields */
.field-grid { display: grid; gap: 14px; padding-top: 16px; }
.field-grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.field-grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.span-2 { grid-column: span 2; }
.field { display: grid; gap: 6px; margin-top: 14px; color: #4c4638; font-size: 13px; line-height: 20px; font-weight: 600; }
.field-grid > .field { margin-top: 0; }
.field > small { color: var(--text-muted); font-size: 12px; line-height: 18px; font-weight: 400; }
.field input,
.field textarea,
.field select,
.search-field input,
.filter-field select,
.filter-field input {
  width: 100%;
  min-height: 42px;
  border: 1px solid #d2cab5;
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  color: var(--text-primary);
  background: #fffefa;
  outline: none;
  font-size: 14px;
  line-height: 22px;
  font-weight: 500;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
.field textarea { resize: vertical; min-height: 88px; }
.field input:hover, .field textarea:hover, .field select:hover, .search-field input:hover, .filter-field select:hover, .filter-field input:hover { border-color: #b9aa79; }
.field input:focus, .field textarea:focus, .field select:focus, .search-field input:focus, .filter-field select:focus, .filter-field input:focus { border-color: var(--brand-500); box-shadow: 0 0 0 3px var(--focus); }
.field input[aria-invalid="true"], .field textarea[aria-invalid="true"], .field select[aria-invalid="true"] { border-color: #cf7070; box-shadow: 0 0 0 3px rgba(183,57,57,.13); }
input[readonly] { color: #655e4e; background: #f0ede4 !important; cursor: not-allowed; }
input:disabled, textarea:disabled, select:disabled { color: #777166; background: #f2efe8 !important; opacity: .8; cursor: not-allowed; }
.field-error { margin: 0; color: var(--danger) !important; font-size: 12px !important; line-height: 18px !important; font-weight: 500 !important; }
.field-help { color: var(--text-muted); }
.choice-fieldset { min-width: 0; margin: 16px 0 0; padding: 0; border: 0; }
.choice-fieldset legend { margin-bottom: 8px; color: #4c4638; font-size: 13px; font-weight: 600; }
.choice-row { display: flex; align-items: stretch; flex-wrap: wrap; gap: 9px; }
.choice,
.check-item {
  display: inline-flex;
  align-items: flex-start;
  gap: 9px;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #484233;
  background: transparent;
  font-size: 13px;
  line-height: 20px;
  font-weight: 500;
  cursor: pointer;
}
.choice { border-color: var(--border); background: var(--surface-warm); }
.choice:hover, .check-item:hover { border-color: #c8bb92; background: var(--brand-50); }
.choice,
.check-item {
  width: 100%;
  min-width: 0;
}
.choice input, .check-item input { width: 18px; height: 18px; flex: 0 0 auto; margin: 1px 0 0; accent-color: var(--brand-700); }
.choice span,
.check-item span {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.checkbox-grid { display: grid; gap: 4px 10px; padding-top: 15px; align-items: start; }
.checkbox-grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.checkbox-grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.attribute-groups { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; margin-top: 16px; }
.attribute-group { padding: 13px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-warm); }
.attribute-group h3 { margin: 0 0 5px; font-size: 13px; }
.attribute-group .checkbox-grid { padding-top: 3px; }
.conditional-field { padding: 12px; border: 1px dashed #cfc39e; border-radius: var(--radius-sm); background: var(--brand-50); }
.input-with-suffix { display: flex; align-items: stretch; width: 100%; }
.input-with-suffix input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-with-suffix em { display: grid; place-items: center; min-width: 58px; border: 1px solid #d2cab5; border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--text-secondary); background: #f1eee4; font-style: normal; font-size: 12px; font-weight: 600; }
.input-with-suffix.narrow { max-width: 260px; }
.signature-options { display: grid; gap: 10px; margin-top: 16px; }
.signature-options .conditional-field { margin-top: -2px; }
.signature-sync { width: fit-content; margin: 0; }
.switch-choice { margin-top: 8px; }

/* Preview */
.preview-panel { position: sticky; top: calc(var(--header-height) + var(--context-height)); height: calc(100vh - var(--header-height) - var(--context-height)); min-width: 0; overflow: hidden; border-left: 1px solid #403c32; background: #39362e; }
.preview-topbar { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 16px; color: #fff; background: #28261f; border-bottom: 1px solid #514c3d; }
.preview-topbar strong { display: block; font-size: 13px; }
.preview-topbar span { display: block; margin-top: 1px; color: #c9c2ac; font-size: 11px; }
.preview-controls { display: flex; align-items: center; gap: 10px; }
.zoom-control { display: flex; align-items: center; gap: 8px; font-size: 11px; }
.zoom-control input { width: 110px; accent-color: var(--brand-300); }
.zoom-control output { min-width: 38px; color: var(--brand-300); font-weight: 700; }
.preview-close { display: none; color: #fff; background: transparent; border-color: #6a6453; }
.preview-scroll { height: calc(100% - 58px); overflow: auto; padding: 22px; }
.page-stage { position: relative; transform-origin: top left; }
.print-page { position: relative; width: 794px; height: 1123px; overflow: hidden; background: #fff; box-shadow: 0 14px 42px rgba(0,0,0,.38); user-select: none; }
#previewCanvas { display: block; width: 100%; height: 100%; background: #fff; }
.preview-backdrop { display: none; }

/* General content views */
.content-view { min-height: calc(100vh - var(--header-height)); padding: clamp(18px, 2.5vw, 34px); }
.content-shell { width: min(var(--content-max), 100%); margin: 0 auto; padding: clamp(18px, 2.4vw, 28px); border: 1px solid var(--border); border-radius: var(--radius-lg); background: rgba(255,255,255,.96); box-shadow: var(--shadow-md); }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.page-heading h1 { font-size: 24px; }
.page-heading p:last-child { margin: 5px 0 0; color: var(--text-secondary); font-size: 13px; }
.database-summary { min-width: 130px; display: grid; justify-items: center; padding: 13px 18px; border: 1px solid #d6c793; border-radius: var(--radius-md); background: var(--brand-100); }
.database-summary strong { font-size: 26px; line-height: 1.1; }
.database-summary span { margin-top: 3px; color: var(--text-secondary); font-size: 11px; font-weight: 600; }
.toolbar { display: grid; gap: 10px; margin-bottom: 15px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-muted); }
.database-toolbar { grid-template-columns: minmax(260px,1fr) 160px 180px auto auto; align-items: end; }
.audit-toolbar { grid-template-columns: minmax(260px,1fr) 190px 150px 150px auto; align-items: end; }
.search-field { display: block; }
.filter-field { display: grid; gap: 4px; color: var(--text-secondary); font-size: 11px; font-weight: 600; }
.table-wrap { position: relative; overflow: visible; border: 1px solid var(--border); border-radius: var(--radius-md); background: #fff; }
.data-table { width: 100%; border-collapse: collapse; table-layout: auto; }
.data-table th, .data-table td { padding: 12px 13px; border-bottom: 1px solid #ebe7dc; vertical-align: top; text-align: left; font-size: 13px; line-height: 20px; }
.data-table th { color: #575143; background: #f3eedf; font-size: 11px; font-weight: 700; letter-spacing: .035em; text-transform: uppercase; }
.data-table th:first-child { border-radius: 11px 0 0 0; }
.data-table th:last-child { border-radius: 0 11px 0 0; }
.data-table tbody tr:hover { background: #fcfaf4; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .primary-cell { font-weight: 600; }
.data-table .muted-cell { color: var(--text-secondary); font-size: 12px; }
.data-table small { display: block; margin-top: 2px; color: var(--text-muted); font-size: 11px; line-height: 16px; }
.jo-link { min-height: 0; border: 0; padding: 0; color: var(--text-primary); background: none; font-weight: 700; text-decoration: underline; text-decoration-color: #c6b77e; text-underline-offset: 3px; }
.table-actions { position: relative; display: flex; align-items: center; justify-content: flex-end; gap: 6px; white-space: nowrap; }
.table-action { min-height: 36px; border: 1px solid var(--border-strong); border-radius: 7px; padding: 7px 10px; color: #403a2b; background: #fff; font-size: 12px; font-weight: 600; }
.table-action:hover { background: var(--brand-50); }
.row-menu-trigger {
  display: grid;
  place-items: center;
  min-width: 38px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 9px;
  color: var(--text-primary);
  background: #fff;
  font-weight: 700;
  letter-spacing: .08em;
}
.row-menu-trigger:hover,
.row-menu-trigger[aria-expanded="true"] { border-color: #b9aa79; background: var(--brand-100); }
.row-action-popover {
  position: fixed;
  z-index: 850;
  display: grid;
  width: 220px;
  max-width: calc(100vw - 24px);
  gap: 2px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow-lg);
}
.row-action-popover button {
  display: block;
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  padding: 9px 10px;
  color: var(--text-primary);
  background: transparent;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
}
.row-action-popover button:hover,
.row-action-popover button:focus-visible { background: var(--surface-muted); }
.row-action-popover button.danger { color: var(--danger); }
/* Detail menu pada tabel pengguna tetap berada di dalam sel. */
.row-menu { position: relative; }
.row-menu > summary { list-style: none; display: grid; place-items: center; min-width: 36px; min-height: 36px; border: 1px solid var(--border); border-radius: 7px; background: #fff; cursor: pointer; font-weight: 700; }
.row-menu > summary::-webkit-details-marker { display: none; }
.row-menu[open] > summary { background: var(--brand-100); }
.row-menu-popover { position: absolute; top: calc(100% + 6px); right: 0; z-index: 30; display: grid; width: 190px; padding: 5px; border: 1px solid var(--border); border-radius: 10px; background: #fff; box-shadow: var(--shadow-md); }
.row-menu-popover button { display: block; width: 100%; min-height: 38px; border: 0; border-radius: 7px; padding: 8px 9px; color: var(--text-primary); background: transparent; text-align: left; font-size: 12px; font-weight: 600; }
.row-menu-popover button:hover { background: var(--surface-muted); }
.row-menu-popover button.danger { color: var(--danger); }
.empty-state { min-height: 190px; display: grid; place-content: center; justify-items: center; gap: 4px; color: var(--text-secondary); text-align: center; }
.empty-state strong { color: var(--text-primary); font-size: 15px; }
.system-note { margin: 14px 2px 0; color: var(--text-muted); font-size: 11px; }
.pagination-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 14px; margin-top: 14px; color: var(--text-secondary); font-size: 12px; }
.pagination-bar > label { display: flex; align-items: center; gap: 7px; }
.pagination-bar select { min-height: 36px; border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px; background: #fff; }
.pagination-bar > span { text-align: center; }
.pagination-bar > div { display: flex; justify-content: flex-end; gap: 7px; }
.audit-change-list { display: grid; gap: 5px; max-width: 430px; }
.audit-change { padding: 7px 8px; border-radius: 7px; background: var(--surface-muted); font-size: 11px; line-height: 17px; }
.audit-change strong { display: block; color: var(--text-primary); }
.audit-change span { color: var(--text-secondary); word-break: break-word; }
.technical-details { margin-top: 6px; color: var(--text-secondary); font-size: 11px; }
.technical-details summary { cursor: pointer; font-weight: 600; }
.technical-details pre { max-width: 430px; max-height: 170px; overflow: auto; margin: 7px 0 0; padding: 8px; border-radius: 7px; background: #2e2a20; color: #f7f2df; font: 10px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.version-panel { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--border); }
.version-panel h2 { margin-bottom: 12px; }
.version-list { display: grid; gap: 9px; }
.version-item { display: grid; grid-template-columns: minmax(200px,1fr) auto; gap: 4px 14px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-warm); }
.version-item strong { font-size: 13px; }
.version-item span { color: var(--text-secondary); font-size: 11px; }
.version-item p { grid-column: 1 / -1; margin: 2px 0 0; color: var(--text-secondary); font-size: 12px; }

/* User drawer */
.drawer { position: fixed; inset: 0; z-index: 500; visibility: hidden; pointer-events: none; }
.drawer.is-open { visibility: visible; pointer-events: auto; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(30,27,20,.45); opacity: 0; transition: opacity .2s ease; }
.drawer.is-open .drawer-backdrop { opacity: 1; }
.drawer-panel { position: absolute; top: 0; right: 0; width: min(460px, 100%); height: 100%; overflow: auto; padding: 22px; background: #fff; box-shadow: -16px 0 42px rgba(37,31,15,.18); transform: translateX(100%); transition: transform .22s ease; }
.drawer.is-open .drawer-panel { transform: translateX(0); }
.drawer-panel > header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.drawer-panel h2 { font-size: 20px; }
.drawer-panel form { display: grid; gap: 2px; padding-top: 6px; }
.drawer-info { margin-top: 14px; padding: 12px; border: 1px solid #d4c796; border-radius: 9px; color: var(--text-secondary); background: var(--brand-50); font-size: 12px; line-height: 1.6; }
.drawer-actions { position: sticky; bottom: -22px; display: flex; justify-content: flex-end; gap: 8px; margin: 24px -22px -22px; padding: 14px 22px; border-top: 1px solid var(--border); background: rgba(255,255,255,.96); backdrop-filter: blur(10px); }

/* Modal */
.app-dialog { width: min(520px, calc(100% - 32px)); max-height: calc(100vh - 40px); padding: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); color: var(--text-primary); background: #fff; box-shadow: var(--shadow-lg); }
.app-dialog::backdrop { background: rgba(30,27,20,.48); backdrop-filter: blur(2px); }
.app-dialog form { display: grid; grid-template-columns: 38px minmax(0,1fr); gap: 13px; padding: 22px; }
.dialog-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: var(--surface-dark); background: var(--brand-300); font-weight: 700; }
.dialog-icon.danger { color: #fff; background: var(--danger); }
.dialog-content h2 { font-size: 19px; }
.dialog-content > p { margin: 6px 0 0; color: var(--text-secondary); font-size: 13px; line-height: 1.65; white-space: pre-line; }
.dialog-content .field { margin-top: 16px; }
.dialog-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 7px; padding-top: 16px; border-top: 1px solid var(--border); }

/* Toast */
.toast-region { position: fixed; right: 20px; bottom: 20px; z-index: 900; display: grid; gap: 8px; width: min(390px, calc(100% - 40px)); pointer-events: none; }
.toast { padding: 12px 14px; border: 1px solid #bfae70; border-radius: 10px; color: var(--text-primary); background: var(--brand-300); box-shadow: var(--shadow-md); font-size: 12px; font-weight: 600; opacity: 0; transform: translateY(10px); animation: toast-in .2s ease forwards; }
.toast.error { color: var(--danger); background: var(--danger-bg); border-color: #d8a2a2; }
.toast.success { color: var(--success); background: var(--success-bg); border-color: #91c5a4; }
@keyframes toast-in { to { opacity: 1; transform: translateY(0); } }

/* Responsive */
@media (max-width: 1450px) {
  :root { --context-height: 82px; }
  .app-header { grid-template-columns: auto minmax(0,1fr) auto; gap: 14px; }
  .view-tab { padding-inline: 9px; }
  .record-context { align-items: flex-start; }
  .context-actions { flex-wrap: wrap; }
  .workspace { grid-template-columns: minmax(620px, 54%) minmax(430px,46%); }
  .form-area { grid-template-columns: 150px minmax(0,1fr); }
  .section-nav { margin-left: 12px; padding-inline: 7px; }
  .section-nav button { padding-inline: 6px; }
  .database-toolbar { grid-template-columns: minmax(240px,1fr) 150px 170px auto; }
  .database-toolbar #exportDatabaseBtn { grid-column: 4; }
}

@media (max-width: 1180px) {
  :root { --header-height: 112px; --context-height: 82px; }
  .app-header { grid-template-columns: minmax(0,1fr) auto; grid-template-areas: "brand user" "nav nav"; align-content: center; }
  .app-brand { grid-area: brand; }
  .header-user-row { grid-area: user; }
  .view-tabs { grid-area: nav; justify-content: flex-start; overflow-x: auto; padding-bottom: 1px; }
  .record-context { top: var(--header-height); }
  .workspace { display: block; }
  .form-area { grid-template-columns: 160px minmax(0,1fr); }
  .form-panel { padding-right: 18px; }
  .preview-panel { position: fixed; inset: 0 0 0 auto; z-index: 300; width: min(720px, 94vw); height: 100vh; transform: translateX(102%); transition: transform .22s ease; box-shadow: -18px 0 45px rgba(0,0,0,.25); }
  .preview-panel.is-open { transform: translateX(0); }
  .preview-close { display: inline-flex; }
  .preview-mobile-trigger { display: inline-flex; }
  .preview-backdrop { position: fixed; inset: 0; z-index: 290; display: block; width: 100%; height: 100%; border: 0; background: rgba(30,27,20,.46); }
  .database-toolbar { grid-template-columns: minmax(240px,1fr) 160px 180px; }
  .database-toolbar .btn { grid-row: 2; }
  .audit-toolbar { grid-template-columns: minmax(240px,1fr) 180px 150px 150px; }
  .audit-toolbar .btn { grid-column: 4; }
}

@media (max-width: 900px) {
  :root { --header-height: 112px; --context-height: auto; }
  .record-context { position: relative; top: auto; align-items: stretch; flex-direction: column; }
  .record-summary > div span { white-space: normal; }
  .context-actions { justify-content: flex-start; }
  .form-area { display: block; }
  .section-nav { position: sticky; top: var(--header-height); z-index: 60; display: flex; max-height: none; margin: 0; overflow-x: auto; border-width: 0 0 1px; border-radius: 0; padding: 8px 14px; box-shadow: var(--shadow-sm); }
  .section-nav > p { display: none; }
  .section-nav button { flex: 0 0 auto; min-height: 42px; grid-template-columns: 22px auto; }
  .section-nav button > span { width: 22px; height: 22px; grid-row: auto; }
  .section-nav button i { display: none; }
  .form-panel { padding: 18px 14px 44px; }
  .form-intro { align-items: flex-start; }
  .completion-meter { width: 130px; }
  .field-grid.cols-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .field-grid.cols-3 .field:first-child { grid-column: span 2; }
  .attribute-groups { grid-template-columns: 1fr; }
  .checkbox-grid.cols-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .content-view { padding: 14px; }
  .content-shell { padding: 17px; border-radius: var(--radius-md); }
  .page-heading { align-items: flex-start; }
  .database-toolbar, .audit-toolbar { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
  .database-toolbar .btn, .audit-toolbar .btn { grid-row: auto; grid-column: auto; }
  .responsive-table-wrap { border: 0; background: transparent; }
  .responsive-table-wrap .data-table, .responsive-table-wrap tbody, .responsive-table-wrap tr, .responsive-table-wrap td { display: block; width: 100%; }
  .responsive-table-wrap thead { display: none; }
  .responsive-table-wrap tbody { display: grid; gap: 10px; }
  .responsive-table-wrap tr { padding: 12px; border: 1px solid var(--border); border-radius: 11px; background: #fff; box-shadow: var(--shadow-sm); }
  .responsive-table-wrap td { display: grid; grid-template-columns: 125px minmax(0,1fr); gap: 10px; padding: 7px 0; border: 0; }
  .responsive-table-wrap td::before { content: attr(data-label); color: var(--text-muted); font-size: 10px; font-weight: 700; letter-spacing: .035em; text-transform: uppercase; }
  .responsive-table-wrap td[data-label="Aksi"] { display: block; padding-top: 10px; border-top: 1px solid var(--border); }
  .responsive-table-wrap td[data-label="Aksi"]::before { display: none; }
  .table-actions { justify-content: flex-start; }
  .row-menu-popover { left: 0; right: auto; }
  .audit-change-list, .technical-details pre { max-width: none; }
}

@media (max-width: 640px) {
  :root { --header-height: auto; }
  .app-header { position: relative; display: flex; align-items: stretch; flex-direction: column; padding: 10px 12px; }
  .header-user-row { position: absolute; top: 10px; right: 12px; }
  .current-user { display: none; }
  .app-brand { padding-right: 72px; }
  .section-nav { top: 0; }
  .view-tabs { width: 100%; }
  .view-tab { flex: 0 0 auto; }
  .record-context { padding: 12px; }
  .record-summary { align-items: flex-start; flex-wrap: wrap; }
  .record-summary > div { order: 3; width: 100%; }
  .context-actions { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); width: 100%; }
  .context-actions .btn { width: 100%; }
  .action-menu { position: absolute; right: 12px; top: 12px; }
  .menu-trigger { min-height: 34px; }
  .form-intro { display: block; }
  .completion-meter { width: 100%; margin-top: 12px; }
  .field-grid.cols-2, .field-grid.cols-3 { grid-template-columns: 1fr; }
  .field-grid.cols-3 .field:first-child, .span-2 { grid-column: auto; }
  .checkbox-grid.cols-2, .checkbox-grid.cols-3 { grid-template-columns: 1fr; }
  .section-heading { grid-template-columns: 34px minmax(0,1fr); padding: 14px; }
  .section-toggle { grid-column: 2; justify-self: start; margin-top: -3px; }
  .section-body { padding-inline: 14px; }
  .page-heading { display: block; }
  .page-heading > .btn, .database-summary { margin-top: 14px; }
  .database-summary { width: fit-content; }
  .database-toolbar, .audit-toolbar { grid-template-columns: 1fr; }
  .search-field { grid-column: auto; }
  .pagination-bar { grid-template-columns: 1fr; justify-items: stretch; }
  .pagination-bar > span { order: -1; text-align: left; }
  .pagination-bar > div { justify-content: stretch; }
  .pagination-bar > div .btn { flex: 1; }
  .responsive-table-wrap td { grid-template-columns: 105px minmax(0,1fr); }
  .login-brand { display: block; }
  .login-brand .brand-monogram { margin-bottom: 14px; }
  .drawer-panel { padding: 18px; }
  .drawer-actions { margin-inline: -18px; padding-inline: 18px; }
  .app-dialog form { grid-template-columns: 1fr; }
  .dialog-icon { display: none; }
  .dialog-actions { grid-column: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

@media print {
  @page { size: A4 portrait; margin: 18mm; }
  body { background: #fff !important; }
  body > * { display: none !important; }
  body::before {
    content: "Gunakan tombol Buka PDF / Cetak pada aplikasi.";
    display: block !important;
    max-width: 640px;
    margin: 40px auto;
    padding: 24px;
    border: 1px solid #bfb49b;
    border-radius: 10px;
    color: #2e2a20;
    background: #fbf8ed;
    font: 600 14px/1.6 "Montserrat", "Segoe UI", Arial, sans-serif;
    text-align: center;
  }
}
