@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Noto+Sans+JP:wght@300;400;500;600;700&display=swap');

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

:root {
  --bg: #0a0d14;
  --bg-2: #0f131c;
  --bg-3: #151b26;
  --line: #1f2634;
  --line-2: #2c3446;
  --text: #f3f4f2;
  --text-dim: #a5abb6;
  --text-mute: #6a7180;
  --gold: #c9a35a;
  --gold-bright: #e3c583;
  --gold-soft: rgba(201, 163, 90, 0.12);
  --navy: #16203a;
  --danger: #e0665e;
  --ok: #7ee0a0;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Noto Sans JP', 'Inter', system-ui, sans-serif;
  height: 100%;
}
body { min-height: 100vh; }

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--text); }

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

/* SIDEBAR */
.sidebar {
  width: 240px; flex-shrink: 0; background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 28px 20px;
}
.brand-mark { font-family: 'Inter', sans-serif; font-weight: 800; font-size: 22px; letter-spacing: 0.02em; }
.brand-mark .dot { color: var(--gold); }
.brand-sub { font-size: 12px; color: var(--text-mute); margin-top: 4px; letter-spacing: 0.08em; }
.side-nav { display: flex; flex-direction: column; gap: 4px; margin-top: 40px; flex: 1; }
.side-item {
  text-align: left; background: none; border: none; color: var(--text-dim);
  padding: 12px 14px; border-radius: 8px; font-size: 14px; transition: all .2s;
}
.side-item:hover { background: var(--bg-3); color: var(--text); }
.side-item.active { background: var(--gold-soft); color: var(--gold-bright); font-weight: 600; }
.side-footer { border-top: 1px solid var(--line); padding-top: 18px; margin-top: 18px; }
.from-badge { font-size: 11px; color: var(--text-mute); letter-spacing: 0.1em; margin-bottom: 6px; }
.from-address { font-size: 13px; color: var(--gold-bright); font-family: 'Inter', sans-serif; }

/* MAIN */
.main { flex: 1; padding: 36px 44px; overflow-y: auto; }
.view { display: none; }
.view.active { display: block; }
.view-header { margin-bottom: 28px; }
.view-header h1 { font-size: 24px; font-weight: 700; }
.view-header .sub { font-size: 13.5px; color: var(--text-dim); margin-top: 6px; }

.compose-grid { display: grid; grid-template-columns: 1.2fr 0.9fr; gap: 24px; align-items: start; }
@media (max-width: 1100px) { .compose-grid { grid-template-columns: 1fr; } }

