/* ============================================================
   ledger — Master Stylesheet  v3 (Large & Wide Layout)
   ============================================================ */

/* ── 1. Variables ─────────────────────────────────────────── */
:root {
  --primary:       #3b82f6;
  --primary-h:     #2563eb;
  --primary-light: #eff6ff;
  --danger:        #ef4444;
  --success:       #10b981;
  --warning:       #f59e0b;
  --bg:            #f1f5f9;
  --card:          #ffffff;
  --text:          #0f172a;
  --text-sub:      #64748b;
  --text-ph:       #94a3b8;
  --border:        #e2e8f0;
  --radius-sm:     6px;
  --radius-md:     10px;
  --radius-lg:     14px;
  --radius-xl:     22px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:     0 4px 16px rgba(0,0,0,.08), 0 1px 4px rgba(0,0,0,.04);
  --shadow-drop:   0 8px 32px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.06);
  --shadow-lg:     0 16px 48px rgba(0,0,0,.14);
  /* sidebar */
  --sb-w:          272px;
  --sb-bg-from:    #1a1a2e;
  --sb-bg-to:      #16213e;
  --sb-text:       #d0d7e5;
  --sb-hover-bg:   rgba(255,255,255,.08);
  --sb-active-bg:  #6366f1;
  --sb-active-txt: #ffffff;
}

/* ── 2. Reset & Base ──────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; -webkit-font-smoothing: antialiased; }

body {
  font-family: 'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0; padding: 0;
  line-height: 1.55;
  font-size: 16px;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; }
a { color: inherit; }
button, input, select, textarea { font-family: inherit; }

/* ── 3. App layout ────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── 4. Sidebar ───────────────────────────────────────────── */
.sidebar {
  width: var(--sb-w);
  background: linear-gradient(170deg, var(--sb-bg-from) 0%, var(--sb-bg-to) 100%);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 200;
  display: flex;
  flex-direction: column;
  scrollbar-width: none;
  border-right: 1px solid rgba(255,255,255,.04);
}
.sidebar::-webkit-scrollbar { display: none; }

.sidebar-logo {
  padding: 24px 20px 22px;
  color: #fff;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -.05em;
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}
.sidebar-logo-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(59,130,246,.45);
}

.sidebar-nav { padding: 10px 12px; flex: 1; }

.sidebar-section-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #8899b4;
  padding: 22px 14px 8px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  color: var(--sb-text);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  transition: background .15s, color .15s;
  margin-bottom: 4px;
  line-height: 1.35;
  min-height: 50px;
}
.sidebar-link:hover {
  background: var(--sb-hover-bg);
  color: #f0f6ff;
}
.sidebar-link.active {
  background: var(--sb-active-bg);
  color: var(--sb-active-txt);
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(99,102,241,.40), inset 3px 0 0 rgba(255,255,255,.55);
  padding-left: 15px;
}
.sidebar-icon {
  font-size: 20px;
  width: 26px;
  text-align: center;
  opacity: .9;
  flex-shrink: 0;
}
.sidebar-link.active .sidebar-icon { opacity: 1; }

.sidebar-footer {
  padding: 6px 12px 20px;
  border-top: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}

/* Mobile (hidden on desktop) */
.mobile-header { display: none; }
.sidebar-overlay { display: none; }

/* ── 5. Main area ─────────────────────────────────────────── */
.main-area {
  margin-left: var(--sb-w);
  flex: 1;
  min-width: 0;
  background: var(--bg);
}

.page-container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 36px 44px 80px;
}

/* ── 6. Page header ───────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 26px;
  gap: 16px;
}
.page-title     { font-size: 26px; font-weight: 800; letter-spacing: -.04em; color: var(--text); }
.page-title-sub { font-size: 14px; color: var(--text-sub); margin-top: 4px; }
.page-actions   { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

/* ── 7. Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 22px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}
.btn-primary {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: #fff;
  border-color: #2563eb;
  box-shadow: 0 4px 14px rgba(59,130,246,.38), 0 1px 3px rgba(0,0,0,.1);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  box-shadow: 0 6px 22px rgba(59,130,246,.48), 0 2px 6px rgba(0,0,0,.12);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); box-shadow: 0 2px 8px rgba(59,130,246,.3); }
.btn-secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover { background: var(--bg); border-color: #cbd5e1; box-shadow: var(--shadow-md); }
.btn-danger { background: #fff; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; box-shadow: 0 4px 12px rgba(239,68,68,.12); }

.btn-icon {
  width: 36px; height: 36px; padding: 0;
  border-radius: var(--radius-sm);
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-sub);
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  line-height: 1;
  box-shadow: var(--shadow-sm);
}
.btn-icon:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: #bfdbfe;
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* ── 8. Dropdown (new doc) ────────────────────────────────── */
.new-doc-dropdown { position: relative; display: inline-block; }

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px); right: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-drop);
  min-width: 180px;
  z-index: 300;
  overflow: hidden;
  display: none;
  animation: fadeDown .15s ease;
}
.dropdown-menu.open { display: block; }
@keyframes fadeDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 18px;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text);
  text-decoration: none;
  transition: background .12s;
}
.dropdown-item:hover { background: var(--bg); color: var(--primary); }

