:root {
  --accent: #0b7a75;
  --ink: #1b2430;
  --sub: #5d6978;
  --line: #dfe4ea;
  --bg: #f4f6f8;
  --card: #ffffff;
  --warn: #b4521a;
  --ok: #1d7a46;
  --err: #b3261e;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

button { font: inherit; cursor: pointer; }

/* ---- 上の帯 ---- */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mark { width: 10px; height: 22px; border-radius: 3px; background: var(--accent); flex: none; }
.who { display: flex; align-items: center; gap: 10px; flex: none; }
.user { color: var(--sub); font-size: 13px; }

.note {
  margin: 0; padding: 6px 20px; font-size: 12px; color: var(--warn);
  background: #fff7ef; border-bottom: 1px solid #f1dcc6;
}

/* ---- 3列 ---- */
.layout {
  flex: 1; min-height: 0;
  display: grid; gap: 12px; padding: 12px;
  grid-template-columns: minmax(360px, 1.15fr) minmax(340px, 1fr) minmax(320px, 0.9fr);
}
.layout.noBack { grid-template-columns: minmax(360px, 1.2fr) minmax(340px, 1fr); }
.layout.noBack .back { display: none; }

.pane {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.paneHead {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--line); flex: none;
}
.paneHead h2 { font-size: 14px; white-space: nowrap; }
.detail .paneHead { align-items: flex-start; }
.count { color: var(--sub); font-size: 12px; margin-right: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- ボタン ---- */
.ghost {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 6px; padding: 5px 12px;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }
.ghost.small { padding: 3px 10px; font-size: 12px; }
.buttons { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.primary {
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  border-radius: 6px; padding: 5px 14px; font-weight: 600;
}
.primary:disabled, .ghost:disabled { opacity: 0.45; cursor: not-allowed; }
button:focus-visible, input:focus-visible, textarea:focus-visible, tr:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

/* ---- 一覧 ---- */
.tableWrap { overflow: auto; flex: 1; min-height: 0; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 12px; text-align: left; white-space: nowrap; border-bottom: 1px solid var(--line); }
th { position: sticky; top: 0; background: #f8fafb; color: var(--sub); font-weight: 600; font-size: 12px; z-index: 1; }
td.money, th.money { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f3f8f8; }
tbody tr.selected { background: color-mix(in srgb, var(--accent) 10%, white); box-shadow: inset 3px 0 0 var(--accent); }
.empty { color: var(--sub); padding: 24px 14px; margin: 0; text-align: center; }

/* ---- 詳細 ---- */
.detailBody { overflow: auto; padding: 4px 14px 16px; flex: 1; min-height: 0; }
.group { margin-top: 14px; }
.group > h3 {
  font-size: 12px; color: var(--sub); letter-spacing: 0.04em;
  padding-bottom: 4px; border-bottom: 1px solid var(--line); margin-bottom: 8px;
}
.field { display: grid; grid-template-columns: 150px 1fr; align-items: center; gap: 8px; padding: 4px 0; }
.field label, .field .label { color: var(--sub); font-size: 13px; }
.field .value { font-variant-numeric: tabular-nums; min-height: 22px; }
.field .value.none { color: #a3acb7; }
.field input, .field textarea {
  width: 100%; font: inherit; color: inherit;
  border: 1px solid #c9d1da; border-radius: 6px; padding: 5px 8px; background: #fff;
}
.field textarea { min-height: 64px; resize: vertical; }
.field input.dirty, .field textarea.dirty { border-color: var(--warn); background: #fffaf4; }
.tag { font-size: 11px; color: var(--sub); border: 1px solid var(--line); border-radius: 10px; padding: 0 7px; margin-left: 6px; }
.items { margin-top: 6px; border: 1px solid var(--line); border-radius: 6px; overflow: auto; }

/* ---- 裏側 ---- */
.back img { width: 100%; display: block; border-bottom: 1px solid var(--line); background: #e9edf1; min-height: 120px; }
.back h3 { font-size: 12px; color: var(--sub); padding: 10px 14px 4px; flex: none; }
.log { list-style: none; margin: 0; padding: 0 10px 12px; overflow: auto; flex: 1; min-height: 0; }
.log li { border: 1px solid var(--line); border-radius: 6px; margin-top: 6px; font-size: 12px; }
.log summary { display: flex; align-items: center; gap: 8px; padding: 6px 10px; cursor: pointer; }
.log .ms { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--sub); }
.log .kind { font-size: 10px; border-radius: 3px; padding: 0 5px; color: #fff; background: #6b7a8c; flex: none; }
.log .kind.write { background: var(--warn); }
.log .fail { color: var(--err); }
.log ol { margin: 0; padding: 4px 10px 8px 30px; color: var(--sub); }
.log ol li { border: 0; margin: 0; }
.log .at { font-variant-numeric: tabular-nums; color: #a3acb7; margin-right: 6px; }

/* ---- お知らせ ---- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 9px 18px; border-radius: 8px; font-size: 13px;
  max-width: min(640px, 90vw); z-index: 20;
}
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }
.busy {
  position: fixed; right: 20px; top: 56px; z-index: 15;
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 5px 14px;
  font-size: 12px; color: var(--sub); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

[hidden] { display: none !important; }

/* ---- 入口のページ ---- */
body.index { display: block; }
body.index main { max-width: 680px; margin: 48px auto; padding: 0 20px; }
body.index h1 { font-size: 20px; margin-bottom: 12px; }
.tenants { list-style: none; padding: 0; margin: 20px 0; }
.tenants li { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px 16px; margin-bottom: 10px; }
.tenants a { font-weight: 600; color: var(--accent); text-decoration: none; margin-right: 10px; }
.tenants a:hover { text-decoration: underline; }
.tenants span { color: var(--sub); font-size: 12px; }
.tenants p { margin: 4px 0 0; color: var(--sub); font-size: 12px; }
.hint { color: var(--sub); font-size: 12px; }

@media (max-width: 1100px) {
  .layout, .layout.noBack { grid-template-columns: 1fr; overflow: auto; }
  .pane { min-height: 320px; }
}

/* ---- 状態と注記 ---- */
.statusLine { margin: 12px 0 0; display: flex; align-items: center; gap: 8px; }
.badge { font-size: 12px; font-weight: 600; color: var(--accent); border: 1px solid var(--accent); border-radius: 10px; padding: 0 9px; }
.empty.small { padding: 6px 0; text-align: left; font-size: 12px; }
.alert { background: #fdecea; border: 1px solid #f3c4bf; color: var(--err); border-radius: 8px; padding: 10px 14px; }
