* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e1e4e8;
  --text: #24292f;
  --muted: #6a737d;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
}

body {
  font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* --- ログイン画面 --- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--panel);
  padding: 36px;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 {
  font-size: 22px;
  text-align: center;
}

.login-sub {
  text-align: center;
  color: var(--muted);
  margin-top: -8px;
  margin-bottom: 6px;
}

.login-card label,
.filters label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

input,
select,
textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

button {
  cursor: pointer;
  font: inherit;
}

[hidden] {
  display: none !important;
}

.login-card button {
  padding: 10px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-weight: 600;
}

.login-card button:hover {
  background: var(--primary-dark);
}

.error-msg {
  color: #d73a49;
  font-size: 13px;
  min-height: 18px;
  text-align: center;
}

/* --- トップバー --- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 10px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
  font-size: 17px;
  letter-spacing: -0.2px;
}

.brand-name {
  font-weight: 800;
  color: var(--primary);
  background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-sub {
  font-weight: 500;
  color: var(--muted);
  font-size: 14px;
}

.brand:hover .brand-sub {
  color: var(--text);
}

/* ログイン画面のロゴ */
.login-logo {
  font-size: 26px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: normal;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-badge {
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--text);
  text-decoration: none;
  display: inline-block;
  font: inherit;
  line-height: 1.4;
}

.btn-ghost:hover {
  background: var(--bg);
}

.btn-ghost:disabled {
  opacity: 0.5;
  cursor: default;
}

/* --- レイアウト --- */
.layout {
  display: grid;
  grid-template-columns: 200px 320px 1fr;
  height: calc(100vh - 53px);
}

/* --- サイドバー --- */
.sidebar {
  background: #f0f2f5;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 10px 8px;
  gap: 2px;
  overflow-y: auto;
}

.btn-compose {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 600;
  text-align: left;
  width: 100%;
  margin-bottom: 6px;
  font-size: 13px;
}

.btn-compose:hover {
  background: var(--primary-dark);
}

.sidebar-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.btn-sync-sb {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  color: var(--muted);
}

.btn-sync-sb:hover {
  background: #e3e7ee;
  color: var(--text);
}

.nav-account-header {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 8px 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-account-header:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 4px;
}

.folder-group {
  border-left: 2px solid var(--border);
  margin-left: 14px;
  margin-top: 1px;
  margin-bottom: 4px;
}

.nav-item-sub {
  padding-left: 10px;
  font-size: 12px;
  color: var(--muted);
}

.nav-item-sub.active {
  color: #fff;
}

.nav-item-sub:hover:not(.active) {
  color: var(--text);
}

.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 10px 8px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  gap: 6px;
}

