/* =============================================
   基本変数・リセット
============================================= */
:root {
  --color-primary: #2c5f8a;
  --color-bg: #f4f6f8;
  --color-border: #d9dee3;
  --color-error: #c0392b;
  --header-h: 56px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  background: var(--color-bg);
  color: #222;
  -webkit-text-size-adjust: 100%;
}

/* =============================================
   ヘッダー（PC）
============================================= */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  padding: 0 1.5rem;
  height: var(--header-h);
  border-bottom: 1px solid var(--color-border);
}
.app-header__title a {
  font-weight: bold;
  color: var(--color-primary);
  text-decoration: none;
  font-size: 1rem;
  white-space: nowrap;
}
.app-header__nav {
  display: flex;
  align-items: center;
  gap: 0.1rem;
  flex-wrap: nowrap;
}
.app-header__nav a {
  display: block;
  padding: 0.4rem 0.6rem;
  text-decoration: none;
  color: #444;
  font-size: 0.85rem;
  border-radius: 4px;
  white-space: nowrap;
}
.app-header__nav a:hover { background: #f0f4f8; color: var(--color-primary); }

/* ハンバーガーボタン（PC では非表示） */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  padding: 6px;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 4px;
  flex-shrink: 0;
}
.nav-toggle span {
  display: block;
  width: 100%;
  height: 2px;
  background: #444;
  border-radius: 2px;
  transition: transform 0.25s, opacity 0.25s;
}
/* 開いたときのアニメーション */
.nav-toggle.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-toggle.is-open span:nth-child(2) { opacity: 0; }
.nav-toggle.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* =============================================
   ヘッダー（スマホ）
============================================= */
@media (max-width: 768px) {
  .nav-toggle { display: flex; }

  .app-header__nav {
    display: none;
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: #fff;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    overflow-y: auto;
    border-top: 1px solid var(--color-border);
    padding: 0.5rem 0;
    z-index: 99;
  }
  .app-header__nav.is-open { display: flex; }
  .app-header__nav a {
    padding: 1rem 1.5rem;
    font-size: 1rem;
    border-radius: 0;
    border-bottom: 1px solid var(--color-border);
  }
  .app-header__nav a:last-child { border-bottom: none; }
}

/* =============================================
   メインコンテンツ
============================================= */
.app-main {
  padding: 1.5rem;
  max-width: 1100px;
  margin: 0 auto;
}
@media (max-width: 600px) {
  .app-main { padding: 1rem; }
}

