/* ===========================
   CSS Variables & Reset
=========================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --green: #4CAF50;
  --green-light: #81C784;
  --green-pale: #f0f9f0;
  --green-dark: #388E3C;
  --gray-bg: #f5f5f5;
  --gray-border: #e0e0e0;
  --gray-label: #9e9e9e;
  --text: #777;
  --text-light: #666;
  --white: #ffffff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.18);
  --radius: 8px;
  --header-h: 52px;
  --tab-h: 44px;
  --fab-size: 48px;
}

html, body {
  height: 100%;
  font-family: 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', 'Yu Gothic', sans-serif;
  background: var(--gray-bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ===========================
   PC レイアウト (縦長中央表示)
=========================== */
@media (min-width: 768px) {
  body {
    display: flex;
    justify-content: center;
    background: #dde8dd;
  }

  #app-header,
  #tab-bar,
  #main-content,
  #fab-container {
    max-width: 360px;
    width: 33vw;
    min-width: 320px;
  }

  #app-header {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    box-shadow: var(--shadow-md);
  }

  #tab-bar {
    position: fixed;
    top: var(--header-h);
    left: 50%;
    transform: translateX(-50%);
    z-index: 99;
  }

  #main-content {
    margin: 0 auto;
    padding-top: calc(var(--header-h) + var(--tab-h));
    padding-bottom: 80px;
    min-height: 100vh;
  }

  #fab-container {
    position: fixed;
    right: calc(50% - 16vw);
    bottom: 24px;
  }
}

/* ===========================
   Header
=========================== */
#app-header {
  background: var(--white);
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--gray-border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.02em;
}

/* ===========================
   Tab Bar
=========================== */
#tab-bar {
  background: var(--white);
  display: flex;
  border-bottom: 2px solid var(--gray-border);
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  z-index: 99;
}

.tab-item {
  flex: 1;
  height: var(--tab-h);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 500;
  color: var(--gray-label);
  cursor: pointer;
  position: relative;
  transition: color 0.2s;
  user-select: none;
}

.tab-item::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--green);
  transform: scaleX(0);
  transition: transform 0.2s ease;
}

.tab-item.active {
  color: var(--green);
}

.tab-item.active::after {
  transform: scaleX(1);
}

/* ===========================
   Main Content
=========================== */
#main-content {
  padding-top: calc(var(--header-h) + var(--tab-h));
  padding-bottom: 30px;
  min-height: 100vh;
}

/* ===========================
   Slip Pages
=========================== */
.slip-page {
  display: none;
  padding: 12px 16px;
}

.slip-page.active {
  display: block;
}

/* ===========================
   Field Groups
=========================== */
.field-group {
  background: var(--white);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.field-label {
  display: block;
  font-size: 12px;
  color: var(--gray-label);
  margin-bottom: 4px;
  font-weight: 500;
}

.field-input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 15px;
  color: var(--text);
  background: transparent;
  font-family: inherit;
  padding: 2px 0;
}

.field-input::placeholder {
  color: #ccc;
}

.field-input:focus {
  border-bottom: 1.5px solid var(--green);
}

/* 日付フィールド */
.field-date {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
}

.field-date .date-part {
  width: calc(33% - 1em);
  flex: 1;
  text-align: right;
  font-size: 15px;
}

.date-sep {
  font-size: 14px;
  color: var(--text-light);
  white-space: nowrap;
}

/* 支払先フィールド */
.field-payee {
  display: flex;
  align-items: center;
  gap: 6px;
}

.field-payee .field-label {
  white-space: nowrap;
  margin-bottom: 0;
  flex-shrink: 0;
  font-size: 13px;
}

.field-payee .field-input {
  flex: 1;
  text-align: right;
}

.field-suffix {
  font-size: 14px;
  color: var(--text-light);
  flex-shrink: 0;
}

/* エントリーブロック（勘定・摘要・金額のセット） */
.entry-block {
  background: var(--white);
  border-radius: var(--radius);
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.entry-block .field-group {
  border-radius: 0;
  box-shadow: none;
  margin-bottom: 0;
  border-bottom: 1px solid var(--gray-border);
}

.entry-block .field-group:last-child {
  border-bottom: none;
}

/* 合計 */
.total-group {
  background: var(--green-pale);
  border: 1px solid var(--green-light);
}

.total-label {
  color: var(--green-dark) !important;
  font-weight: 600;
}

.total-input {
  font-weight: 700;
  font-size: 21px;
  color: var(--green-dark);
  text-align: left;
}

/* ===========================
   FAB Buttons
=========================== */
#fab-container {
  position: fixed;
  right: 16px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
}

