:root {
  --c-primary: #2563eb;
  --c-primary-dark: #1d4ed8;
  --c-danger: #dc2626;
  --c-danger-dark: #b91c1c;
  --c-text: #111827;
  --c-muted: #6b7280;
  --c-border: #e5e7eb;
  --c-bg: #f5f6f8;
  --c-card: #ffffff;
  --c-success-bg: #ecfdf5;
  --c-success-text: #047857;
  --c-warn-bg: #fffbeb;
  --c-warn-text: #b45309;
  --c-error-bg: #fef2f2;
  --c-error-text: #b91c1c;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Noto Sans JP', 'Yu Gothic UI', sans-serif;
  color: var(--c-text);
  background: var(--c-bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 16px;
}

.main {
  padding-top: 16px;
  padding-bottom: 64px;
}

h1 {
  font-size: 1.4rem;
  margin: 12px 0;
}

h2 {
  font-size: 1.1rem;
  margin: 8px 0;
}

a {
  color: var(--c-primary);
}

/* ---- ヘッダー ---- */
.site-header {
  background: var(--c-card);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding-top: 10px;
  padding-bottom: 10px;
}

.brand {
  font-weight: 700;
  text-decoration: none;
  color: var(--c-text);
  font-size: 1.05rem;
}

.nav {
  display: flex;
  gap: 12px;
}

.nav a {
  text-decoration: none;
  font-size: 0.95rem;
}

.logout-form {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-name {
  color: var(--c-muted);
  font-size: 0.85rem;
}

/* ---- 汎用 ---- */
.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px;
}

.section {
  margin: 24px 0;
}

.muted {
  color: var(--c-muted);
}

.small {
  font-size: 0.85rem;
}

.prewrap {
  white-space: pre-wrap;
}

.sep {
  color: var(--c-muted);
}

.alert {
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 12px 0;
  font-size: 0.95rem;
}

.alert ul {
  margin: 0;
  padding-left: 20px;
}

.alert-success {
  background: var(--c-success-bg);
  color: var(--c-success-text);
}

.alert-warn {
  background: var(--c-warn-bg);
  color: var(--c-warn-text);
}

.alert-error {
  background: var(--c-error-bg);
  color: var(--c-error-text);
}

.count-badge {
  display: inline-block;
  background: var(--c-primary);
  color: #fff;
  border-radius: 999px;
  font-size: 0.75rem;
  padding: 1px 8px;
  vertical-align: middle;
}

.count-badge.danger {
  background: var(--c-danger);
}

/* ---- ボタン ---- */
.btn {
  display: inline-block;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  background: var(--c-card);
  color: var(--c-text);
  transition: background 0.15s;
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-primary {
  background: var(--c-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--c-primary-dark);
}

.btn-danger {
  background: var(--c-danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--c-danger-dark);
}

.btn-secondary {
  border-color: var(--c-primary);
  color: var(--c-primary);
}

.btn-ghost {
  border-color: var(--c-border);
  color: var(--c-muted);
  background: transparent;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-lg {
  padding: 14px 24px;
  font-size: 1.05rem;
}

.btn-block {
  display: block;
  width: 100%;
}

/* ---- フォーム ---- */
.field {
  display: block;
  margin: 16px 0;
}

.field-label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.field-label em {
  font-style: normal;
  color: var(--c-danger);
  font-size: 0.75rem;
  margin-left: 6px;
}

input[type='text'],
input[type='number'],
input[type='email'],
input[type='date'],
select,
textarea {
  width: 100%;
  font-size: 16px; /* iOSの自動ズーム防止 */
  font-family: inherit;
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  background: var(--c-card);
  color: var(--c-text);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--c-primary);
  outline-offset: 1px;
}

input[type='file'] {
  font-size: 15px;
}

.companions {
  margin: 16px 0;
}

.companion-row {
  display: flex;
  gap: 8px;
  margin: 8px 0;
}

.companion-row input {
  flex: 1;
  min-width: 0;
}

.companion-row .remove-companion {
  flex-shrink: 0;
}

/* ---- 画像プレビュー ---- */
.image-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}

.preview-item {
  position: relative;
}

.preview-item img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--c-border);
}

