:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1f2328;
  --muted: #656d76;
  --border: #d8dee4;
  --primary: #2458d6;
  --primary-hover: #1c47b0;
  --danger: #c62828;
  --unread: #e5534b;
  --success-bg: #e7f5ea;
  --success-text: #1e6b30;
  --error-bg: #fdecea;
  --error-text: #a3261c;
  --notice-bg: #fff8e1;
  --notice-border: #f0c14b;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #181c22;
    --surface-2: #20252c;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --border: #2d333b;
    --primary: #5b8cff;
    --primary-hover: #7aa2ff;
    --danger: #ef5350;
    --unread: #ff6b61;
    --success-bg: #173320;
    --success-text: #8fd6a0;
    --error-bg: #3a1714;
    --error-text: #ffab9f;
    --notice-bg: #2e2610;
    --notice-border: #8a6d1d;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--primary); }
h1 { font-size: 1.45rem; margin: 0 0 .75rem; word-break: break-word; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap { max-width: 1160px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 20px; padding-bottom: 48px; }

/* footer */
.site-footer { padding: 0 0 24px; text-align: center; font-size: .8rem; color: var(--muted); opacity: .8; }

/* header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 52px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.brand-logo { width: 28px; height: 28px; }
nav { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; font-size: .95rem; }
nav a { text-decoration: none; }
form.inline { display: inline; margin: 0; }

/* 表示中の組織（担当者・管理者のみ） */
.org-band { border-bottom: 1px solid rgba(0,0,0,.15); }
.org-band-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; flex-wrap: wrap; }
.org-band-label { font-size: .8rem; opacity: .85; margin-right: 10px; }
.org-band-name { font-size: 1.2rem; letter-spacing: .02em; }
.org-band a { font-size: .9rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .85rem; margin: 4px 0 0; }
.narrow { max-width: 420px; }
.login { margin: 40px auto; }

.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; }
.flash ul { margin: 0; padding-left: 1.2em; }
.flash-success { background: var(--success-bg); color: var(--success-text); }
.flash-error { background: var(--error-bg); color: var(--error-text); }

/* forms */
.form { max-width: 820px; }
.form.narrow { max-width: 420px; }
.field { margin-bottom: 16px; flex: 1; min-width: 0; }
fieldset.field { border: 0; padding: 0; margin: 0 0 16px; }
.field > label, .field legend, .field-label { display: block; font-weight: 600; margin-bottom: 4px; padding: 0; }
.req { font-size: .72rem; color: var(--danger); font-weight: 400; margin-left: 4px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > .field { min-width: 180px; }
.row-tight { display: flex; gap: 8px; }
.row-tight select { flex: 1; }
.radio-group { display: flex; gap: 20px; flex-wrap: wrap; margin-bottom: 8px; }
.radio, .check { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; cursor: pointer; }
input[type=text], input[type=search], input[type=password], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
input[type=color] { width: 64px; height: 36px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
[hidden] { display: none !important; }

.btn {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.small { padding: 4px 12px; font-size: .88rem; }
.btn.wide { width: 100%; }
button.link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; }

/* list */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1 { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px; }
.filters input[type=search] { flex: 2 1 200px; width: auto; }
.filters select { flex: 1 1 130px; width: auto; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.tickets { width: 100%; border-collapse: collapse; }
.tickets th, .tickets td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tickets th { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tickets td.title { min-width: 240px; }
.tickets tbody tr:last-child td { border-bottom: 0; }
.tickets tbody tr:hover { background: var(--surface-2); }
.tickets tr.is-unread td.title a { font-weight: 700; }
.unread-col { width: 20px; padding-right: 0 !important; }
.unread-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--unread); }
.nowrap { white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 32px !important; }
.due { font-size: .85rem; }
.overdue { color: var(--danger); font-weight: 700; }

/* アナウンス */
/* トップページ: 1行1件・最大3行程度の一覧 */
.ann-box { --ann-row: 2.5rem; background: var(--notice-bg); border: 1px solid var(--notice-border); border-radius: var(--radius); margin-bottom: 20px; overflow: hidden; }
.ann-box-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 14px; border-bottom: 1px solid var(--notice-border); }
.ann-box-title { font-weight: 700; font-size: .92rem; }
.ann-count { font-weight: 400; color: var(--muted); font-size: .82rem; margin-left: 4px; }
.ann-box-head .small-link { margin-left: 0; }
.ann-list { list-style: none; margin: 0; padding: 0; max-height: calc(var(--ann-row) * 3); overflow-y: auto; }
.ann-empty { margin: 0; padding: 10px 14px; font-size: .9rem; }
.ann-list li + li { border-top: 1px solid var(--notice-border); }
.ann-row {
  display: flex; align-items: center; gap: 12px; width: 100%; height: var(--ann-row);
  padding: 0 14px; background: none; border: 0; color: var(--text); font: inherit; text-align: left; cursor: pointer;
  white-space: nowrap;
}
.ann-row:hover, .ann-row:focus-visible { background: rgba(0, 0, 0, .04); }
.ann-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--unread); }
.ann-date { flex: none; color: var(--muted); font-size: .85rem; }
.ann-title { flex: 0 1 auto; max-width: 40%; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.ann-body { flex: 1 1 0; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.ann-row.is-read { color: var(--muted); }
.ann-row.is-read .ann-dot { visibility: hidden; }
.ann-row.is-read .ann-title { font-weight: 400; }
/* 縦長の画面ではタイトルのみ表示する */
@media (orientation: portrait) {
  .ann-date, .ann-body { display: none; }
  .ann-title { flex: 1 1 0; min-width: 0; max-width: none; }
}
.ann-dialog { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 64px); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px 24px; }
.ann-dialog::backdrop { background: rgba(0, 0, 0, .45); }
.ann-dialog-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.ann-dialog-head h2 { margin: 0; font-size: 1.15rem; }
.ann-dialog-actions { display: flex; justify-content: flex-end; margin-top: 20px; }

/* アナウンス一覧画面 */
.announcement-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.announcement-head h2 { margin: 0; }
.announcement-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: .85rem; }
.announcement-item .body-text { margin: 6px 0 10px; }
.inline-actions { display: inline-flex; gap: 6px; margin-right: 6px; }
.org-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 16px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; }