/* ── 9. Forms ─────────────────────────────────────────────── */
.form-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 28px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.form-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-sub);
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.form-grid   { display: grid; gap: 0 18px; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-sub);
  margin-bottom: 6px;
}
.field label .req { color: var(--danger); margin-left: 2px; }

input[type=text], input[type=date], input[type=tel],
input[type=email], input[type=number], select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 15px;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  line-height: 1.5;
}
input::placeholder, textarea::placeholder { color: var(--text-ph); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
input[type=number] { text-align: right; }

/* Type toggle pill */
.type-toggle-group { display: flex; gap: 8px; flex-wrap: wrap; }
.type-toggle-label { cursor: pointer; }
.type-toggle-label input[type=radio] { display: none; }
.type-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-sub);
  background: #fff;
  transition: all .15s;
  user-select: none;
}
.type-toggle-label input:checked + .type-toggle-btn {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

/* ── 10. Badges ───────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-estimate { background: #f0fdf4; color: #15803d; }
.badge-invoice  { background: #eff6ff; color: #1d4ed8; }
.badge-receipt  { background: #fdf4ff; color: #7e22ce; }

.badge-draft   { background: #f8fafc; color: #64748b; border: 1px solid var(--border); }
.badge-sent    { background: #fffbeb; color: #b45309; }
.badge-paid    { background: #f0fdf4; color: #15803d; }
.badge-trashed { background: #fef2f2; color: #dc2626; }

/* ── 11. Toast ────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 28px; left: 50%;
  transform: translateX(-50%) translateY(14px);
  background: #0f172a;
  color: #fff;
  padding: 13px 26px;
  border-radius: var(--radius-xl);
  font-size: 14.5px; font-weight: 500;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 9999;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow-drop);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── 12. Doc list: search bar ─────────────────────────────── */
.search-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}
.search-wrap input {
  padding-left: 40px;
  height: 40px;
  font-size: 14.5px;
  border-radius: var(--radius-xl);
  background: var(--bg);
  border-color: transparent;
}
.search-wrap input:focus {
  background: #fff;
  border-color: var(--primary);
}
.search-icon {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-ph);
  font-size: 14px;
  pointer-events: none;
}

.filter-select {
  height: 40px;
  padding: 0 12px;
  font-size: 14px;
  min-width: 90px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

/* ── 13. Doc list: status tabs ────────────────────────────── */
.status-tabs {
  display: flex;
  gap: 0;
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.status-tabs::-webkit-scrollbar { display: none; }

.status-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 13px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-sub);
  text-decoration: none;
  border-bottom: 2.5px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
  margin-bottom: -1px;
}
.status-tab:hover { color: var(--text); }
.status-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 700; }

.tab-count {
  background: #f1f5f9;
  color: var(--text-sub);
  font-size: 12px; font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
}
.status-tab.active .tab-count { background: var(--primary-light); color: var(--primary); }

