:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #dfe1e6;
  --text: #172b4d;
  --muted: #5e6c84;
  --primary: #1f5fbf;
  --primary-dark: #174a96;
  --danger: #c9372c;
  --warning: #b65c02;
  --success: #216e4e;
  --sidebar: #1d2433;
  --radius: 6px;
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0 0 16px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pre { white-space: pre-wrap; word-break: break-word; }
.mono { font-family: Consolas, "Courier New", monospace; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* レイアウト */
.layout { display: grid; grid-template-columns: 200px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: #c7d1e0; padding: 16px 0; position: sticky; top: 0; height: 100vh; }
.sidebar .brand { color: #fff; font-weight: 700; font-size: 1.1rem; padding: 0 20px 16px; }
.sidebar .brand small { display: block; font-weight: 400; font-size: 11px; color: #8d9ab0; }
.sidebar nav a { display: block; color: #c7d1e0; padding: 9px 20px; border-left: 3px solid transparent; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .06); text-decoration: none; }
.sidebar nav a.active { color: #fff; background: rgba(255, 255, 255, .1); border-left-color: #5b9dff; }
.sidebar nav .sep { height: 1px; background: rgba(255, 255, 255, .1); margin: 8px 16px; }
.sidebar .user { position: absolute; bottom: 16px; left: 20px; right: 20px; font-size: 12px; }
.sidebar .user button { margin-top: 6px; }
main { padding: 24px 32px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

/* 部品 */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 20px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 20px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
@media (max-width: 1000px) { .grid3, .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 6px 14px; border-radius: var(--radius); cursor: pointer; display: inline-block; line-height: 1.4;
}
button:hover, .btn:hover { background: #f0f2f5; text-decoration: none; }
button.primary, .btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--primary-dark); }
button.danger { color: var(--danger); border-color: #f0b8b3; }
button.danger:hover { background: #fdecea; }
button.link { border: none; background: none; color: var(--primary); padding: 0; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 3px 10px; font-size: 12px; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); min-width: 0; }
label.field .req { color: var(--danger); margin-left: 2px; }
input, select, textarea {
  font: inherit; color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 8px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc3ff; border-color: var(--primary); }
input[type=checkbox], input[type=radio] { width: auto; }
textarea { min-height: 80px; resize: vertical; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.checks label { display: inline-flex; align-items: center; gap: 4px; color: var(--text); font-size: 13px; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; }
.field-hint { font-size: 11px; color: var(--muted); }

table.list { width: 100%; border-collapse: collapse; background: var(--surface); }
table.list th, table.list td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; white-space: nowrap; }
table.list th.sortable { cursor: pointer; user-select: none; }
table.list th.sortable:hover { color: var(--text); }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: #f5f8ff; }
table.list tr.inactive td { color: var(--muted); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.table-wrap table.list tr:last-child td { border-bottom: none; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.prio-P0 { background: #c9372c; color: #fff; }
.prio-P1 { background: #f5cd47; color: #533f04; }
.prio-P2 { background: #cce0ff; color: #09326c; }
.prio-P3 { background: #e9ebee; color: #44546f; }
.st { background: #e9ebee; color: #44546f; }
.st-received, .st-checking, .st-waiting { background: #fff3d6; color: #7f5f01; }
.st-in_progress { background: #cce0ff; color: #09326c; }
.st-customer_review { background: #dfd8fd; color: #352c63; }
.st-completed, .st-closed { background: #dcfff1; color: #164b35; }
.st-cancelled, .st-rejected { background: #f1f2f4; color: #626f86; text-decoration: line-through; }
.tag-internal { background: #fff3d6; color: #7f5f01; }
.tag-customer { background: #dcfff1; color: #164b35; }
.tag-deleted { background: #fdecea; color: var(--danger); }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

/* ダッシュボード */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; display: block; color: var(--text); }
a.stat:hover { border-color: var(--primary); text-decoration: none; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 1.8rem; font-weight: 700; margin-top: 4px; }
.stat.alert .value { color: var(--danger); }
.meter { height: 8px; background: #e9ebee; border-radius: 4px; overflow: hidden; margin-top: 6px; }
.meter > span { display: block; height: 100%; background: var(--primary); }
.meter.over > span { background: var(--danger); }
.warn { color: var(--danger); font-weight: 600; }

/* チケット詳細 */
.ticket-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.ticket-head .num { font-family: Consolas, monospace; color: var(--muted); font-size: 13px; }
.ticket-head h1 { margin: 4px 0 10px; word-break: break-word; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-word; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .detail-grid { grid-template-columns: 1fr; } }
.section-body { margin-bottom: 12px; }
.section-body h3 { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 110px 1fr; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.timeline li:last-child { border-bottom: none; }
.timeline time { color: var(--muted); font-size: 12px; }

.comment { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 10px; }
.comment.internal { background: #fffbeb; border-color: #f8e3a3; }
.comment .who { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 8px; align-items: center; }

.notice { padding: 10px 12px; border-radius: var(--radius); margin-bottom: 12px; }
.notice.warn-bg { background: #fff3d6; color: #7f5f01; }
.notice.danger-bg { background: #fdecea; color: var(--danger); }

/* ログイン */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login { width: 340px; max-width: calc(100vw - 32px); }
.login h1 { text-align: center; }
.login .sub { text-align: center; color: var(--muted); margin: -10px 0 20px; font-size: 12px; }
.login label.field { margin-bottom: 12px; }
.login button { width: 100%; padding: 8px; }
.login .help { color: var(--muted); margin: 16px 0 0; font-size: 12px; line-height: 1.6; }
.error-text { color: var(--danger); font-size: 13px; min-height: 1.2em; margin-bottom: 8px; }

/* トースト */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #172b4d; color: #fff; padding: 10px 16px; border-radius: var(--radius); box-shadow: 0 4px 12px rgba(0, 0, 0, .2); max-width: 420px; }
.toast.error { background: var(--danger); }

.comment.staff { background: #f5f8ff; border-color: #cfdcf5; }

/* ---------- 印刷 ---------- */
.print-doc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 32px; max-width: 820px; }
.print-header { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid #172b4d; padding-bottom: 8px; }
.print-kind { font-size: 12px; color: var(--muted); letter-spacing: .2em; }
.print-number { font-size: 20px; font-weight: 700; }
.print-org { text-align: right; font-size: 13px; }
.print-title { font-size: 18px; margin: 14px 0 10px; word-break: break-word; }
.print-doc section { margin-top: 18px; break-inside: auto; }
.print-doc h2 { font-size: 14px; border-left: 4px solid #172b4d; padding-left: 8px; margin-bottom: 8px; }
.print-doc h3 { font-size: 12px; color: var(--muted); margin: 0 0 2px; }
.print-block { margin-bottom: 10px; }
.print-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.print-table th, .print-table td { border: 1px solid #c1c7d0; padding: 5px 8px; text-align: left; vertical-align: top; }
.print-table th { background: #f4f5f7; width: 130px; font-weight: 600; }
.print-table.list-table th { width: auto; }
.print-comment { border-bottom: 1px dashed #c1c7d0; padding: 6px 0; break-inside: avoid; }
.print-comment .who { font-size: 12px; color: var(--muted); }
.print-confidential { margin-top: 18px; font-size: 11px; color: var(--danger); }
.print-footer { margin-top: 24px; font-size: 11px; color: var(--muted); text-align: right; }

@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; }
  .sidebar, .no-print, #toasts { display: none !important; }
  .layout { display: block; }
  main { padding: 0; }
  .print-doc { border: none; padding: 0; max-width: none; }
  .print-doc h2 { break-after: avoid; }
  .print-table tr { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}
