/* 姊妹淘中台 — Dashboard 風格（參考雷蒙三十） */

:root {
  --bg: #f8fafb;
  --fg: #1a1a2e;
  --muted: #6b7280;
  --muted-light: #9ca3af;
  --primary: #0f172a;
  --accent: #0d9488;
  --accent-light: #ccfbf1;
  --accent-dark: #065f46;
  --warn: #f59e0b;
  --warn-bg: #fffbeb;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --success: #10b981;
  --success-bg: #ecfdf5;
  --border: #e5e7eb;
  --card: #ffffff;
  --sidebar-bg: #ffffff;
  --sidebar-active: #f0fdfa;
  --sans: system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Menlo", monospace;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.03);
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
}
body { min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); }

/* ============================================================
   Layout：左側欄 + 主內容區
   ============================================================ */

.app-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

/* 側邊欄 */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.sidebar-brand h1 {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  color: var(--primary);
}
.sidebar-brand .sub {
  font-size: 11px;
  color: var(--muted-light);
  margin-top: 2px;
}
.sidebar-section {
  padding: 12px 16px 4px;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted-light);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.sidebar-nav {
  list-style: none;
  margin: 0;
  padding: 0;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  font-size: 13px;
  color: var(--muted);
  transition: all 0.1s;
  border-left: 3px solid transparent;
}
.sidebar-nav a:hover {
  background: var(--sidebar-active);
  color: var(--accent-dark);
}
.sidebar-nav a.active {
  background: var(--sidebar-active);
  color: var(--accent);
  border-left-color: var(--accent);
  font-weight: 600;
}
.sidebar-nav .icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}
.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted-light);
}

/* 主內容區 */
.main-content {
  padding: 24px 32px;
  max-width: 1200px;
  overflow-y: auto;   /* 內容超過時自己捲，不撐爆 sidebar grid */
  min-width: 0;       /* 防 grid 子元素 overflow */
}
.page-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--primary);
}
.page-subtitle {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 24px;
}

/* ============================================================
   統計卡片
   ============================================================ */

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.stat-card .label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}
.stat-card .value.accent { color: var(--accent); }
.stat-card .value.warn { color: var(--warn); }
.stat-card .value.danger { color: var(--danger); }
.stat-card .change {
  font-size: 12px;
  margin-top: 4px;
}
.stat-card .change.up { color: var(--success); }
.stat-card .change.down { color: var(--danger); }

/* ============================================================
   通用卡片
   ============================================================ */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-body {
  padding: 16px 20px;
}

/* ============================================================
   功能入口格 (Dashboard)
   ============================================================ */

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.feature-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
  transition: border 0.15s, box-shadow 0.15s, transform 0.05s;
  display: block;
  color: var(--fg);
}
.feature-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  color: var(--fg);
}
.feature-card .icon {
  font-size: 24px;
  margin-bottom: 12px;
}
.feature-card h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 6px;
}
.feature-card p {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}
.feature-card .tag {
  display: inline-block;
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-top: 10px;
  background: var(--accent-light);
  color: var(--accent-dark);
  font-weight: 600;
}
.feature-card .tag.pending {
  background: #f3f4f6;
  color: var(--muted);
}

/* ============================================================
   對話區（press-release 等頁面用）
   ============================================================ */

.app-main {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 16px;
  height: calc(100vh - 48px);  /* 扣掉上方 padding */
  min-height: 500px;
}


.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-shadow: var(--shadow-sm);
}
.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
}
.stepper-panel {
  overflow-y: auto;
}