/* ── 14. Doc list: table ──────────────────────────────────── */
.doc-table-wrap {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

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

.doc-table th {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-sub);
  padding: 13px 20px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.doc-table td {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  vertical-align: middle;
}
.doc-table tbody tr:last-child td { border-bottom: none; }
.doc-table tbody tr:hover td { background: #f8faff; }

.doc-table .td-check   { width: 44px; padding: 16px 4px 16px 20px; }
.doc-table .td-status  { width: 110px; }
.doc-table .td-subject { }
.doc-table .td-date    { width: 110px; color: var(--text-sub); white-space: nowrap; }
.doc-table .td-due     { width: 110px; color: var(--text-sub); white-space: nowrap; }
.doc-table .td-amount  { width: 148px; text-align: right; font-weight: 700; white-space: nowrap; letter-spacing: -.02em; font-size: 16px; }
.doc-table .td-actions { width: 160px; text-align: right; white-space: nowrap; }

.doc-subject-primary {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  display: block;
}
.doc-subject-primary:hover { color: var(--primary); }
.doc-subject-sub {
  font-size: 12.5px;
  color: var(--text-sub);
  margin-top: 3px;
  display: block;
}

.actions-group {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  justify-content: flex-end;
}

/* ── 15. Pagination ───────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-sub);
  background: #fafbfc;
}

.pagination-nav { display: flex; gap: 5px; align-items: center; }

.page-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px; height: 38px;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px; font-weight: 500;
  background: #fff; color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: all .15s;
  box-shadow: var(--shadow-sm);
}
.page-btn:hover:not(.disabled) { background: var(--bg); border-color: #cbd5e1; }
.page-btn.current {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(59,130,246,.3);
}
.page-btn.disabled { opacity: .38; pointer-events: none; }

/* ── 16. Empty state ──────────────────────────────────────── */
.empty-state { padding: 80px 20px; text-align: center; }
.empty-state-icon  { font-size: 48px; margin-bottom: 16px; }
.empty-state-title { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.empty-state-sub   { font-size: 15px; color: var(--text-sub); margin-bottom: 28px; }

/* ── 17. Doc form page ────────────────────────────────────── */
.doc-form-layout { max-width: 980px; }

.form-back-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  color: var(--text-sub);
  text-decoration: none;
  margin-bottom: 20px;
  font-weight: 500;
}
.form-back-link:hover { color: var(--text); }

.doc-header-bar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}
.doc-header-number {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 17px; font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 5px 14px;
  border-radius: var(--radius-md);
  letter-spacing: .02em;
}

/* Line items */
.lines-wrap { overflow-x: auto; }
.lines-tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
  min-width: 560px;
}
.lines-tbl thead th {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-sub);
  padding: 8px 7px 12px;
  border-bottom: 2px solid var(--border);
  text-align: left;
}
.lines-tbl thead th.th-num { text-align: right; }
.lines-tbl tbody tr { border-bottom: 1px solid var(--border); }
.lines-tbl tbody tr:last-child { border-bottom: none; }
.lines-tbl td { padding: 6px 5px; vertical-align: middle; }
.lines-tbl input { padding: 8px 10px; font-size: 14px; border-radius: var(--radius-sm); height: 38px; }

.td-desc  { width: 40%; }
.td-qty   { width: 10%; }
.td-price { width: 16%; }
.td-amt   { width: 17%; font-weight: 600; text-align: right; padding-right: 8px !important; white-space: nowrap; color: var(--text); font-size: 15px; }
.td-del   { width: 7%; text-align: center; }