/* =============================================
   ログイン
============================================= */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-box {
  background: #fff;
  padding: 2rem 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  width: 100%;
  max-width: 360px;
}
.login-box h1 { font-size: 1.1rem; margin-bottom: 1.5rem; text-align: center; }
.login-box label { display: block; font-size: 0.85rem; margin-bottom: 1rem; }
.login-box input { width: 100%; padding: 0.6rem; margin-top: 0.3rem; border: 1px solid var(--color-border); border-radius: 4px; font-size: 1rem; }
.login-box button { width: 100%; padding: 0.75rem; background: var(--color-primary); color: #fff; border: none; border-radius: 4px; cursor: pointer; font-size: 1rem; }
.error { color: var(--color-error); font-size: 0.85rem; }

/* =============================================
   フラッシュメッセージ
============================================= */
.flash { padding: 0.7rem 1rem; border-radius: 4px; margin-bottom: 1.2rem; font-size: 0.9rem; }
.flash.success { background: #e6f4ea; color: #1e7e34; }
.flash.error   { background: #fbe9e7; color: var(--color-error); }
.flash.info    { background: #e8f0fe; color: var(--color-primary); }

/* =============================================
   ダッシュボードカード
============================================= */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin: 1.2rem 0;
}
.card {
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1rem;
  text-decoration: none;
  color: #222;
  display: block;
}
.card__num { font-size: 1.6rem; font-weight: bold; color: var(--color-primary); }
.card--danger .card__num { color: var(--color-error); }
.card__label { font-size: 0.82rem; color: #666; margin-top: 0.3rem; }

/* =============================================
   ボタン
============================================= */
.btn {
  display: inline-block;
  padding: 0.55rem 1rem;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn--outline { background: #fff; color: var(--color-primary); border: 1px solid var(--color-primary); }
.btn--danger  { background: var(--color-error); color: #fff; }
.btn--small   { padding: 0.3rem 0.65rem; font-size: 0.78rem; }

.quick-actions { display: flex; gap: 0.6rem; margin-bottom: 1.5rem; flex-wrap: wrap; }

/* =============================================
   ツールバー
============================================= */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.toolbar h1 { margin: 0; font-size: 1.3rem; }
.filters { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.filters select, .filters input {
  padding: 0.4rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.9rem;
  max-width: 100%;
}

/* =============================================
   データテーブル（スクロール対応）
============================================= */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table.data-table {
  width: 100%;
  min-width: 540px;        /* これ以下になったら横スクロール */
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
}
table.data-table th,
table.data-table td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.85rem;
  text-align: left;
  white-space: nowrap;
}
table.data-table th { background: #f0f2f4; font-weight: 600; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
/* 品目・件名列は折り返し許可 */
table.data-table td:first-child { white-space: normal; }

/* =============================================
   バッジ
============================================= */
.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 12px; font-size: 0.72rem; background: #eee; color: #444; white-space: nowrap; }
.badge--draft    { background: #eee; color: #666; }
.badge--sent, .badge--issued { background: #e8f0fe; color: var(--color-primary); }
.badge--accepted, .badge--paid { background: #e6f4ea; color: #1e7e34; }
.badge--rejected, .badge--void, .badge--overdue { background: #fbe9e7; color: var(--color-error); }
.badge--converted { background: #f0e8fd; color: #6a3fc7; }

/* =============================================
   フォームカード
============================================= */
form.form-card {
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.25rem;
  max-width: 640px;
  width: 100%;
}
form.form-card.wide { max-width: 900px; }
.form-row { margin-bottom: 1rem; }
.form-row label { display: block; font-size: 0.85rem; margin-bottom: 0.3rem; color: #444; }
.form-row input[type=text],
.form-row input[type=email],
.form-row input[type=password],
.form-row input[type=date],
.form-row input[type=number],
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 0.55rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.9rem;
  max-width: 100%;
}
.form-row--inline { display: flex; gap: 0.75rem; }
.form-row--inline > div { flex: 1; min-width: 0; }
@media (max-width: 480px) {
  .form-row--inline { flex-direction: column; gap: 0; }
}
.hint { font-size: 0.78rem; color: #888; margin-top: 0.25rem; }
.form-actions { margin-top: 1.5rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* =============================================
   明細テーブル（スクロール対応）
============================================= */
.item-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 0.5rem;
}
table.item-table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
}
table.item-table th {
  text-align: left;
  font-size: 0.78rem;
  color: #666;
  padding: 0.3rem;
  white-space: nowrap;
}
table.item-table td { padding: 0.3rem; }
table.item-table input {
  width: 100%;
  padding: 0.4rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.85rem;
}
table.item-table input.qty,
table.item-table input.price { text-align: right; }
table.item-table select.tax-rate { padding: 0.4rem; }

/* =============================================
   合計ボックス
============================================= */
.totals-box {
  margin-left: auto;
  width: 100%;
  max-width: 300px;
  background: #f8f9fa;
  border-radius: 6px;
  padding: 0.85rem 1rem;
  margin-top: 0.5rem;
}
.totals-box div { display: flex; justify-content: space-between; font-size: 0.88rem; padding: 0.2rem 0; }
.totals-box .grand-total {
  font-weight: bold;
  font-size: 1.05rem;
  border-top: 1px solid var(--color-border);
  margin-top: 0.4rem;
  padding-top: 0.5rem;
}

/* =============================================
   詳細ページ（アクションボタン群）
============================================= */
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.detail-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* 電話番号自動リンク化の防止 */
.no-tel { -webkit-touch-callout: none; pointer-events: none; }

/* =============================================
   検索バー
============================================= */
.search-bar {
  margin-bottom: 1rem;
}
.search-bar__row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}
.search-bar__input-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
}
.search-bar__input {
  width: 100%;
  padding: 0.55rem 2rem 0.55rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.9rem;
  font-family: inherit;
}
.search-bar__clear {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
  text-decoration: none;
  font-size: 0.9rem;
  line-height: 1;
}
.search-bar__clear:hover { color: var(--color-error); }
.search-bar__status {
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 0.9rem;
  background: #fff;
}
.search-bar__result {
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  color: #666;
}
@media (max-width: 480px) {
  .search-bar__input-wrap { min-width: 100%; }
  .search-bar__row { gap: 0.4rem; }
}

/* =============================================
   画像プレビュー
============================================= */
.logo-preview { max-width: 200px; max-height: 100px; display: block; margin-bottom: 0.6rem; }

/* =============================================
   印刷
============================================= */
@media print {
  .app-header, .toolbar, .detail-actions, .quick-actions, .nav-toggle { display: none !important; }
}

/* =============================================
   ページング
============================================= */
.paging {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  margin-top: 1.2rem;
  flex-wrap: wrap;
}
.paging__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: #fff;
  color: var(--color-primary);
  text-decoration: none;
  font-size: 0.88rem;
}
.paging__btn:hover { background: #f0f4f8; }
.paging__btn--current {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
  font-weight: bold;
}
.paging__btn--disabled { color: #bbb; cursor: default; }
.paging__btn--disabled:hover { background: #fff; }
.paging__ellipsis { padding: 0 0.2rem; color: #999; line-height: 36px; }