/* 對話泡泡 */
.chat-interface {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 500px;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

.msg { margin-bottom: 12px; display: flex; }
.msg-user { justify-content: flex-end; }
.msg-bot, .msg-error { justify-content: flex-start; }
.msg-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 12px;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.7;
}
.msg-user .msg-bubble {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}
.msg-bot .msg-bubble {
  background: #f3f4f6;
  color: var(--fg);
  border-bottom-left-radius: 4px;
  white-space: normal;
}
.msg-bot .msg-bubble h1,
.msg-bot .msg-bubble h2,
.msg-bot .msg-bubble h3 { margin: 10px 0 4px; }
.msg-bot .msg-bubble h1 { font-size: 15px; }
.msg-bot .msg-bubble h2 { font-size: 14px; color: var(--primary); }
.msg-bot .msg-bubble h3 { font-size: 13px; color: var(--accent-dark); }
.msg-bot .msg-bubble p { margin: 4px 0; }
.msg-bot .msg-bubble ul, .msg-bot .msg-bubble ol { margin: 4px 0; padding-left: 20px; }
.msg-bot .msg-bubble hr { border: none; border-top: 1px dashed var(--border); margin: 8px 0; }

.msg-error .msg-bubble { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.msg-loading .msg-bubble { color: var(--muted); font-style: italic; }

.spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 選項按鈕 */
.msg-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 12px 0;
  max-width: 90%;
}
.choice-btn {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  text-align: left;
  cursor: pointer;
  transition: border 0.1s, background 0.1s;
  font-family: inherit;
  font-size: 13px;
  color: var(--fg);
}
.choice-btn:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.choice-label { font-weight: 600; }
.choice-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.choice-other { color: var(--muted); }
.choice-other-input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
}
.choice-other-submit {
  margin-top: 6px;
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
}
.choice-other-submit:hover { background: var(--accent); }

/* 輸入區 */
.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: #fafbfc;
}
.chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 13px;
  resize: none;
  min-height: 40px;
  max-height: 160px;
  line-height: 1.5;
  background: white;
}
.chat-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.chat-send-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  min-width: 64px;
}
.chat-send-btn:hover:not(:disabled) { background: var(--accent); }
.chat-send-btn:disabled { background: #d1d5db; cursor: not-allowed; }

/* Stepper */
.stepper {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.step-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}
.step-item.active { background: var(--accent-light); }
.step-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--border);
  margin-top: 6px;
  flex-shrink: 0;
}
.step-item.active .step-dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(13,148,136,0.15); }
.step-item.done .step-dot { background: #9ca3af; }
.step-content { flex: 1; }
.step-title { font-size: 12px; font-weight: 600; }
.step-item.done .step-title { color: var(--muted-light); font-weight: 500; }
.step-item.pending .step-title { color: #d1d5db; }
.step-item.active .step-title { color: var(--accent-dark); }
.step-meta { font-size: 11px; color: var(--muted-light); margin-top: 1px; }

.stepper-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted-light);
}
.stepper-footer code {
  background: #f3f4f6;
  padding: 1px 4px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 10px;
  word-break: break-all;
}

/* Badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 10px;
  margin-right: 4px;
  background: #f3f4f6;
  color: var(--muted);
  font-weight: 500;
}
.badge-final { background: var(--success-bg); color: var(--accent-dark); }
.badge-high-diff { background: var(--warn-bg); color: #92400e; }
.badge-hot { background: #fef2f2; color: var(--danger); }

/* ============================================================
   RWD
   ============================================================ */

@media (max-width: 780px) {
  .app-layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: -260px;
    z-index: 100;
    width: 260px;
    transition: left 0.2s;
    box-shadow: var(--shadow-md);
  }
  .sidebar.open { left: 0; }
  .mobile-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
  }
  .mobile-header .menu-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    cursor: pointer;
    font-size: 16px;
  }
  .mobile-header h1 {
    font-size: 14px;
    margin: 0;
    font-weight: 600;
  }
  .main-content {
    padding: 16px;
  }
  .app-main {
    grid-template-columns: 1fr;
    height: auto;
  }
  .stepper-panel {
    order: -1;
    max-height: 120px;
  }
  .stepper {
    flex-direction: row;
    overflow-x: auto;
    gap: 6px;
    padding: 8px;
  }
  .step-item {
    flex-shrink: 0;
    padding: 6px 10px;
    flex-direction: row;
    align-items: center;
  }
  .step-meta { display: none; }
}

@media (min-width: 781px) {
  .mobile-header { display: none; }
}

/* ============================================================
   舊版相容（app-header → 隱藏，改用 sidebar）
   ============================================================ */
.app-header { display: none; }