.btn-del-row {
  background: none; border: none; color: var(--text-ph);
  cursor: pointer; font-size: 17px;
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.btn-del-row:hover { color: var(--danger); background: #fef2f2; }

.totals-preview {
  display: flex; flex-direction: column; align-items: flex-end;
  padding-top: 18px; margin-top: 18px;
  border-top: 1px solid var(--border);
}
.totals-preview-inner { width: 300px; }
.total-pr-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 0; font-size: 14.5px; color: var(--text-sub);
  border-bottom: 1px solid #f1f5f9;
}
.total-pr-row.grand {
  font-size: 20px; font-weight: 800; color: var(--text);
  padding-top: 14px; margin-top: 6px;
  border-top: 2px solid var(--text); border-bottom: none;
}
.form-actions {
  display: flex; justify-content: flex-end; align-items: center;
  gap: 12px; padding-top: 6px;
}

/* ── 18. Settings ─────────────────────────────────────────── */
.settings-wrap { max-width: 780px; }
.saved-banner {
  display: flex; align-items: center; gap: 9px;
  background: #f0fdf4; color: var(--success);
  border: 1px solid #a7f3d0;
  border-radius: var(--radius-md);
  padding: 13px 20px; font-size: 14.5px; font-weight: 600;
  margin-bottom: 20px;
  box-shadow: 0 2px 8px rgba(16,185,129,.1);
}

/* ── 19. Login ────────────────────────────────────────────── */
body.login-bg {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
  min-height: 100vh;
  display: flex; flex-direction: column;
}
.login-wrap {
  flex: 1; display: flex;
  align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 48px 44px;
  width: 100%; max-width: 400px;
  text-align: center;
}
.login-logo {
  font-size: 22px; font-weight: 800;
  letter-spacing: -.05em;
  display: inline-flex; align-items: center; gap: 10px;
  margin-bottom: 30px;
}
.error-banner {
  background: #fef2f2; color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
  padding: 12px 18px; font-size: 14px;
  margin-bottom: 16px; text-align: left;
}

/* ── 20. Responsive ───────────────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(calc(-1 * var(--sb-w)));
    width: var(--sb-w);
    transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .main-area { margin-left: 0; }

  .mobile-header {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 58px;
    padding: 0 20px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 150;
    box-shadow: var(--shadow-sm);
  }
  .sidebar-toggle {
    background: none; border: none;
    cursor: pointer; font-size: 24px;
    color: var(--text); padding: 4px;
    display: flex; align-items: center; justify-content: center;
  }
  .mobile-brand {
    font-weight: 800; font-size: 18px;
    letter-spacing: -.05em;
    text-decoration: none; color: var(--text);
  }
  .sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 199;
    display: none;
    backdrop-filter: blur(2px);
  }
  .sidebar-overlay.show { display: block; }

  .page-container { padding: 22px 20px 64px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .doc-table .td-date, .doc-table .td-due { display: none; }
  .form-grid-2, .form-grid-3, .form-grid-4 { grid-template-columns: 1fr; gap: 0; }
  .form-section { padding: 20px; }
  .totals-preview-inner { width: 100%; }
  .search-bar { flex-wrap: wrap; }
}

@media (max-width: 640px) {
  .login-card { padding: 32px 24px; }
  .doc-table .td-status { display: none; }
  .doc-table .td-due { display: none; }
  .page-title { font-size: 21px; }
}

/* ── 21. Status toggle button ─────────────────────────────── */
.btn-status-fwd {
  background: linear-gradient(135deg, #f0fdf4, #dcfce7);
  border-color: #a7f3d0;
  color: #059669;
}
.btn-status-fwd:hover { background: #dcfce7; box-shadow: 0 4px 12px rgba(16,185,129,.2); }

/* ── 22. Customer table columns ───────────────────────────── */
.doc-table .td-cust-name    { min-width: 200px; }
.doc-table .td-cust-kana    { width: 160px; }
.doc-table .td-cust-addr    { }
.doc-table .td-cust-contact { width: 180px; }

@media (max-width: 1024px) {
  .doc-table .td-cust-kana    { display: none; }
  .doc-table .td-cust-contact { display: none; }
}

/* ── 23. Customer search (doc form) ───────────────────────── */
.customer-search-wrap {
  position: relative;
  width: 280px;
  flex-shrink: 0;
}
.customer-search-input {
  width: 100%;
  height: 38px;
  padding: 5px 14px;
  font-size: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--bg);
  color: var(--text);
}
.customer-search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
  background: #fff;
}
.customer-search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-drop);
  z-index: 400;
  max-height: 280px;
  overflow-y: auto;
}
.cust-dd-item {
  padding: 12px 18px;
  cursor: pointer;
  font-size: 14.5px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.cust-dd-item:last-child { border-bottom: none; }
.cust-dd-item:hover { background: var(--bg); color: var(--primary); }
.cust-dd-item strong { font-weight: 600; color: var(--text); }
.cust-dd-item span { font-size: 12px; color: var(--text-sub); }

/* ── 24. NTA result list ──────────────────────────────────── */
.nta-result-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  max-height: 340px;
  overflow-y: auto;
  box-shadow: var(--shadow-sm);
}
.nta-result-item {
  padding: 13px 18px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}
.nta-result-item:last-child { border-bottom: none; }
.nta-result-item:hover { background: var(--bg); }
.nta-result-name { font-size: 14.5px; font-weight: 600; color: var(--text); }
.nta-result-sub  { font-size: 12.5px; color: var(--text-sub); margin-top: 2px; }

/* ── 25. Summary / stat cards ─────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 26px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, transform .15s;
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.stat-card-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-sub);
  margin-bottom: 10px;
}
.stat-card-value {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -.03em;
  color: var(--text);
}
.stat-card-sub {
  font-size: 13px;
  color: var(--text-sub);
  margin-top: 5px;
}

/* ── 26. Section divider ──────────────────────────────────── */
.section-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 28px 0 20px;
  color: var(--text-sub);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.section-divider::before,
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── 27. B-4: 全体フォントサイズ拡大（読みやすさ改善）─────── */
body {
  font-size: 17px;
  line-height: 1.65;
}