/* Wizard (mobile-first step flow) */
.wizard-steps { display: flex; gap: 8px; margin-top: 16px; }
.wizard-step {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 8px; border-radius: 8px; background: var(--bg-2); border: 1px solid var(--line);
  color: var(--text-mute); font-size: 13px; font-weight: 600;
}
.wizard-step .wn {
  width: 20px; height: 20px; border-radius: 50%; background: var(--line-2); color: var(--text-dim);
  display: flex; align-items: center; justify-content: center; font-size: 11px; flex-shrink: 0;
}
.wizard-step.active { background: var(--gold-soft); border-color: var(--gold); color: var(--gold-bright); }
.wizard-step.active .wn { background: var(--gold); color: #0a0d14; }
.wizard-step.done { color: var(--ok); }
.wizard-step.done .wn { background: var(--ok); color: #0a0d14; }

.wizard-pane { display: none; }
.wizard-pane.active { display: block; }
.wizard-nav-row { display: flex; gap: 10px; margin-top: 4px; }
.wizard-nav-row .wizard-back { flex: 0 0 auto; }
.wizard-nav-row .wizard-next { flex: 1; }
.btn-large { font-size: 15px !important; padding: 16px 20px !important; min-height: 54px !important; }

.search-input {
  width: 100%; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 10px 14px; font-size: 14px; margin-bottom: 12px; color: var(--text);
}
.search-input:focus { outline: none; border-color: var(--gold); }

.step-count-badge {
  margin-left: auto; background: var(--gold-soft); color: var(--gold-bright);
  border-radius: 100px; padding: 2px 10px; font-size: 11px;
}

.card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 22px 24px; margin-bottom: 20px;
}
.card-title { font-size: 13px; font-weight: 700; color: var(--gold-bright); letter-spacing: 0.08em; margin-bottom: 16px; text-transform: uppercase; }

.filter-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.filter-row select {
  background: var(--bg-3); border: 1px solid var(--line-2); color: var(--text);
  padding: 8px 12px; border-radius: 6px; font-size: 13px;
}
.recipient-count { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }
.recipient-count span { color: var(--gold-bright); font-weight: 700; }
.recipient-list {
  max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg-3);
}
.recipient-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; font-size: 13px;
  border-bottom: 1px solid var(--line);
}
.recipient-row:last-child { border-bottom: none; }
.recipient-row .name { font-weight: 600; min-width: 100px; }
.recipient-row .company { color: var(--text-dim); flex: 1; }
.recipient-row .email { color: var(--text-mute); font-size: 12px; font-family: 'Inter', sans-serif; }
.recipient-row .tag {
  font-size: 10.5px; color: var(--gold-bright); border: 1px solid var(--line-2);
  border-radius: 100px; padding: 2px 8px;
}

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 8px;
  padding: 10px 14px; font-size: 14px; resize: vertical;
}
.field input:focus, .field textarea:focus { outline: none; border-color: var(--gold); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 8px; padding: 10px 18px; font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent; transition: all .2s;
}
.btn-primary { background: linear-gradient(120deg, var(--gold-bright), var(--gold)); color: #0a0d14; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--bg-3); border: 1px solid var(--gold); color: var(--gold-bright); }
.btn-secondary:hover { background: var(--gold-soft); }
.btn-ghost { background: none; border: 1px solid var(--line-2); color: var(--text-dim); }
.btn-ghost:hover { border-color: var(--gold); color: var(--gold-bright); }
.btn-block { width: 100%; margin-top: 10px; }

.preview-card { position: sticky; top: 0; }
.mail-preview { background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.mp-row { display: flex; padding: 8px 14px; font-size: 12.5px; border-bottom: 1px solid var(--line); }
.mp-label { width: 60px; color: var(--text-mute); flex-shrink: 0; }
.mp-body { padding: 18px 16px; font-size: 13.5px; line-height: 1.9; color: var(--text); white-space: pre-wrap; min-height: 160px; }
.mp-body .placeholder { color: var(--text-mute); }

.send-summary { font-size: 14px; margin-bottom: 6px; }
.send-summary strong { color: var(--gold-bright); font-size: 18px; }
.send-note { font-size: 12.5px; color: var(--text-mute); margin-top: 12px; line-height: 1.7; }
.send-note.ok { color: var(--ok); }
.send-note.warn { color: var(--gold-bright); }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; color: var(--text-mute); font-weight: 600; font-size: 11.5px;
  letter-spacing: 0.06em; padding: 10px 12px; border-bottom: 1px solid var(--line-2);
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.data-table tr:hover td { background: var(--bg-3); }

/* ============ MOBILE / RESPONSIVE ============ */

/* Hamburger toggle button (hidden on desktop) */
.mobile-topbar { display: none; }

@media (max-width: 860px) {
  html, body { font-size: 17px; }

  .app { flex-direction: column; }

  /* Mobile top bar with hamburger */
  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--bg-2); border-bottom: 1px solid var(--line);
    padding: 16px 18px; position: sticky; top: 0; z-index: 50;
  }
  .mobile-topbar .brand-mark { font-size: 20px; }
  .mobile-menu-btn {
    background: none; border: 1px solid var(--line-2); color: var(--text);
    border-radius: 8px; padding: 10px 16px; font-size: 22px; line-height: 1;
    min-width: 48px; min-height: 48px;
  }

  /* Sidebar becomes an off-canvas drawer */
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100%; width: 82vw; max-width: 320px;
    transform: translateX(-100%); transition: transform .25s ease; z-index: 100;
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 90;
  }
  .sidebar-overlay.open { display: block; }

  .side-item {
    font-size: 17px; padding: 16px 16px; min-height: 52px;
  }

  .main { padding: 20px 16px 100px; }
  .view-header { margin-bottom: 22px; }
  .view-header h1 { font-size: 22px; line-height: 1.4; }
  .view-header .sub { font-size: 14.5px; line-height: 1.6; margin-top: 8px; }

  /* Compose grid stacks fully */
  .compose-grid { grid-template-columns: 1fr; gap: 18px; }
  .preview-card { position: static; }

  .card { padding: 18px 16px; margin-bottom: 16px; border-radius: 14px; }
  .card-title { font-size: 14px; margin-bottom: 14px; }

  .filter-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .filter-row select, .filter-row button {
    width: 100%; font-size: 16px; padding: 14px 14px; min-height: 50px;
  }

  .recipient-count { font-size: 15px; margin-bottom: 12px; }

  .recipient-list { max-height: 320px; }
  .recipient-row {
    flex-wrap: wrap; row-gap: 6px; padding: 14px 12px; font-size: 15px;
    align-items: flex-start;
  }
  .recipient-row input[type=checkbox] {
    width: 24px; height: 24px; flex-shrink: 0; margin-top: 2px; accent-color: var(--gold);
  }
  .recipient-row .name { min-width: 0; width: auto; font-size: 16px; }
  .recipient-row .company { width: 100%; font-size: 13.5px; order: 3; }
  .recipient-row .tag { font-size: 12px; padding: 3px 10px; }
  .recipient-row .email { width: 100%; font-size: 12.5px; order: 4; word-break: break-all; }

  .field { margin-bottom: 20px; }
  .field label { font-size: 14px; margin-bottom: 8px; }
  .field input, .field textarea, .field select {
    font-size: 16px; padding: 14px 14px; min-height: 50px;
  } /* avoid iOS zoom-in on focus */
  .field textarea { min-height: 80px; }

  .btn { width: 100%; font-size: 16px; padding: 15px 18px; min-height: 52px; }
  .btn-block { width: 100%; }
  .filter-row .btn { width: 100%; flex: none; }

  .mail-preview { font-size: 14px; }
  .mp-row { padding: 10px 14px; font-size: 13.5px; }
  .mp-body { padding: 16px 14px; font-size: 14.5px; }

  .send-summary { font-size: 16px; }
  .send-summary strong { font-size: 20px; }
  .send-note { font-size: 13.5px; }

  /* Tables become horizontally scrollable cards */
  .data-table { display: block; width: 100%; overflow-x: auto; white-space: nowrap; }
  .data-table thead { display: none; }
  .data-table tbody { display: block; }
  .data-table tr {
    display: block; border: 1px solid var(--line); border-radius: 10px;
    margin-bottom: 12px; padding: 12px 14px; white-space: normal;
  }
  .data-table td {
    display: flex; justify-content: space-between; gap: 12px;
    border-bottom: 1px solid var(--line); padding: 8px 0; font-size: 14px;
  }
  .data-table td:last-child { border-bottom: none; }
  .data-table td::before {
    content: attr(data-label); color: var(--text-mute); font-size: 12px; flex-shrink: 0;
  }

  input[type="file"] {
    font-size: 14px; padding: 10px !important; width: 100%;
  }

  .wizard-steps { margin-top: 14px; gap: 6px; }
  .wizard-step { font-size: 12px; padding: 10px 4px; flex-direction: column; gap: 4px; }
  .wizard-step .wn { width: 22px; height: 22px; font-size: 12px; }

  .wizard-nav-row { flex-direction: column-reverse; }
  .wizard-nav-row .btn { width: 100%; }

  .recipient-list { max-height: 45vh; }
}

@media (max-width: 420px) {
  .main { padding: 16px 12px 100px; }
  .card { padding: 16px 12px; }
  .view-header h1 { font-size: 20px; }
}
