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

:root {
  --bg: #f5f7fb;
  --sidebar: #eef2f8;
  --panel: #ffffff;
  --panel-soft: #f7f9fd;
  --line: #d9e1ef;
  --text: #1f2a3d;
  --muted: #5f6f86;
  --accent: #7ea9e1;
  --accent-2: #5e8fcf;
  --danger: #c35a5a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 0% 0%, #e8f0ff, transparent 42%), var(--bg);
  color: var(--text);
  font-family: 'Noto Sans JP', sans-serif;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
  align-items: start;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  padding: 18px 14px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow: auto;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
}

.brand p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.menu {
  display: grid;
  gap: 6px;
  align-content: start;
  grid-auto-rows: min-content;
}

.menu-item {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
  border-radius: 10px;
  padding: 11px 10px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.12s, border-color 0.12s;
  box-shadow: none;
}

.menu-item:hover {
  background: #dde6f5;
  border-color: #c8d9f0;
}

.menu-item:active {
  background: #cdd8ee;
}

.menu-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.menu-item.active {
  background: linear-gradient(135deg, #dfe9fb, #e9f1ff);
  border-color: #bdd0ee;
  font-weight: 600;
}

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #eef3fb;
  border-radius: 12px;
  margin-bottom: 10px;
}

.user-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid #c8d9f0;
}

.user-info {
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 700;
  color: #1a2a4a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  font-size: 11px;
  color: #6a7ea8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.gmail-badge {
  font-size: 10px;
  margin-top: 3px;
  font-weight: 600;
}

.gmail-badge.connected {
  color: #2a7a4a;
}

.gmail-badge.disconnected {
  color: #9a5a00;
}

.logout-link {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  color: #8a9ab8;
  text-decoration: none;
  text-align: center;
  padding: 4px;
  border-radius: 6px;
  transition: background 0.12s, color 0.12s;
}

.logout-link:hover {
  background: #f0f4fb;
  color: #c0392b;
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.workspace-head {
  border-bottom: 1px solid var(--line);
  padding: 16px 24px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
}

.workspace-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.view {
  display: none;
  padding: 20px;
  min-width: 0;
}

.view.active {
  display: block;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  padding: 16px;
}

.panel h3 {
  margin: 0 0 12px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  align-items: end;
}

.inline-actions {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 240px repeat(2, minmax(160px, 220px));
  gap: 10px;
  align-items: end;
}

.status-tabs {
  margin: 6px 0 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-tab.active {
  background: #c8dcf8;
  color: #1e3f74;
  box-shadow: 0 0 0 1px #a7c6f0 inset;
}

label {
  display: grid;
  gap: 5px;
  font-size: 13px;
  color: var(--muted);
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
  padding: 10px;
}

button {
  border: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 2px 6px rgba(100, 150, 220, 0.30);
  transition: filter 0.15s, box-shadow 0.15s, transform 0.1s;
  user-select: none;
}

button:hover {
  filter: brightness(1.08);
  box-shadow: 0 4px 12px rgba(100, 150, 220, 0.45);
  transform: translateY(-1px);
}

button:active {
  filter: brightness(0.94);
  box-shadow: 0 1px 3px rgba(100, 150, 220, 0.25);
  transform: translateY(0);
}

button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
  transform: none;
  box-shadow: none;
}

button.ghost {
  background: #dbe7f8;
  color: #2c405f;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

button.ghost:hover {
  background: #ccddf5;
  box-shadow: 0 3px 8px rgba(0,0,0,0.13);
}

.chat-surface {
  min-height: 72vh;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #f8fbff, #f1f6ff);
  padding: 14px;
  overflow: auto;
  display: grid;
  gap: 10px;
}

.chat-item {
  max-width: 80%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.45;
}

.chat-item.system {
  background: #e9f0fb;
  justify-self: start;
}

.chat-item.user {
  background: #d9e8ff;
  justify-self: end;
}

.table-wrap {
  overflow: auto;
  border: 1px solid #cfdbee;
  border-radius: 14px;
  background: #ffffff;
  box-shadow: inset 0 1px 0 #f8fbff;
  max-width: 100%;
}

#view-leads #filter-form {
  margin-bottom: 14px;
}

.export-tools {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

#export-result {
  margin: 0;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 980px;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid #e6edf8;
  padding: 10px 11px;
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

#lead-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: linear-gradient(180deg, #f4f8ff, #edf4ff);
  color: #334766;
  font-weight: 700;
}

#lead-table thead th.sortable {
  cursor: pointer;
  user-select: none;
}

#lead-table thead th.sortable:hover {
  background: linear-gradient(180deg, #eaf3ff, #e3eeff);
}

#lead-table .sort-indicator {
  display: inline-block;
  margin-left: 6px;
  width: 12px;
  color: #8ba0c2;
}

#lead-table thead th.sorted-asc .sort-indicator::before {
  content: "▲";
  font-size: 10px;
  color: #2f5fa7;
}

#lead-table thead th.sorted-desc .sort-indicator::before {
  content: "▼";
  font-size: 10px;
  color: #2f5fa7;
}

#lead-table tbody tr:nth-child(even) {
  background: #fbfdff;
}

#lead-table tbody tr:hover {
  background: #eef5ff;
}

#lead-table a {
  color: #2e5fa8;
  text-decoration: none;
  font-weight: 600;
}

#lead-table a:hover {
  text-decoration: underline;
}

#lead-table th:nth-child(1),
#lead-table td:nth-child(1) {
  width: 42px;
  text-align: center;
}

#lead-table th:nth-child(2),
#lead-table td:nth-child(2) {
  width: 220px;
}

#lead-table th:nth-child(3),
#lead-table td:nth-child(3) {
  width: 170px;
}

