:root {
  --bg: #f7f8ef;
  --card: #ffffff;
  --ink: #1a2a24;
  --brand: #0d7f5f;
  --brand-2: #f4a259;
  --line: #d7ded8;
}

* {
  box-sizing: border-box;

}

body {
  margin: 0;
  color: var(--ink);
  background: radial-gradient(circle at top right, #d7efe7 0, #f7f8ef 45%);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

.app-header {
  background: linear-gradient(100deg, #0f4c3a, #0d7f5f);
  color: #fff;
  padding: 1rem 1.5rem;
  display: flex;
  gap: 1.5rem;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand h1 {
  margin: 0;
}

.brand p {
  margin: 0.2rem 0 0;
  opacity: 0.9;
  font-size: 0.9rem;
}

.logo {
  width: 52px;
  height: 52px;
  object-fit: contain;
  background: #fff;
  border-radius: 10px;
  padding: 0.25rem;
}

nav {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

nav a {
  color: #fff;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}

.page {
  max-width: 1200px;
  margin: 1.2rem auto;
  padding: 0 1rem 2rem;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  box-shadow: 0 8px 20px rgba(12, 28, 21, 0.05);
}

.panel.narrow {
  max-width: 760px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.7rem;
  flex-wrap: wrap;
}

.inline-form,
.grid-form {
  margin-top: 1rem;
}

.inline-form {
  display: flex;
  gap: 0.6rem;
}

input,
select,
textarea,
button {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  font: inherit;
}

.grid-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}

.grid-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.grid-form .full {
  grid-column: 1 / -1;
}

.btn,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand);
  color: #fff;
  border: none;
  cursor: pointer;
  text-decoration: none;
  padding: 0.65rem 0.95rem;
  border-radius: 8px;
  font-weight: 600;
  max-width: fit-content;
}

.logout-form {
  margin: 0;
}

.auth-panel {
  margin-top: 2rem;
}

.btn:hover,
button:hover {
  background: #0b684f;
}

.table-wrap {
  overflow: auto;
  margin-top: 0.75rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.7rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.93rem;
}

.alerts {
  margin-bottom: 1rem;
}

.alert {
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

.alert.success {
  background: #d3f3e6;
  border: 1px solid #9bd5bc;
}

.alert.error {
  background: #f9dfdf;
  border: 1px solid #e8aaaa;
}

.hint {
  color: #40534c;
  font-size: 0.92rem;
}

.actions-inline {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.actions-inline form {
  margin: 0;
}

.status-cell {
  display: grid;
  gap: 0.35rem;
}

.status-select {
  max-width: 160px;
  padding: 0.35rem 0.45rem;
}

.status-pill {
  color: #ffffff;
  border: 0;
  border-radius: 999px;
  font-weight: 600;
}

.assign-pill {
  color: #ffffff;
  border: 0;
  border-radius: 999px;
  font-weight: 600;
}



.pagination {
  margin-top: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
}

.page-link {
  text-decoration: none;
  color: #0f4c3a;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem 0.6rem;
  background: #f2f7f4;
}

.page-link.disabled {
  color: #7a8f86;
  background: #edf0ee;
  pointer-events: none;
}

.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}

.config-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 1rem;
  margin-top: 1rem;
}

.config-left {
  display: grid;
  gap: 1rem;
}

.config-right {
  align-self: start;
  position: sticky;
  top: 1rem;
}

.config-links {
  display: grid;
  gap: 0.45rem;
}

.config-links a {
  text-decoration: none;
  color: #0f4c3a;
  background: #f2f7f4;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
}

.config-card h3 {
  margin-top: 0;
}

.status-list {
  margin-top: 1rem;
  display: grid;
  gap: 0.5rem;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.row-editor {
  display: grid;
  grid-template-columns: 140px 1fr 72px auto auto;
  gap: 0.5rem;
  align-items: center;
}

.btn-danger {
  background: #c44545;
}

.btn-danger:hover {
  background: #a73333;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.checkbox-row input {
  width: auto;
}

.mobile-quickbar {
  display: none;
}

.mobile-collapsible > h3 {
  margin-top: 0;
}

@media (max-width: 1100px) {
  .app-header {
    padding: 0.9rem 1rem;
  }

  .brand p {
    font-size: 0.82rem;
  }

  .status-select {
    max-width: 180px;
  }
}

@media (max-width: 900px) {
  .page {
    padding: 0 0.7rem 1.5rem;
  }
  .dashboard-layout {
    grid-template-columns: 1fr;
  }
  .dashboard-charts-grid {
    grid-template-columns: 1fr;
  }
  .dashboard-chart-card.full {
    grid-column: 1;
  }
  .dashboard-side {
    position: static;
  }
  .db-pie-wrap {
    grid-template-columns: 1fr;
  }

  .inline-form {
    flex-direction: column;
  }

  .panel-head {
    align-items: stretch;
  }

  .panel-head .btn {
    width: 100%;
    max-width: none;
  }

  .pagination {
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .config-layout {
    grid-template-columns: 1fr;
  }

  .config-right {
    position: static;
    order: -1;
  }

  .config-links {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .row-editor {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  body {
    font-size: 15px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
    min-height: 44px;
  }

  .btn,
  button,
  .mini-btn,
  .history-filter-btn {
    min-height: 44px;
  }

  .panel {
    padding: 0.8rem;
  }

  .mobile-collapsible {
    position: relative;
  }

  .mobile-collapsible > h3,
  .mobile-collapsible > .ce-label {
    margin: 0;
    padding: 0.2rem 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    cursor: pointer;
  }

  .mobile-collapsible > h3::after,
  .mobile-collapsible > .ce-label::after {
    content: '+';
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    font-weight: 700;
    font-size: 0.95rem;
    color: #35584c;
    flex-shrink: 0;
  }

  .mobile-collapsible.expanded > h3::after,
  .mobile-collapsible.expanded > .ce-label::after {
    content: '-';
  }

  .mobile-collapsible:not(.expanded) > :not(h3):not(.ce-label) {
    display: none;
  }

  .mobile-collapsible.expanded > :not(h3):not(.ce-label) {
    margin-top: 0.55rem;
  }

  .app-header {
    gap: 0.85rem;
  }

  .brand {
    width: 100%;
    align-items: flex-start;
  }

  .logo {
    width: 44px;
    height: 44px;
  }

  nav {
    width: 100%;
    gap: 0.5rem;
  }

  nav a {
    flex: 1 1 auto;
    justify-content: center;
    font-size: 0.9rem;
    min-height: 42px;
  }

  .page {
    padding-bottom: 5.8rem;
  }

  .grid-form {
    grid-template-columns: 1fr;
  }

  .config-grid {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .email-modal-overlay {
    align-items: flex-end;
  }

  .email-modal-box {
    max-width: none;
    width: 100%;
    max-height: 92vh;
    border-radius: 12px 12px 0 0;
  }

  .email-modal-body {
    max-height: 64vh;
    overflow-y: auto;
  }

  .email-modal-footer {
    flex-direction: column;
  }

  .email-modal-footer .btn,
  .email-modal-footer button {
    width: 100%;
    max-width: none;
  }

  .opportunity-table thead {
    display: none;
  }

  .opportunity-table,
  .opportunity-table tbody,
  .opportunity-table tr,
  .opportunity-table td {
    display: block;
    width: 100%;
  }

  .opportunity-table tr {
    border: 1px solid var(--line);
    border-radius: 12px;
    margin-bottom: 0.75rem;
    background: #fafcfb;
    padding: 0.35rem 0.35rem 0.15rem;
  }

  .opportunity-table td {
    border-bottom: none;
    padding: 0.45rem 0.5rem;
  }

  .opportunity-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #637870;
    margin-bottom: 0.2rem;
  }

  .opportunity-table td[data-label="Actions"] {
    padding-top: 0.35rem;
  }

  .status-select {
    max-width: none;
  }

  .actions-inline {
    justify-content: flex-start;
    gap: 0.55rem;
  }

  .mini-btn {
    font-size: 0.78rem;
    padding: 0.28rem 0.45rem;
  }

  .mobile-quickbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.4rem;
    padding: 0.5rem 0.6rem calc(0.5rem + env(safe-area-inset-bottom));
    background: rgba(247, 248, 239, 0.96);
    border-top: 1px solid var(--line);
    backdrop-filter: blur(4px);
  }

  .mobile-quickbar a {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    text-decoration: none;
    background: var(--brand);
    color: #fff;
    font-weight: 600;
    font-size: 0.86rem;
    padding: 0.35rem;
  }

  .mobile-sticky-submit {
    position: sticky;
    bottom: calc(0.55rem + env(safe-area-inset-bottom));
    z-index: 8;
    width: 100%;
    max-width: none;
    box-shadow: 0 8px 18px rgba(12, 28, 21, 0.18);
  }

  .dashboard-side-controls {
    flex-direction: column;
  }

  .dashboard-side-controls select,
  .dashboard-side-controls .btn {
    width: 100%;
    max-width: none;
  }

  .dashboard-chart-card {
    min-height: 235px;
  }

  .dashboard-chart-card.full {
    min-height: 250px;
  }

  .db-chart-slot {
    min-height: 180px;
  }

  .dashboard-history-list {
    max-height: 44vh;
  }

  .config-links {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tpl-table thead {
    display: none;
  }

  .tpl-table,
  .tpl-table tbody,
  .tpl-table tr,
  .tpl-table td {
    display: block;
    width: 100%;
  }

  .tpl-table tr {
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 0.6rem;
    padding: 0.35rem 0.35rem 0.15rem;
    background: #fafcfb;
  }

  .tpl-table td {
    border-bottom: none;
    padding: 0.42rem 0.5rem;
  }

  .tpl-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #637870;
    margin-bottom: 0.18rem;
  }

  .opp-edit-sidebar {
    gap: 0.55rem;
  }

  .sidebar-tabs {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar-tab {
    flex: 0 0 auto;
    justify-content: center;
    text-align: center;
    font-size: 0.8rem;
    padding: 0.45rem 0.6rem;
  }
}

@media (max-width: 520px) {
  .config-links {
    grid-template-columns: 1fr;
  }

  .dashboard-filters label,
  .dashboard-filters select,
  .dashboard-filters input,
  .dashboard-filters .btn {
    width: 100%;
    min-width: 0;
    max-width: none;
  }
}

/* ── Email Send Modal ─────────────────────────────────── */
.email-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.email-modal-box {
  background: #fff;
  border-radius: 10px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.22);
  overflow: hidden;
}

.email-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.2rem;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
}

.email-modal-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.2rem;
  line-height: 1;
}

.email-modal-body {
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.email-modal-body label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted, #555);
}

.email-modal-body select {
  width: 100%;
}

.email-modal-recipient {
  font-size: 0.9rem;
  color: #555;
  margin: 0;
}

.email-modal-msg {
  padding: 0.55rem 0.8rem;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 500;
}

.email-modal-msg.success {
  background: #d4edda;
  color: #155724;
}

.email-modal-msg.error {
  background: #f8d7da;
  color: #721c24;
}

.email-modal-footer {
  display: flex;
  gap: 0.6rem;
  padding: 0.85rem 1.2rem;
  border-top: 1px solid var(--line, #e5e5e5);
  justify-content: flex-end;
}

.history-modal-body {
  max-height: 62vh;
  overflow-y: auto;
}

.history-modal-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  background: #fbfcfb;
  margin-bottom: 0.55rem;
}

.history-modal-meta {
  font-size: 0.78rem;
  color: #6e7c75;
  margin-bottom: 0.3rem;
}

.history-modal-change {
  font-size: 0.86rem;
  white-space: normal;
}

.history-modal-remark {
  margin-top: 0.35rem;
  font-size: 0.82rem;
  color: #0f4c3a;
}

/* Dashboard */
.dashboard-layout {
  margin-top: 0.85rem;
  display: grid;
  grid-template-columns: 3fr 1fr;
  gap: 0.9rem;
  align-items: start;
}

.dashboard-main {
  min-width: 0;
}

.dashboard-summary {
  font-size: 0.9rem;
  color: #334155;
  margin-bottom: 0.65rem;
}

.dashboard-charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.dashboard-chart-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.6rem;
  min-height: 290px;
  display: flex;
  flex-direction: column;
}

.dashboard-chart-card.full {
  grid-column: 1 / -1;
  min-height: 320px;
}

.dashboard-chart-card h4 {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
}

.db-chart-slot {
  width: 100%;
  min-height: 245px;
}

.db-pie-wrap {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 0.7rem;
  align-items: center;
}

.db-pie {
  width: 170px;
  height: 170px;
  border-radius: 50%;
  border: 1px solid #e5e7eb;
  margin: 0 auto;
}

.db-legend {
  display: grid;
  gap: 0.3rem;
}

.db-legend-item {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
}

.db-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.db-legend-label {
  color: #334155;
}

.db-legend-value {
  color: #6b7280;
}

.db-bars {
  display: grid;
  gap: 0.38rem;
}

.db-bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 160px) 1fr auto;
  align-items: center;
  gap: 0.45rem;
}

.db-bar-label {
  font-size: 0.78rem;
  color: #334155;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.db-bar-track {
  height: 11px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}

.db-bar-fill {
  height: 100%;
  border-radius: 999px;
}

.db-bar-value {
  font-size: 0.76rem;
  color: #6b7280;
}

.dashboard-side {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem;
  background: #fcfdfc;
  position: sticky;
  top: 0.8rem;
}

.dashboard-side-head {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.dashboard-side-head h3 {
  margin: 0;
}

.dashboard-side-controls {
  display: flex;
  gap: 0.45rem;
}

.dashboard-side-controls select {
  max-width: 160px;
  padding: 0.4rem 0.45rem;
}

.dashboard-history-list {
  margin-top: 0.6rem;
  max-height: 74vh;
  overflow-y: auto;
  display: grid;
  gap: 0.45rem;
}

.dashboard-history-item {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 0.5rem;
  background: #fff;
}

.dashboard-history-meta {
  font-size: 0.74rem;
  color: #64748b;
  margin-bottom: 0.25rem;
}

.dashboard-tag {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.42rem;
  border-radius: 999px;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
}

.dashboard-history-text {
  font-size: 0.84rem;
  color: #1f2937;
}

.dashboard-history-remark {
  margin-top: 0.2rem;
  font-size: 0.76rem;
  color: #6b7280;
}

.dashboard-filters {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.dashboard-filters label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.82rem;
}

.dashboard-filters select,
.dashboard-filters input {
  min-width: 130px;
  padding: 0.4rem 0.45rem;
}

.btn-secondary {
  background: #6c757d;
}

.btn-secondary:hover {
  background: #545b62;
}

/* ── Template list table delete button ─────────────────── */
.mini-btn.danger {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  background: #c44545;
  color: #fff;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}

.mini-btn.danger:hover {
  background: #a73333;
}

code {
  background: #f0f4f2;
  border: 1px solid #dde4df;
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
  font-size: 0.82rem;
  color: #0f4c3a;
}

/* ── Template list page ────────────────────────────────── */
.tpl-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.tpl-list-head h3 {
  margin: 0;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.86rem;
}

.tpl-inline-form {
  background: #f8fbf9;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}

.tpl-inline-form h4 {
  margin: 0 0 0.5rem;
}

.tpl-form-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tpl-edit-cell {
  padding: 0.75rem 0.5rem !important;
  background: #f8fbf9;
}

.tpl-table td,
.tpl-table th {
  vertical-align: middle;
}

.mini-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.mini-btn:hover {
  background: #0b684f;
}

/* ── Custom Email Form ─────────────────────────────────── */
.ce-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 0.75rem;
}

.ce-label {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--brand);
  margin: 0 0 0.65rem;
}

.ce-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}

.ce-tab {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.38rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  font-size: 0.86rem;
  cursor: pointer;
  background: #f6faf8;
  transition: background 0.15s;
}

.ce-tab:has(input:checked) {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.ce-tab input[type="radio"] {
  display: none;
}

.ce-sub {
  margin-top: 0.5rem;
}

.ce-customer-list {
  display: grid;
  gap: 0.35rem;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.6rem;
  margin-top: 0.4rem;
  background: #fafcfb;
}

.ce-customer-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.88rem;
  cursor: pointer;
  padding: 0.25rem 0.3rem;
  border-radius: 4px;
}

.ce-customer-item:hover {
  background: #edf7f3;
}

.ce-customer-item input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.hint-inline {
  color: #888;
  font-size: 0.8rem;
}

/* ── Customer list search toolbar ─────────────────────── */
.ce-cust-toolbar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.ce-search {
  flex: 1;
  padding: 0.38rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.88rem;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  background: #fbfcfb;
}

.history-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.45rem;
}

