/* ===== CSS Custom Properties ===== */
:root {
  --c-primary:   #2563EB;
  --c-primary-d: #1D4ED8;
  --c-primary-l: #EFF6FF;
  --c-success:   #16A34A;
  --c-warning:   #D97706;
  --c-danger:    #DC2626;
  --c-bg:        #F1F5F9;
  --c-card:      #FFFFFF;
  --c-border:    #E2E8F0;
  --c-border-l:  #F1F5F9;
  --c-text:      #1E293B;
  --c-muted:     #64748B;
  --c-muted-l:   #94A3B8;
  --radius:      10px;
  --radius-sm:   6px;
  --radius-xs:   4px;
  --shadow:      0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:   0 4px 12px rgba(0,0,0,.08);
  --font:        -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  --tap:         44px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.5;
  overscroll-behavior: none;
}
img { max-width: 100%; display: block; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* ===== Layout ===== */
#app { min-height: 100dvh; display: flex; flex-direction: column; }
.page { flex: 1; padding-bottom: calc(64px + var(--safe-bottom)); }
.container { max-width: 640px; margin: 0 auto; padding: 0 16px; }

/* ===== Splash ===== */
.splash {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100dvh; gap: 12px;
}
.splash-logo { font-size: 56px; }
.splash-text  { font-size: 20px; font-weight: 700; color: var(--c-primary); }

/* ===== Top Bar ===== */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: var(--c-card);
  border-bottom: 1px solid var(--c-border);
  padding: 0 16px;
  height: 52px;
  display: flex; align-items: center; gap: 10px;
}
.topbar-title {
  font-size: 16px; font-weight: 700; flex: 1;
  letter-spacing: -.2px;
}
.topbar-back {
  min-width: 36px; min-height: var(--tap);
  display: flex; align-items: center;
  color: var(--c-primary); font-size: 14px; font-weight: 500;
}

/* ===== Bottom Nav ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: var(--c-card);
  border-top: 1px solid var(--c-border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -1px 8px rgba(0,0,0,.06);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px;
  min-height: 56px; padding: 6px 4px;
  color: var(--c-muted-l); font-size: 10px; font-weight: 500;
  transition: color .15s; position: relative;
}
.nav-item .icon { font-size: 20px; line-height: 1; }
.nav-item.active { color: var(--c-primary); }
.nav-item.active .icon { transform: scale(1.05); }
.nav-badge {
  position: absolute; top: 6px; left: 50%; transform: translateX(4px);
  background: var(--c-danger); color: #fff;
  font-size: 9px; font-weight: 700; min-width: 16px; height: 16px;
  border-radius: 100px; padding: 0 3px;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ===== Panel (white card with border) ===== */
.panel {
  background: var(--c-card);
  border-radius: var(--radius);
  border: 1px solid var(--c-border);
  margin-bottom: 12px;
  overflow: hidden;
}
.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--c-border-l);
  display: flex; align-items: center; gap: 8px;
}
.panel-title {
  font-size: 13px; font-weight: 700;
  color: var(--c-text); flex: 1; letter-spacing: -.1px;
}
.panel-action {
  font-size: 12px; color: var(--c-primary); font-weight: 600;
}

/* ===== Data Table ===== */
.data-table { margin-bottom: 12px; }
.data-table-hd {
  display: flex; align-items: center;
  padding: 7px 16px;
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-border);
}
.data-table-hd span {
  font-size: 11px; font-weight: 600;
  color: var(--c-muted); letter-spacing: .3px;
}
.data-row {
  display: flex; align-items: center;
  min-height: 50px; padding: 10px 16px;
  background: var(--c-card);
  border-bottom: 1px solid var(--c-border-l);
  gap: 10px; color: var(--c-text);
  transition: background .1s;
}
.data-row:last-child { border-bottom: none; }
.data-row:active, .data-row:hover { background: var(--c-primary-l); }