.preview-remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: var(--c-danger);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

/* ---- 一覧カード ---- */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.request-card {
  display: block;
  text-decoration: none;
  color: var(--c-text);
}

.request-card:hover {
  border-color: var(--c-primary);
}

.request-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.request-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.request-card-sub {
  margin-top: 4px;
  font-size: 0.92rem;
}

.request-card-meta {
  margin-top: 2px;
  color: var(--c-muted);
  font-size: 0.8rem;
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--c-muted);
}

.empty-state .btn {
  margin-top: 8px;
}

/* ---- バッジ ---- */
.badge {
  display: inline-block;
  border-radius: 999px;
  font-size: 0.75rem;
  padding: 2px 10px;
  white-space: nowrap;
  font-weight: 600;
}

.badge-pending {
  background: #fef3c7;
  color: #92400e;
}

.badge-approved {
  background: #d1fae5;
  color: #065f46;
}

.badge-rejected {
  background: #fee2e2;
  color: #991b1b;
}

/* ---- 詳細 ---- */
.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.detail-table th,
.detail-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--c-border);
  text-align: left;
  vertical-align: top;
  font-size: 0.95rem;
}

.detail-table tr:last-child th,
.detail-table tr:last-child td {
  border-bottom: none;
}

.detail-table th {
  width: 90px;
  background: #f9fafb;
  white-space: nowrap;
  font-weight: 600;
}

.companion-view {
  margin: 0;
  padding-left: 18px;
}

.receipt-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.receipt-img {
  max-width: 160px;
  max-height: 160px;
  border-radius: 8px;
  border: 1px solid var(--c-border);
}

.receipt-deleted {
  background: #f3f4f6;
  color: var(--c-muted);
  border-radius: 8px;
  padding: 16px;
  font-size: 0.85rem;
}

/* ---- 承認タイムライン ---- */
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 3px solid var(--c-border);
}

.timeline-item {
  position: relative;
  padding: 8px 0 8px 20px;
}

.timeline-item::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 16px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--c-border);
}

.timeline-approved::before {
  background: #10b981;
}

.timeline-rejected::before {
  background: var(--c-danger);
}

.timeline-current::before {
  background: #f59e0b;
}

.timeline-skipped::before {
  background: #9ca3af;
}

.timeline-role {
  display: inline-block;
  font-weight: 700;
  margin-right: 8px;
}

.timeline-comment {
  color: var(--c-muted);
  font-size: 0.9rem;
}

/* ---- 決裁ボックス ---- */
.decision-box {
  border: 2px solid var(--c-primary);
}

.reject-form {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed var(--c-border);
}

/* ---- ログイン ---- */
.login-box {
  max-width: 420px;
  margin: 48px auto;
  text-align: center;
}

.login-box .btn {
  margin: 16px 0;
}

/* ---- 管理 ---- */
.admin-links {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.filter-form {
  margin: 12px 0;
}

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

.filter-grid label {
  font-size: 0.85rem;
  color: var(--c-muted);
}

.filter-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
  flex-wrap: wrap;
}

.table-wrap {
  overflow-x: auto;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  min-width: 560px;
}

.admin-table th,
.admin-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--c-border);
  text-align: left;
  white-space: nowrap;
}

.admin-table td.num {
  text-align: right;
}

.admin-table td.audit-detail {
  white-space: normal;
  word-break: break-all;
  font-size: 0.78rem;
  color: var(--c-muted);
  max-width: 260px;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  margin: 16px 0;
}

.role-fieldset {
  margin: 12px 0;
  border: 1px solid var(--c-border);
}

.role-fieldset legend {
  font-weight: 700;
  padding: 0 6px;
}

.error-box {
  text-align: center;
  margin: 48px auto;
  max-width: 480px;
}

@media (min-width: 640px) {
  .filter-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