#lead-table th:nth-child(4),
#lead-table td:nth-child(4),
#lead-table th:nth-child(5),
#lead-table td:nth-child(5) {
  width: 92px;
}

#lead-table th:nth-child(6),
#lead-table td:nth-child(6),
#lead-table th:nth-child(7),
#lead-table td:nth-child(7) {
  width: 86px;
}

#lead-table th:nth-child(8),
#lead-table td:nth-child(8) {
  width: 170px;
}

#lead-table th:nth-child(9),
#lead-table td:nth-child(9) {
  width: 130px;
}

#lead-table th:nth-child(10),
#lead-table td:nth-child(10) {
  width: 160px;
}

#my-list-table th:nth-child(1),
#my-list-table td:nth-child(1) {
  width: 36px;
}

#my-list-table th:nth-child(2),
#my-list-table td:nth-child(2) {
  width: 160px;
}

#my-list-table th:nth-child(3),
#my-list-table td:nth-child(3),
#my-list-table th:nth-child(4),
#my-list-table td:nth-child(4),
#my-list-table th:nth-child(5),
#my-list-table td:nth-child(5),
#my-list-table th:nth-child(6),
#my-list-table td:nth-child(6) {
  width: 90px;
}

#my-list-table th:nth-child(7),
#my-list-table td:nth-child(7),
#my-list-table th:nth-child(8),
#my-list-table td:nth-child(8) {
  width: 110px;
}

#my-list-table th:nth-child(9),
#my-list-table td:nth-child(9),
#my-list-table th:nth-child(10),
#my-list-table td:nth-child(10) {
  width: 160px;
}

#history-table th:nth-child(1),
#history-table td:nth-child(1) {
  width: 170px;
}

#history-table th:nth-child(2),
#history-table td:nth-child(2) {
  width: 160px;
}

#history-table th:nth-child(3),
#history-table td:nth-child(3),
#history-table th:nth-child(4),
#history-table td:nth-child(4) {
  width: 120px;
}

#history-table th:nth-child(5),
#history-table td:nth-child(5) {
  width: 90px;
}

#history-table th:nth-child(6),
#history-table td:nth-child(6) {
  width: 210px;
}

#history-table th:nth-child(7),
#history-table td:nth-child(7) {
  width: 210px;
}

#history-table th:nth-child(8),
#history-table td:nth-child(8) {
  width: 96px;
}

mark {
  background: #ffe89a;
  color: #2a2a2a;
  padding: 0 1px;
  border-radius: 3px;
}

.show-timeline-btn {
  min-width: 72px;
  padding: 6px 8px;
  font-size: 11px;
}

#history-timeline {
  margin-top: 12px;
  max-height: 260px;
}

th {
  background: #eef3fb;
}

.simple-list {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
  max-height: 300px;
  overflow: auto;
}

.simple-list .row {
  padding: 10px;
  border-bottom: 1px solid #e2e8f4;
  font-size: 12px;
}

.simple-list .row:last-child {
  border-bottom: 0;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  margin-top: 10px;
}

.field-note {
  margin: -4px 0 0;
  font-size: 12px;
  color: #8a5a00;
}

.history-presets {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.history-summary {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.summary-total {
  font-size: 12px;
  color: #3d516f;
  font-weight: 700;
}

.summary-badge {
  border-radius: 999px;
  background: #e6eefc;
  color: #2a4572;
  padding: 2px 8px;
  font-size: 11px;
}

.summary-badge.channel {
  background: #e8f6ef;
  color: #22613e;
}

.status-badge,
.priority-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
}

.status-new {
  background: #e6eefc;
  color: #23467f;
}

.status-contacted {
  background: #e2f7ec;
  color: #1d6b41;
}

.status-nurturing {
  background: #fff4df;
  color: #8a5a00;
}

.status-closed {
  background: #e6e7eb;
  color: #3f4755;
}

.status-excluded {
  background: #fde6e6;
  color: #8a2f2f;
}

.priority-high {
  background: #fde4e4;
  color: #9e2525;
}

.priority-medium {
  background: #fff0d6;
  color: #8a5a00;
}

.priority-low {
  background: #e6f4ec;
  color: #21613f;
}

.timeline-row {
  display: grid;
  gap: 6px;
}

.timeline-message summary {
  cursor: pointer;
  color: #4a5f80;
}

.timeline-message pre {
  margin: 6px 0 0;
  padding: 10px;
  border-radius: 8px;
  background: #eef3fb;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 12px;
}

.timeline-message .copy-message-btn {
  margin-top: 6px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 90;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  border-radius: 10px;
  padding: 10px 12px;
  color: #ffffff;
  background: #3a4a66;
  box-shadow: 0 8px 20px rgba(30, 44, 68, 0.28);
  font-size: 12px;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  background: #27643f;
}

.toast.error {
  background: #8d2f2f;
}

.hint-box {
  background: #eef5ff;
  border: 1px solid #bdd0ee;
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.7;
}

.hint-title {
  font-weight: 700;
  color: #2c4a80;
  margin: 0 0 4px;
}

.hint-desc {
  color: #4a5f80;
  margin: 0 0 8px;
}

.hint-list {
  margin: 0 0 8px;
  padding-left: 18px;
  color: var(--text);
}

.hint-list li {
  margin-bottom: 2px;
}

.hint-list code,
.hint-example code {
  background: #d8e7fa;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
  font-family: 'Courier New', monospace;
  color: #1a3a6e;
}

.hint-example {
  color: var(--muted);
  margin: 0;
  font-size: 12px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    position: static;
    height: auto;
  }

  table {
    min-width: 720px;
  }

  .inline-actions {
    grid-template-columns: 1fr;
  }
}