/* 組織選択 */
.org-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.org-item { display: flex; align-items: center; gap: 12px; padding: 14px 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none; }
.org-item:hover { border-color: var(--primary); }
.org-name { font-weight: 600; font-size: 1.05rem; }
.org-count { margin-left: auto; color: var(--muted); white-space: nowrap; }
.org-count strong { color: var(--text); font-size: 1.1rem; }
.unread-label { color: var(--unread); font-size: .85rem; font-weight: 600; }
.org-swatch { display: inline-block; width: 16px; height: 16px; border-radius: 4px; vertical-align: -3px; margin-right: 4px; border: 1px solid rgba(0,0,0,.15); }

/* 詳細 */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 860px) { .detail-grid { grid-template-columns: 1fr; } .detail-side { order: -1; } }
.section-title { font-size: .85rem; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.body-text { white-space: pre-wrap; word-break: break-word; }
dl.props { display: grid; grid-template-columns: 6.5em 1fr; gap: 8px 12px; margin: 0; }
dl.props dt { color: var(--muted); font-size: .85rem; }
dl.props dd { margin: 0; word-break: break-word; }
ul.related, ul.files { list-style: none; padding: 0; margin: 8px 0 0; }
ul.related li { margin-bottom: 4px; }
ul.files li { font-size: .92rem; }

.timeline { margin: 20px 0; }
.comment { padding: 12px 16px; margin-bottom: 10px; }
.comment-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 4px; font-size: .92rem; }
.small-link { font-size: .85rem; margin-left: auto; }
.event { font-size: .85rem; color: var(--muted); margin: 6px 0 10px 12px; padding-left: 12px; border-left: 2px solid var(--border); }
.comment-form textarea { margin-bottom: 8px; }
.comment-form .btn { margin-top: 10px; }

.actions-card { display: grid; gap: 12px; }
.actions-card .form { margin: 0; }
.actions-card label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
.actions-card textarea { margin-bottom: 8px; }
.action-details summary { list-style: none; }
.action-details summary::-webkit-details-marker { display: none; }
.action-details[open] summary { margin-bottom: 8px; }

/* badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.type-request { background: #e3edff; color: #1d4ab8; }
.type-bug { background: #fde7e7; color: #b42318; }
.type-question { background: #efe7fd; color: #6b2fbf; }
.status-new { background: #e3edff; color: #1d4ab8; }
.status-in_progress { background: #fff4d6; color: #8a5a00; }
.status-on_hold { background: #eceff3; color: #4b5563; }
.status-waiting { background: #dff5f5; color: #0e6a6a; }
.status-done { background: #e2f5e7; color: #1e6b30; }
.status-canceled { background: #eceff3; color: #6b7280; }
.sent-back { background: #b42318; color: #fff; }
.prio-normal { background: #eceff3; color: #4b5563; }
.prio-urgent { background: #b42318; color: #fff; }
.prio-dated { background: #ffe9d6; color: #a64b00; }
.scheduled { background: #efe7fd; color: #6b2fbf; }
.target { background: var(--surface-2); color: var(--muted); }
.acked { background: #e2f5e7; color: #1e6b30; }
@media (prefers-color-scheme: dark) {
  .type-request, .status-new { background: #1b2b4d; color: #9dbbff; }
  .type-bug { background: #45191a; color: #ffa39e; }
  .type-question, .scheduled { background: #2e2147; color: #c8a8ff; }
  .status-in_progress { background: #3d2f0b; color: #f5cf6a; }
  .status-waiting { background: #123838; color: #7fdada; }
  .status-on_hold, .status-canceled, .prio-normal { background: #2a2f36; color: #b0b8c1; }
  .status-done, .acked { background: #173320; color: #8fd6a0; }
  .prio-dated { background: #43280f; color: #ffbb80; }
  .prio-urgent, .sent-back { background: #d6453b; color: #fff; }
}