/* ページタイトル */
.page-title     { font-size: 30px; }
.page-title-sub { font-size: 15px; }

/* テーブルセル */
.doc-table td   { font-size: 16px; padding: 18px 20px; }
.doc-table th   { font-size: 13px; padding: 14px 20px; }
.doc-table .td-amount { font-size: 18px; }

/* 主要ボタン */
.btn { font-size: 16px; padding: 13px 26px; }

/* 入力欄 */
input[type=text], input[type=date], input[type=tel],
input[type=email], input[type=number], select, textarea {
  font-size: 16px;
  padding: 11px 16px;
}

/* ラベル */
.field label { font-size: 13px; }
.form-section-title { font-size: 13px; }

/* 検索バー */
.search-wrap input { font-size: 16px; }
.filter-select { font-size: 15px; }

/* ステータスタブ */
.status-tab { font-size: 15px; padding: 14px 18px; }

/* ページネーション */
.pagination { font-size: 15px; }
.page-btn   { font-size: 15px; min-width: 42px; height: 42px; }

/* サイドバーリンク */
.sidebar-link { font-size: 15px; padding: 12px 16px; min-height: 44px; }
.sidebar-section-label { font-size: 12px; }
.sidebar-icon { font-size: 17px; }
.sidebar-link.active {
  box-shadow: 0 4px 20px rgba(59,130,246,.5), inset 4px 0 0 rgba(255,255,255,.8);
  letter-spacing: .01em;
}

/* ドロップダウンアイテム */
.dropdown-item { font-size: 16px; }

/* フォームセクション */
.form-section { padding: 28px 32px; }

/* 取引先表示 */
.doc-subject-primary { font-size: 16px; }
.doc-subject-sub     { font-size: 13.5px; }
.doc-subject-title   { font-size: 13.5px; }

/* 件名行ラベル */
.td-actions { width: auto; }

/* 空状態 */
.empty-state-title { font-size: 22px; }
.empty-state-sub   { font-size: 16px; }

/* ── 28. 右側コンテンツ品質向上・枠整列 ──────────────── */

/* コンテナ最大幅と余白を最適化 */
.page-container {
  max-width: 1440px;
  padding: 36px 48px 80px;
}

