* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
  background: #f2f4f7;
  color: #1c2733;
}

/* 画面切り替え(一覧/詳細) */
.view {
  display: none;
  min-height: 100vh;
  padding-bottom: 90px;
}

.view.active {
  display: block;
}

/* ログイン画面 */
.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.login-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.login-box h1 {
  margin: 0 0 8px;
  text-align: center;
  color: #1c2541;
}

/* スタッフ権限(閲覧のみ): 追加・編集・削除・インポート系の操作UIを非表示にする。
   実際の書き込み禁止はSupabase側のRLSで保証しており、これは表示上の制御。 */
body.role-staff .fab,
body.role-staff #editCustomerBtn,
body.role-staff #customerArchiveBtn,
body.role-staff #customerSaveBtn,
body.role-staff #transactionSaveBtn,
body.role-staff #transactionDeleteBtn,
body.role-staff .import-label,
body.role-staff #importFileInput,
body.role-staff #settingsDataBtn,
body.role-staff #settingsAccountBtn {
  display: none !important;
}

.app-header {
  background: #1c2541;
  color: #fff;
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.app-header h1 {
  margin: 0;
  font-size: 1.15rem;
}

.settings-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 8px;
  background: #f2f4f7;
  font-size: 0.95rem;
}

.account-current-email-row {
  margin-top: 8px;
}

.settings-row-label {
  color: #57626d;
}

.settings-row-value {
  font-weight: bold;
  color: #1c2541;
}

button.settings-row-button {
  border: none;
  width: 100%;
  text-align: left;
  cursor: pointer;
  color: #1c2733;
}

button.settings-row-button.danger {
  color: #a12626;
}

.detail-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  overflow: hidden;
}

.detail-title span#detailCustomerName {
  font-size: 1.05rem;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.detail-label {
  font-size: 0.78rem;
  opacity: 0.8;
}

.header-btn {
  display: inline-block;
  background: #fff;
  color: #1c2541;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.85rem;
  min-height: 38px;
  cursor: pointer;
  white-space: nowrap;
}

main {
  padding: 12px 16px 24px;
  max-width: 640px;
  margin: 0 auto;
}

/* フォーム共通 */
.field-label {
  display: block;
  font-size: 0.8rem;
  color: #57626d;
  margin: 12px 0 4px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
select {
  width: 100%;
  border: 1px solid #c4ccd6;
  border-radius: 6px;
  padding: 10px;
  font-size: 1rem;
  min-height: 42px;
  background: #fff;
}

input[type="file"] {
  width: 100%;
  font-size: 0.85rem;
}

.amount-row {
  display: flex;
  gap: 12px;
}

.amount-field {
  flex: 1;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0 4px;
}

.checkbox-field input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.checkbox-field label {
  font-size: 0.95rem;
}

.current-balance-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #eef1f8;
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 16px;
}

.current-balance-preview-value {
  font-size: 1.15rem;
  font-weight: bold;
  color: #1c2541;
}

.current-balance-preview-value.negative {
  color: #a12626;
}

.error-text {
  color: #a12626;
  font-size: 0.82rem;
  min-height: 1.2em;
  margin: 8px 0 0;
}

.primary-btn {
  width: 100%;
  background: #1c2541;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 1rem;
  min-height: 46px;
  cursor: pointer;
  margin-top: 16px;
}

.danger-btn {
  background: #ffe3e3;
  color: #a12626;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 0.95rem;
  min-height: 46px;
  cursor: pointer;
}

/* 検索 */
.search-row {
  margin-bottom: 12px;
}

/* 顧客一覧 */
.customer-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.customer-card {
  background: #fff;
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.customer-card-name {
  font-weight: bold;
  font-size: 1.02rem;
}

.customer-card-label {
  font-size: 0.78rem;
  color: #57626d;
  margin-left: 6px;
}

.customer-card-balance {
  font-size: 1.1rem;
  font-weight: bold;
  color: #1c2541;
}

.customer-card-balance.negative {
  color: #a12626;
}

.empty-state {
  text-align: center;
  color: #8a94a3;
  font-size: 0.9rem;
  margin-top: 40px;
}

/* 残高バナー */
.balance-banner {
  background: #eef1f8;
  padding: 16px;
  text-align: center;
  position: sticky;
  top: 62px;
  z-index: 15;
}

.balance-label {
  display: block;
  font-size: 0.8rem;
  color: #57626d;
}

.balance-value {
  display: block;
  font-size: 1.7rem;
  font-weight: bold;
  color: #1c2541;
  margin-top: 2px;
}

.balance-value.negative {
  color: #a12626;
}

/* 取引履歴 */
.transaction-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.transaction-row {
  background: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  cursor: pointer;
}

.transaction-row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.transaction-date {
  font-size: 0.78rem;
  color: #57626d;
}

.transaction-memo {
  font-size: 0.98rem;
  margin-top: 2px;
  word-break: break-word;
}

.transaction-amounts {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.85rem;
}

.transaction-income {
  color: #1a6b3a;
}

.transaction-deduction {
  color: #a12626;
}

.transaction-balance {
  font-weight: bold;
  color: #1c2733;
}

.transaction-balance.negative {
  color: #a12626;
}

.transaction-tag {
  background: #eef1f8;
  color: #57626d;
  font-size: 0.72rem;
  border-radius: 999px;
  padding: 2px 8px;
}

/* FAB */
.fab {
  position: fixed;
  right: 20px;
  bottom: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #1c2541;
  color: #fff;
  font-size: 1.6rem;
  border: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 25;
}

/* モーダル共通 */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

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

.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 18px;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
}

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

.modal-header h2 {
  font-size: 1.05rem;
  margin: 0;
}

.icon-btn {
  border: none;
  background: #eef1f5;
  border-radius: 6px;
  min-width: 32px;
  min-height: 32px;
  cursor: pointer;
  font-size: 0.9rem;
}

.required {
  color: #a12626;
  margin-left: 2px;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 8px;
}

/* データ管理モーダル */
.data-modal-desc {
  font-size: 0.85rem;
  color: #57626d;
  line-height: 1.6;
  margin: 4px 0 0;
}

.import-label {
  margin-top: 20px;
}

@media (min-width: 640px) {
  .app-header h1 {
    font-size: 1.3rem;
  }
}