.nav-item:hover {
  background: #e3e7ee;
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.nav-item.has-unread {
  font-weight: 600;
}

.nav-item .nav-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-badge {
  margin-left: auto;
  background: #d73a49;
  color: #fff;
  border-radius: 9px;
  font-size: 10px;
  padding: 1px 6px;
  font-weight: 700;
  flex-shrink: 0;
}

.nav-item.active .nav-badge {
  background: rgba(255, 255, 255, 0.35);
}

/* 要対応: 0件ならグレー、残っていれば赤で目立たせる */
.nav-pending .nav-badge {
  background: #c5ccd6;
}

.nav-pending.has-pending {
  color: #d73a49;
  font-weight: 700;
}

.nav-pending.has-pending .nav-badge {
  background: #d73a49;
}

.nav-pending.active {
  color: #fff;
}

.list-panel {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.search-bar {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.search-bar input {
  width: 100%;
}

.filters {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.counts {
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
}

.filter-check {
  flex-direction: row !important;
  align-items: center;
  gap: 5px;
  color: var(--text) !important;
  align-self: center;
  font-size: 13px;
  cursor: pointer;
}

.filter-check input {
  width: auto;
}

/* --- メール一覧 --- */
.email-list {
  overflow-y: auto;
  flex: 1;
}

.email-empty,
.detail-empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

.email-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.email-row:hover {
  background: #f0f4ff;
}

.email-row.selected {
  background: #e0e9ff;
  border-left: 3px solid var(--primary);
  padding-left: 11px;
}

/* 既読メールは件名を細く、未読は太字 + 青ドット */
.email-row:not(.unread) .email-subject {
  font-weight: 400;
}

.email-row.unread .email-subject {
  font-weight: 700;
}

.email-row.unread .email-subject::before {
  content: '●';
  color: var(--primary);
  font-size: 9px;
  margin-right: 5px;
  vertical-align: middle;
}

.email-row-main {
  min-width: 0;
  flex: 1;
}

.email-subject {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-sub {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.email-row-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  white-space: nowrap;
}

.email-date {
  font-size: 11px;
  color: var(--muted);
}

/* --- バッジ --- */
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 600;
}

.badge-account {
  background: #eef1f4;
  color: var(--muted);
}

.badge-folder {
  background: #e7e9fd;
  color: #4338ca;
}

.badge-admin {
  background: #fde9c8;
  color: #b7791f;
}

.badge-mailbox {
  background: #f1f3f5;
  color: #6a737d;
}

.st-open {
  background: #fdecea;
  color: #d73a49;
}

.st-progress {
  background: #fff3cd;
  color: #b7791f;
}

.st-done {
  background: #e3f6e8;
  color: #1a7f37;
}

/* --- 詳細パネル --- */
.detail-panel {
  overflow-y: auto;
  padding: 20px 24px;
}

.detail-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 14px;
}

.d-subject {
  font-size: 18px;
  margin-bottom: 8px;
}

.d-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
  align-items: center;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.status-label {
  color: var(--muted);
  font-size: 13px;
}

.status-buttons {
  display: flex;
  gap: 6px;
}

.status-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  padding: 5px 12px;
  font-weight: 600;
}

.status-btn.active {
  outline: 2px solid var(--primary);
}

.status-btn:disabled {
  cursor: default;
}

.d-assigned {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
}

.d-body {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  max-height: 360px;
  overflow-y: auto;
}

/* --- 返信 --- */
.reply-box {
  margin-top: 20px;
}

.reply-box h3,
.history h3 {
  font-size: 15px;
  margin-bottom: 8px;
}

.reply-input {
  width: 100%;
  resize: vertical;
}

.reply-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.reply-sig {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.reply-sig select {
  padding: 4px 8px;
}

.move-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.move-actions:empty {
  display: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  opacity: 0.5;
}

.reply-msg {
  font-size: 13px;
  color: var(--muted);
}

.reply-msg.error {
  color: #d73a49;
}

/* --- 履歴 --- */
.history {
  margin-top: 24px;
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  display: flex;
  gap: 12px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: 6px;
}

.history-item.status {
  border-left-color: var(--primary);
}

.history-item.reply {
  border-left-color: #1a7f37;
}

.history-time {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  min-width: 130px;
}

.history-text {
  font-size: 13px;
}

.history-reply {
  margin-top: 6px;
  padding: 8px;
  background: var(--bg);
  border-radius: 4px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
}

.history-empty {
  color: var(--muted);
  font-size: 13px;
}

/* --- アカウント管理ページ --- */
.account-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.account-form-card,
.account-list-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px;
}

.account-form-card h2,
.account-list-card h2 {
  font-size: 16px;
  margin-bottom: 16px;
}

#accountForm,
#ruleForm {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.inline-form {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.inline-form input {
  flex: 1;
  min-width: 240px;
}

.form-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.form-row label {
  flex: 1;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.form-row .field-narrow {
  flex: 0 0 120px;
  min-width: 120px;
}

.form-row .field-full {
  flex-basis: 100%;
}

.checkbox-label {
  flex: 0 0 auto !important;
  min-width: auto !important;
  flex-direction: row !important;
  align-items: center;
  gap: 6px !important;
  color: var(--text) !important;
  padding-bottom: 9px;
}

.checkbox-label input {
  width: auto;
}

.form-hint {
  font-size: 12px;
  color: var(--muted);
  background: var(--bg);
  border-radius: 6px;
  padding: 8px 10px;
  line-height: 1.5;
}

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 4px;
}

.form-msg {
  font-size: 13px;
  color: var(--muted);
}

.form-msg.error {
  color: #d73a49;
}

.form-msg.ok {
  color: #1a7f37;
}

.account-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}

