:root {
  --navy: #12366b;
  --navy-deep: #0b274f;
  --navy-soft: #e8eef6;
  --teal: #0f766e;
  --teal-soft: #e6f4f2;
  --bg: #eef2f6;
  --white: #fff;
  --ink: #1f2937;
  --muted: #5b677a;
  --line: #d7e0ea;
  --warn-bg: #fff7e8;
  --warn-ink: #8a5a00;
  --danger-bg: #fef2f2;
  --danger-ink: #991b1b;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Noto Sans JP", Meiryo, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
}
.topbar h1 {
  margin: 0;
  font-size: 18px;
  color: var(--navy);
}
.topbar .sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.badge-demo {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--navy-soft);
  color: var(--navy);
  font-size: 12px;
  font-weight: 700;
  vertical-align: middle;
}
.btn {
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--navy);
  font-weight: 700;
  padding: 8px 12px;
}
.btn:hover { border-color: var(--teal); color: var(--teal); }
.btn-primary {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}
.btn-primary:hover { background: var(--navy-deep); color: #fff; }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

.shell {
  flex: 1;
  display: grid;
  grid-template-columns: 230px 1fr;
  min-height: 0;
}

.sidebar {
  background: var(--navy-deep);
  color: #fff;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.sidebar-brand small { color: rgba(255,255,255,.55); font-size: 11px; }
.sidebar-brand strong { display: block; margin-top: 4px; }
.sidebar nav { padding: 10px; flex: 1; }
.sidebar button.nav-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: rgba(255,255,255,.75);
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 700;
  margin-bottom: 2px;
}
.sidebar button.nav-item:hover,
.sidebar button.nav-item.is-on {
  background: rgba(255,255,255,.14);
  color: #fff;
}
.sidebar-foot {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.12);
  font-size: 13px;
}
.sidebar-foot span { color: rgba(255,255,255,.55); display: block; }

.main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mail-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 0;
}

.list-pane, .detail-pane, .page-pane {
  min-height: 0;
  overflow: auto;
  background: var(--white);
}
.list-pane { border-right: 1px solid var(--line); }
.list-head, .page-pane > .page-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--white);
  z-index: 1;
}
.list-head h2, .page-head h2 {
  margin: 0;
  font-size: 16px;
  color: var(--navy);
}
.list-head p, .page-head p { margin: 4px 0 0; font-size: 12px; color: var(--muted); }

.mail-row {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid #f1f5f9;
  background: transparent;
  padding: 12px 16px;
}
.mail-row:hover { background: #f8fafc; }
.mail-row.is-on { background: var(--teal-soft); }
.mail-row .from { display: flex; justify-content: space-between; gap: 8px; font-weight: 700; color: var(--navy); }
.mail-row .from time { font-weight: 500; color: var(--muted); font-size: 12px; }
.mail-row .subj { margin-top: 2px; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chips { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  font-size: 11px;
  font-weight: 700;
  border-radius: 4px;
  border: 1px solid var(--line);
  padding: 2px 6px;
  background: #fff;
  color: var(--muted);
}
.chip.high { background: #fee2e2; color: #b91c1c; border-color: #fecaca; }
.chip.medium { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.chip.low { background: #f1f5f9; color: #475569; }

.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100%;
}
.workspace > section {
  padding: 18px;
  min-width: 0;
}
.workspace > section + section {
  background: #f8fafc;
  border-left: 1px solid var(--line);
}
.workspace h3 {
  margin: 0 0 10px;
  color: var(--navy);
  font-size: 15px;
}
.meta { color: var(--muted); font-size: 13px; margin: 0 0 4px; }
.mail-body {
  margin-top: 12px;
  white-space: pre-wrap;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  font-size: 14px;
}
.ja-gloss {
  border: 1px solid #cfe8e3;
  background: #eef6f4;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
}
.ja-gloss-label {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  color: var(--teal);
}
.ja-gloss-body {
  margin: 0;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink);
  font-family: inherit;
}
.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 14px;
  margin-bottom: 12px;
}
.card ul { margin: 6px 0 0; padding-left: 1.2em; }
.alert-danger {
  background: var(--danger-bg);
  color: var(--danger-ink);
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 12px 14px;
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 12px;
}
.alert-info {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 10px;
}
.loading-bar {
  background: var(--teal-soft);
  color: var(--teal);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
}
.intent-note { font-size: 12px; font-weight: 700; color: var(--teal); }
.field { display: block; margin-bottom: 10px; font-size: 13px; font-weight: 700; color: var(--muted); }
.field input, .field textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 500;
  color: var(--ink);
}
.field textarea { min-height: 200px; resize: vertical; line-height: 1.6; }
#aiPrompt { min-height: 280px; font-size: 13px; line-height: 1.65; }
.prompt-preview {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
  padding: 8px 12px;
}
.prompt-preview summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: var(--navy);
}
.prompt-preview-body {
  margin: 10px 0 0;
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
  font-family: inherit;
  max-height: 180px;
  overflow: auto;
}
.reply-draft {
  margin: 12px 0 14px;
  padding: 14px 14px 16px;
  border-radius: 12px;
  border: 2px solid var(--navy);
  background: linear-gradient(180deg, #f3f7fc 0%, #fff 28%);
  box-shadow: 0 0 0 4px rgba(18, 54, 107, 0.08);
}
.reply-draft-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-bottom: 12px;
}
.reply-draft-badge {
  display: inline-block;
  padding: 5px 12px;
  border-radius: 6px;
  background: var(--navy);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
.reply-draft-sub {
  font-size: 12px;
  font-weight: 700;
  color: var(--navy);
}
.reply-draft-field { color: var(--navy); }
.reply-draft-field input,
.reply-draft-field textarea {
  border-color: #9bb0cc;
  background: #fff;
  font-size: 15px;
  font-weight: 600;
}
.reply-draft-field textarea {
  min-height: 220px;
  line-height: 1.7;
}
.reply-draft-field input:focus,
.reply-draft-field textarea:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(18, 54, 107, 0.15);
}
.intent-wrap { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.intent-wrap button {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--navy);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
}
.intent-wrap button:hover:not(:disabled) { border-color: var(--teal); color: var(--teal); }
.intent-wrap button:disabled {
  opacity: 0.45;
  cursor: default;
}
.intent-wrap button[data-action="reset-default"] {
  border-color: var(--navy);
  background: var(--navy-soft);
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

.page-body { padding: 20px; max-width: 860px; }
.page-body .card h3 { margin-bottom: 6px; }
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid rgba(15,118,110,.25);
  background: var(--teal-soft);
  font-weight: 700;
  color: var(--navy);
}
.scenario-btn {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.scenario-btn:hover { border-color: var(--teal); background: var(--teal-soft); }
.scenario-btn strong { display: block; color: var(--navy); }
.scenario-btn span { color: var(--muted); font-size: 13px; }

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 40;
}
.modal {
  width: min(520px, 100%);
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,.2);
}
.modal h3 { margin: 0 0 10px; color: var(--navy); }
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  background: var(--navy);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 13px;
}

.empty { padding: 24px; color: var(--muted); font-size: 14px; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .workspace > section + section { border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mail-layout { grid-template-columns: 1fr; }
  .mobile-nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 8px 12px;
    background: var(--navy-deep);
  }
  .mobile-nav button {
    flex: 0 0 auto;
    border: 0;
    border-radius: 999px;
    padding: 8px 12px;
    background: rgba(255,255,255,.12);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
  }
  .mobile-nav button.is-on { background: #fff; color: var(--navy); }
}
@media (min-width: 861px) {
  .mobile-nav { display: none; }
}
