:root {
  --sidebar-w: 240px;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-hover: #1e293b;
  --sidebar-active-bg: rgba(37,99,235,0.15);
  --sidebar-active-text: #60a5fa;
  --sidebar-border: #1e293b;
}

* { box-sizing: border-box; }
body {
  font-family: 'Microsoft JhengHei', 'Noto Sans TC', 'Segoe UI', sans-serif;
  background: #f1f5f9;
  min-height: 100vh;
  margin: 0;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0;
  z-index: 200;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: 1.25rem 1.25rem 1.1rem;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.brand-icon {
  width: 38px; height: 38px;
  background: var(--primary);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.1rem; flex-shrink: 0;
}
.brand-name { font-size: 1.05rem; font-weight: 700; color: #f1f5f9; }
.brand-sub  { font-size: .7rem; color: #475569; }
.sidebar-nav { flex: 1; padding: .75rem 0; }
.nav-section {
  padding: .5rem 1.25rem .2rem;
  font-size: .68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em;
  color: #334155;
}
.sidebar-nav a {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem 1.25rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: .875rem;
  transition: all .15s;
  border-left: 3px solid transparent;
}
.sidebar-nav a:hover { background: var(--sidebar-hover); color: #cbd5e1; }
.sidebar-nav a.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  border-left-color: var(--primary);
}
.sidebar-nav a .ni { width: 18px; text-align: center; font-size: .9rem; flex-shrink: 0; }
.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.user-row {
  display: flex; align-items: center; gap: .6rem;
  margin-bottom: .6rem;
}
.user-av {
  width: 34px; height: 34px;
  background: var(--primary); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: .85rem; font-weight: 700; flex-shrink: 0;
}
.user-name { font-size: .82rem; font-weight: 600; color: #e2e8f0; }
.user-role { font-size: .7rem; color: #475569; }

/* ── Main ── */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
  width: calc(100% - var(--sidebar-w));
}
.page-header {
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  padding: 1rem 1.75rem;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
  flex-wrap: wrap;
  gap: .5rem;
}
.page-header h1 { font-size: 1.2rem; font-weight: 700; color: #1e293b; margin: 0; }
.page-body {
  padding: 1.5rem 1.75rem;
  flex: 1;
  width: 100%;
  max-width: 100%;
}
@media (min-width: 1400px) {
  .page-body { padding: 1.75rem 2.25rem; }
}
@media (min-width: 1920px) {
  .page-body { padding: 2rem 3rem; }
}

/* ── Cards ── */
.card { border: 1px solid #e2e8f0; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.card + .card { margin-top: 1.25rem; }
.card-header {
  background: #fff; border-bottom: 1px solid #e2e8f0;
  padding: .9rem 1.25rem; font-weight: 600; color: #1e293b;
  border-radius: 12px 12px 0 0 !important;
}
.card-body { padding: 1.25rem; }
@media (min-width: 1400px) { .card-body { padding: 1.5rem; } }
.stat-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px;
  padding: 1.25rem; display: flex; align-items: center; gap: 1rem;
  transition: box-shadow .2s;
}
.stat-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.07); }
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem; flex-shrink: 0;
}
.stat-val { font-size: 1.75rem; font-weight: 800; color: #1e293b; line-height: 1; }
.stat-lbl { font-size: .8rem; color: #64748b; margin-top: .15rem; }

/* ── Table ── */
.table th {
  background: #f8fafc; font-weight: 600; font-size: .775rem;
  text-transform: uppercase; letter-spacing: .04em;
  color: #64748b; white-space: nowrap;
  padding: .75rem 1rem;
}
.table td { vertical-align: middle; font-size: .875rem; padding: .7rem 1rem; }
.table-sm th, .table-sm td { padding: .5rem .75rem; }
.table-hover tbody tr:hover { background: #f8fafc; }
.table-responsive { width: 100%; }

/* ── Status badges ── */
.s-badge {
  display: inline-block; padding: .2rem .65rem;
  border-radius: 20px; font-size: .72rem; font-weight: 600; white-space: nowrap;
}
.s-uncontacted { background:#f1f5f9; color:#64748b; }
.s-contacted   { background:#dbeafe; color:#1d4ed8; }
.s-negotiating { background:#fef9c3; color:#a16207; }
.s-closed      { background:#dcfce7; color:#15803d; }
.s-lost        { background:#fee2e2; color:#dc2626; }

/* ── Tag badges ── */
.t-badge {
  display: inline-block; padding: .18rem .55rem;
  border-radius: 20px; font-size: .7rem; font-weight: 600;
  color: #fff; margin: 1px;
}

/* ── Filter bar ── */
.filter-bar {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px;
  padding: 1rem 1.25rem; margin-bottom: 1.25rem;
}
@media (min-width: 1400px) {
  .filter-bar { padding: 1.15rem 1.5rem; }
}

/* ── Forms ── */
.form-label { font-size: .85rem; font-weight: 600; color: #374151; }
.form-control, .form-select {
  border-color: #e2e8f0; border-radius: 8px; font-size: .875rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

/* ── Buttons ── */
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

/* ── Modal ── */
.modal-header { background: #f8fafc; border-bottom: 1px solid #e2e8f0; }
.modal-title { font-weight: 700; color: #1e293b; }

/* ── Login ── */
.login-bg {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: #fff; border-radius: 16px; padding: 2.5rem;
  width: 100%; max-width: 420px;
  box-shadow: 0 25px 60px rgba(0,0,0,.3);
}
.login-logo {
  width: 64px; height: 64px; background: var(--primary);
  border-radius: 16px; display: flex; align-items: center;
  justify-content: center; color: #fff; font-size: 1.8rem;
  margin: 0 auto 1.5rem;
}

/* ── Quill ── */
.ql-container.ql-snow { min-height: 280px; font-size: .9rem; }
@media (min-width: 1400px) {
  .ql-container.ql-snow { min-height: 360px; }
}
@media (min-width: 1920px) {
  .ql-container.ql-snow { min-height: 440px; }
}

/* ── Pagination ── */
.page-link { color: var(--primary); border-color: #e2e8f0; font-size: .85rem; }
.page-item.active .page-link { background: var(--primary); border-color: var(--primary); }

/* ── Color swatch ── */
.color-swatch {
  display: inline-block; width: 14px; height: 14px;
  border-radius: 3px; vertical-align: middle; margin-right: 4px;
  border: 1px solid rgba(0,0,0,.1);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ── Step wizard ── */
.step-wizard { display: flex; gap: 0; margin-bottom: 1.5rem; }
.step-item {
  flex: 1; text-align: center; padding: .65rem;
  font-size: .82rem; font-weight: 600; color: #94a3b8;
  border-bottom: 3px solid #e2e8f0; cursor: pointer;
  transition: all .2s;
}
.step-item.active { color: var(--primary); border-bottom-color: var(--primary); }
.step-item.done   { color: #22c55e; border-bottom-color: #22c55e; }
.step-pane { display: none; }
.step-pane.active { display: block; }

@media (max-width: 768px) {
  .sidebar { width: 56px; }
  .brand-name, .brand-sub, .sidebar-nav a span, .nav-section, .user-name, .user-role { display: none; }
  .main-content { margin-left: 56px; width: calc(100% - 56px); }
  .page-header, .page-body { padding-left: 1rem; padding-right: 1rem; }
}

/* ── 寬螢幕版面優化 ── */
.stat-val { font-size: 1.75rem; }
@media (min-width: 1400px) {
  .stat-card { padding: 1.4rem 1.5rem; }
  .stat-icon { width: 54px; height: 54px; font-size: 1.4rem; }
  .stat-val  { font-size: 2rem; }
}

/* 表格在大螢幕用比較舒服的列高 */
@media (min-width: 1400px) {
  .table td, .table th { padding-top: .85rem; padding-bottom: .85rem; }
}

/* 寄信頁／模板頁的雙欄在 lg(992px) 就分開，不必等到 xl(1200px) */
@media (min-width: 992px) {
  .col-xl-6.col-split-lg { flex: 0 0 auto; width: 50%; }
}

/* 卡片內表格的 max-height 視窗高度自適應，不要寫死 350px */
.table-flex {
  max-height: calc(100vh - 360px);
  min-height: 320px;
  overflow-y: auto;
}

/* Modal 在大螢幕也可以拉寬 */
@media (min-width: 1400px) {
  .modal-xl { max-width: 1320px; }
  .modal-lg { max-width: 900px; }
}