.fab-btn {
  width: var(--fab-size);
  height: var(--fab-size);
  border-radius: 50%;
  background: var(--green);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(76, 175, 80, 0.4);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s;
  color: var(--white);
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

.fab-btn svg {
  width: 22px;
  height: 22px;
  stroke: var(--white);
}

.fab-btn:active {
  transform: scale(0.92);
  box-shadow: 0 1px 6px rgba(76, 175, 80, 0.3);
}

.fab-btn:hover {
  background: var(--green-dark);
  box-shadow: 0 4px 14px rgba(56, 142, 60, 0.45);
}

/* ===========================
   Modal
=========================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  animation: fadeOverlay 0.2s ease;
}

.modal-overlay.open {
  display: flex;
}

@keyframes fadeOverlay {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--white);
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}

.modal-card-wide {
  max-width: 600px;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--gray-border);
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.modal-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--gray-bg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  transition: background 0.15s;
}

.modal-close-btn svg {
  width: 16px;
  height: 16px;
}

.modal-close-btn:hover {
  background: var(--gray-border);
}

.modal-body {
  padding: 16px 20px 20px;
}

/* ===========================
   Action Button
=========================== */
.action-btn {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 12px;
  background: var(--green);
  color: var(--white);
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  font-family: inherit;
}

.action-btn:hover {
  background: var(--green-dark);
}

.action-btn:active {
  transform: scale(0.98);
}

.action-btn-secondary {
  background: var(--white);
  color: var(--green);
  border: 2px solid var(--green);
}

.action-btn-secondary:hover {
  background: var(--green-pale);
}

/* ===========================
   Save List
=========================== */
.empty-msg {
  text-align: center;
  color: var(--gray-label);
  padding: 2rem 0;
  font-size: 14px;
}

.save-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-border);
  gap: 8px;
}

.save-item:last-child {
  border-bottom: none;
}

.save-item-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
  cursor: pointer;
}

.save-item-date {
  font-size: 11px;
  color: var(--gray-label);
}

.save-item-btns {
  display: flex;
  gap: 6px;
}

.save-item-load-btn,
.save-item-del-btn {
  padding: 5px 10px;
  border-radius: 6px;
  border: none;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s;
}

.save-item-load-btn {
  background: var(--green);
  color: var(--white);
}

.save-item-del-btn {
  background: #ffebee;
  color: #e53935;
}

.save-item-load-btn:hover,
.save-item-del-btn:hover {
  opacity: 0.8;
}

/* ===========================
   Help Slideshow
=========================== */
.slideshow {
  position: relative;
  overflow: hidden;
}

.slide {
  display: none;
}

.slide.active {
  display: block;
  animation: fadeSlide 0.25s ease;
}

@keyframes fadeSlide {
  from { opacity: 0; transform: translateX(10px); }
  to { opacity: 1; transform: translateX(0); }
}

.slide-placeholder {
  background: var(--green-pale);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  justify-content: center;
}

.slide-placeholder svg {
  max-width: 200px;
  height: auto;
}

.slide-caption {
  font-size: 13px;
  color: var(--text-light);
  line-height: 1.6;
  padding: 0 4px;
}

.slideshow-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.slide-nav {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--green);
  background: var(--white);
  color: var(--green);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}

.slide-nav:hover {
  background: var(--green);
  color: var(--white);
}

.slide-dots {
  display: flex;
  gap: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray-border);
  cursor: pointer;
  transition: background 0.2s;
}

.dot.active {
  background: var(--green);
}

/* ===========================
   Spinner
=========================== */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--gray-border);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===========================
   Toast Notification
=========================== */
#toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,0.75);
  color: white;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 13px;
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===========================
   Mobile specific
=========================== */
@media (max-width: 767px) {
  #app-header {
    left: 0;
    right: 0;
  }

  #tab-bar {
    left: 0;
    right: 0;
  }

  #fab-container {
    right: 14px;
    bottom: 20px;
  }
}
