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

:root {
  --primary: #0052CC;
  --primary-hover: #0747A6;
  --primary-light: #DEEBFF;
  --danger: #DE350B;
  --danger-light: #FFEBE6;
  --success: #006644;
  --success-light: #E3FCEF;
  --warning: #FF991F;
  --warning-light: #FFFAE6;
  --border: #DFE1E6;
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --text: #172B4D;
  --text-muted: #6B778C;
  --text-light: #97A0AF;
  --radius: 4px;
  --radius-lg: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
  color: #fff;
  padding: 24px 16px;
  text-align: center;
}
.header-inner { max-width: 1200px; margin: 0 auto; }
.header h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.header p { font-size: 14px; opacity: 0.85; }
.lang-switch { margin-top: 12px; display: flex; justify-content: center; gap: 8px; }
.lang-btn {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 4px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}
.lang-btn:hover { background: rgba(255,255,255,0.25); }
.lang-btn.active { background: #fff; color: var(--primary); border-color: #fff; font-weight: 600; }

.main { max-width: 1200px; margin: 0 auto; padding: 16px; }

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
}
.tab {
  padding: 10px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all 0.2s;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Grid Layout */
.editor-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  align-items: start;
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.card-desc { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }

/* Form */
.form-row { display: flex; gap: 12px; margin-bottom: 0; }
.form-group { margin-bottom: 12px; flex: 1; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}
.input-hint { font-size: 11px; color: var(--text-light); margin-top: 2px; display: block; }

textarea { resize: vertical; font-family: inherit; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  gap: 6px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #EBECF0; }
.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 13px; padding: 4px 0; }
.btn-link:hover { text-decoration: underline; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #BF2600; }
.btn-full { width: 100%; margin-bottom: 8px; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Items List */
.items-header {
  display: grid;
  grid-template-columns: 1fr 60px 70px 100px 70px 100px 36px;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.item-row {
  display: grid;
  grid-template-columns: 1fr 60px 70px 100px 70px 100px 36px;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
  align-items: center;
}
.item-row input, .item-row select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  width: 100%;
}
.item-row input:focus, .item-row select:focus {
  outline: none;
  border-color: var(--primary);
}
.item-amount {
  font-weight: 600;
  font-size: 13px;
  text-align: right;
  white-space: nowrap;
}
.item-delete {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 18px;
  padding: 2px;
  border-radius: var(--radius);
  transition: all 0.2s;
}
.item-delete:hover { color: var(--danger); background: var(--danger-light); }

.template-actions { margin-top: 8px; }

/* Summary */
.summary-card { position: sticky; top: 16px; }
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}
.summary-row.total {
  border-top: 2px solid var(--text);
  margin-top: 8px;
  padding-top: 12px;
  font-size: 18px;
  font-weight: 700;
}
.tax-row { font-size: 13px; color: var(--text-muted); }

/* Advice Card */
.advice-card {
  background: var(--warning-light);
  border: 1px solid #FFE380;
}
.advice-card h3 { font-size: 14px; margin-bottom: 8px; }
.advice-card p { font-size: 13px; color: var(--text); line-height: 1.6; margin-bottom: 6px; }

/* Related Links */
.related-card { background: var(--primary-light); border: 1px solid #B3D4FF; }
.related-card h3 { font-size: 14px; margin-bottom: 8px; color: var(--primary-hover); }
.related-links { list-style: none; }
.related-links li { margin-bottom: 6px; }
.related-links a {
  color: var(--primary);
  text-decoration: none;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.related-links a::before { content: '→'; }
.related-links a:hover { text-decoration: underline; }

/* History */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.history-actions { display: flex; gap: 8px; }
.search-input, .sort-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}

.history-list {}
.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.history-item:last-child { border-bottom: none; }
.history-item-info { flex: 1; min-width: 0; }
.history-item-no { font-weight: 600; font-size: 14px; }
.history-item-client { font-size: 13px; color: var(--text-muted); }
.history-item-date { font-size: 12px; color: var(--text-light); }
.history-item-amount { font-weight: 700; font-size: 15px; white-space: nowrap; }
.history-item-actions { display: flex; gap: 4px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  line-height: 1;
}
.modal-body { padding: 16px 20px; }
.template-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #f0f0f0;
}
.template-item:last-child { border-bottom: none; }
.template-item-name { font-size: 14px; font-weight: 500; }
.template-item-price { font-size: 13px; color: var(--text-muted); }

/* Logo Upload */
.logo-upload { display: flex; flex-direction: column; gap: 8px; }
.logo-preview, .stamp-preview {
  width: 120px;
  height: 60px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.logo-preview img, .stamp-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
.stamp-preview { width: 80px; height: 80px; }

/* Item Template in settings */
.item-template-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 13px;
}
.item-template-row:last-child { border-bottom: none; }

/* FAQ */
.faq-section {
  max-width: 800px;
  margin: 40px auto 0;
  padding: 0 16px;
}
.faq-section h2 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 16px;
  text-align: center;
}
.faq-list { display: flex; flex-direction: column; gap: 8px; }
.faq-item {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.faq-item summary {
  padding: 14px 20px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.faq-item summary::before { content: '▶'; font-size: 10px; transition: transform 0.2s; }
.faq-item[open] summary::before { transform: rotate(90deg); }
.faq-item p { padding: 0 20px 14px; font-size: 14px; line-height: 1.8; color: var(--text-muted); }

.flex-grow { flex: 1; }

/* Responsive */
@media (max-width: 900px) {
  .editor-grid { grid-template-columns: 1fr; }
  .preview-column { order: -1; }
  .summary-card { position: static; }
  .items-header, .item-row {
    grid-template-columns: 1fr 50px 60px 80px 60px 80px 30px;
    font-size: 11px;
  }
}
@media (max-width: 600px) {
  .header h1 { font-size: 20px; }
  .items-header { display: none; }
  .item-row {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 12px 0;
  }
  .item-row > :first-child { grid-column: 1 / -1; }
  .item-amount { grid-column: 1 / -1; text-align: left; padding-top: 4px; }
  .form-row { flex-direction: column; gap: 0; }
  .history-header { flex-direction: column; }
  .history-actions { width: 100%; }
  .history-actions input, .history-actions select { flex: 1; }
}

/* Print */
@media print {
  .header, .tabs, .actions-card, .advice-card, .related-card,
  .faq-section, footer, .lang-switch, .btn, .template-actions,
  .item-delete { display: none !important; }
  .main { padding: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