/* ページヘッダーの縦余白を統一 */
.page-header {
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

/* テーブルヘッダー背景をやや強調 */
.doc-table th {
  background: #f1f5fb;
  padding: 14px 20px;
  border-bottom: 2px solid var(--border);
}

/* テーブルセル左右余白を揃える */
.doc-table td {
  padding: 18px 20px;
}

/* テーブルラッパーのシャドウを少し強く */
.doc-table-wrap {
  box-shadow: 0 2px 12px rgba(0,0,0,.07), 0 1px 4px rgba(0,0,0,.04);
  margin-bottom: 24px;
}

/* カード・フォームセクション余白統一 */
.form-section {
  padding: 28px 32px;
  margin-bottom: 20px;
}

/* doc-form はコンテナ幅を揃える */
.doc-form-layout {
  max-width: 1280px;
  width: 100%;
}

/* 設定ページ */
.settings-wrap {
  max-width: 1040px;
}

/* stat-card の余白を少し増やす */
.stat-card {
  padding: 24px 28px;
}

/* テーブル内の長いテキストを省略表示 */
.doc-subject-primary {
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 送付画面・2カラムレイアウトの整列 */
.send-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 1024px) {
  .send-layout { grid-template-columns: 1fr; }
  .doc-subject-primary { max-width: 200px; }
}
@media (max-width: 640px) {
  .page-container { padding: 16px 16px 56px; }
  .doc-subject-primary { max-width: 140px; }
  .page-header { margin-bottom: 20px; padding-bottom: 16px; }
}

/* ── 29. Mobile usability overrides ──────────────────────── */
html, body {
  overflow-x: hidden;
}

img, svg, canvas, video, iframe {
  max-width: 100%;
  height: auto;
}

button, input, select, textarea {
  max-width: 100%;
}

.page-title,
.page-title-sub,
.doc-subject-primary,
.doc-subject-sub,
.field label,
.sidebar-link,
.empty-state-title,
.empty-state-sub {
  overflow-wrap: anywhere;
}

@media (max-width: 1023px) {
  body.sidebar-open {
    overflow: hidden;
    touch-action: none;
  }

  .sidebar {
    width: min(88vw, 320px);
    max-width: 320px;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open { transform: translateX(0); }

  .mobile-header {
    justify-content: space-between;
    padding: 0 16px;
  }

  .page-container {
    max-width: none;
    padding: 22px 20px 72px;
  }

  .page-header,
  .page-actions,
  .search-bar,
  .form-actions {
    flex-wrap: wrap;
  }

  .page-actions {
    width: 100%;
    gap: 8px;
  }

  .page-actions .btn,
  .page-actions .btn-primary,
  .page-actions .btn-secondary,
  .page-actions .btn-danger {
    min-height: 44px;
  }

  .btn {
    min-height: 44px;
  }
}

@media (max-width: 767px) {
  .mobile-header {
    height: 56px;
  }

  .page-container {
    padding: 16px 14px 76px;
  }

  .page-header {
    align-items: stretch;
    gap: 12px;
  }

  .page-title {
    font-size: 24px;
  }

  .page-title-sub {
    font-size: 13px;
  }

  .page-actions .btn,
  .page-actions .btn-primary,
  .page-actions .btn-secondary,
  .page-actions .btn-danger {
    width: 100%;
    justify-content: center;
  }

  .search-bar {
    padding: 14px;
  }

  .search-wrap,
  .search-bar .btn,
  .filter-select {
    width: 100%;
    min-width: 0;
  }

  .pagination {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .pagination-nav {
    justify-content: space-between;
  }

  .form-section,
  .stat-card {
    padding: 18px 16px;
  }

  .form-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .form-actions .btn {
    width: 100%;
    justify-content: center;
  }
}

/* ── 30. Full-width content with shared drawer navigation ─────────────── */
.app-layout {
  display: block;
  min-height: 100vh;
}

.sidebar {
  width: min(84vw, 320px);
  max-width: 320px;
  transform: translateX(-100%);
  transition: transform .24s ease, box-shadow .24s ease;
  box-shadow: 0 18px 48px rgba(15, 23, 42, .28);
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-logo {
  padding: 18px 18px 16px;
  font-size: 16px;
  gap: 10px;
}

.sidebar-logo-icon {
  width: 30px;
  height: 30px;
  font-size: 15px;
  border-radius: 8px;
}

.sidebar-logo-icon.has-image,
.mobile-brand-icon.has-image {
  padding: 0;
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(148, 163, 184, .22);
  box-shadow: 0 8px 18px rgba(15, 23, 42, .12);
}

.brand-icon-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.sidebar-nav {
  padding: 8px 10px;
}

.sidebar-section-label {
  padding: 18px 12px 8px;
}

.sidebar-link {
  min-height: 44px;
  padding: 11px 14px;
  gap: 11px;
}

.sidebar-footer {
  padding: 6px 10px 16px;
}

.mobile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  height: 62px;
  padding: 0 18px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 180;
  background: rgba(255, 255, 255, .92);
  border-bottom: 1px solid rgba(226, 232, 240, .95);
  backdrop-filter: blur(16px);
  box-shadow: 0 4px 18px rgba(15, 23, 42, .06);
}

.sidebar-toggle {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
}

.sidebar-toggle:hover {
  background: #f8fafc;
}

.mobile-brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -.04em;
  text-decoration: none;
  color: var(--text);
}

.mobile-brand-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 6px 16px rgba(59, 130, 246, .28);
  flex-shrink: 0;
}

.mobile-brand-text {
  white-space: nowrap;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .38);
  z-index: 170;
  display: none;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.show {
  display: block;
}

.main-area {
  margin-left: 0;
  width: 100%;
  min-height: 100vh;
  padding-top: 62px;
}

.page-container {
  max-width: 1760px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 28px 84px;
}

body.sidebar-open {
  overflow: hidden;
  touch-action: none;
}

@media (max-width: 1023px) {
  .page-container {
    max-width: none;
    padding: 22px 20px 80px;
  }
}

@media (max-width: 767px) {
  .mobile-header {
    height: 56px;
    padding: 0 14px;
  }

  .sidebar {
    width: min(88vw, 320px);
  }

  .main-area {
    padding-top: 56px;
  }

  .page-container {
    padding: 16px 14px 76px;
  }

  .mobile-brand {
    font-size: 14px;
    gap: 8px;
  }

  .mobile-brand-icon {
    width: 26px;
    height: 26px;
  }
}
