/* web/css/style.css */
:root {
  --bg-app: #0f172a;
  --bg-panel: #1e293b;
  --bg-input: #334155;
  --border-color: #475569;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-cyan: #06b6d4;
  --accent-blue: #3b82f6;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* App Header */
header {
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge-wasm {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 9999px;
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--accent-green);
  border: 1px solid rgba(16, 185, 129, 0.3);
  font-weight: 600;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* Icons */
.ui-icon {
  display: inline-block;
  vertical-align: middle;
  width: 15px;
  height: 15px;
  stroke: currentColor;
  flex-shrink: 0;
}

/* Buttons */
.btn {
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease-in-out;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-blue), #2563eb);
  color: #fff;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
}

.btn-primary:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-success {
  background: linear-gradient(135deg, var(--accent-green), #059669);
  color: #fff;
}

.btn-secondary {
  background-color: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: #475569;
}

.btn-danger {
  background-color: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background-color: var(--accent-red);
  color: #fff;
}

/* Main Layout */
.app-container {
  display: grid;
  grid-template-columns: 480px 1fr;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 61px);
}

/* Left Sidebar: Controls & Inputs */
.sidebar {
  background-color: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.nav-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  background-color: rgba(15, 23, 42, 0.4);
}

.tab-btn {
  flex: 1;
  padding: 12px;
  text-align: center;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: var(--accent-cyan);
  border-bottom-color: var(--accent-cyan);
  background-color: var(--bg-panel);
}

.tab-content {
  padding: 16px;
  display: none;
  flex-direction: column;
  gap: 16px;
}

.tab-content.active {
  display: flex;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

input, select, textarea {
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
  outline: none;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 0 1px var(--accent-cyan);
}

/* Items Table inside Form */
.items-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 4px;
}

.items-table th, .items-table td {
  padding: 6px;
  text-align: left;
}

.items-table th {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.item-row {
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

/* History & Master Lists */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-card {
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  padding: 12px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color 0.15s;
}

.list-card:hover {
  border-color: var(--accent-cyan);
}

.list-card-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.list-card-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Right Panel: A4 Preview Stage */
.preview-stage {
  background-color: #0b0f19;
  overflow-y: auto;
  padding: 30px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* A4 Sheet Simulation */
.sheet-a4 {
  background: #ffffff;
  color: #1a1a1a;
  width: 210mm;
  min-height: 297mm;
  padding: 20mm 18mm;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  line-height: 1.5;
  box-sizing: border-box;
}

.sheet-title {
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.5em;
  margin-bottom: 24px;
  padding-bottom: 8px;
  border-bottom: 2px solid #222;
}

.sheet-header-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.recipient-block {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.recipient-name {
  font-size: 20px;
  font-weight: 700;
  border-bottom: 1.5px solid #333;
  padding-bottom: 4px;
  margin-bottom: 8px;
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  gap: 8px;
}

.recipient-honorific {
  font-size: 16px;
  font-weight: 600;
  color: #1a1a1a;
  white-space: nowrap;
}

.recipient-address {
  font-size: 12px;
  color: #555;
}

.issuer-block {
  text-align: right;
  font-size: 12px;
  color: #333;
}

.issuer-name {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.issuer-invoice-no {
  font-weight: 600;
  color: #000;
  margin-top: 4px;
}

.grand-total-box {
  background-color: #f8fafc;
  border: 2px solid #0f172a;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 24px;
}

.grand-total-label {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.grand-total-amount {
  font-size: 28px;
  font-weight: 800;
}

/* Invoice Table in A4 */
.invoice-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}

.invoice-table th, .invoice-table td {
  border: 1px solid #cbd5e1;
  padding: 8px 10px;
  font-size: 12px;
}

.invoice-table th {
  background-color: #f1f5f9;
  font-weight: 700;
  text-align: center;
}

.invoice-table .col-amount, .invoice-table .col-price, .invoice-table .col-qty {
  text-align: right;
  white-space: nowrap;
}

.invoice-table .col-tax-rate {
  text-align: center;
  white-space: nowrap;
}

.invoice-table .col-name {
  text-align: left;
  line-height: 1.35;
  word-break: break-word;
}

.invoice-table .col-name.long-text {
  font-size: 10.5px;
  letter-spacing: -0.02em;
}

/* Tax Breakdown & Bank Info Grid */
.sheet-footer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: auto;
  font-size: 12px;
}

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

.tax-summary-table th, .tax-summary-table td {
  border: 1px solid #cbd5e1;
  padding: 6px 8px;
  font-size: 11px;
}

.tax-summary-table th {
  background-color: #f8fafc;
}

.bank-info-box {
  border: 1px solid #cbd5e1;
  padding: 8px 12px;
  background-color: #fcfcfc;
  border-radius: 4px;
}

.bank-info-title {
  font-weight: 700;
  margin-bottom: 4px;
  border-bottom: 1px dashed #ccc;
  padding-bottom: 2px;
  font-size: 11px;
}

.bank-info-content {
  font-size: 11px;
  line-height: 1.45;
}

.bank-line-account {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.bank-line-holder {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #333;
  margin-top: 2px;
  font-size: 10.5px;
}

.bank-line-holder.long-holder {
  font-size: 9.5px;
  letter-spacing: -0.02em;
}

.note-box {
  margin-top: 14px;
  font-size: 11px;
  color: #444;
  border-left: 3px solid #64748b;
  padding-left: 8px;
}

/* Modal for Master/Backup */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.75);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-overlay.active {
  display: flex;
}

/* Footer */
footer {
  background-color: var(--bg-panel);
  border-top: 1px solid var(--border-color);
  padding: 6px 20px;
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 50;
}

.footer-link {
  color: var(--accent-cyan);
  text-decoration: none;
  cursor: pointer;
}

.footer-link:hover {
  text-decoration: underline;
}

/* Terms Modal */
.terms-box {
  width: 640px;
  max-width: 95vw;
}

.terms-scroll-area {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 14px;
  max-height: 320px;
  overflow-y: auto;
  font-size: 0.78rem;
  line-height: 1.6;
  color: #cbd5e1;
  margin: 12px 0;
}

.terms-scroll-area h4 {
  color: var(--text-main);
  font-size: 0.85rem;
  margin: 10px 0 4px 0;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 2px;
}

.terms-scroll-area p, .terms-scroll-area ul {
  margin-bottom: 8px;
}

.terms-scroll-area ul {
  padding-left: 18px;
}

.terms-agreement-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: rgba(15, 23, 42, 0.5);
  border-radius: 6px;
  border: 1px solid var(--border-color);
  margin-bottom: 14px;
  font-size: 0.8rem;
  cursor: pointer;
}

.terms-agreement-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-cyan);
  cursor: pointer;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.modal-box {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  width: 480px;
  max-width: 90vw;
  padding: 20px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

/* ==========================================================================
   Dashboard View (初期ページ: リスト & 取説)
   ========================================================================== */
.dashboard-container {
  padding: 24px;
  flex: 1;
  overflow-y: auto;
  background-color: var(--bg-app);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 24px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

.dashboard-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
}

.section-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-tabs {
  display: flex;
  gap: 6px;
  background: rgba(15, 23, 42, 0.4);
  padding: 4px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.filter-btn {
  flex: 1;
  padding: 6px 8px;
  border-radius: 4px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.15s;
}

.filter-btn:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.filter-btn.active {
  background: var(--accent-blue);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.invoice-list-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 250px);
  overflow-y: auto;
  padding-right: 4px;
}

.inv-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  transition: border-color 0.15s, background-color 0.15s;
}

.inv-card:hover {
  border-color: var(--accent-cyan);
  background: rgba(15, 23, 42, 0.85);
}

.inv-card-info {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

.inv-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inv-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inv-card-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.inv-card-amount {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent-cyan);
}

.badge-status {
  font-size: 0.7rem;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-draft {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.badge-completed {
  background: rgba(6, 182, 212, 0.15);
  color: #06b6d4;
  border: 1px solid rgba(6, 182, 212, 0.35);
}

.badge-printed {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.badge-sample {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.3);
  font-size: 0.68rem;
  padding: 1px 5px;
  border-radius: 3px;
}

/* Manual styling */
.manual-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 250px);
  overflow-y: auto;
  padding-right: 6px;
}

.manual-card {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 12px 14px;
}

.manual-card h3 {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--accent-cyan);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.manual-card p, .manual-card ul {
  font-size: 0.8rem;
  color: #cbd5e1;
  line-height: 1.5;
}

.manual-card ul {
  padding-left: 18px;
  margin-top: 4px;
}

.manual-card li {
  margin-bottom: 4px;
}

.empty-list-placeholder {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 30px 10px;
  background: rgba(15, 23, 42, 0.4);
  border-radius: 8px;
  border: 1px dashed var(--border-color);
}

/* Editor back button & autosave */
.autosave-badge {
  font-size: 0.75rem;
  color: var(--accent-green);
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
}

/* ==========================================================================
   Seal & Logo Styles
   ========================================================================== */
.checkerboard-bg {
  background-color: #1e293b;
  background-image: 
    linear-gradient(45deg, #0f172a 25%, transparent 25%), 
    linear-gradient(-45deg, #0f172a 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #0f172a 75%), 
    linear-gradient(-45deg, transparent 75%, #0f172a 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

.issuer-seal {
  position: absolute;
  pointer-events: none;
  user-select: none;
  z-index: 10;
  mix-blend-mode: multiply;
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
}

.badge-pro {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.05em;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.seal-preview-box {
  width: 76px;
  height: 76px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.seal-preview-box img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.crop-canvas-wrapper {
  position: relative;
  display: inline-block;
  max-width: 100%;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
  background: #0f172a;
}

/* Version & PWA Modal Styles */
.badge-version-btn {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--border);
  color: var(--accent-cyan);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  margin-left: 4px;
}

.badge-version-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent-cyan);
  color: #fff;
}

.version-specs-table th,
.version-specs-table td {
  vertical-align: middle;
}

/* Tri-state Module Status Indicators (✕, △, ○) */
.status-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 800;
  margin-right: 6px;
  vertical-align: -1px;
}

.status-mark.status-x {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
  border: 1px solid #ef4444;
}

.status-mark.status-triangle {
  background: rgba(245, 158, 11, 0.2);
  color: #f59e0b;
  border: 1px solid #f59e0b;
}

.status-mark.status-circle {
  background: rgba(16, 185, 129, 0.2);
  color: #10b981;
  border: 1px solid #10b981;
}

.addon-header-row td {
  padding-top: 12px !important;
  padding-bottom: 4px !important;
  font-weight: 700;
  color: var(--accent-cyan);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* LocalStorage Protection & Backup Banner */
.backup-recommend-banner {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.9));
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-left: 4px solid var(--accent-cyan);
  border-radius: 8px;
  padding: 12px 18px;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

@media (max-width: 768px) {
  .backup-recommend-banner {
    flex-direction: column;
    align-items: stretch;
  }
}

/* Plan Quota Badges */
.quota-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 4px;
  background: rgba(56, 189, 248, 0.1);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
  letter-spacing: 0.02em;
}

.quota-badge.limit-reached {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.4);
}

.quota-badge-sm {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-muted);
  border: 1px solid var(--border);
  letter-spacing: 0.02em;
}

.quota-badge-sm.limit-reached {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.4);
}