/* ===== Legacy Cards (kept for compat) ===== */
.card {
  background: var(--c-card);
  border-radius: var(--radius);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.card-row {
  display: flex; align-items: center; gap: 12px;
  min-height: 50px; padding: 10px 16px;
  background: var(--c-card);
  border-bottom: 1px solid var(--c-border-l);
  transition: background .1s;
}
.card-row:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.card-row:last-child  { border-bottom: none; border-radius: 0 0 var(--radius) var(--radius); }
.card-row:only-child  { border-radius: var(--radius); border-bottom: none; }
.card-row:active      { background: var(--c-primary-l); }
.card-list {
  border-radius: var(--radius);
  border: 1px solid var(--c-border);
  box-shadow: var(--shadow);
  overflow: hidden; margin-bottom: 12px;
}

.card-label { font-size: 12px; color: var(--c-muted); margin-bottom: 2px; }
.card-value { font-size: 15px; font-weight: 500; }
.card-amount { font-size: 22px; font-weight: 700; color: var(--c-text); }

/* ===== Section Headers ===== */
.section-header {
  font-size: 11px; font-weight: 700; color: var(--c-muted);
  text-transform: uppercase; letter-spacing: .6px;
  padding: 18px 4px 8px;
}

/* ===== Tab Bar ===== */
.tab-bar {
  display: flex; gap: 0;
  background: var(--c-card);
  border-bottom: 2px solid var(--c-border);
  overflow-x: auto; scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-btn {
  flex-shrink: 0; padding: 11px 16px;
  font-size: 13px; font-weight: 500;
  color: var(--c-muted); cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px; background: none;
  transition: all .15s; white-space: nowrap;
}
.tab-btn.active {
  color: var(--c-primary);
  border-bottom-color: var(--c-primary);
  font-weight: 700;
}

/* ===== Filter chips (legacy) ===== */
.filter-bar { display: flex; gap: 6px; overflow-x: auto; padding: 10px 0; scrollbar-width: none; }
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip {
  flex-shrink: 0; padding: 5px 14px; border-radius: 100px;
  font-size: 13px; font-weight: 500;
  border: 1.5px solid var(--c-border); color: var(--c-muted);
  background: var(--c-card); cursor: pointer; transition: all .15s;
}
.filter-chip.active {
  border-color: var(--c-primary); color: var(--c-primary);
  background: var(--c-primary-l); font-weight: 600;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--c-text); margin-bottom: 6px;
}
.form-label .required { color: var(--c-danger); margin-left: 2px; }
.form-control {
  width: 100%; min-height: 42px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--c-border);
  font-size: 15px; font-family: inherit; color: var(--c-text);
  background: var(--c-card);
  transition: border-color .15s, box-shadow .15s;
  appearance: none; -webkit-appearance: none;
}
.form-control:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
textarea.form-control { min-height: 88px; resize: vertical; }
select.form-control {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2364748B' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
.form-hint { font-size: 12px; color: var(--c-muted); margin-top: 4px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 9px 18px;
  border-radius: var(--radius-sm); font-size: 14px; font-weight: 600;
  font-family: inherit; transition: all .15s;
  border: none; cursor: pointer; letter-spacing: -.1px;
}
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-sm { min-height: 32px; padding: 5px 12px; font-size: 13px; }
.btn-primary  { background: var(--c-primary); color: #fff; }
.btn-primary:active  { background: var(--c-primary-d); }
.btn-success  { background: var(--c-success);  color: #fff; }
.btn-danger   { background: var(--c-danger);   color: #fff; }
.btn-outline  { background: transparent; color: var(--c-primary); border: 1.5px solid var(--c-primary); }
.btn-ghost    { background: var(--c-bg); color: var(--c-muted); }
.btn-ghost:active { background: var(--c-border); }
.btn-block    { width: 100%; }
.btn-fab {
  position: fixed; bottom: calc(64px + var(--safe-bottom) + 16px); right: 16px;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--c-primary); color: #fff; font-size: 24px;
  box-shadow: var(--shadow-md); z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.btn-submit-fixed {
  position: fixed; bottom: calc(64px + var(--safe-bottom)); left: 0; right: 0;
  padding: 10px 16px;
  background: var(--c-card);
  border-top: 1px solid var(--c-border);
  z-index: 50;
}

/* ===== Badges ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: var(--radius-xs);
  font-size: 11px; font-weight: 700; white-space: nowrap; letter-spacing: .2px;
}
.badge-pending  { background: #FEF3C7; color: #92400E; }
.badge-approved { background: #DCFCE7; color: #166534; }
.badge-rejected { background: #FEE2E2; color: #991B1B; }
.badge-draft    { background: var(--c-bg); color: var(--c-muted); }

/* ===== Stats Grid ===== */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat-card {
  background: var(--c-card); border-radius: var(--radius);
  border: 1px solid var(--c-border); box-shadow: var(--shadow);
  padding: 14px 16px;
}
.stat-label { font-size: 11px; color: var(--c-muted); font-weight: 600; letter-spacing: .3px; margin-bottom: 6px; }
.stat-value { font-size: 26px; font-weight: 800; color: var(--c-text); line-height: 1; }
.stat-unit  { font-size: 12px; color: var(--c-muted); margin-top: 4px; }
.stat-card.accent { background: var(--c-primary); border-color: var(--c-primary); }
.stat-card.accent .stat-label,
.stat-card.accent .stat-value,
.stat-card.accent .stat-unit { color: #fff; }
.stat-card.accent .stat-label { opacity: .8; }

/* ===== Summary Banner ===== */
.month-summary {
  background: var(--c-card); border-radius: var(--radius);
  border: 1px solid var(--c-border); box-shadow: var(--shadow);
  padding: 14px 16px; display: flex; align-items: center; margin-bottom: 10px;
}
.month-summary-total { font-size: 22px; font-weight: 800; flex: 1; color: var(--c-primary); }
.month-summary-meta  { font-size: 11px; color: var(--c-muted); font-weight: 600; }

/* ===== Chart Bar ===== */
.chart-bar-wrap  { display: flex; flex-direction: column; gap: 10px; }
.chart-bar-item  { display: flex; align-items: center; gap: 8px; }
.chart-bar-label { font-size: 12px; min-width: 80px; flex-shrink: 0; color: var(--c-muted); }
.chart-bar-track { flex: 1; background: var(--c-bg); border-radius: 3px; height: 6px; overflow: hidden; }
.chart-bar-fill  { height: 100%; background: var(--c-primary); border-radius: 3px; transition: width .4s; }
.chart-bar-val   { font-size: 12px; font-weight: 700; min-width: 64px; text-align: right; }

/* ===== Camera / OCR ===== */
.camera-btn {
  width: 100%; min-height: 160px;
  border: 2px dashed var(--c-border); border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 6px;
  color: var(--c-muted); background: var(--c-card);
  cursor: pointer; transition: all .15s;
}
.camera-btn:active { border-color: var(--c-primary); background: var(--c-primary-l); }
.camera-btn .icon  { font-size: 40px; }
.camera-main { font-size: 14px; font-weight: 700; color: var(--c-text); }
.camera-sub  { font-size: 12px; color: var(--c-muted); }
.receipt-preview   { width: 100%; border-radius: var(--radius); overflow: hidden; margin-bottom: 10px; }
.receipt-preview img { width: 100%; }

.ocr-field {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--c-border-l);
}
.ocr-field:last-child { border-bottom: none; padding-bottom: 0; }
.ocr-field:first-child { padding-top: 0; }
.ocr-field-icon  { font-size: 18px; width: 26px; text-align: center; flex-shrink: 0; }
.ocr-field-body  { flex: 1; }
.ocr-field-label { font-size: 11px; color: var(--c-muted); font-weight: 600; }
.ocr-field-value { font-size: 14px; font-weight: 700; }
.ocr-auto-badge  {
  font-size: 10px; background: #DCFCE7; color: #166534; font-weight: 700;
  padding: 2px 7px; border-radius: 100px; flex-shrink: 0;
}
@keyframes field-filled { 0%,5% { background: #FEF9C3; } 100% { background: transparent; } }
.field-autofilled { animation: field-filled 1.8s ease forwards; }

.input-prefix-wrap { position: relative; display: flex; align-items: center; }
.input-prefix { position: absolute; left: 12px; font-size: 15px; font-weight: 700; color: var(--c-muted); pointer-events: none; }
.form-control.has-prefix { padding-left: 28px; }

/* ===== Petty Cash ===== */
.balance-banner {
  background: linear-gradient(135deg, var(--c-primary) 0%, #4F46E5 100%);
  color: #fff; border-radius: var(--radius); padding: 18px;
  margin-bottom: 12px; box-shadow: var(--shadow-md);
}
.balance-label { font-size: 12px; opacity: .8; margin-bottom: 4px; font-weight: 600; }
.balance-amount { font-size: 32px; font-weight: 800; }

/* ===== Step Indicator ===== */
.steps { display: flex; align-items: center; padding: 14px 0; justify-content: center; }
.step-dot {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--c-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--c-muted); background: var(--c-card);
}
.step-dot.active { border-color: var(--c-primary); color: var(--c-primary); }
.step-dot.done   { border-color: var(--c-success); background: var(--c-success); color: #fff; }
.step-line { flex: 1; height: 2px; background: var(--c-border); }
.step-line.done { background: var(--c-success); }

/* ===== Empty State ===== */
.empty {
  text-align: center; padding: 48px 16px;
  color: var(--c-muted); font-size: 14px;
}
.empty .icon { font-size: 36px; margin-bottom: 10px; }

/* ===== Toast ===== */
#toast-container {
  position: fixed; top: 56px; left: 0; right: 0; z-index: 200;
  pointer-events: none; display: flex; flex-direction: column;
  align-items: center; gap: 6px; padding: 0 16px;
}
.toast {
  background: #1E293B; color: #fff;
  padding: 10px 18px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; max-width: 360px;
  box-shadow: var(--shadow-md); pointer-events: auto;
  animation: toast-in .2s ease;
}
.toast.success { background: var(--c-success); }
.toast.error   { background: var(--c-danger); }
@keyframes toast-in { from { opacity:0; transform:translateY(-8px); } to { opacity:1; transform:none; } }

/* ===== Loading ===== */
.spinner {
  width: 28px; height: 28px; border: 3px solid var(--c-border);
  border-top-color: var(--c-primary); border-radius: 50%;
  animation: spin .7s linear infinite; margin: 32px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.5);
  z-index: 300; display: flex; align-items: flex-end;
  animation: fade-in .2s;
}
.modal {
  background: var(--c-card); width: 100%;
  border-radius: 14px 14px 0 0;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  max-height: 85dvh; overflow-y: auto;
  animation: slide-up .25s ease;
}
.modal-title { font-size: 17px; font-weight: 800; margin-bottom: 16px; letter-spacing: -.2px; }
.modal-handle {
  width: 36px; height: 4px; background: var(--c-border);
  border-radius: 2px; margin: 0 auto 14px;
}
@keyframes fade-in  { from { opacity:0; } to { opacity:1; } }
@keyframes slide-up { from { transform: translateY(100%); } to { transform: none; } }

/* ===== Auth Page ===== */
.auth-page {
  min-height: 100dvh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 24px 16px;
  background: linear-gradient(160deg, #EFF6FF 0%, var(--c-bg) 100%);
}
.auth-logo  { font-size: 44px; margin-bottom: 4px; }
.auth-title { font-size: 20px; font-weight: 800; color: var(--c-primary); margin-bottom: 28px; text-align: center; letter-spacing: -.3px; }
.auth-card  { width: 100%; max-width: 400px; }

/* ===== Info List (detail pages) ===== */
.info-list { margin-bottom: 12px; }
.info-row {
  display: flex; align-items: flex-start;
  padding: 11px 16px; background: var(--c-card);
  border-bottom: 1px solid var(--c-border-l);
}
.info-row:first-child { border-radius: var(--radius) var(--radius) 0 0; border: 1px solid var(--c-border); border-bottom: 1px solid var(--c-border-l); }
.info-row:last-child  { border-radius: 0 0 var(--radius) var(--radius); border: 1px solid var(--c-border); border-top: none; }
.info-row:only-child  { border-radius: var(--radius); border: 1px solid var(--c-border); }
.info-label { font-size: 12px; color: var(--c-muted); font-weight: 600; min-width: 90px; flex-shrink: 0; padding-top: 1px; }
.info-value { font-size: 14px; font-weight: 500; flex: 1; }

/* ===== Amount display ===== */
.amount-display {
  font-size: 32px; font-weight: 800; color: var(--c-primary);
  letter-spacing: -1px; line-height: 1;
}

/* ===== Utilities ===== */
.text-muted   { color: var(--c-muted); }
.text-sm      { font-size: 13px; }
.text-xs      { font-size: 12px; }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.font-bold    { font-weight: 700; }
.flex         { display: flex; }
.flex-1       { flex: 1; }
.items-center { align-items: center; }
.gap-4        { gap: 4px; }
.gap-8        { gap: 8px; }
.gap-12       { gap: 12px; }
.mr-4  { margin-right: 4px; }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-4  { margin-bottom: 4px; }
.mb-8  { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.pt-16 { padding-top: 16px; }
.pb-16 { padding-bottom: 16px; }
.hidden { display: none !important; }
.separator { height: 1px; background: var(--c-border-l); margin: 8px 0; }
.divider   { height: 1px; background: var(--c-border); margin: 12px 0; }
