:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #dfe2e6;
  --text: #1f2328;
  --muted: #6a737d;
  --primary: #1f6feb;
  --primary-dark: #1858c4;
  --danger: #cf222e;
  --side: #20262e;
  --side-text: #d0d7de;
  --hover: #f0f4fa;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
ul.plain { list-style: none; margin: 0; padding: 0; }
pre { white-space: pre-wrap; word-break: break-word; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 24px; height: 48px; padding: 0 16px; background: var(--side); color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar a { color: #fff; }
.brand { font-weight: 700; font-size: 16px; }
.topnav { display: flex; gap: 16px; flex: 1; }
.topnav a { color: var(--side-text); }
.user-menu { display: flex; align-items: center; gap: 8px; color: var(--side-text); }
.user-menu form { margin: 0; }
.user-menu .btn-link { color: var(--side-text); }

/* layout */
.layout { display: flex; min-height: calc(100vh - 48px); }
.sidebar { width: 240px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--border); padding: 12px; overflow-y: auto; height: calc(100vh - 48px); position: sticky; top: 48px; }
.content { flex: 1; padding: 16px 24px; min-width: 0; }
.content.narrow { max-width: 1000px; margin: 0 auto; }
.signed-out .content.narrow { max-width: 420px; margin-top: 60px; }

.side-section { margin-top: 16px; }
.side-title { font-weight: 700; font-size: 13px; display: flex; justify-content: space-between; gap: 4px; }
.side-sub { font-size: 11px; color: var(--muted); margin-bottom: 4px; word-break: break-all; }
.side-link { display: flex; justify-content: space-between; padding: 5px 8px; border-radius: 6px; color: var(--text); }
.side-link:hover { background: var(--hover); text-decoration: none; }
.side-link.active { background: #dbe9ff; font-weight: 700; }
.count { background: var(--primary); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; line-height: 18px; height: 18px; }
.warn { color: var(--danger); font-size: 11px; font-weight: 400; }

/* flash */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }
.flash-notice { background: #dafbe1; border: 1px solid #aceebb; }
.flash-alert { background: #ffebe9; border: 1px solid #ffcecb; }

/* buttons / forms */
.btn { display: inline-block; padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border); background: #f6f8fa; color: var(--text); cursor: pointer; font-size: 13px; line-height: 1.4; text-decoration: none; white-space: nowrap; font-family: inherit; }
.btn:hover { background: #eef1f4; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); }
.btn-link { background: none; border: none; padding: 0; color: var(--primary); }
.btn-block { display: block; text-align: center; width: 100%; }
.btn-sm { padding: 3px 8px; font-size: 12px; }
form.inline, .button_to { display: inline; margin: 0; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; font-family: inherit; background: #fff;
}
textarea { min-height: 120px; }
select.auto, input.auto { width: auto; }
.field { margin-bottom: 12px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 13px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.field-check label { display: inline; font-weight: 400; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 0 16px; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 16px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; margin: 0 0 16px; background: var(--panel); }
legend { font-weight: 700; padding: 0 6px; }

/* toolbar / filters */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar form { display: flex; gap: 6px; align-items: center; }
.toolbar .spacer { flex: 1; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.tab { padding: 4px 10px; border-radius: 14px; border: 1px solid var(--border); background: #fff; color: var(--text); font-size: 13px; }
.tab.active { background: var(--text); color: #fff; border-color: var(--text); }
.tab:hover { text-decoration: none; }

/* table */
table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.list th { background: #f6f8fa; font-size: 12px; color: var(--muted); font-weight: 600; }
table.list tr:hover td { background: var(--hover); }
table.list tr.unhandled td { font-weight: 700; }
table.list td.subject a { color: var(--text); display: block; }
td.nowrap, th.nowrap { white-space: nowrap; }
.preview { color: var(--muted); font-weight: 400; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 520px; }
.clip { color: var(--muted); }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 12px; }

/* badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-unhandled { background: #ffebe9; color: #a40e26; }
.badge-in_progress { background: #fff8c5; color: #7d4e00; }
.badge-replied { background: #ddf4ff; color: #0550ae; }
.badge-on_hold { background: #fbefff; color: #8250df; }
.badge-done { background: #dafbe1; color: #116329; }
.badge-no_action { background: #eaeef2; color: #57606a; }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; background: #eaeef2; font-size: 11px; color: var(--muted); }

/* message detail */
.message-layout { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
.message-header h1 { margin-bottom: 8px; word-break: break-word; }
.meta { display: grid; grid-template-columns: 70px 1fr; gap: 2px 8px; font-size: 13px; margin-bottom: 12px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-all; }
.mail-body { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 16px; }
.mail-body pre { font-family: inherit; margin: 0; font-size: 14px; }
.mail-html { width: 100%; height: 600px; border: 1px solid var(--border); border-radius: 6px; background: #fff; resize: vertical; }
.attachments { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; }
.attachments a { padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; background: #f6f8fa; font-size: 12px; }
.side-panel .panel h3 { margin: 0 0 8px; font-size: 13px; }
.side-panel select { margin-bottom: 6px; }
.thread-item { padding: 8px 10px; border-left: 3px solid var(--border); margin-bottom: 6px; background: var(--panel); border-radius: 0 6px 6px 0; }
.thread-item.current { border-left-color: var(--primary); background: #f0f6ff; }
.thread-item.outgoing { border-left-color: #2da44e; }
.events { list-style: none; margin: 0; padding: 0; }
.events li { padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 12px; }
.events li.comment { background: #fffbe6; padding: 6px 8px; border-radius: 6px; border: 1px solid #f5e3a3; margin: 4px 0; font-size: 13px; }
.spam-note { background: #fff1e5; border: 1px solid #ffd8b5; padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; }
.reply-buttons { display: flex; gap: 6px; margin: 12px 0; flex-wrap: wrap; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .message-layout { grid-template-columns: 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .topnav { overflow-x: auto; }
}
