/* ==============================
   CW Auto — Global Styles
   ============================== */

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

:root {
  --sidebar-w: 200px;
  --color-primary: #2563eb;
  --color-accent: #7c3aed;
  --color-success: #16a34a;
  --color-warning: #ca8a04;
  --color-danger: #dc2626;
  --color-bg: #f1f5f9;
  --color-card: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-muted: #64748b;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", sans-serif;
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-bg);
  display: flex;
  min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  background: #1e293b;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar__logo {
  padding: 18px 16px 8px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  letter-spacing: .04em;
}
.sidebar__user {
  padding: 4px 16px 16px;
  font-size: 12px;
  color: #94a3b8;
  border-bottom: 1px solid #334155;
}
.sidebar ul { list-style: none; padding: 8px 0; flex: 1; }
.sidebar ul li a {
  display: block;
  padding: 10px 16px;
  color: #94a3b8;
  text-decoration: none;
  border-radius: 4px;
  margin: 1px 6px;
  transition: background .15s, color .15s;
}
.sidebar ul li a:hover { background: #334155; color: #e2e8f0; }
.sidebar ul li a.active { background: var(--color-primary); color: #fff; }
.sidebar__bottom { margin-top: auto; }

/* ---- Main Content ---- */
.content {
  margin-left: var(--sidebar-w);
  padding: 24px;
  flex: 1;
  max-width: 1200px;
}

/* ---- Login Page ---- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
}
.login-box {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 360px;
  box-shadow: var(--shadow);
}
.login-box h1 { text-align: center; margin-bottom: 4px; }
.login-box p  { text-align: center; margin-bottom: 24px; }

/* ---- Cards ---- */
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 16px; margin-bottom: 12px; }
.card h3 { font-size: 14px; margin: 16px 0 8px; color: var(--color-muted); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-card);
  color: var(--color-text);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s;
}
.btn:hover { background: var(--color-bg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--sm { padding: 4px 10px; font-size: 12px; }
.btn--full { width: 100%; justify-content: center; }
.btn--primary  { background: var(--color-primary);  color: #fff; border-color: var(--color-primary);  }
.btn--accent   { background: var(--color-accent);   color: #fff; border-color: var(--color-accent);   }
.btn--green    { background: var(--color-success);  color: #fff; border-color: var(--color-success);  }
.btn--yellow   { background: var(--color-warning);  color: #fff; border-color: var(--color-warning);  }
.btn--danger   { background: var(--color-danger);   color: #fff; border-color: var(--color-danger);   }
.btn--primary:hover  { background: #1d4ed8; }
.btn--accent:hover   { background: #6d28d9; }
.btn--green:hover    { background: #15803d; }
.btn--yellow:hover   { background: #b45309; }
.btn--danger:hover   { background: #b91c1c; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

/* ---- Forms ---- */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 12px;
  color: var(--color-muted);
  margin-bottom: 4px;
}
.form-row { display: flex; gap: 8px; align-items: center; }
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-card);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}
.inline-input {
  width: 100%;
  padding: 3px 6px;
  border: 1px solid transparent;
  border-radius: 3px;
  font-size: 13px;
  font-family: inherit;
  background: transparent;
}
.inline-input:focus {
  border-color: var(--color-primary);
  background: var(--color-card);
  outline: none;
}
.message-textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}
.toggle-switch {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.toggle-switch input[type="checkbox"] {
  width: 36px; height: 20px;
  appearance: none;
  background: #94a3b8;
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: background .2s;
}
.toggle-switch input[type="checkbox"]:checked { background: var(--color-primary); }
.toggle-switch input[type="checkbox"]::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: left .2s;
}
.toggle-switch input[type="checkbox"]:checked::after { left: 18px; }

/* ---- Tables ---- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th, .table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
}
.table th {
  background: var(--color-bg);
  font-weight: 600;
  color: var(--color-muted);
  font-size: 12px;
}
.table tr:hover td { background: #f8fafc; }
.table--info th { width: 80px; }
.text-center { text-align: center; }

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.badge--pass,    .badge--green  { background: #dcfce7; color: #166534; }
.badge--check,   .badge--yellow { background: #fef9c3; color: #854d0e; }
.badge--reject,  .badge--red    { background: #fee2e2; color: #991b1b; }
.badge--pending, .badge--gray   { background: #f1f5f9; color: #475569; }
.badge--warning                 { background: #fef3c7; color: #92400e; }
.badge--confirmed               { background: #dbeafe; color: #1e40af; }
.badge--approved                { background: #e0e7ff; color: #3730a3; }
.badge--sent                    { background: #dcfce7; color: #166534; }
.badge--draft                   { background: #f1f5f9; color: #475569; }
.badge--queued                  { background: #ede9fe; color: #5b21b6; }
.badge--none                    { background: #f1f5f9; color: #94a3b8; }
.badge--negotiating             { background: #fef9c3; color: #854d0e; }
.badge--done                    { background: #dcfce7; color: #166534; }
.badge--failed                  { background: #fee2e2; color: #991b1b; }

/* ---- Filter Tabs ---- */
.filter-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--color-border);
}
.tab {
  padding: 8px 14px;
  text-decoration: none;
  color: var(--color-muted);
  font-size: 13px;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s;
}
.tab:hover { color: var(--color-text); }
.tab--active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: 600; }

/* ---- Page Header ---- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.page-header h1 { font-size: 20px; }
.page-header__actions { display: flex; gap: 8px; }

/* ---- Stats Grid ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}
.stat-card__num   { font-size: 32px; font-weight: 700; line-height: 1; }
.stat-card__label { font-size: 12px; color: var(--color-muted); margin-top: 4px; }
.stat-card--blue   .stat-card__num { color: var(--color-primary); }
.stat-card--yellow .stat-card__num { color: var(--color-warning); }
.stat-card--orange .stat-card__num { color: #ea580c; }
.stat-card--green  .stat-card__num { color: var(--color-success); }

/* ---- Account Cards ---- */
.account-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.account-card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.account-card__name { font-weight: 600; margin-bottom: 2px; }
.account-card__email { margin-bottom: 10px; }
.account-card__links { display: flex; gap: 4px; flex-wrap: wrap; }

/* ---- Detail Grid ---- */
.detail-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  align-items: start;
}

/* ---- Message Thread ---- */
.message-thread { display: flex; flex-direction: column; gap: 10px; max-height: 400px; overflow-y: auto; padding: 4px; }
.bubble { max-width: 85%; }
.bubble--inbound  { align-self: flex-start; }
.bubble--outbound { align-self: flex-end; }
.bubble__meta {
  font-size: 11px;
  color: var(--color-muted);
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.bubble--outbound .bubble__meta { justify-content: flex-end; }
.bubble__text {
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}
.bubble--inbound  .bubble__text { background: var(--color-bg); border: 1px solid var(--color-border); border-radius: 2px 10px 10px 10px; }
.bubble--outbound .bubble__text { background: var(--color-primary); color: #fff; border-radius: 10px 2px 10px 10px; }

/* ---- Profile Text ---- */
.profile-text {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--color-text);
}

/* ---- Pagination ---- */
.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

/* ---- Flash Messages ---- */
.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 13px;
}
.flash--success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.flash--danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.flash--info    { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.flash--warning { background: #fef9c3; color: #854d0e; border: 1px solid #fde047; }

/* ---- Notification Bar ---- */
#notif-bar { min-height: 0; }
.notif {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fef3c7;
  border: 1px solid #fde047;
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: 13px;
}
.notif a { color: var(--color-primary); text-decoration: none; font-weight: 600; }
.notif__close { cursor: pointer; color: var(--color-muted); padding: 0 4px; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
  z-index: 9999;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity:0; transform: translateY(8px); } to { opacity:1; transform: translateY(0); } }

/* ---- APO Result ---- */
.apo-result { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.text-success { color: var(--color-success); }
.text-danger  { color: var(--color-danger); }

/* ---- Misc ---- */
.text-muted  { color: var(--color-muted); }
.text-small  { font-size: 12px; }
.mt-1 { margin-top: 12px; }
.mt-2 { margin-top: 20px; }
h2 { font-size: 18px; margin-bottom: 12px; }
h3 { font-size: 15px; margin-bottom: 8px; }

/* ---- Settings Page ---- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.template-list { display: flex; flex-direction: column; gap: 8px; }
.template-item {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.template-item__body { flex: 1; font-size: 13px; }
.template-item__label { font-weight: 600; margin-bottom: 2px; }
.template-item__text  { color: var(--color-muted); font-size: 12px; white-space: pre-wrap; max-height: 80px; overflow: hidden; }
.filter-rule-list { display: flex; flex-direction: column; gap: 6px; }
.filter-rule-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 6px 10px;
  background: var(--color-bg);
  border-radius: var(--radius);
}
.filter-rule-item__key { font-weight: 600; min-width: 90px; }
.filter-rule-item__val { flex: 1; color: var(--color-muted); }

/* ---- Inbox ---- */
.inbox-list { display: flex; flex-direction: column; gap: 8px; }
.inbox-item {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--color-card);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.inbox-item--unread { border-left: 3px solid var(--color-primary); }
.inbox-item__left { min-width: 120px; }
.inbox-item__name { font-weight: 600; }
.inbox-item__time { font-size: 11px; color: var(--color-muted); }
.inbox-item__preview { flex: 1; font-size: 13px; color: var(--color-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inbox-item__actions { display: flex; gap: 4px; flex-shrink: 0; }

/* ---- Send Queue ---- */
.send-queue { display: flex; flex-direction: column; gap: 8px; }
.send-item {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--color-card);
}
.send-item__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.send-item__name { font-weight: 600; }
.send-item__preview {
  font-size: 13px;
  color: var(--color-muted);
  white-space: pre-wrap;
  max-height: 80px;
  overflow: hidden;
  background: var(--color-bg);
  border-radius: 4px;
  padding: 8px;
  margin-bottom: 8px;
}

/* ---- Posts ---- */
.post-list { display: flex; flex-direction: column; gap: 8px; }
.post-item {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--color-card);
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
/* min-width:0 が無いとflexの既定(min-width:auto)で長文が縮まず、
   本文が横に伸びてボタンがカードの外へはみ出す */
.post-item__body { flex: 1; min-width: 0; overflow: hidden; }
.post-item__title { font-weight: 600; margin-bottom: 4px; }
.post-item__preview { font-size: 12px; color: var(--color-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.post-item__actions { display: flex; gap: 4px; flex-shrink: 0; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

/* ---- Appointment List ---- */
.apo-table th:first-child { width: 140px; }

/* ---- Admin ---- */
.user-list { display: flex; flex-direction: column; gap: 6px; }
.user-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.user-item__name { font-weight: 600; min-width: 120px; }
.user-item__role { min-width: 60px; }
.user-item__status { min-width: 80px; }
.user-item__actions { margin-left: auto; display: flex; gap: 4px; }

/* ---- Empty State ---- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-muted);
}
.empty-state__icon { font-size: 36px; margin-bottom: 10px; }
.empty-state__text { font-size: 15px; font-weight: 600; margin-bottom: 6px; color: var(--color-text); }
.empty-state__sub  { font-size: 13px; }
.empty-state__sub a { color: var(--color-primary); }

/* ---- Required Mark ---- */
.required-mark { color: var(--color-danger); font-size: 13px; }

/* ---- Spinner ---- */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
  margin-right: 4px;
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .detail-grid       { grid-template-columns: 1fr; }
  .settings-grid     { grid-template-columns: 1fr; }
  .stats-grid        { grid-template-columns: repeat(2, 1fr); }
  .account-cards     { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }
  .content { margin-left: 0; padding: 16px; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .filter-tabs { flex-wrap: wrap; }
  .table th, .table td { padding: 6px 8px; font-size: 12px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .inbox-item { flex-direction: column; gap: 6px; }
  .inbox-item__preview { white-space: normal; }
}

/* ─── プロフィール実績サマリー / アポ進捗 ───────────────── */
.summary-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0 8px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #eef2f7;
  color: #334155;
  font-size: 12px;
  border: 1px solid #dbe3ec;
}
.chip b { font-weight: 700; }
.chip--ok {
  background: #e7f6ec;
  color: #166534;
  border-color: #b7e3c5;
}

/* ---- Tab count badges ---- */
.tab-count {
  display: inline-block;
  background: var(--color-muted);
  color: #fff;
  border-radius: 999px;
  font-size: 10px;
  padding: 0 5px;
  line-height: 16px;
  vertical-align: middle;
}
.tab--active .tab-count { background: var(--color-primary); }

/* ---- Extra button styles ---- */
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--color-bg); }
.btn--active { box-shadow: 0 0 0 2px rgba(0,0,0,.2) inset; filter: brightness(.9); }

/* ---- Extra badge colors ---- */
.badge--orange { background: #fed7aa; color: #9a3412; }

/* ---- Clickable table rows ---- */
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: #eef4ff; }

/* ---- Filter reason ellipsis ---- */
.reason-ellipsis {
  display: inline-block;
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
}

/* AI補正のインラインエラー表示 */
.inline-error {
  display: none;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 4px;
  background: #fdeaea;
  color: #b42318;
  border: 1px solid #f3c2bd;
  font-size: 12px;
  white-space: pre-wrap;
}
.inline-error.show { display: block; }

/* 予約投稿の行（ボタン群と別の行にして、はみ出し・段崩れを防ぐ） */
.post-item-wrap {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-card);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.post-item-wrap .post-item { border: none; border-radius: 0; box-shadow: none; margin: 0; }
.post-item__schedule {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px; border-top: 1px dashed var(--color-border);
  background: #f8fafc; font-size: 12px;
}

/* 本文の装飾ツールバー（大きく・太字・赤色） */
.deco-bar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 6px 8px; border: 1px solid var(--color-border); border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0; background: #f8fafc;
}

/* 本文の見たまま編集エリア（装飾がそのまま見える） */
.rich-editor {
  min-height: 300px; padding: 10px 12px;
  border: 1px solid var(--color-border); border-radius: 0 0 var(--radius) var(--radius);
  background: var(--color-card); font-size: 13px; line-height: 1.7;
  overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}
.rich-editor:focus { outline: none; border-color: var(--color-primary); }
.rich-editor .deco-big { font-size: 1.3em; }
.rich-editor .deco-red { color: #dc2626; }
