:root {
  --fg: #1f2328;
  --muted: #59636e;
  --bg: #ffffff;
  --surface: #f6f8fa;
  --border: #d1d9e0;
  --accent: #1f6feb;
  --danger: #cf222e;
  --ok: #1a7f37;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--fg);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Segoe UI", sans-serif;
  line-height: 1.6;
}

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

.site-header { border-bottom: 1px solid var(--border); background: var(--surface); }
.site-header .container { display: flex; align-items: center; justify-content: space-between; min-height: 56px; }
.brand { font-weight: 700; color: var(--fg); text-decoration: none; }

main.container { padding-top: 24px; padding-bottom: 48px; }

.site-footer { border-top: 1px solid var(--border); color: var(--muted); padding: 16px 0; }

.flash { padding: 8px 12px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); }
.flash-error { border-color: var(--danger); color: var(--danger); }
.flash-success { border-color: var(--ok); color: var(--ok); }

a { color: var(--accent); }

.user-menu { position: relative; font-size: 14px; }
.user-menu summary {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 6px;
  cursor: pointer; list-style: none; user-select: none;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover, .user-menu[open] summary { background: var(--border); }
.user-menu .user-name { max-width: 14em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-items {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; min-width: 160px;
  margin: 0; padding: 4px 0; list-style: none;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
.user-menu-items form { margin: 0; }
.user-menu-items a, .user-menu-items button {
  display: block; width: 100%; padding: 8px 16px; text-align: left;
  font: inherit; color: var(--fg); text-decoration: none; background: none; border: 0; cursor: pointer;
}
.user-menu-items a:hover, .user-menu-items button:hover { background: var(--surface); }
.user-menu-items a[aria-current="page"] { font-weight: 700; color: var(--accent); }
.user-menu-items .separator { height: 1px; margin: 4px 0; background: var(--border); }
.inline-form { display: inline; margin: 0; }
.link-button { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

.card { border: 1px solid var(--border); border-radius: 8px; padding: 24px; background: var(--bg); }
.narrow { max-width: 480px; margin: 0 auto; }
h1 { font-size: 22px; margin: 0 0 12px; }

label { display: block; font-weight: 600; margin: 16px 0 4px; }
input[type="text"], input[type="email"], input:not([type]), select {
  width: 100%; padding: 10px 12px; font-size: 16px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--fg);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.button {
  display: inline-block; margin-top: 20px; padding: 10px 20px; font-size: 16px; font-weight: 600;
  color: #fff; background: var(--accent); border: 0; border-radius: 6px; cursor: pointer;
  text-decoration: none;
}
.button:hover { filter: brightness(0.95); }
.field-error { color: var(--danger); margin: 4px 0 0; font-size: 14px; }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.readonly { margin: 0; padding: 10px 0; }
.flash-info { border-color: var(--accent); }

h2 { font-size: 17px; margin: 24px 0 8px; }
textarea {
  width: 100%; padding: 10px 12px; font: inherit; font-size: 16px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--fg); resize: vertical;
}
.required { margin-left: 8px; font-size: 12px; font-weight: 600; color: var(--danger); }
.checkbox, .radio { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 12px 0 0; }
.radio-group { border: 0; padding: 0; margin: 16px 0 0; }
.radio-group legend { font-weight: 600; padding: 0; }
.radio-group .radio { display: inline-flex; margin-right: 20px; }
.preview { margin-top: 12px; padding: 10px 12px; background: var(--surface); border-radius: 6px; }

.form-section { border-bottom: 1px solid var(--border); padding-bottom: 20px; margin-bottom: 4px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.page-head .button { margin-top: 0; }

.dropzone {
  border: 2px dashed var(--border); border-radius: 8px; padding: 28px 16px; text-align: center;
  color: var(--muted); background: var(--surface);
}
.dropzone p { margin: 4px 0; }
.dropzone.dragover { border-color: var(--accent); background: #ddf4ff; }
.dropzone label.link-button { display: inline; font-weight: 400; margin: 0; }

.file-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 14px; }
.file-table th, .file-table td { padding: 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.file-table td.name, .file-table td:first-child { word-break: break-all; }
.file-table .num { text-align: right; white-space: nowrap; }
.file-table .upload-status { white-space: nowrap; }
.file-table progress { width: 80px; margin-left: 8px; vertical-align: middle; }
.file-table tr[data-status="done"] .status-text { color: var(--ok); }
.file-table tr[data-status="failed"] .status-text { color: var(--danger); font-weight: 600; }
.file-table tfoot td { font-weight: 600; }

.summary { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; }
.break { word-break: break-all; }
.plain-list { list-style: none; padding: 0; }
.plain-list li { padding: 4px 0; }
.badge { display: inline-block; min-width: 72px; padding: 0 6px; font-size: 12px; border: 1px solid var(--border); border-radius: 10px; text-align: center; color: var(--muted); }

@media (max-width: 600px) {
  .summary { grid-template-columns: 1fr; }
  .summary dd { margin-bottom: 8px; }
  .radio-group .radio { display: flex; }
}

/* メールアドレスのタグ入力 */
.tag-input {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  min-height: 46px; padding: 6px 8px; cursor: text;
  border: 1px solid var(--border); border-radius: 6px; background: var(--bg);
}
.tag-input:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.tag-input.disabled { background: var(--surface); cursor: default; }
.tag-input .tag-input-field {
  flex: 1 0 12em; min-width: 12em; width: auto; padding: 4px; border: 0; outline: none; background: transparent;
}
.tag {
  display: inline-flex; align-items: center; max-width: 100%;
  background: #ddf4ff; border: 1px solid #b6e3ff; border-radius: 14px; font-size: 14px;
}
.tag.invalid { background: #ffebe9; border-color: var(--danger); color: var(--danger); }
.tag button { background: none; border: 0; font: inherit; color: inherit; cursor: pointer; }
.tag .tag-text { padding: 2px 4px 2px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 28em; }
.tag .tag-remove { padding: 2px 8px 2px 4px; color: var(--muted); }
.tag .tag-remove:hover { color: var(--danger); }
.tag-input .tag-editor {
  width: auto; padding: 2px 8px; font-size: 14px; border: 1px solid var(--accent); border-radius: 14px;
}
.field-note { margin: 4px 0 0; font-size: 14px; color: #9a6700; }
.tag.locked { background: var(--surface); border-color: var(--border); color: var(--muted); }
.tag.locked .tag-text { padding: 2px 10px; }

/* 送信の手順と確認画面 */
.steps { display: flex; gap: 8px; padding: 0; margin: 0 0 20px; list-style: none; counter-reset: step; font-size: 14px; }
.steps li { counter-increment: step; padding: 4px 12px; border-radius: 14px; background: var(--surface); color: var(--muted); }
.steps li::before { content: counter(step) ". "; }
.steps li[aria-current="step"] { background: var(--accent); color: #fff; font-weight: 600; }
.file-table.locked .remove-file { display: none; }
.mail-preview { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.mail-headers { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; padding: 12px 16px; background: var(--surface); font-size: 14px; }
.mail-headers dt { color: var(--muted); }
.mail-headers dd { margin: 0; word-break: break-all; }
.mail-body { margin: 0; padding: 16px; font: 14px/1.7 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-all; }
.field-note span { display: block; }

/* ボタンの配置ルール: 進む・確定は右、戻る・キャンセルは左（docs/REQUIREMENTS.md 12.1）
   HTML は「戻る → 確定」の順に書く（Tab の順も左から右になる） */
.actions { display: flex; align-items: center; gap: 16px; margin-top: 24px; }
.actions .button { margin-top: 0; }
.actions .actions-primary { margin-left: auto; }
.actions .actions-back { font-size: 15px; }
.resend { margin: 16px 0 0; font-size: 14px; color: var(--muted); }
@media (max-width: 600px) {
  /* スマートフォンでは確定を横幅いっぱいにし、戻るをその下に置く */
  .actions { flex-direction: column-reverse; align-items: stretch; gap: 12px; }
  .actions .actions-primary { margin-left: 0; width: 100%; text-align: center; }
  .actions .actions-back { align-self: center; }
}

/* 受信者の画面 */
.recipient-footer { margin: 0 0 4px; font-size: 14px; }
.privacy { margin-top: 12px; }
.message { white-space: pre-wrap; word-break: break-word; padding: 12px 16px; background: var(--surface); border-radius: 6px; }
.button.small { margin-top: 0; padding: 6px 14px; font-size: 14px; }
.download-table td:last-child { width: 1%; }
.scan-badge { display: inline-block; margin-left: 8px; padding: 0 8px; font-size: 12px; border-radius: 10px; border: 1px solid var(--border); white-space: nowrap; }
.scan-badge.clean { color: var(--ok); border-color: var(--ok); }
.scan-badge.pending { color: var(--muted); }
.scan-badge.threat { color: var(--danger); border-color: var(--danger); }
.session-note { margin-top: 24px; }
.bundle { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin: 4px 0 8px; }
.bundle .button { margin-top: 0; }
.button[aria-disabled="true"] { background: var(--border); color: var(--muted); cursor: not-allowed; }

/* 一覧・詳細 */
.table-scroll { overflow-x: auto; }
.list-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.list-table th, .list-table td { padding: 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.list-table th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.list-table .num { text-align: right; }
.nowrap { white-space: nowrap; }
.status { display: inline-block; padding: 0 8px; font-size: 12px; font-weight: 600; border-radius: 10px; white-space: nowrap; border: 1px solid var(--border); vertical-align: middle; }
.status-active, .status-ready { color: var(--ok); border-color: var(--ok); }
.status-expired, .status-pending, .status-draft { color: var(--muted); }
.status-revoked, .status-deleted, .status-failed { color: var(--danger); border-color: var(--danger); }
h1 .status { font-size: 13px; margin-left: 8px; }
.button.secondary { background: var(--bg); color: var(--accent); border: 1px solid var(--accent); }
.button.danger { background: var(--danger); color: #fff; }
.button.outline-danger { background: var(--bg); color: var(--danger); border: 1px solid var(--danger); }
.list-table .button { margin-top: 0; }
.operations { list-style: none; padding: 0; margin: 0; }
.operations li { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.operations li p { margin: 2px 0 0; }
.operations .button { margin-top: 0; white-space: nowrap; }
.confirm-dialog { max-width: 440px; width: calc(100% - 32px); border: 1px solid var(--border); border-radius: 10px; padding: 24px; }
.confirm-dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.confirm-dialog h2 { margin-top: 0; }
@media (max-width: 600px) {
  .operations li { flex-direction: column; align-items: stretch; }
  .operations .button { width: 100%; }
}

/* 右側に並ぶ操作ボタンは横幅をそろえる（表の中は小、操作欄は通常の大きさ） */
.button.fixed { min-width: 8.5em; text-align: center; box-sizing: border-box; }
.button.small.fixed { min-width: 7.5em; }
.back-link { margin: 0 0 8px; font-size: 14px; }
.back-link a { text-decoration: none; }
.back-link a:hover { text-decoration: underline; }

/* セクションのパネル（詳細画面など）: 見出し帯に背景色を付け、中身は白地にする */
.panel { margin-top: 20px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); overflow: hidden; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 16px; }
.panel-head .button { margin-top: 0; }
.panel-count { margin-left: 8px; font-size: 13px; font-weight: 400; color: var(--muted); }
.panel-body { padding: 16px; }
.panel-body .summary { margin: 0; }
.panel-subhead { margin: 16px 0 8px; font-size: 14px; color: var(--muted); }
.panel-note, .panel-foot { margin: 0; padding: 12px 16px; }
.panel .list-table th:first-child, .panel .list-table td:first-child { padding-left: 16px; }
.panel .list-table th:last-child, .panel .list-table td:last-child { padding-right: 16px; }
.panel .list-table tr:last-child td { border-bottom: 0; }
.panel .operations { padding: 0 16px; }
.panel .operations li:last-child { border-bottom: 0; }
.panel .operations h3 { margin: 0; font-size: 15px; }
.panel-note { border-bottom: 1px solid var(--border); }
.button { white-space: nowrap; }
@media (max-width: 600px) {
  /* 表は縮めて崩すより、横にスクロールさせる */
  .list-table { min-width: 640px; }
  .panel-head .button { width: 100%; text-align: center; }
}
.badge { white-space: nowrap; }
@media (max-width: 600px) {
  .list-table td.break { word-break: normal; white-space: nowrap; }
}
/* 枠線付きのボタンと塗りつぶしのボタンで高さをそろえる */
.button { border: 1px solid transparent; }
.button { font-family: inherit; line-height: 1.5; }
.button.small.fixed { min-width: 8.5em; }

/* 受信者の画面: グレーの背景に白いカード（ダウンロードを主役にする） */
body.page-recipient { background: #eef0f3; }
.page-recipient .site-header, .page-recipient .site-footer { background: transparent; border-color: transparent; }
.page-recipient .card { background: var(--bg); border: 0; border-radius: 12px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06); }
.receive-card { padding: 32px; }
.receive-title { text-align: center; font-size: 24px; margin: 0 0 24px; }
.receive-table { width: 100%; border-collapse: collapse; }
.receive-table th { padding: 10px 12px; text-align: left; font-size: 14px; border-bottom: 2px solid #8c959f; }
.receive-table td { padding: 14px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.receive-table .num { text-align: right; white-space: nowrap; }
.receive-table .name { word-break: break-all; }
.receive-table .size { color: var(--muted); }
.receive-table .action { width: 1%; white-space: nowrap; text-align: right; }
.download-link { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; text-decoration: none; }
.download-link:hover { text-decoration: underline; }
.icon { flex: none; }
.receive-total { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; margin-top: 16px; }
.receive-total .total-text { color: var(--muted); }
.receive-total .total-size { margin-left: 16px; }
.receive-total .bundle { justify-content: flex-end; margin: 0; }
.receive-info { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 14px; color: var(--muted); }
.receive-info dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.receive-info dd { margin: 0; color: var(--fg); }
.receive-info-label { margin: 16px 0 6px; }
.receive-info .message { color: var(--fg); }
.receive-info .session-note { margin-top: 16px; }
@media (max-width: 600px) {
  .receive-card { padding: 20px 16px; }
  .receive-title { font-size: 20px; }
  .receive-table thead { display: none; }
  .receive-table tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
  .receive-table td { padding: 0; border: 0; }
  .receive-table .name { grid-column: 1 / -1; }
  .receive-table .size { text-align: left; }
  .receive-total { align-items: stretch; }
  .receive-total .total-text { text-align: right; }
  .receive-total .bundle { flex-direction: column; align-items: stretch; }
  .receive-total .bundle-button { text-align: center; }
  .receive-info dl { grid-template-columns: 1fr; }
  .receive-info dd { margin-bottom: 8px; }
}

/* ウイルススキャンのアイコンとツールチップ */
.scan-icon {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 4px; margin: -4px 0; border: 0; border-radius: 50%; background: none; cursor: help; vertical-align: middle;
}
.scan-icon:focus-visible { outline: 2px solid var(--accent); }
.scan-clean { color: var(--ok); }
.scan-pending, .scan-none { color: var(--muted); }
.scan-failed { color: #bf8700; }
.scan-threat { color: var(--danger); }
.scan-note { display: flex; align-items: flex-start; gap: 6px; margin: 0; font-size: 13px; color: var(--muted); }
.scan-note svg { flex: none; margin-top: 1px; }
.scan-note-on svg { color: var(--ok); }
.scan-note-off { padding: 8px 12px; background: #fff8c5; border-radius: 6px; color: #6f5400; }

.receive-table .scan, .list-table td.scan { width: 1%; text-align: center; }
.receive-foot { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-top: 16px; }
.receive-foot .receive-total { margin-top: 0; flex: none; }
.receive-scan { flex: 1; max-width: 440px; }
@media (max-width: 600px) {
  .receive-foot { flex-direction: column; align-items: stretch; }
  .receive-table .scan { text-align: right; }
}
@media (max-width: 600px) {
  /* ファイル名の下に「サイズ・スキャン・ダウンロード」を並べる */
  .receive-table tr { grid-template-columns: 1fr auto auto; }
}
.receive-table th, .list-table th { white-space: nowrap; }

/* ツールチップ（static/js/tooltip.js が <body> 直下に置き、位置を計算する） */
.tooltip {
  position: fixed; z-index: 1000; max-width: 280px; padding: 8px 10px;
  font-size: 13px; line-height: 1.6; color: #fff; background: #24292f;
  border-radius: 6px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); pointer-events: none;
}
.tooltip.sheet { left: 16px; right: 16px; bottom: 16px; max-width: none; }
/* スキャンの列は見出しもアイコンも中央にそろえる */
.receive-table th.scan, .list-table th.scan { text-align: center; }