.history-filter-btn {
  border: 1px solid var(--line);
  background: #f2f7f4;
  color: #0f4c3a;
  border-radius: 14px;
  padding: 0.22rem 0.62rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.history-filter-btn.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.history-meta {
  font-size: 0.78rem;
  color: #6e7c75;
  margin-bottom: 0.3rem;
}

.history-change {
  font-size: 0.86rem;
  white-space: pre-wrap;
}

.history-remark {
  margin-top: 0.35rem;
  font-size: 0.82rem;
  color: #0f4c3a;
}

/* ── Email History badges ──────────────────────────────── */
.badge-status {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-ok {
  background: #d4edda;
  color: #155724;
}

.badge-fail {
  background: #f8d7da;
  color: #721c24;
  cursor: help;
}

.badge-custom {
  display: inline-block;
  padding: 0.18rem 0.45rem;
  border-radius: 10px;
  font-size: 0.76rem;
  background: #e8f0fe;
  color: #1a56a0;
  font-weight: 600;
}

.badge-type {
  display: inline-block;
  padding: 0.18rem 0.45rem;
  border-radius: 10px;
  font-size: 0.76rem;
  font-weight: 600;
  background: #f0f4f2;
  color: #444;
}

.badge-type-bulk     { background: #fff3cd; color: #856404; }
.badge-type-template { background: #d4edda; color: #155724; }
.badge-type-custom   { background: #e8f0fe; color: #1a56a0; }
.badge-type-resend   { background: #fde7e7; color: #721c24; }
.badge-type-welcome  { background: #e0f4ff; color: #0a4e78; }
.badge-type-welcome-assigned { background: #efe5ff; color: #4f2a8a; }

/* ── Page Tabs ─────────────────────────────────────────── */
/* ── Page Tabs (kept for non-edit pages) ──────────────── */
.page-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--line);
  margin: 0.75rem 0 1rem;
  flex-wrap: wrap;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  padding: 0.6rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  color: #637870;
  border-radius: 0;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: none;
  min-height: auto;
  line-height: 1.4;
}

.tab-btn:hover { color: var(--ink); background: #f2f7f4; }
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); background: none; }

/* ── Opportunity Edit: two-column layout ───────────────── */
.opp-edit-layout {
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 1.25rem;
  align-items: start;
  margin-top: 0.75rem;
}

.opp-edit-content { min-width: 0; }

/* ── Right sidebar ─────────────────────────────────────── */
.opp-edit-sidebar {
  position: sticky;
  top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sidebar-tabs {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  background: #f4f7f5;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem;
}

.sidebar-tab {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 7px;
  padding: 0.55rem 0.75rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: #455a52;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
  max-width: none;
  min-height: auto;
  line-height: 1.4;
}

.sidebar-tab:hover { background: #e4ede8; color: var(--ink); }
.sidebar-tab.active { background: var(--brand); color: #fff; }

.sidebar-meta {
  background: #f4f7f5;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.sidebar-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.8rem;
  gap: 0.4rem;
}

.sidebar-meta-row span { color: #6e7c75; white-space: nowrap; }
.sidebar-meta-row strong { text-align: right; word-break: break-word; font-size: 0.82rem; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Document list ─────────────────────────────────────── */
.doc-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.65rem 0.9rem;
  background: #fafcfb;
}

.doc-meta {
  flex: 1;
  min-width: 0;
}

.doc-name {
  font-weight: 600;
  font-size: 0.92rem;
  word-break: break-all;
}

.doc-info {
  font-size: 0.78rem;
  color: #6e7c75;
  margin-top: 0.2rem;
}

.doc-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

/* ── Gathering block inside edit page ──────────────────── */
.ce-block + .table-wrap {
  margin-top: 0.5rem;
}

.gather-subtab-pane {
  display: none;
}

.gather-subtab-pane.active {
  display: block;
}

@media (max-width: 760px) {
  .page-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .tab-btn {
    font-size: 0.82rem;
    padding: 0.5rem 0.7rem;
  }

  .doc-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .doc-actions {
    width: 100%;
    justify-content: flex-start;
  }

    .opp-edit-layout {
      grid-template-columns: 1fr;
    }

    .opp-edit-sidebar {
      position: static;
      order: -1;
    }

    .sidebar-tabs {
      flex-direction: row;
      flex-wrap: nowrap;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }

    .sidebar-tab {
      flex: 0 0 auto;
      justify-content: center;
      text-align: center;
      font-size: 0.8rem;
      padding: 0.45rem 0.6rem;
    }
}