.account-item-info {
  min-width: 0;
}

.account-item-name {
  font-weight: 600;
}

.account-item-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  word-break: break-all;
}

.account-item-actions {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.btn-sm:hover {
  background: var(--bg);
}

.btn-danger {
  color: #d73a49;
  border-color: #f3c5c8;
}

.btn-danger:hover {
  background: #fdecea;
}

.account-empty {
  color: var(--muted);
  font-size: 13px;
}

/* --- ユーザー管理ページ --- */
.user-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.user-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-card-body {
  margin-top: 8px;
}

.account-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px 11px;
  font-size: 13px;
  cursor: pointer;
}

.check-pill input {
  margin: 0;
  width: auto;
}

/* --- フォルダ絞り込みバー --- */
.folder-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.folder-bar-label {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.folder-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.folder-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 14px;
  padding: 4px 11px;
  font-size: 12px;
  color: var(--text);
}

.folder-btn:hover {
  background: var(--bg);
}

.folder-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.folder-btn.has-unread {
  font-weight: 700;
}

.unread-dot {
  background: #d73a49;
  color: #fff;
  border-radius: 9px;
  font-size: 10px;
  padding: 1px 6px;
  font-weight: 700;
}

.folder-btn.active .unread-dot {
  background: #fff;
  color: var(--primary);
}

/* --- 一括操作バー --- */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.bulk-info {
  font-size: 12px;
  color: var(--muted);
}

/* --- 一覧の選択チェックボックス --- */
.row-check {
  align-self: center;
  width: auto;
  margin: 0;
  padding: 0;
  flex: 0 0 auto;
}

.email-row.row-selected {
  background: #fff7e0;
}

/* --- 新規メール作成フォーム --- */
.compose-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.compose-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.compose-form input,
.compose-form textarea,
.compose-form select {
  width: 100%;
}

.reply-msg.ok {
  color: #1a7f37;
}

/* --- メール本文iframe --- */
.d-body-iframe {
  width: 100%;
  border: none;
  min-height: 200px;
  height: 400px;
  display: block;
  background: #fff;
}

.d-body-text {
  white-space: pre-wrap;
  word-break: break-word;
}

/* --- 詳細: 添付ファイルエリア --- */
.d-attachments {
  margin: 8px 0;
  padding: 10px 14px;
  background: #f6f8fa;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.d-attachments-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}

.d-attachments .attach-chip {
  text-decoration: none;
  color: var(--primary);
  background: #e8f0fe;
  border-radius: 12px;
  padding: 4px 12px;
  font-size: 12px;
  display: inline-block;
}

.d-attachments .attach-chip:hover {
  background: #c7d9fc;
}

/* --- 添付ファイル --- */
.attach-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--muted);
  background: #fff;
  white-space: nowrap;
}

.attach-label:hover {
  background: var(--bg);
  color: var(--text);
}

.attach-label input[type="file"] {
  display: none;
}

.attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  padding: 0 2px;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #e8f0fe;
  border-radius: 12px;
  padding: 2px 10px 2px 8px;
  font-size: 12px;
  color: #1e3a6e;
}

.attach-chip button {
  background: none;
  border: none;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  color: #666;
  line-height: 1;
}

.attach-chip button:hover {
  color: #d73a49;
}

/* --- アプリ内のみ削除ボタン --- */
.btn-local-del {
  border: 1px dashed #aaa;
  color: var(--muted);
  background: transparent;
}

.btn-local-del:hover {
  border-color: #d73a49;
  color: #d73a49;
  background: #fff5f5;
}

/* --- フォルダ並べ替えボタン --- */
.folder-move-btns {
  display: flex;
  gap: 2px;
  margin-right: 4px;
}

.folder-move-btns button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1.4;
}

.folder-move-btns button:hover {
  background: var(--bg);
  color: var(--text);
}

.folder-move-btns button:disabled {
  opacity: 0.3;
  cursor: default;
}
