:root {
  --canvas: #FAF8F9;
  --surface: #FFFFFF;
  --surface-muted: #F5F1F3;
  --ink: #241A21;
  --muted: #746A71;
  --border: #E8DFE3;
  --rose: #C02F62;
  --rose-dark: #8E2047;
  --rose-soft: #F8E8EE;
  --success: #23846C;
  --warning: #A96818;
  --danger: #B6404B;
  --info: #4765A8;
  --shadow: 0 8px 24px rgba(36, 26, 33, .06);
  --radius: 10px;
  --display: 'Noto Serif SC', Georgia, serif;
  --body: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'DM Mono', 'SFMono-Regular', Consolas, monospace;
}
* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; color: var(--ink); font-family: var(--body); background: var(--canvas); line-height: 1.55; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
:focus-visible { outline: 3px solid rgba(192,47,98,.35); outline-offset: 3px; }
.app { min-height: 100vh; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0,1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 24px 16px; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 28px; z-index: 3; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; position: relative; background: var(--rose); box-shadow: inset 0 -7px 0 rgba(0,0,0,.08); }
.brand-mark::after { content: ''; position: absolute; left: 7px; right: 7px; top: 9px; height: 2px; background: #fff; border-radius: 2px; box-shadow: 0 5px 0 #fff, 0 10px 0 rgba(255,255,255,.7); }
.brand h1 { margin: 0; font: 700 20px/1.1 var(--display); letter-spacing: .02em; }
.brand small { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; letter-spacing: .05em; }
.nav { display: grid; gap: 6px; }
.nav-group { display: grid; gap: 3px; }
.nav-group-label { padding: 0 12px 5px; color: var(--muted); font-size: 11px; font-weight: 700; }
.nav-settings { margin-top: 18px; }
.nav button, .nav-cta, .mobile-nav button { border: 0; text-align: left; padding: 11px 12px; border-radius: 8px; display: flex; gap: 10px; align-items: center; font-weight: 600; background: transparent; }
.nav button:hover, .nav button.active, .mobile-nav button.active { background: var(--rose-soft); color: var(--rose-dark); }
.nav-cta { width: 100%; margin: 8px 0; background: var(--rose); color: #fff; justify-content: flex-start; box-shadow: 0 5px 12px rgba(192,47,98,.18); }
.nav-cta:hover { background: var(--rose-dark); }
.nav-icon { width: 20px; text-align: center; font-size: 17px; color: currentColor; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding: 16px 12px 0; font-size: 12px; color: var(--muted); }
.sidebar-foot strong { display: block; color: var(--ink); font-family: var(--mono); font-size: 13px; margin: 3px 0; }
.main { min-width: 0; padding: 28px clamp(20px, 4vw, 52px) 72px; }
.content { max-width: 1100px; margin: 0 auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .04em; }
h2, h3, h4 { margin: 0; font-family: var(--body); font-weight: 700; }
h2 { font-size: 28px; line-height: 34px; }
h3 { font-size: 18px; line-height: 24px; }
h4 { font-size: 16px; }
.mono { font-family: var(--mono); }.muted { color: var(--muted); }.small { font-size: 12px; }
.btn { min-height: 44px; border: 1px solid transparent; border-radius: 8px; padding: 10px 16px; font-weight: 700; display: inline-flex; justify-content: center; align-items: center; gap: 8px; transition: transform .16s ease, background .16s ease, color .16s ease, box-shadow .16s ease; }
.btn:active { transform: translateY(1px); }.btn-primary { background: var(--rose); color: #fff; box-shadow: 0 5px 12px rgba(192,47,98,.15); }.btn-primary:hover { background: var(--rose-dark); }.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--rose-dark); }.btn-ghost:hover { background: var(--surface-muted); border-color: #d7cbd1; }.btn-soft { background: var(--rose-soft); color: var(--rose-dark); border-color: transparent; }.btn-danger { background: var(--danger); color: #fff; }.btn-link { border: 0; background: transparent; color: var(--rose); padding: 5px 0; min-height: 32px; font-weight: 700; }.btn-block { width: 100%; }.icon-btn { width: 44px; height: 44px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; display: inline-grid; place-items: center; font-size: 18px; }
.paper-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: none; }.paper-card.flat { box-shadow: none; }.panel { padding: 20px; }.panel + .panel { margin-top: 16px; }.ledger-spine { border-left: 0; padding-left: 20px; }.rule-title { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }.login-wrap { width: min(100%, 980px); display: grid; grid-template-columns: 1fr 410px; gap: 36px; align-items: center; }.login-hero { padding: 38px; }.login-hero .display-number { color: var(--rose-dark); font: 600 clamp(46px,7vw,88px)/.95 var(--display); letter-spacing: -.06em; margin: 24px 0; }.login-hero p { max-width: 440px; color: var(--muted); font-size: 16px; }.login-card { padding: 30px; }.form-stack { display: grid; gap: 16px; }.field { display: grid; gap: 7px; }.field label { font-size: 13px; font-weight: 700; }.field input, .field select, .field textarea, .search-input { width: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); padding: 11px 13px; min-height: 46px; }.field input:focus, .field select:focus, .field textarea:focus, .search-input:focus { border-color: var(--rose); outline: 3px solid rgba(192,47,98,.12); }.field textarea { min-height: 92px; resize: vertical; }.field input::placeholder, .field textarea::placeholder { color: #A79CA2; }.field-error { color: var(--danger); font-size: 12px; }.password-wrap { position: relative; }.password-wrap input { padding-right: 54px; }.password-toggle { position: absolute; right: 8px; top: 6px; height: 34px; border: 0; background: transparent; color: var(--muted); }
.month-bar { display: flex; align-items: end; justify-content: space-between; gap: 16px; padding: 12px 0 18px; }.month-label { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }.month-select { border: 0; background: transparent; padding: 0; font-weight: 700; font-size: 16px; }.month-select span { color: var(--rose); margin-left: 5px; }.date-range { color: var(--muted); font-size: 13px; }
.hero-grid { display: grid; grid-template-columns: minmax(0,7fr) minmax(300px,5fr); gap: 16px; }.cover-sheet { position: relative; overflow: hidden; padding: 24px; min-height: 220px; background: var(--rose-dark); color: #fff; border-color: var(--rose-dark); }.cover-sheet::before { content: ''; position: absolute; right: -30px; bottom: -70px; width: 180px; height: 180px; border: 1px solid rgba(255,255,255,.15); border-radius: 50%; box-shadow: 0 0 0 22px rgba(255,255,255,.06), 0 0 0 44px rgba(255,255,255,.04); }.cover-sheet .label { color: #f4cbd8; font-size: 13px; margin: 0; }.total { margin: 18px 0 12px; font: 500 clamp(34px,5vw,52px)/1 var(--mono); letter-spacing: -.07em; }.cover-meta { display: flex; gap: 20px; flex-wrap: wrap; color: #f4cbd8; font-size: 12px; }.kpi-head { display:flex; justify-content:space-between; gap:16px; align-items:center; }.kpi-trend { color:#f4cbd8; font-size:12px; }.hero-cta { position: relative; margin-top: 20px; background:#fff; color:var(--rose-dark); box-shadow:none; }.hero-cta:hover { background:#fbeef2; }
.spine-note { display: flex; flex-direction: column; justify-content: space-between; padding: 20px; }.review-summary { display:flex; align-items:flex-start; gap:12px; }.review-icon { width:32px; height:32px; display:grid; place-items:center; border-radius:50%; color:var(--warning); background:#FFF4DF; font-weight:800; }.review-summary .label { margin:0 0 4px; color:var(--muted); font-size:12px; }.review-summary h3 { font-size:20px; }.review-summary p:last-child { margin:5px 0 0; font-size:12px; }.spine-note > .btn { margin: 20px 0 12px; }.note-list { display: grid; gap: 0; }.note-row { display: flex; justify-content: space-between; gap: 10px; border-top: 1px solid var(--border); padding: 10px 0 0; margin-top: 10px; font-size: 13px; }
.section { margin-top: 22px; }.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 11px; }.section-head h3 { font-size: 18px; }.section-head a { font-size: 13px; color: var(--rose); font-weight: 700; }.action-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }.action-card { text-align: left; min-height: 84px; padding: 15px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); position: relative; overflow: hidden; transition: border-color .16s ease, background .16s ease, transform .16s ease; }.action-card:hover { border-color: #d5a7b7; background: #fffafc; transform: translateY(-1px); }.action-card strong { display:block; margin-top: 8px; font-size: 16px; }.action-card small { display:block; color:var(--muted); margin-top:3px; }.action-card .action-icon { position:absolute; top:14px; right:16px; color:var(--rose); font-size:22px; }
.bill-list { display:grid; gap:0; background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); overflow:hidden; }.bill-group-label { padding:11px 16px 8px; color:var(--muted); font-size:11px; font-weight:700; background:var(--surface-muted); }.bill-row { width:100%; text-align:left; border:0; border-bottom:1px solid var(--border); background:transparent; padding:14px 16px; display:grid; grid-template-columns:minmax(0,1fr) auto auto auto; gap:14px; align-items:center; transition:background .16s ease; }.bill-row:last-child { border-bottom:0; }.bill-row:hover, .bill-row:focus-visible { background:var(--surface-muted); }.bill-row::after { content:'›'; color:var(--muted); font-size:20px; }.bill-primary { min-width:0; }.bill-primary strong { display:block; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }.bill-primary small { display:block; margin-top:4px; color:var(--muted); font-size:12px; }.bill-amount { font:500 16px var(--mono); white-space:nowrap; }.status { display:inline-flex; align-items:center; gap:5px; border:0; border-radius:999px; padding:4px 9px; font-size:11px; font-weight:700; white-space:nowrap; }.status.confirmed { color:var(--success); background:#E8F5F0; }.status.review { color:var(--warning); background:#FFF4DF; }.status.draft { color:var(--info); background:#EEF1FB; }
.query-toolbar { display:grid; grid-template-columns:minmax(0,1fr) repeat(4,minmax(130px,auto)); gap:8px; align-items:center; }.search-wrap { position:relative; }.search-wrap span { position:absolute; left:13px; top:11px; color:var(--muted); }.search-wrap input { padding-left:38px; }.summary-strip { display:flex; gap:18px; flex-wrap:wrap; padding:12px 0 0; color:var(--muted); font-size:13px; }.summary-strip strong { color:var(--ink); font-family:var(--mono); }
.upload-grid { display:grid; gap:10px; }.upload-slot { border:1px dashed #d9cbd1; border-radius:8px; padding:14px; background:var(--surface-muted); min-height:96px; }.upload-slot.required { border-left:3px solid var(--rose); }.slot-head { display:flex; justify-content:space-between; gap:12px; align-items:flex-start; }.slot-head strong { font-size:14px; }.slot-head small { color:var(--muted); display:block; margin-top:4px; }.slot-count { color:var(--rose); font:12px var(--mono); white-space:nowrap; }.slot-empty { margin-top:12px; display:flex; justify-content:space-between; align-items:center; gap:10px; }.slot-file { margin-top:12px; display:flex; gap:12px; align-items:center; }.file-icon { width:40px; height:40px; border-radius:7px; border:1px solid var(--border); background:var(--surface); display:grid; place-items:center; color:var(--rose); font:700 11px var(--mono); }.file-meta { min-width:0; flex:1; }.file-meta strong { display:block; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }.file-meta small { color:var(--muted); }.file-actions { display:flex; gap:8px; flex-wrap:wrap; }.form-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:16px; }.form-grid .full { grid-column:1/-1; }.sticky-save { position:sticky; bottom:12px; display:flex; justify-content:flex-end; gap:8px; padding-top:16px; z-index:2; }
.detail-grid { display:grid; grid-template-columns:minmax(0,1.15fr) minmax(320px,.85fr); gap:16px; }.detail-amount { font:500 40px var(--mono); letter-spacing:-.05em; margin:14px 0 4px; }.fact-list { display:grid; gap:0; }.fact { display:flex; justify-content:space-between; gap:18px; padding:12px 0; border-bottom:1px solid var(--border); font-size:14px; }.fact dt { color:var(--muted); }.fact dd { margin:0; text-align:right; font-weight:600; }.attachment-stack { display:grid; gap:10px; }.attachment-card { border:1px solid var(--border); border-radius:8px; padding:13px; background:var(--surface); }.attachment-card .slot-head { align-items:center; }.attachment-card.empty { border-style:dashed; }
.config-tabs { display:flex; gap:8px; border-bottom:1px solid var(--border); margin-bottom:16px; overflow-x:auto; }.tab { border:0; border-bottom:3px solid transparent; background:transparent; padding:10px 4px; white-space:nowrap; font-weight:700; color:var(--muted); }.tab.active { border-bottom-color:var(--rose); color:var(--rose-dark); }.config-row { display:grid; grid-template-columns:28px minmax(0,1fr) auto auto auto; gap:12px; align-items:center; padding:14px 0; border-bottom:1px solid var(--border); }.drag { color:var(--rose); font-size:18px; cursor:grab; }.config-row strong { display:block; }.config-row small { color:var(--muted); }.badge { padding:4px 8px; border:0; border-radius:999px; color:var(--muted); background:var(--surface-muted); font-size:11px; }.toggle { width:42px; height:24px; border:0; border-radius:999px; padding:3px; background:#d9cfd4; }.toggle::after { content:''; display:block; width:18px; height:18px; border-radius:50%; background:#fff; transition:transform .16s ease; }.toggle.on { background:var(--rose); }.toggle.on::after { transform:translateX(18px); }
.mobile-nav { display:none; }.toast { position:fixed; left:50%; bottom:26px; transform:translateX(-50%); background:var(--ink); color:#fff; padding:11px 15px; border-radius:8px; box-shadow:var(--shadow); z-index:20; font-size:13px; }.modal-backdrop { position:fixed; inset:0; background:rgba(36,26,33,.42); display:grid; place-items:center; z-index:10; padding:18px; }.modal { width:min(100%,520px); max-height:min(90vh,720px); overflow:auto; background:var(--surface); border:1px solid var(--border); border-radius:12px; box-shadow:0 28px 80px rgba(36,26,33,.2); }.modal-head { display:flex; justify-content:space-between; align-items:center; gap:12px; padding:18px 20px; border-bottom:1px solid var(--border); }.modal-body { padding:20px; }.modal-actions { display:flex; justify-content:flex-end; gap:8px; margin-top:20px; }.viewer { width:min(100%,900px); max-height:92vh; background:var(--rose-dark); color:#fff; border:1px solid var(--rose); border-radius:12px; overflow:hidden; }.viewer-head { display:flex; justify-content:space-between; align-items:center; padding:14px 16px; }.viewer-canvas { min-height:360px; display:grid; place-items:center; padding:26px; background:#241421; }.fake-image { width:min(100%,480px); min-height:300px; padding:30px; display:grid; place-items:center; text-align:center; background:linear-gradient(135deg,#f7e8ee,#fff); color:var(--rose-dark); border:10px solid #fff; box-shadow:0 0 0 1px var(--border); font-family:var(--display); font-size:25px; }.fake-pdf { width:min(100%,520px); min-height:330px; background:#fff; color:var(--ink); padding:30px; border:1px solid var(--border); position:relative; }.fake-pdf::before { content:'PURCHASE DOCUMENT'; color:var(--rose); font:12px var(--mono); letter-spacing:.12em; }.fake-pdf h3 { margin:34px 0 20px; }.fake-pdf .pdf-lines { display:grid; gap:12px; }.fake-pdf .pdf-lines i { display:block; height:8px; background:var(--surface-muted); width:88%; }.fake-pdf .pdf-lines i:nth-child(2) { width:64%; }.fake-pdf .pdf-lines i:nth-child(3) { width:78%; }.viewer-foot { background:#fff; color:var(--ink); padding:15px 16px; display:flex; justify-content:space-between; gap:16px; align-items:center; flex-wrap:wrap; }.viewer-foot small { display:block; color:var(--muted); }.empty-state { text-align:center; padding:42px 20px; color:var(--muted); }.empty-state strong { display:block; color:var(--ink); font:700 20px var(--body); margin-bottom:6px; }.notice { padding:12px 14px; border-left:3px solid var(--warning); border-radius:4px; background:#FFF4DF; color:#754713; font-size:13px; }.notice.info { border-left-color:var(--info); background:#EEF1FB; color:#2e477f; }.notice.success { border-left-color:var(--success); background:#E8F5F0; color:#255e50; }
@media (max-width:1023px) and (min-width:768px) { .app-shell { grid-template-columns:72px minmax(0,1fr); }.sidebar { padding:20px 10px; }.brand > div, .nav-group-label, .nav button span:not(.nav-icon), .nav-cta span:not(.nav-icon), .sidebar-foot { display:none; }.nav button, .nav-cta { justify-content:center; padding-inline:8px; }.main { padding-inline:28px; }.content { max-width:1000px; } }
@media (max-width:767px) { .app-shell { grid-template-columns:1fr; }.sidebar { display:none; }.main { padding:20px 16px 128px; }.topbar { align-items:flex-start; margin-bottom:10px; }.topbar .btn { padding-inline:12px; }.topbar .top-actions { display:none; } h2 { font-size:26px; }.mobile-nav { display:grid; position:fixed; left:12px; right:12px; bottom:calc(10px + env(safe-area-inset-bottom)); grid-template-columns:repeat(4,1fr); gap:4px; padding:6px; background:#fff; border:1px solid var(--border); border-radius:12px; box-shadow:0 8px 24px rgba(36,26,33,.12); z-index:5; }.mobile-nav button { min-height:52px; padding:6px 4px; justify-content:center; flex-direction:column; gap:2px; font-size:11px; }.mobile-nav button[data-nav='bill-record'] { background:var(--rose); color:#fff; border-radius:8px; }.mobile-nav .nav-icon { font-size:16px; }.hero-grid { grid-template-columns:1fr; gap:12px; }.month-bar { padding-top:8px; }.cover-sheet { min-height:auto; padding:20px; }.total { font-size:38px; }.spine-note { padding:16px; }.quick-section { margin-top:20px; }.action-card { min-height:76px; }.panel { padding:16px; }.section { margin-top:20px; }.form-grid { grid-template-columns:1fr; gap:13px; }.form-grid .full { grid-column:auto; }.action-grid { grid-template-columns:1fr 1fr; }.bill-row { grid-template-columns:minmax(0,1fr) auto; gap:7px 12px; padding:13px 12px; }.bill-row .status { grid-column:1; justify-self:start; }.bill-amount { grid-column:2; grid-row:1/span 2; align-self:center; }.bill-row::after { display:none; }.query-toolbar { grid-template-columns:1fr 1fr; }.query-toolbar .search-wrap { grid-column:1/-1; }.config-row { grid-template-columns:24px minmax(0,1fr) auto; }.config-row .badge,.config-row .toggle { grid-row:2; }.config-row .btn-link { grid-column:3; grid-row:1; }.slot-empty { align-items:flex-start; flex-direction:column; }.sticky-save { bottom:82px; flex-direction:column-reverse; background:linear-gradient(transparent,#fff 22%); margin-inline:-2px; padding-bottom:4px; }.sticky-save .btn { width:100%; }.viewer-canvas { min-height:300px; padding:16px; }.viewer-foot { align-items:stretch; flex-direction:column; }.viewer-foot .file-actions { width:100%; }.viewer-foot .btn { flex:1; } }

@media (min-width: 768px) {
  .form-grid { grid-template-areas: 'amount supplier' 'date category' 'dynamic dynamic'; }
  .field-amount { grid-area: amount; }
  .field-supplier { grid-area: supplier; }
  .field-date { grid-area: date; }
  .field-category { grid-area: category; }
}
@media (max-width: 767px) {
  .form-grid { display: flex; flex-direction: column; }
  .field-amount { order: 1; }
  .field-supplier { order: 2; }
  .field-date { order: 3; }
  .field-category { order: 4; }
  .form-grid > .field:not(.field-amount):not(.field-supplier):not(.field-date):not(.field-category):not(.full) { order: 5; }
  .form-grid > .full { order: 6; }
}
.invoice-result { color: var(--success) !important; margin-top: 4px; }

/* Detail layout safeguards */
.detail-grid > * { min-width: 0; }

/* Attachment filename overflow safeguards */
.viewer-foot > div:first-child { min-width: 0; flex: 1 1 240px; }
.viewer-foot > div:first-child strong { display: block; min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.modal-body ul { min-width: 0; max-width: 100%; padding-left: 22px; }
.modal-body li { overflow-wrap: anywhere; word-break: break-word; }

.detail-amount { font-size: clamp(30px, 4vw, 40px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.detail-actions { align-items: center; }
.btn-danger-text { min-height: 44px; border: 0; background: transparent; color: var(--danger); padding: 10px 8px; font-weight: 700; border-radius: 8px; }
.btn-danger-text:hover { background: #FFF0F2; }
.attachment-card .file-meta { min-width: 0; }
.attachment-card .file-meta strong { overflow-wrap: anywhere; white-space: normal; }
.attachment-card .file-actions { gap: 6px; }
.nav-cta { min-height: 48px; background: var(--rose) !important; color: #fff !important; border: 0; }
.nav-cta:hover { background: var(--rose-dark) !important; }
.top-actions .btn-primary { min-width: 132px; box-shadow: 0 8px 18px rgba(192,47,98,.22); }
.cover-sheet { background: linear-gradient(135deg, var(--rose-dark) 0%, #B42B61 62%, #D65B82 100%); animation: hero-arrive .5s ease both; }
.cover-sheet::after { content: ''; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 25%, rgba(255,255,255,.13) 45%, transparent 65%); transform: translateX(-120%); animation: hero-shine 5s ease-in-out 1s infinite; pointer-events: none; }
.action-card, .spine-note, .bill-list, .detail-grid > * { animation: surface-arrive .42s ease both; }
.action-card:nth-child(2) { animation-delay: .06s; }
.bill-row { transition: background .18s ease, transform .18s ease, box-shadow .18s ease; }
.bill-row:hover { transform: translateX(3px); box-shadow: inset 3px 0 var(--rose); }
.mobile-nav button.active { background: var(--rose-soft); color: var(--rose-dark); }
.mobile-nav button[data-nav='bill-record'] { background: transparent; color: inherit; }
@keyframes hero-arrive { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes surface-arrive { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes hero-shine { 0%, 55%, 100% { transform: translateX(-120%); } 75% { transform: translateX(120%); } }
@media (max-width: 1023px) {
  .detail-grid { grid-template-columns: 1fr; gap: 12px; }
  .detail-grid > div, .detail-grid > section { width: 100%; }
}
@media (max-width: 767px) {
  .topbar .top-actions.detail-back { display: block; }
}
@media (max-width: 767px) {
  .main { padding-bottom: calc(124px + env(safe-area-inset-bottom)); }
  .detail-actions { position: static; bottom: auto; align-items: stretch; margin-top: 16px; padding-top: 0; flex-direction: column; }
  .detail-actions .btn { min-height: 46px; }
  .detail-actions .btn-danger-text { width: 100%; }
  .attachment-card .slot-file { flex-wrap: wrap; }
  .attachment-card .file-meta { flex-basis: calc(100% - 52px); }
  .attachment-card .file-actions { flex-basis: 100%; width: 100%; padding-top: 4px; }
  .attachment-card .file-actions .btn, .attachment-card .file-actions .btn-link { min-height: 40px; }
}

/* Query filter controls */
.query-toolbar { grid-template-columns: minmax(220px, 2fr) repeat(6, minmax(0, 1fr)); gap: 10px; }
.query-toolbar > * { min-width: 0; }
.query-toolbar .search-input,
.query-toolbar select { width: 100%; min-height: 46px; height: 46px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--ink); font-size: 13px; line-height: 1.2; }
.query-toolbar select { padding-right: 30px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }
.query-toolbar .search-input:focus,
.query-toolbar select:focus,
.query-toolbar input[type='date']:focus { border-color: var(--rose); outline: 3px solid rgba(192,47,98,.12); }
.query-toolbar .search-wrap { min-width: 0; }
.query-date { min-width: 0; display: grid; gap: 4px; }
.query-date > span { color: var(--muted); font-size: 11px; line-height: 1.1; font-weight: 700; }
.query-date input { min-width: 0; }
@media (max-width: 1023px) and (min-width: 768px) {
  .query-toolbar { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .query-toolbar .search-wrap { grid-column: 1 / -1; }
}
@media (max-width: 767px) {
  .query-toolbar { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .query-toolbar .search-wrap { grid-column: 1 / -1; }
  .query-toolbar select { font-size: 12px; }
  .query-date input { font-size: 12px; padding-inline: 9px; }
}

/* Configuration list layout */
.config-panel { max-width: 880px; }
.config-header { align-items: flex-start; }
.config-header > div { min-width: 0; }
.config-add-btn { flex: 0 0 auto; white-space: nowrap; }
.config-row { min-width: 0; }
.config-row > div { min-width: 0; }
.config-row small { display: block; overflow-wrap: anywhere; }
@media (max-width: 767px) {
  .config-panel { padding: 16px; }
  .config-header { display: grid; grid-template-columns: 1fr; gap: 14px; }
  .config-add-btn { width: 100%; }
  .fields-panel .config-row { grid-template-columns: 28px minmax(0, 1fr) 52px; grid-template-rows: auto auto; column-gap: 10px; row-gap: 6px; padding: 16px 0; }
  .fields-panel .config-row .drag { grid-column: 1; grid-row: 1 / span 2; align-self: start; padding-top: 2px; }
  .fields-panel .config-row > div { grid-column: 2; grid-row: 1; }
  .fields-panel .config-row .badge { grid-column: 2; grid-row: 2; justify-self: start; }
  .fields-panel .config-row .toggle { grid-column: 3; grid-row: 2; justify-self: end; }
  .fields-panel .config-row .btn-link { grid-column: 3; grid-row: 1; justify-self: end; }
}
@media (min-width: 768px) {
  .config-row { grid-template-columns: 28px minmax(180px, 1fr) auto auto auto; }
  .config-row .badge { white-space: nowrap; }
  .config-row .btn-link { min-width: 44px; }
}

/* Mobile interaction and control polish */
.inline-control { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; min-width: 0; }
.inline-control select { min-width: 0; }
.inline-control .btn { white-space: nowrap; }
.viewer-head .icon-btn { flex: 0 0 44px; min-width: 44px; margin-left: auto; background: var(--rose-soft); color: var(--rose-dark); border-color: rgba(255,255,255,.45); }
.viewer-head > strong { min-width: 0; }
.summary-strip { align-items: center; }
.export-btn { margin-left: auto; flex: 0 0 auto; white-space: nowrap; }
.mobile-nav { grid-template-columns: 1fr 1.35fr 1fr; }
.mobile-nav button[data-nav='bill-record'] { background: var(--rose); color: #fff; border-radius: 10px; transform: translateY(-5px); box-shadow: 0 8px 18px rgba(192,47,98,.24); }
.mobile-nav button[data-nav='bill-record'] .nav-icon { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.18); font-size: 22px; }
.mobile-nav button[data-nav='bill-record']:hover { background: var(--rose-dark); }
@media (max-width: 767px) {
  .inline-control { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  .inline-control .btn { width: auto; padding-inline: 10px; white-space: nowrap; }
  .summary-strip { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
  .summary-strip .export-btn { grid-column: 1 / -1; width: 100%; margin-left: 0; }
  .mobile-nav { padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .topbar .top-actions.detail-back { display: block; }
}

/* iPhone Safari mobile navigation and native controls */
.query-toolbar > * { min-width: 0; max-width: 100%; }
.query-toolbar .search-wrap .search-input { padding-left: 40px; }
.query-toolbar select,
.query-toolbar input[type="date"],
.query-toolbar .search-input {
  width: 100%; min-width: 0; min-height: 46px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--ink); font-size: 16px; line-height: 24px; -webkit-appearance: none; appearance: none; touch-action: manipulation;
}
.query-toolbar select { background-image: linear-gradient(45deg, transparent 50%, var(--rose-dark) 50%), linear-gradient(135deg, var(--rose-dark) 50%, transparent 50%); background-position: calc(100% - 16px) 20px, calc(100% - 11px) 20px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.query-toolbar input[type="date"] { -webkit-appearance: none; appearance: none; color-scheme: light; }
.query-toolbar input[type="date"]::-webkit-calendar-picker-indicator { opacity: .7; width: 20px; height: 20px; margin-left: 4px; }
.query-toolbar input:focus-visible, .query-toolbar select:focus-visible { border-color: var(--rose); box-shadow: 0 0 0 3px rgba(192,47,98,.14); outline: none; }
.query-date { display: grid; gap: 5px; min-width: 0; }
.query-date span { color: var(--muted); font-size: 12px; font-weight: 700; }

@media (max-width: 767px) {
  :root { --mobile-nav-height: 68px; }
  .mobile-nav { position: fixed; top: 0; bottom: auto; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: 1fr 1.2fr 1fr; gap: 4px; padding: max(8px, env(safe-area-inset-top)) 12px 8px; min-height: calc(var(--mobile-nav-height) + env(safe-area-inset-top)); border: 0; border-bottom: 1px solid var(--border); border-radius: 0 0 16px 16px; background: rgba(255,255,255,.94); box-shadow: 0 8px 22px rgba(36,26,33,.10); backdrop-filter: blur(14px); }
  .mobile-nav button { min-height: 48px; border-radius: 10px; }
  .mobile-nav button[data-nav="bill-record"] { transform: translateY(3px); }
  .main { padding-top: calc(86px + env(safe-area-inset-top)); padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
  .sticky-save { position: sticky; bottom: 0; padding-bottom: max(8px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--surface) 24%); }
  .query-toolbar { grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 10px; }
  .query-toolbar .search-wrap { grid-column: 1 / -1; }
  .query-date input, .query-toolbar select { font-size: 16px; }

/* iPhone-first refinements */
.clear-filters { min-width: 108px; }
.viewer-image { display: block; max-width: 100%; max-height: 560px; object-fit: contain; background: #fff; transform-origin: center center; transition: transform .2s ease; }
.viewer-controls { align-items: center; }
.viewer-controls .btn { min-width: 44px; padding-inline: 10px; }
@media (max-width: 767px) {
  .login-page { display: block; min-height: 100dvh; padding: calc(28px + env(safe-area-inset-top)) 16px 28px; }
  .login-wrap { display: flex; flex-direction: column; gap: 20px; width: 100%; }
  .login-hero { padding: 0 4px; }
  .login-hero h1 { font-size: 36px !important; }
  .login-hero .display-number { margin: 12px 0; font-size: 52px; }
  .login-hero p { font-size: 14px; line-height: 1.6; margin: 0; }
  .login-card { padding: 20px; }
  .login-card .brand h1 { font-size: 18px; }
  .query-toolbar { width: 100%; }
  .query-toolbar select, .query-toolbar input[type="date"], .query-toolbar .search-input { font-size: 16px; min-height: 48px; }
  .summary-strip { grid-template-columns: 1fr 1fr; }
  .clear-filters, .export-btn { width: 100%; min-width: 0; }
  .summary-strip .clear-filters, .summary-strip .export-btn { grid-column: 1 / -1; }
  .viewer { width: calc(100vw - 24px); max-height: calc(100dvh - 24px); }
  .viewer-canvas { min-height: 300px; max-height: 58dvh; overflow: auto; }
  .viewer-image { max-height: 52dvh; }
}

.home-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 8px; }
.home-header h2 { font-size: 24px; }
.home-add { min-width: 128px; }
@media (max-width: 767px) {
  .home-header { align-items: flex-start; }
  .home-header .home-add { min-width: 44px; padding-inline: 12px; font-size: 0; }
  .home-header .home-add::before { content: '+'; font-size: 24px; line-height: 1; }
}

/* Cute simplified home and top-left back controls */
.topbar.has-back { justify-content: flex-start; }
.topbar.has-back .topbar-back { flex: 0 0 46px; width: 46px; height: 46px; border: 0; border-radius: 50%; background: var(--rose-soft); color: var(--rose-dark); font-size: 34px; line-height: 1; display: grid; place-items: center; cursor: pointer; transition: transform .2s ease, background .2s ease; }
.topbar.has-back .topbar-back:hover { background: var(--rose); color: #fff; transform: translateX(-2px); }
.topbar.has-back > div { min-width: 0; }
.home-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.home-heading h2 { font-size: 28px; }
.home-actions { display: flex; gap: 8px; }
.home-action { min-height: 44px; }
.home-shortcuts { margin-top: 12px; }
.shortcut-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.cute-shortcut { min-height: 88px; display: flex; align-items: center; gap: 12px; padding: 14px 16px; border: 1px solid #F0D2DE; border-radius: 20px 12px 20px 12px; background: linear-gradient(135deg, #FFF8FB, #FBE7F0); color: var(--rose-dark); text-align: left; box-shadow: 0 8px 20px rgba(192,47,98,.10); transition: transform .2s ease, box-shadow .2s ease; }
.cute-shortcut:nth-child(2) { border-radius: 12px 20px 12px 20px; background: linear-gradient(135deg, #FFF9F4, #FFF0D9); color: #94601E; }
.cute-shortcut:hover { transform: translateY(-3px) rotate(-.5deg); box-shadow: 0 12px 26px rgba(192,47,98,.16); }
.cute-icon { flex: 0 0 42px; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 15px; background: rgba(255,255,255,.78); font-size: 28px; font-weight: 700; }
.cute-shortcut strong { display: block; font-size: 16px; }
.cute-shortcut small { display: block; margin-top: 4px; color: currentColor; opacity: .72; font-size: 12px; }
.overview-card { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 18px 20px; border-radius: 18px; background: linear-gradient(135deg, #FFF, #FFF7FA); }
.overview-card strong { font-size: 22px; color: var(--rose-dark); }
.overview-card span { color: var(--muted); font-size: 13px; }
@media (max-width: 767px) {
  .main { padding-top: calc(24px + env(safe-area-inset-top)); padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .topbar.has-back { gap: 10px; margin-bottom: 20px; }
  .topbar.has-back .topbar-back { width: 44px; height: 44px; font-size: 32px; }
  .topbar.has-back h2 { font-size: 24px; }
  .topbar.has-back .eyebrow { font-size: 11px; }
  .shortcut-row { grid-template-columns: 1fr; gap: 10px; }
  .cute-shortcut { min-height: 76px; }
  .overview-card { align-items: flex-start; flex-direction: column; gap: 6px; }
}
@media (max-width: 767px) {
  .view-home .topbar .top-actions { display: block; }
  .view-home .topbar .top-actions .btn { min-height: 44px; padding-inline: 12px; white-space: nowrap; }
  .view-home .hero-grid { gap: 12px; }
  .view-home .overview-card { min-height: 104px; justify-content: center; }
}

/* iPhone form-control hardening */
.field, .field > *, .inline-control, .inline-control > * { min-width: 0; max-width: 100%; }
.field select { min-width: 0; max-width: 100%; min-height: 48px; padding-right: 38px; background-image: linear-gradient(45deg, transparent 50%, var(--rose-dark) 50%), linear-gradient(135deg, var(--rose-dark) 50%, transparent 50%); background-position: calc(100% - 16px) 21px, calc(100% - 11px) 21px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; -webkit-appearance: none; appearance: none; touch-action: manipulation; }
.field select:focus-visible { border-color: var(--rose); box-shadow: 0 0 0 3px rgba(192,47,98,.14); outline: none; }
.field input[type="date"], .field input[type="month"], #bill-date, .month-input { width: 100%; min-width: 0; max-width: 100%; height: 48px; min-height: 48px; padding: 10px 12px; box-sizing: border-box; font-size: 16px; line-height: 24px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--ink); -webkit-appearance: auto; appearance: auto; }
.field input[type="date"]::-webkit-date-and-time-value, .field input[type="month"]::-webkit-date-and-time-value, #bill-date::-webkit-date-and-time-value, .month-input::-webkit-date-and-time-value { text-align: left; }
.topbar-back { position: relative; overflow: visible; }
.topbar-back .back-glyph { display: block; transform: translateY(-2px); font-family: Arial, sans-serif; font-size: 34px; line-height: 38px; font-weight: 400; }
.month-input-label { display: block; color: var(--muted); font-size: 12px; font-weight: 700; margin-bottom: 5px; }
.month-input { width: 156px; height: 42px; min-height: 42px; font-size: 16px; font-weight: 700; }
@media (max-width: 767px) {
  .field input[type="date"], .field input[type="month"], #bill-date, .month-input { width: 100%; max-width: 100%; font-size: 16px; }
  .month-input { width: 150px; }
}
}
/* Safari file picker and upload hit target */
body > input[type="file"] { position: fixed; left: -10000px; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
@media (max-width: 767px) {
  .view-bill-record .sticky-save { position: static; bottom: auto; margin-top: 18px; padding: 0; background: transparent; }
  .view-bill-record .upload-grid { padding-bottom: 8px; }
}

/* iOS Safari can keep an intrinsic date-control width unless the control and
   its inner value box are constrained with logical sizing. */
@media (max-width: 767px) {
  .view-bill-record .field-date,
  .view-bill-record .field-date > input {
    inline-size: 100%;
    min-inline-size: 0;
    max-inline-size: 100%;
  }

  .view-bill-record #bill-date {
    display: block;
    width: 100%;
    inline-size: 100%;
    min-width: 0;
    min-inline-size: 0;
    max-width: 100%;
    max-inline-size: 100%;
    -webkit-appearance: none;
    appearance: none;
    overflow: hidden;
  }

  .view-bill-record #bill-date::-webkit-date-and-time-value {
    display: block;
    width: 100%;
    min-width: 0;
    text-align: left;
  }
}

