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

/* CSS Variables for Finance components */
:root {
  --accent: #2563eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg-primary: #f5f5f7;
  --bg-secondary: #f8fafc;
  --bg-card: #fff;
  --bg-input: #fff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --text-primary: #1d1d1f;
  --text-secondary: #64748b;
  --text-muted: #64748b;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
}

/* Fix for invisible finance form buttons */
.fin-add-submit-btn, .fin-type-btn, .fin-period-btn, .fin-tab {
  background: var(--accent, #2563eb) !important;
  color: #fff !important;
  border: 1px solid var(--accent, #2563eb) !important;
}

.fin-type-btn:not(.active), .fin-period-btn:not(.active) {
  background: var(--bg-primary, #f5f5f7) !important;
  color: var(--text-primary, #1d1d1f) !important;
  border: 1px solid var(--border, #e2e8f0) !important;
}

/* Ensure all buttons in finance forms are visible */
#page-finance button {
  background: var(--bg-primary, #f5f5f7) !important;
  border: 1px solid var(--border, #e2e8f0) !important;
  color: var(--text-primary, #1d1d1f) !important;
  padding: 8px 12px !important;
  border-radius: 6px !important;
  cursor: pointer !important;
}

#page-finance button[style*="background:var(--accent"],
#page-finance .fin-add-submit-btn,
#page-finance .fin-tab.active {
  background: var(--accent, #2563eb) !important;
  color: #fff !important;
  border-color: var(--accent, #2563eb) !important;
}

/* Fix for buttons with background:none inline style */
#page-finance button[style*="background:none"] {
  background: var(--bg-primary, #f5f5f7) !important;
  border: 1px solid var(--border, #e2e8f0) !important;
  color: var(--text-primary, #1d1d1f) !important;
}

/* Special handling for icon buttons */
#page-finance button[title="Редагувати"],
#page-finance button[title="Видалити"] {
  background: var(--bg-card, #fff) !important;
  border: 1px solid var(--border, #e2e8f0) !important;
  border-radius: 6px !important;
  padding: 6px !important;
}

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  padding-bottom: 100px;
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: var(--tracking-normal);
  /* Prevent layout breaks from very long URLs */
  word-break: break-all;
  overflow-wrap: break-word;
}

/* ===== HEADER ===== */
.app-header {
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 0.5px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  transform: translateZ(0);
  will-change: transform;
}

@media (max-width: 1023px) {
  .icon-sidebar { display: none !important; }
  .app-header {
    left: 0;
    justify-content: center;
  }
  .app-header img {
    margin: 0 auto;
  }
}

.page {
  padding-top: calc(56px + env(safe-area-inset-top, 0px));
}

#page-ai {
  padding-top: 0 !important;
  height: calc(100vh - 56px - env(safe-area-inset-top, 0px));
  overflow: hidden;
  margin-top: calc(56px + env(safe-area-inset-top, 0px));
}

.app-header img {
  height: 34px;
}

.app-header .date {
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== PAGE ===== */
.page { display: none; }
.page.active { display: block; }

/* ===== PERIOD SELECTOR ===== */
.period-selector {
  display: none;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(255,255,255,0.92);
  overflow-x: auto;
  white-space: nowrap;
  border-bottom: 0.5px solid var(--border);
  position: fixed;
  transform: translateZ(0);
  top: calc(56px + env(safe-area-inset-top, 0px));
  left: 72px;
  right: 0;
  z-index: 99;
}

@media (max-width: 1023px) {
  .period-selector {
    left: 0;
    top: calc(56px + env(safe-area-inset-top, 0px));
  }
}

.page.has-period {
  padding-top: calc(104px + env(safe-area-inset-top, 0px));
}

.period-btn {
  padding: 8px 16px;
  min-height: 36px;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-pill);
  background: var(--bg-card-solid);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--duration-fast) var(--ease-default);
  white-space: nowrap;
  position: relative;
  outline: none;
  overflow: hidden;
}

.period-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.period-btn:active {
  transform: translateY(0);
}

.period-btn:focus-visible {
  box-shadow: 0 0 0 2px var(--accent);
  outline: none;
}

.period-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.period-btn.active::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.2), transparent);
  pointer-events: none;
}

/* ===== LOADING / ERROR ===== */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 14px;
}

.stale-banner {
  background: var(--warning-bg);
  border-left: 3px solid var(--warning);
  padding: 8px 15px;
  font-size: 12px;
  color: var(--warning-text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.error-msg {
  text-align: center;
  padding: 40px;
  color: var(--danger);
  font-size: 14px;
}

/* ===== METRICS GRID ===== */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 12px 15px;
}

/* Admin quick-nav cards on Home. Default 6 cols (inline style in home.js),
   but on phones 6 cols = ~48px per card which squashes the 40px icon +
   labels below legibility. Collapse to 3 cols on mobile, 2 on very narrow. */
@media (max-width: 1023px) {
  #home-quick-cards {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
    padding: 0 4px !important;
  }
  #home-quick-cards > div {
    padding: 14px 8px 12px !important;
    min-height: 80px !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    text-align: center !important;
  }
  #home-quick-cards > div > div:first-child {
    width: 32px !important;
    height: 32px !important;
    margin-bottom: 6px !important;
  }
  #home-quick-cards [id^="hqc-val-"] {
    font-size: 14px !important;
    line-height: 1.2 !important;
    font-weight: 600 !important;
    margin: 2px 0 !important;
  }
  #home-quick-cards .hqc-label {
    font-size: 10px !important;
    opacity: 0.8 !important;
    line-height: 1.1 !important;
  }

  /* Better dashboard layout */
  .dashboard-section {
    margin-bottom: 12px !important;
    padding: 0 4px !important;
  }

  .dashboard-section h3 {
    font-size: 16px !important;
    margin-bottom: 8px !important;
  }
}
@media (max-width: 360px) {
  #home-quick-cards {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* Team page — two 3-column stat grids squash under 360px. Keep 3 cols on
   larger phones where each cell still has room; collapse to a horizontal
   flex on very narrow screens so the numeric values don't truncate. */
@media (max-width: 1023px) {
  .team-summary-triplet { gap: 6px !important; }
  .team-summary-triplet > div { padding: 10px 6px !important; }
  .team-summary-triplet > div > div:first-child { font-size: 18px !important; }
}
@media (max-width: 400px) {
  .team-stat-triplet,
  .team-summary-triplet {
    grid-template-columns: 1fr !important;
    gap: 6px !important;
  }
  .team-stat-triplet > div,
  .team-summary-triplet > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left !important;
    padding: 10px 12px !important;
  }
  .team-stat-triplet > div > div:first-child,
  .team-summary-triplet > div > div:first-child {
    font-size: 18px !important;
  }
}

.metric-card {
  background: var(--bg-card);
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--duration-fast) var(--ease-default);
}

.metric-card:hover {
  box-shadow: var(--shadow-sm);
}

.metric-card .label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.metric-card .value {
  font-size: 28px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.1;
  letter-spacing: var(--tracking-tight);
}

.metric-card .subtext {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

.metric-card .subtext-amount {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 3px;
  font-weight: 500;
}

/* ===== SECTION ===== */
.section {
  padding: 12px 15px;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: var(--tracking-normal);
}

/* ===== SIGNAL CARDS ===== */
.signal-card {
  background: var(--bg-card);
  padding: 12px 15px;
  border-radius: var(--radius-lg);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 0.5px solid var(--border);
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  transition: box-shadow var(--duration-fast) var(--ease-default);
}

.signal-card:hover { box-shadow: var(--shadow-md); }
.signal-card.alert { background: var(--danger-bg); border-left: 3px solid var(--danger); }
.signal-card.warning { background: var(--warning-bg); border-left: 3px solid var(--warning); }

.signal-card .sig-title { font-size: 13px; color: var(--text-primary); font-weight: 500; }
.signal-card .sig-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.signal-card .sig-count { font-size: 28px; font-weight: 600; color: var(--danger); letter-spacing: var(--tracking-tight); }
.signal-card.warning .sig-count { color: var(--warning); }

/* ===== PRODUCTION GRID ===== */
.production-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.production-card {
  background: var(--bg-card);
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.production-card.clickable { cursor: pointer; transition: box-shadow var(--duration-fast) var(--ease-default); }
.production-card.clickable:hover { box-shadow: var(--shadow-md); }

.production-card .label { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.02em; }
.production-card .value { font-size: 30px; font-weight: 600; color: var(--text-primary); letter-spacing: var(--tracking-tight); }

/* ===== CHART SECTION ===== */
.chart-section {
  background: var(--bg-card);
  margin: 0 15px 15px;
  border-radius: var(--radius-lg);
  padding: 16px;
  border: 0.5px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.chart-selector {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  overflow-x: auto;
}

.chart-btn {
  padding: 6px 14px;
  border: 0.5px solid var(--border-md);
  border-radius: var(--radius-pill);
  background: var(--bg-card-solid);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: background var(--duration-fast) var(--ease-default), color var(--duration-fast) var(--ease-default), border-color var(--duration-fast) var(--ease-default);
}

.chart-btn.active { background: var(--btn-primary-bg); color: var(--btn-primary-text); border-color: var(--btn-primary-bg); }

/* ===== ORDER LIST (modal) ===== */
.order-item {
  background: var(--bg-primary);
  padding: 12px;
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  border-left: 3px solid var(--danger);
}

.order-item.warning { border-left-color: var(--warning); }

.order-item .order-id { font-weight: 600; color: var(--text-primary); margin-bottom: 4px; font-size: 13px; }
.order-item .order-detail { font-size: 12px; color: var(--text-secondary); margin-bottom: 3px; }

.order-link {
  display: inline-block;
  margin-top: 8px;
  padding: 5px 12px;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
}

/* ===== MODAL ===== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1000;
  overflow-y: auto;
  padding: 40px 16px;
  box-sizing: border-box;
}

.modal.active { display: block; }

.modal-content {
  background: var(--bg-card-solid);
  margin: 0 auto;
  padding: 24px;
  border-radius: var(--radius-xl);
  max-width: 500px;
  width: 100%;
  box-sizing: border-box;
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
}

@media (max-width: 600px) {
  .modal-content {
    padding: 16px;
    border-radius: var(--radius-lg);
  }
}

/* TTN Modal - wider for better UX on desktop */
.modal-content:has(.ttn-modal-wrap) {
  max-width: 900px;
  width: 90vw;
}

.ttn-modal-wrap {
  max-width: 100%;
  width: 100%;
}

@media (max-width: 1000px) {
  .modal-content:has(.ttn-modal-wrap) {
    max-width: 800px;
  }
}

@media (max-width: 900px) {
  .modal-content:has(.ttn-modal-wrap) {
    max-width: 700px;
  }
}

@media (max-width: 768px) {
  .modal-content:has(.ttn-modal-wrap) {
    max-width: 500px;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h3 { font-size: 17px; font-weight: 600; color: var(--text-primary); letter-spacing: var(--tracking-normal); }

.modal-close {
  background: var(--bg-active);
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-round);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--duration-fast) var(--ease-default);
}

.modal-close:hover { background: var(--border-strong); }

/* ===== TABLES ===== */
.orders-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border);
  box-shadow: var(--shadow-xs);
}

.orders-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card-solid);
  font-size: 13px;
}

.orders-table thead tr {
  border-bottom: 0.5px solid var(--border-md);
}

.orders-table thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 1px 0 var(--border-md), 0 2px 4px rgba(0, 0, 0, 0.04);
}

.orders-table th {
  padding: 10px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  background: var(--bg-primary);
}

.orders-table th.op-sortable {
  cursor: pointer;
  user-select: none;
}
.orders-table th.op-sortable:hover { color: var(--text-primary); }
.orders-table th .op-sort-arrow {
  display: inline-block;
  margin-left: 3px;
  font-size: 10px;
  opacity: 0.5;
}
.orders-table th.op-sort-active { color: var(--accent); }
.orders-table th.op-sort-active .op-sort-arrow { opacity: 1; }

.orders-table td {
  padding: 10px 12px;
  border-bottom: 0.5px solid var(--border);
  vertical-align: middle;
  color: var(--text-primary);
  position: relative;
}

.orders-table tr:hover td {
  background: var(--bg-hover);
}

/* Row hover quick actions */
.orders-table tr .op-row-actions {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  gap: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
  background: var(--bg-card-solid);
  padding: 4px 6px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border: 0.5px solid var(--border);
  z-index: 5;
}
.orders-table tr:hover .op-row-actions {
  opacity: 1;
  pointer-events: auto;
}
.orders-table .op-row-actions button {
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
  color: var(--text-secondary);
}
.orders-table .op-row-actions button:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.orders-table tr:last-child td {
  border-bottom: none;
}

.orders-cards-mobile { display: none; }

/* ===== ORDERS FILTER PANEL ===== */
.op-filter-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.op-filter-backdrop.op-open {
  opacity: 1;
  pointer-events: auto;
}
.op-filter-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 640px;
  max-width: 96vw;
  background: var(--bg-card-solid);
  border-left: 0.5px solid var(--border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
  z-index: 1101;
  transform: translateX(100%);
  transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex;
  flex-direction: column;
}
.op-filter-panel.op-open {
  transform: translateX(0);
}
.op-filter-header {
  padding: 16px 20px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card-solid);
}
.op-filter-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}
.op-filter-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0 6px;
}
.op-filter-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
}
.op-filter-section {
  border-bottom: 0.5px solid var(--border);
  padding: 8px 0;
}
.op-filter-section summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  color: var(--text-primary);
  list-style: none;
  padding: 8px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}
.op-filter-section summary::-webkit-details-marker { display: none; }
.op-filter-section summary::after {
  content: '›';
  font-size: 18px;
  color: var(--text-muted);
  transform: rotate(90deg);
  transition: transform 0.15s ease;
}
.op-filter-section:not([open]) summary::after { transform: rotate(0deg); }
.op-filter-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
  padding: 6px 0 12px 0;
}
.op-filter-field { display: flex; flex-direction: column; gap: 4px; }
.op-filter-field.op-filter-span2 { grid-column: 1 / span 2; }
.op-filter-field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.op-filter-field input,
.op-filter-field select,
.op-filter-field textarea {
  padding: 8px 10px;
  border: 0.5px solid var(--border-input);
  border-radius: 8px;
  font-size: 13px;
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
  width: 100%;
  box-sizing: border-box;
}
.op-filter-field input:focus,
.op-filter-field select:focus { border-color: var(--accent); }
.op-filter-range { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: center; }
.op-filter-range .op-dash { color: var(--text-muted); font-weight: 600; }
.op-filter-footer {
  padding: 14px 20px;
  border-top: 0.5px solid var(--border);
  display: flex;
  gap: 8px;
  background: var(--bg-card-solid);
}
.op-filter-footer button {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border: 0.5px solid var(--border-input);
}
.op-filter-footer .op-filter-apply  { flex: 1; background: var(--btn-primary-bg); color: white; border-color: var(--btn-primary-bg); }
.op-filter-footer .op-filter-reset  { background: var(--bg-primary); color: var(--text-secondary); }
.op-filter-footer .op-filter-save   { background: var(--bg-primary); color: var(--text-secondary); }

/* Active filter chips (below toolbar) */
.op-chips-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.op-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-light);
  color: var(--accent);
  border: 0.5px solid var(--accent);
  border-radius: 999px;
  padding: 3px 4px 3px 10px;
  font-size: 12px;
  font-weight: 500;
}
.op-chip button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 4px;
}
.op-filter-badge {
  display: inline-block;
  background: var(--accent);
  color: white;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  margin-left: 4px;
  line-height: 1.4;
}

/* Saved searches dropdown */
.op-saved-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--bg-card-solid);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  min-width: 240px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 30;
  display: none;
  padding: 4px 0;
}
.op-saved-menu.op-open { display: block; }
.op-saved-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
}
.op-saved-item:hover { background: var(--bg-hover); }
.op-saved-item button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
}
.op-saved-item button:hover { color: var(--danger-text); }
.op-saved-empty { padding: 10px 12px; font-size: 12px; color: var(--text-muted); text-align: center; }

/* ===== CUSTOM FIELD TOGGLE (order detail) ===== */
.cf-toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.cf-toggle input { opacity: 0; width: 0; height: 0; }
.cf-toggle-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 22px;
  transition: 0.2s;
}
.cf-toggle-slider::before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.cf-toggle input:checked + .cf-toggle-slider { background: var(--accent); }
.cf-toggle input:checked + .cf-toggle-slider::before { transform: translateX(18px); }
.cf-toggle input:focus-visible + .cf-toggle-slider { box-shadow: 0 0 0 3px var(--accent-light); }

/* ===== RICH TASK MODAL (orders detail) ===== */
.tm-type-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.tm-type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  border: 0.5px solid var(--border-input);
  border-radius: 10px;
  background: var(--bg-primary);
  cursor: pointer;
  font-size: 10px;
  color: var(--text-secondary);
  transition: all 0.12s ease;
}
.tm-type-btn .tm-type-emoji { font-size: 18px; line-height: 1; }
.tm-type-btn:hover { border-color: var(--accent); color: var(--text-primary); }
.tm-type-btn.tm-active {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}
.tm-preset-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tm-preset-btn {
  padding: 4px 10px;
  border: 0.5px solid var(--border-input);
  border-radius: 999px;
  background: var(--bg-card-solid);
  font-size: 11px;
  cursor: pointer;
  color: var(--text-secondary);
}
.tm-preset-btn:hover { border-color: var(--accent); color: var(--accent); }
.tm-priority-row { display: flex; gap: 6px; }
.tm-prio-btn {
  flex: 1;
  padding: 8px;
  border: 0.5px solid var(--border-input);
  border-radius: 10px;
  background: var(--bg-card-solid);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-secondary);
}
.tm-prio-btn.tm-active { color: white; border-color: transparent; }
.tm-prio-btn[data-prio="normal"].tm-active    { background: #64748b; }
.tm-prio-btn[data-prio="important"].tm-active { background: #d97706; }
.tm-prio-btn[data-prio="critical"].tm-active  { background: #dc2626; }
.tm-assignee-list {
  max-height: 180px;
  overflow-y: auto;
  border: 0.5px solid var(--border-input);
  border-radius: 10px;
  margin-top: 4px;
}
.tm-assignee-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
}
.tm-assignee-item:hover { background: var(--bg-hover); }
.tm-assignee-item.tm-active { background: var(--accent-light); color: var(--accent); font-weight: 600; }
.tm-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  object-fit: cover;
}
.tm-checklist-item { display: flex; gap: 6px; margin-bottom: 4px; }
.tm-checklist-item input[type="text"] {
  flex: 1;
  padding: 6px 10px;
  border: 0.5px solid var(--border-input);
  border-radius: 8px;
  font-size: 12px;
  outline: none;
}
.tm-checklist-item button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
}

@media (max-width: 1023px) {
  .orders-table-wrap { display: none; }
  .orders-cards-mobile { display: block; }
}

/* ===== MOBILE ORDER CARD ===== */
.order-card {
  background: var(--bg-card-solid);
  border-radius: var(--radius-lg);
  padding: 12px;
  margin-bottom: 10px;
  border: 0.5px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.order-card-selected {
  background: var(--accent-light);
  border-color: var(--accent);
}
.oc-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.oc-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  min-height: 24px;
}
.oc-check input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}
.oc-id {
  font-size: 15px;
  font-weight: 700;
  color: #1a1a2e;
}
.oc-age { display: inline-flex; align-items: center; }
.oc-fu { display: inline-flex; align-items: center; }
.oc-status {
  margin-left: auto;
  border-radius: var(--radius-pill);
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.oc-buyer {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}
.oc-buyer-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 14px;
}
.oc-phone {
  color: var(--success-text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}
.oc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.oc-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-primary);
  white-space: nowrap;
}
.oc-chip-accent { color: var(--accent); background: var(--accent-light); }
.oc-chip-warn { color: #d97706; background: #fef3c7; font-weight: 600; }
.oc-chip-danger { color: #b91c1c; background: #fee2e2; font-weight: 700; }
.oc-product {
  display: flex;
  align-items: center;
  gap: 10px;
}
.oc-photo {
  width: 56px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
}
.oc-photo-empty {
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.oc-product-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.oc-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.oc-total {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 15px;
}
.oc-pay { font-weight: 600; font-size: 12px; }
.oc-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.oc-tag {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.oc-tag-more { background: var(--bg-primary); color: var(--text-muted); }
.oc-tag-ttn { background: #f0fdf4; color: #059669; display: inline-flex; align-items: center; gap: 3px; }
.oc-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 2px;
  padding-top: 8px;
  border-top: 0.5px solid var(--border);
}
.oc-btn {
  min-height: 44px;
  border: 0.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg-primary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  text-decoration: none;
  padding: 0;
}
.oc-btn:active { background: var(--bg-hover); transform: scale(0.97); }
.oc-btn-primary { background: var(--success-bg); color: var(--success-text); }
.oc-btn-disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== MOBILE FILTER PANEL (bottom sheet) ===== */
@media (max-width: 1023px) {
  .op-filter-panel {
    width: 100% !important;
    max-width: 100% !important;
    height: 88vh !important;
    top: auto !important;
    right: 0 !important;
    bottom: 0 !important;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    border-left: none;
    transform: translateY(100%);
    box-shadow: 0 -8px 24px rgba(0,0,0,0.2);
  }
  .op-filter-panel.op-open { transform: translateY(0); }
  .op-filter-panel::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border-md);
    border-radius: 2px;
    margin: 8px auto 0;
  }
  .op-filter-header {
    padding: 10px 16px;
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .op-filter-close {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .op-filter-body { padding: 8px 14px 14px; }
  .op-filter-fields { grid-template-columns: 1fr !important; gap: 8px; }
  .op-filter-field.op-filter-span2 { grid-column: auto !important; }
  .op-filter-footer {
    position: sticky;
    bottom: 0;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  }
  .op-filter-footer button { min-height: 44px; }
}

/* ===== MOBILE BULK BAR ===== */
@media (max-width: 1023px) {
  #orders-bulk-bar {
    left: 8px !important;
    right: 8px !important;
    transform: none !important;
    max-width: none !important;
    width: auto !important;
    padding: 8px 10px !important;
    gap: 6px !important;
    flex-wrap: nowrap !important;
    border-radius: var(--radius-lg) !important;
  }
  .bulk-desktop-only { display: none !important; }
  .bulk-more-menu {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 6px;
    background: var(--bg-card-solid);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    padding: 6px 0;
    z-index: 1001;
  }
  .bulk-more-menu button {
    display: flex !important;
    width: 100%;
    border: none !important;
    border-radius: 0 !important;
    padding: 10px 14px !important;
    font-size: 13px !important;
    background: none !important;
    text-align: left;
    cursor: pointer;
    color: var(--text-primary);
    min-height: 44px;
  }
  .bulk-more-menu button:active { background: var(--bg-hover); }
}
.bulk-more-only { display: none; }
@media (min-width: 768px) {
  .bulk-more-toggle { display: none !important; }
}

/* ===== MOBILE TOOLBAR ===== */
.orders-toolbar-mobile-only { display: none !important; }
@media (max-width: 1023px) {
  .orders-toolbar-desktop-only { display: none !important; }
  .orders-toolbar-mobile-only { display: flex !important; }
  .orders-mobile-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    background: var(--bg-card-solid);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    padding: 6px 0;
    z-index: 40;
  }
  .orders-mobile-menu button,
  .orders-mobile-menu label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: none !important;
    border-radius: 0 !important;
    padding: 11px 14px !important;
    font-size: 13px !important;
    background: none !important;
    text-align: left;
    cursor: pointer;
    color: var(--text-primary);
    min-height: 44px;
  }
  .orders-mobile-menu button:active,
  .orders-mobile-menu label:active { background: var(--bg-hover); }
  .orders-mobile-menu-section {
    border-top: 0.5px solid var(--border);
    margin-top: 4px;
    padding-top: 4px;
  }
}

/* ===== MOBILE ORDER DETAIL (fullscreen) =====
   The wrap is its own scroll container (position:fixed + overflow-y:auto),
   so the body no longer needs overflow:hidden. Dropping the body lock
   prevents the "scroll dead" bug that appeared when body.order-detail-open
   was not cleared on error or on route change. */
@media (max-width: 1023px) {
  .order-detail-wrap {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    overflow-y: auto;
    background: var(--bg-primary);
    /* Leave room for the fixed bottom bar incl. home indicator safe area */
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    -webkit-overflow-scrolling: touch;
  }
  .order-detail-wrap .od-hdr {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-card-solid);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    /* Push content below notch / Dynamic Island */
    padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
    padding-left: calc(env(safe-area-inset-left, 0px) + 12px);
    padding-right: calc(env(safe-area-inset-right, 0px) + 12px);
  }
  .order-detail-bottombar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding:
      10px
      calc(env(safe-area-inset-right, 0px) + 10px)
      calc(env(safe-area-inset-bottom, 0px) + 10px)
      calc(env(safe-area-inset-left, 0px) + 10px);
    background: var(--bg-card-solid);
    border-top: 0.5px solid var(--border);
    z-index: 1001;
    box-shadow: 0 -4px 14px rgba(0,0,0,0.08);
  }
  .order-detail-bottombar a,
  .order-detail-bottombar button {
    min-height: 48px;
    border-radius: 12px;
    border: 0.5px solid var(--border);
    background: var(--bg-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--text-primary);
    text-decoration: none;
  }
  .order-detail-bottombar a.odb-primary,
  .order-detail-bottombar button.odb-primary {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: var(--success-bg);
  }
}
@media (min-width: 768px) {
  .order-detail-bottombar { display: none !important; }
}

/* ===== ORDER DETAIL (extracted from inline <style>) ===== */
.od-back {
  background: none;
  border: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  padding: 8px 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  min-width: 44px;
}
.od-hdr {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
  background: var(--bg-card-solid);
}
.od-hdr-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
  flex: 1;
}
.od-title {
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
}
.od-meta {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.od-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0;
  border-bottom: 0.5px solid var(--border);
}
.od-col {
  padding: 14px 16px;
  border-right: 0.5px solid var(--border);
  min-width: 0;
}
.od-col:last-child { border-right: none; }
.od-lbl {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.od-field {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  font-size: 13px;
  border-bottom: 0.5px solid var(--border);
  min-height: 44px;
  gap: 8px;
}
.od-field:last-child { border-bottom: none; }
.od-fk {
  color: var(--text-muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.od-fv {
  color: var(--text-primary);
  font-weight: 500;
  text-align: right;
  max-width: 60%;
  word-break: break-word;
}
.od-add {
  color: var(--text-placeholder);
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.od-add:hover { color: var(--accent); }
.od-sec {
  padding: 14px 16px;
  border-bottom: 0.5px solid var(--border);
  /* Establish a stacking context per section + guarantee pointer-events
     so a stray off-screen overlay (filter backdrop, bulk-bar, modal that
     missed its close) cannot eat clicks targeted at section buttons. */
  position: relative;
  z-index: 1;
  pointer-events: auto;
}
/* Status / pay badge variants. Both spans ship in HTML always; only the
   width-appropriate one is shown. The mobile rule lower in the file
   used to flip them only on <768px, which left BOTH inline by default
   on desktop → "ВиконаноВиконано". Hide short by default; show on
   mobile breakpoint. */
.od-badge-short { display: none; }
.od-sec button,
.od-sec a,
.od-sec [onclick],
.od-sec input,
.od-sec select,
.od-sec textarea {
  position: relative;
  z-index: 2;
  pointer-events: auto;
}
.od-badge {
  display: inline-block;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.od-contact-btn {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
}
.od-icon-btn {
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.od-prod-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}

/* Desktop: treat <details> like plain sections (always expanded, no arrow) */
@media (min-width: 768px) {
  .od-collapse > summary {
    list-style: none;
    cursor: default;
    pointer-events: none;
  }
  .od-collapse > summary::-webkit-details-marker { display: none; }
  .od-collapse > summary .od-collapse-arrow { display: none; }
  .od-collapse > summary .od-lbl { margin-bottom: 0; }
  /* Force body visible regardless of [open] — but skip the mobile-only
     card blocks, otherwise this !important rule wins over the hide rule
     below and products/payments render twice (table + cards). */
  details.od-collapse > *:not(summary):not(.od-products-mobile):not(.od-payments-mobile) {
    display: block !important;
  }
  /* Hide mobile-only card blocks on desktop */
  .od-products-mobile, .od-payments-mobile { display: none !important; }
}

/* Mobile — the real collapse + compact layout */
@media (max-width: 1023px) {
  /* Flex column lets us re-order sections on mobile without touching HTML.
     Header + 3-col grid pinned on top, then CF + Docs (quickly needed),
     then the remaining sections fall into source order. */
  .order-detail-wrap { display: flex; flex-direction: column; }
  .od-hdr { order: -10; }
  .od-grid { order: -9; }
  .od-cf-section { order: -2; }
  .od-docs-section { order: -1; }
  .od-back-label { display: none; }
  .od-grid { grid-template-columns: 1fr !important; }
  .od-col {
    border-right: none !important;
    border-bottom: 0.5px solid var(--border);
  }
  .od-col:last-child { border-bottom: none; }
  .od-title { font-size: 16px; }
  .od-sec { padding: 12px 14px; }
  .od-hdr { padding: 10px 12px; gap: 6px; }
  .od-hdr-row { gap: 6px; }
  .od-status-badge, .od-pay-badge { max-width: 140px; }
  .od-badge-full { display: none; }
  .od-badge-short { display: inline; }
  .od-meta {
    font-size: 11px;
    white-space: normal;
    width: 100%;
    overflow: visible;
    text-overflow: clip;
  }
  .od-prod-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
  }
  /* Collapsible summary look */
  .od-collapse > summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    user-select: none;
    min-height: 44px;
  }
  .od-collapse > summary::-webkit-details-marker { display: none; }
  .od-collapse > summary .od-lbl { margin-bottom: 0; }
  .od-collapse-arrow {
    font-size: 20px;
    color: var(--text-muted);
    transform: rotate(90deg);
    transition: transform 0.15s ease;
  }
  .od-collapse:not([open]) > summary .od-collapse-arrow {
    transform: rotate(0deg);
  }
  /* Mobile product / payment cards */
  .od-products-desktop, .od-payments-desktop { display: none; }
  .od-products-mobile { display: flex; flex-direction: column; gap: 8px; }
  .od-prod-card {
    display: flex;
    gap: 10px;
    padding: 10px;
    background: var(--bg-primary);
    border-radius: 10px;
    border: 0.5px solid var(--border);
  }
  .od-prod-photo {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
  }
  .od-prod-photo-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card-solid);
    font-size: 22px;
  }
  .od-prod-body { flex: 1; min-width: 0; }
  .od-prod-name {
    font-weight: 700;
    font-size: 13px;
    color: var(--text-primary);
    word-break: break-word;
  }
  .od-prod-sku { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
  .od-prod-comment {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    word-break: break-word;
  }
  .od-prod-pricing {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-top: 6px;
    font-size: 13px;
  }
  .od-prod-pricing b { font-weight: 700; color: var(--text-primary); }
  .od-payments-mobile { display: flex; flex-direction: column; gap: 8px; }
  .od-pay-card {
    padding: 10px;
    background: var(--bg-primary);
    border-radius: 10px;
    border: 0.5px solid var(--border);
  }
  .od-pay-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
  }
  .od-pay-method { font-size: 12px; color: var(--text-secondary); }
  .od-pay-amount { font-size: 15px; font-weight: 700; color: var(--text-primary); }
  .od-pay-bot {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-top: 4px;
    font-size: 11px;
  }
  .od-pay-date { color: var(--text-muted); }
  /* Follow-up form stacks vertically */
  .od-fu-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 6px;
  }
  .od-fu-form .od-fu-text,
  .od-fu-form .od-fu-due { width: 100%; }
  .od-fu-form .od-fu-add { width: 100%; min-height: 44px; }
  /* Bottom bar: adjust to 4 columns (Back + 3 actions) */
  .order-detail-bottombar {
    grid-template-columns: 1.2fr 1fr 1fr 1fr !important;
  }
  .order-detail-bottombar .odb-back {
    background: var(--bg-primary);
    color: var(--text-primary);
    font-weight: 600;
  }
}

/* Follow-up form — desktop inline */
@media (min-width: 768px) {
  .od-fu-form {
    display: flex;
    gap: 6px;
    margin-top: 6px;
  }
  .od-fu-form .od-fu-text {
    flex: 1;
    padding: 6px 8px;
    border: 0.5px solid var(--border-input);
    border-radius: 6px;
    font-size: 12px;
    box-sizing: border-box;
  }
  .od-fu-form .od-fu-due {
    padding: 6px 8px;
    border: 0.5px solid var(--border-input);
    border-radius: 6px;
    font-size: 12px;
  }
  .od-fu-form .od-fu-add {
    padding: 6px 10px;
    font-size: 11px;
    white-space: nowrap;
    border: 0.5px solid var(--border-input);
    border-radius: 6px;
    background: var(--bg-card-solid);
    color: var(--text-placeholder);
    cursor: pointer;
  }
}
@media (max-width: 1023px) {
  .od-fu-form .od-fu-text,
  .od-fu-form .od-fu-due {
    padding: 10px 12px;
    border: 0.5px solid var(--border-input);
    border-radius: 8px;
    font-size: 13px;
    box-sizing: border-box;
    min-height: 44px;
  }
  .od-fu-form .od-fu-add {
    padding: 10px 14px;
    border: 0.5px solid var(--accent);
    border-radius: 8px;
    background: var(--accent-light);
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
  }
}

/* ===== ORDER PAYMENTS (linked bank tx + suggestions) ===== */
.od-pay-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  padding: 10px 12px;
  background: var(--bg-primary);
  border-radius: 10px;
  margin-bottom: 10px;
}
.od-pay-sum-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 110px;
}
.od-pay-sum-lbl {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.od-pay-actions-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}
.od-pay-add-btn {
  padding: 9px 14px;
  border-radius: 10px;
  border: 0.5px solid var(--accent);
  background: var(--accent-light);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
}
.od-pay-linked {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.od-pay-item,
.od-pay-suggest-item {
  padding: 10px 12px;
  background: var(--bg-card-solid);
  border: 0.5px solid var(--border);
  border-radius: 10px;
}
.od-pay-item-top,
.od-pay-suggest-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.od-pay-date { font-size: 12px; color: var(--text-muted); min-width: 58px; }
.od-pay-account { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.od-pay-amount { margin-left: auto; font-size: 14px; color: var(--success-text); white-space: nowrap; }
.od-pay-src {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}
.od-pay-src-bank { background: #dbeafe; color: #1d4ed8; }
.od-pay-src-manual { background: #fef3c7; color: #92400e; }
.od-pay-unlink {
  background: none;
  border: 0.5px solid var(--border);
  border-radius: 6px;
  color: var(--danger-text);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  min-width: 32px;
  min-height: 32px;
}
.od-pay-unlink:hover { background: var(--danger-bg); }
.od-pay-comment {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
  word-break: break-word;
}

.od-pay-suggest-section { margin-top: 14px; }
.od-pay-suggest-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.od-pay-suggest-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.od-pay-suggest-item {
  background: #fafafa;
}
.od-pay-suggest-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
}
.od-pay-link-btn {
  padding: 9px 14px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  min-height: 40px;
}
.od-pay-link-btn:disabled { opacity: 0.5; cursor: wait; }
.od-pay-score {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}
.od-pay-score-high { background: #dcfce7; color: #15803d; }
.od-pay-score-mid  { background: #fef3c7; color: #92400e; }
.od-pay-score-low  { background: #f1f5f9; color: #64748b; }

/* Payment modal (manual entry + bank search tabs) */
.od-pay-modal { padding: 4px; }
.od-pay-tabs {
  display: flex;
  gap: 6px;
  border-bottom: 0.5px solid var(--border);
  margin-bottom: 12px;
}
.od-pay-tab {
  flex: 1;
  padding: 10px 12px;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  min-height: 44px;
}
.od-pay-tab-active { color: var(--accent); border-bottom-color: var(--accent); }
.od-pay-tab-body { max-height: 60vh; overflow-y: auto; }
.od-pay-fop-note {
  padding: 8px 10px;
  background: #f0fdf4;
  color: #065f46;
  border: 0.5px solid #10b98140;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 10px;
}
.od-pay-fop-chip {
  display: inline-block;
  background: #d1fae5;
  color: #065f46;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  margin-left: 6px;
  vertical-align: middle;
}
.od-pay-search-input {
  width: 100%;
  padding: 10px 12px;
  border: 0.5px solid var(--border-input);
  border-radius: 10px;
  font-size: 14px;
  box-sizing: border-box;
  margin-bottom: 10px;
  min-height: 44px;
}
.od-pay-modal-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.od-pay-label {
  display: block;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 10px;
}
.od-pay-label input,
.od-pay-label select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 0.5px solid var(--border-input);
  border-radius: 8px;
  font-size: 14px;
  box-sizing: border-box;
  min-height: 44px;
  background: var(--bg-input, var(--bg-primary));
}
.od-pay-save-btn {
  flex: 1;
  padding: 12px;
  background: var(--btn-primary-bg);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
}
.od-pay-cancel-btn {
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-secondary);
  min-height: 48px;
}

@media (max-width: 1023px) {
  .od-pay-item-top,
  .od-pay-suggest-top { gap: 6px; }
  .od-pay-date { min-width: auto; }
  .od-pay-amount { font-size: 13px; }
  .od-pay-suggest-actions .od-pay-link-btn { width: 100%; }
}

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge-overdue { background: var(--badge-red-bg); color: var(--badge-red-text); }
.badge-today { background: var(--badge-gold-bg); color: var(--badge-gold-text); }
.badge-ok { background: var(--badge-green-bg); color: var(--badge-green-text); }
.badge-new { background: var(--badge-blue-bg); color: var(--badge-blue-text); }
.badge-production { background: var(--badge-gold-bg); color: var(--badge-gold-text); }
.badge-done { background: var(--badge-green-bg); color: var(--badge-green-text); }
.badge-shipped { background: var(--badge-gray-bg); color: var(--badge-gray-text); }

/* ===== PLACEHOLDER ===== */
.placeholder {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-placeholder);
}

.placeholder .icon { font-size: 60px; margin-bottom: 16px; }
.placeholder p { font-size: 14px; }

/* ===== MOBILE SIDEBAR (hamburger) ===== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 300;
}
.sidebar-overlay.open { display: block; }

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: min(320px, calc(100vw - 40px));
  height: 100%;
  background: var(--bg-card-solid);
  z-index: 301;
  transform: translateX(-100%);
  transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  will-change: transform;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
}
.sidebar.open { transform: translateX(0); }

.sidebar-header {
  padding: 16px 20px 12px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-round);
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 16px;
  font-weight: 600;
}

.sidebar-name { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.sidebar-role { font-size: 11px; color: var(--text-muted); }

.sidebar-close {
  width: 44px; height: 44px;
  border: none; background: var(--bg-active);
  border-radius: var(--radius-round); cursor: pointer;
  font-size: 16px; color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all var(--duration-fast) var(--ease-default);
  outline: none;
}
.sidebar-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: scale(1.05);
}
.sidebar-close:active {
  background: var(--bg-active);
  transform: scale(0.95);
}
.sidebar-close:focus-visible {
  background: var(--bg-hover);
  box-shadow: 0 0 0 2px var(--accent);
  outline: none;
}

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }

.sidebar-section {
  padding: 12px 16px 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ===== SIDEBAR ACCORDION GROUPS ===== */
.sb-group { }

.sb-group-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 20px;
  min-height: 48px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: left;
  transition: all var(--duration-fast) var(--ease-default);
  gap: 8px;
  outline: none;
  border-radius: 0;
  margin: 2px 0;
}
.sb-group-hdr:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  transform: translateX(2px);
}
.sb-group-hdr:hover .mob-icon { background: var(--accent); color: #fff; }
.sb-group-hdr:focus-visible {
  background: var(--bg-hover);
  box-shadow: inset 3px 0 0 var(--accent);
  outline: none;
}
.sb-group.open .sb-group-hdr {
  color: var(--accent);
}
.sb-group.open .sb-group-hdr .mob-icon { background: var(--accent); color: #fff; }

.sb-group-hdr > span:first-child {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sb-arrow {
  font-size: 16px;
  font-weight: 400;
  line-height: 1;
  transition: transform 0.2s ease;
  display: inline-block;
  color: var(--text-muted);
}
.sb-group.open .sb-arrow { transform: rotate(90deg); color: var(--accent); }

.sb-group-body {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease;
}
.sb-group.open .sb-group-body { max-height: 600px; }

/* Improved hover feedback for mobile */
@media (hover: hover) {
  .sb-group-hdr:hover {
    background: var(--bg-hover);
    transform: translateX(2px);
  }
  .sb-group-hdr:hover .sb-arrow {
    color: var(--accent);
    transform: scale(1.1);
  }
}

/* Focus ring for better accessibility */
.sb-group-hdr:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Sub-items in accordion are slightly indented */
.sb-group-body .sidebar-item {
  padding-left: 64px;
  font-size: 13.5px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  min-height: 48px;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: 0;
  margin: 2px 0;
  transition: all var(--duration-fast) var(--ease-default);
  /* Accessibility improvements */
  outline: none;
  position: relative;
}
.sidebar-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  transform: translateX(2px);
}
.sidebar-item:active {
  background: var(--bg-active);
  transform: translateX(1px);
}
.sidebar-item:focus-visible {
  background: var(--bg-hover);
  box-shadow: inset 3px 0 0 var(--accent);
  outline: none;
}
.sidebar-item.active {
  color: var(--accent);
  background: var(--accent-light);
  box-shadow: inset 3px 0 0 var(--accent);
}
.sidebar-item.active .mob-icon { background: var(--accent); color: white; }
.sidebar-item .s-icon { font-size: 20px; width: 28px; text-align: center; }

/* Flat-list items (manager / production) use a larger hit area + slight tint when active */
.sidebar-item-flat {
  padding: 16px 20px;
  min-height: 52px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  margin: 3px 8px;
}
.sidebar-item-flat:hover {
  background: var(--bg-hover);
  transform: translateX(2px);
}
.sidebar-item-flat:focus-visible {
  background: var(--bg-hover);
  box-shadow: 0 0 0 2px var(--accent);
  outline: none;
}
.sidebar-item-flat .sidebar-item-label { flex: 1; min-width: 0; }

.mob-icon {
  width: 32px;
  height: 32px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--duration-fast) var(--ease-default), color var(--duration-fast) var(--ease-default);
}
.mob-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  flex-shrink: 0;
}
.sidebar-item.active .mob-icon svg { stroke: #fff; }
.sidebar-logout .mob-icon svg { width: 16px; height: 16px; stroke: currentColor; }

.sidebar-footer {
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-logout {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  background: var(--bg-primary);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--danger-text);
  cursor: pointer;
}
.sidebar-logout:active { background: var(--danger-bg); }
.sidebar-logout .mob-icon {
  background: var(--danger-bg);
  color: var(--danger-text);
  font-size: 14px;
}
.sidebar-version {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  letter-spacing: 0.03em;
}

/* ===== ICON SIDEBAR (desktop) ===== */
.icon-sidebar {
  width: 72px !important;
  min-width: 72px !important;
  height: 100vh;
  background: rgba(255,255,255,0.94);
  border-right: 0.5px solid var(--border);
  display: flex !important;
  flex-direction: column;
  align-items: center;
  padding: 0;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 200;
  flex-shrink: 0;
  overflow: visible;
  transform: translateZ(0);
}

.icon-sidebar-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 100%;
  padding: 8px 0;
  overflow-y: auto;
  gap: 2px;
}

.isb-logo {
  padding: 12px 0 8px;
  display: flex;
  justify-content: center;
  width: 100%;
}

.isb-logo img {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.isb-item {
  width: 100%;
  position: relative;
}

.isb-btn {
  width: calc(100% - 12px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 4px;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-lg);
  transition: background var(--duration-fast) var(--ease-default);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  text-decoration: none;
  margin: 0 6px;
}

.isb-btn:hover {
  background: var(--bg-hover);
  color: var(--accent);
}

.isb-btn.active {
  background: var(--accent-light);
  color: var(--accent);
}

.isb-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: transparent;
  transition: background var(--duration-fast) var(--ease-default);
}

.isb-btn.active .isb-icon {
  background: var(--accent-light);
}

.isb-btn:hover .isb-icon {
  background: var(--bg-hover);
}

.isb-label {
  font-size: 10px;
  font-weight: 500;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  display: block !important;
  color: inherit;
}

.isb-submenu { display: none !important; }
.isb-spacer { flex: 1; }

.isb-user-info {
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
}

.isb-user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-round);
  background: var(--accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  border: 1.5px solid var(--border-md);
}

/* ===== DESKTOP LAYOUT ===== */
@media (min-width: 1024px) {
  .sidebar-overlay { display: none !important; }

  /* Show icon sidebar by default on desktop */
  .icon-sidebar {
    display: flex !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 72px !important;
    height: 100vh !important;
    z-index: 150 !important;
  }

  /* Hide desktop toggle button */
  .desktop-sidebar-toggle { display: none !important; }

  /* Hide full sidebar on desktop - only show icon sidebar */
  .sidebar {
    display: none !important;
  }

  .sidebar.open {
    display: none !important;
  }

  /* Hide mobile close button */
  .sidebar-close { display: none !important; }

  /* Desktop sidebar styling improvements */
  .sidebar-header {
    padding: 20px 24px 16px !important;
    border-bottom: 1px solid var(--border-light) !important;
    background: rgba(248, 250, 252, 0.8) !important;
  }

  .sidebar-user {
    gap: 12px !important;
  }

  .sidebar-avatar {
    width: 44px !important;
    height: 44px !important;
    font-size: 18px !important;
  }

  .sidebar-name {
    font-size: 16px !important;
    font-weight: 600 !important;
  }

  .sidebar-role {
    font-size: 12px !important;
    opacity: 0.8 !important;
  }

  /* Desktop navigation styling */
  .sidebar-nav {
    padding: 16px 0 !important;
  }

  .sb-group-hdr {
    padding: 16px 24px !important;
    min-height: 56px !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    border-radius: 0 !important;
  }

  .sb-group-hdr:hover {
    background: rgba(37, 99, 235, 0.08) !important;
    transform: none !important;
    border-left: 3px solid var(--accent) !important;
    padding-left: 21px !important;
  }

  .sb-group.open .sb-group-hdr {
    background: rgba(37, 99, 235, 0.12) !important;
    border-left: 3px solid var(--accent) !important;
    padding-left: 21px !important;
  }

  .sb-group-body .sidebar-item {
    padding-left: 56px !important;
    font-size: 14px !important;
    min-height: 48px !important;
  }

  .sidebar-item {
    padding: 14px 24px !important;
    min-height: 52px !important;
    font-size: 15px !important;
    font-weight: 500 !important;
    margin: 1px 8px !important;
    border-radius: 8px !important;
  }

  .sidebar-item:hover {
    background: rgba(37, 99, 235, 0.08) !important;
    transform: none !important;
    color: var(--accent) !important;
  }

  .sidebar-item.active {
    background: rgba(37, 99, 235, 0.15) !important;
    color: var(--accent) !important;
    font-weight: 600 !important;
    box-shadow: none !important;
    border-left: 3px solid var(--accent) !important;
    margin-left: 5px !important;
    padding-left: 21px !important;
  }

  .mob-icon {
    width: 36px !important;
    height: 36px !important;
    border-radius: 8px !important;
  }

  .mob-icon svg {
    width: 20px !important;
    height: 20px !important;
  }

  /* Desktop footer */
  .sidebar-footer {
    padding: 16px 24px calc(16px + env(safe-area-inset-bottom, 0px)) !important;
    border-top: 1px solid var(--border-light) !important;
    background: rgba(248, 250, 252, 0.6) !important;
  }

  .sidebar-logout {
    padding: 12px 16px !important;
    font-size: 15px !important;
    border-radius: 8px !important;
    margin: 0 !important;
  }

  /* Layout with icon sidebar only (72px) */
  .app-header {
    left: 72px !important;
    padding-left: 20px !important;
  }

  .page {
    margin-left: 72px !important;
  }

  .period-selector {
    left: 72px !important;
  }

  /* Hide desktop sidebar overlay */
  .desktop-sidebar-overlay {
    display: none !important;
  }

  /* Icon sidebar styling improvements */
  .icon-sidebar {
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(20px) !important;
    -webkit-backdrop-filter: blur(20px) !important;
    border-right: 1px solid var(--border) !important;
  }

  /* Make icon buttons clickable for expansion */
  .isb-btn {
    transition: all 0.2s ease !important;
  }

  .isb-btn:hover {
    background: var(--bg-hover) !important;
    color: var(--accent) !important;
    transform: scale(1.05) !important;
  }
}

@media (max-width: 1023px) {
  .icon-sidebar { display: none !important; }
  .app-header { left: 0 !important; }
  .main-content { margin-left: 0 !important; }
  .page { margin-left: 0 !important; }

  /* Ensure sidebar is visible on mobile and positioned correctly */
  .sidebar {
    display: flex !important;
    transform: translateX(-100%) !important;
    z-index: 1000 !important;
  }
  .sidebar.open {
    transform: translateX(0) !important;
    z-index: 1000 !important;
  }
  .sidebar-toggle {
    display: flex !important;
  }
  .sidebar-overlay {
    display: none; /* Hidden by default, shown with .open class */
  }
  .sidebar-overlay.open {
    display: block !important;
  }
  #page-ai { height: calc(100vh - 56px - env(safe-area-inset-top, 0px)) !important; margin-top: calc(56px + env(safe-area-inset-top, 0px)) !important; }

  .sidebar-header {
    padding: 16px 20px;
    justify-content: space-between;
  }
  .sidebar-user { gap: 10px; }
  .sidebar-name, .sidebar-role, .sidebar-section { opacity: 1 !important; white-space: normal; }
  .sidebar-item {
    padding: 11px 20px;
    justify-content: flex-start;
  }
  .sidebar-item span { opacity: 1 !important; width: auto !important; overflow: visible !important; }
  .sidebar-icon { font-size: 22px; flex-shrink: 0; }
  .app-header {
    padding-left: 16px !important;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    background: rgba(255,255,255,0.96);
  }
}

/* Sidebar toggle */
.sidebar-toggle {
  position: relative;
  width: 44px;
  height: 44px;
  background: var(--bg-card);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  color: var(--text-primary);
  transition: all var(--duration-fast) var(--ease-default);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  outline: none;
  box-shadow: var(--shadow-xs);
}

.sidebar-toggle:hover {
  background: var(--bg-hover);
  transform: scale(1.05);
  box-shadow: var(--shadow-sm);
}

.sidebar-toggle:active {
  transform: scale(0.95);
  background: var(--bg-active);
}

.sidebar-toggle:focus-visible {
  box-shadow: 0 0 0 2px var(--accent);
  outline: none;
}

/* Hamburger menu animation */
.hamburger-icon {
  transition: transform var(--duration-fast) var(--ease-default);
}

.hamburger-icon line {
  transition: all var(--duration-normal) var(--ease-default);
  transform-origin: center;
}

/* Hamburger icon animation when sidebar is open */
.sidebar-toggle.open .hamburger-icon .line-1 {
  transform: translate(0, 6px) rotate(45deg);
}

.sidebar-toggle.open .hamburger-icon .line-2 {
  opacity: 0;
}

.sidebar-toggle.open .hamburger-icon .line-3 {
  transform: translate(0, -6px) rotate(-45deg);
}
.sidebar-toggle.visible { display: flex; }

@media (max-width: 1023px) {
  .sidebar-toggle { display: flex !important; }
}

/* ===== ISB FLOATING POPUP ===== */
.isb-dropdown {
  display: none;
  position: fixed;
  left: 72px;
  top: 0;
  z-index: 9999;
  background: var(--bg-card-solid);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 180px;
  padding: 8px 0;
  flex-direction: column;
}
.isb-dropdown.open {
  display: flex;
}
.isb-dropdown-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 16px 8px;
  border-bottom: 0.5px solid var(--border);
  margin-bottom: 4px;
}
.isb-drop-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 16px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: left;
  width: 100%;
  border-radius: 0;
  transition: background var(--duration-fast) var(--ease-default), color var(--duration-fast) var(--ease-default);
}
.isb-drop-item:hover {
  background: var(--bg-hover);
  color: var(--accent);
}
.isb-drop-item svg {
  flex-shrink: 0;
  opacity: 0.6;
}

/* ===== MOBILE BOTTOM NAV ===== */
.mobile-bottom-nav {
  display: none;
}
@media (max-width: 1023px) {
  .mobile-bottom-nav {
    display: flex;
    position: fixed;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    left: 12px;
    right: 12px;
    background: rgba(255,255,255,0.96);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-pill);
    z-index: 300;
    box-shadow: var(--shadow-lg);
    padding: 4px 0;
    transform: translateZ(0);
  }
  .mbn-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 4px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 500;
    border-radius: var(--radius-xl);
    transition: color var(--duration-fast) var(--ease-default);
  }
  .mbn-item.active, .mbn-item:active {
    color: var(--accent);
  }
  .mbn-item svg { stroke: currentColor; }
  .mbn-popup {
    display: none;
    position: fixed;
    bottom: 80px;
    left: 12px;
    right: 12px;
    background: var(--bg-card-solid);
    border: 0.5px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    z-index: 400;
    padding: 8px 0;
    flex-direction: column;
  }
  .mbn-popup.open { display: flex; }
  .mbn-popup-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 6px 16px 8px;
    border-bottom: 0.5px solid var(--border);
    margin-bottom: 4px;
  }
  .mbn-popup-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 16px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: left;
    width: 100%;
    transition: background var(--duration-fast) var(--ease-default);
  }
  .mbn-popup-item:hover { background: var(--bg-hover); color: var(--accent); }
  .mbn-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 350;
    background: rgba(0,0,0,0.15);
  }
  .mbn-overlay.open { display: block; }
  .main-content { padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
}

.main-content {
  flex: 1;
  min-width: 0;
  overflow-x: hidden;
  padding-top: 0;
}

/* ===== TRAINING MOBILE ===== */
@media (max-width: 1023px) {
  .training-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ===== AI streaming cursor ===== */
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }
.ai-cursor::after {
  content: '\25CB';
  display: inline-block;
  animation: blink 0.8s infinite;
  color: var(--accent);
  font-size: 12px;
  margin-left: 2px;
}

/* ===== Utility classes ===== */
.u-label { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; font-weight: 500 }
.u-label-sm { font-size: 10px; color: var(--text-muted) }
.u-label-dark { font-size: 11px; color: var(--text-secondary); margin-bottom: 4px }
.u-section-title { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.03em }
.u-section-title-sm { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px }
.u-empty { text-align: center; padding: 20px; color: var(--text-muted) }
.u-empty-sm { text-align: center; color: var(--text-muted); padding: 16px }
.u-card { background: var(--bg-card); border-radius: var(--radius-lg); padding: 12px; border: 0.5px solid var(--border); box-shadow: var(--shadow-xs) }
.u-card-lg { background: var(--bg-card); border-radius: var(--radius-lg); padding: 12px; margin-bottom: 14px; border: 0.5px solid var(--border); box-shadow: var(--shadow-xs) }
.u-card-center { background: var(--bg-card); border-radius: var(--radius-lg); padding: 10px; text-align: center; border: 0.5px solid var(--border); box-shadow: var(--shadow-xs) }
.u-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px }
.u-row-between { display: flex; justify-content: space-between }
.u-input { width: 100%; padding: 10px 12px; border: 0.5px solid var(--border-input); border-radius: var(--radius-md); font-size: 14px; outline: none; background: var(--bg-input); color: var(--text-primary); transition: border-color var(--duration-fast) var(--ease-default) }
.u-input:focus { border-color: var(--accent) }
.u-input-sm { width: 100%; border: 0.5px solid var(--border-input); border-radius: var(--radius-md); padding: 8px 10px; font-size: 14px; font-weight: 500; box-sizing: border-box; background: var(--bg-input) }
.u-btn-primary { width: 100%; padding: 12px; background: var(--btn-primary-bg); color: var(--btn-primary-text); border: none; border-radius: var(--radius-md); font-size: 14px; font-weight: 600; cursor: pointer; transition: opacity var(--duration-fast) var(--ease-default) }
.u-btn-primary:hover { opacity: 0.85 }
.u-btn-close { border: none; background: none; color: var(--text-muted); cursor: pointer; font-size: 16px; padding: 0 }
.u-success { text-align: center; background: var(--success-bg); border-radius: var(--radius-md); padding: 10px }
.u-warning { text-align: center; background: var(--warning-bg); border-radius: var(--radius-md); padding: 10px }
.u-danger { text-align: center; background: var(--danger-bg); border-radius: var(--radius-md); padding: 10px }
.u-danger-row { background: var(--danger-bg); border-radius: var(--radius-md); padding: 10px; margin-bottom: 6px; border: 0.5px solid #fecaca }
.u-value-green { font-size: 22px; font-weight: 600; color: var(--success-text); letter-spacing: var(--tracking-tight) }
.u-page-wrap { padding: 16px; max-width: 900px; margin: 0 auto }
.u-p4 { padding: 4px }
.u-mb6 { margin-bottom: 6px }
.u-mb8 { margin-bottom: 8px }
.u-mb12 { margin-bottom: 12px }
.u-mb16 { margin-bottom: 16px }
.u-right { text-align: right }
.u-center { text-align: center }

/* Kanban board — desktop */
@media (min-width: 768px) {
  .kanban-board {
    overflow-x: auto !important;
    overflow-y: visible !important;
    scrollbar-width: none !important;
  }
  .kanban-board::-webkit-scrollbar {
    display: none !important;
  }
  .kanban-col {
    overflow-y: visible;
    overflow-x: hidden;
    height: auto;
  }
}

/* Kanban board — mobile. The mobile bottom-nav is cleared globally by
   .main-content { padding-bottom: 80px + safe-area }, so the per-column
   padding only needs a small amount of breathing room under the last card.
   Previous 100px rule doubled up with .main-content and left a ~180px gap. */
@media (max-width: 1023px) {
  .kanban-drop-zone {
    padding-bottom: 16px !important;
  }
}

/* Kanban filter button — show text on desktop, icon only on mobile
   (saves ~70px so it fits beside the search input on 360px screens). */
.kanban-filter-icon { display: inline; }
.kanban-filter-label { display: inline; }
@media (max-width: 1023px) {
  .kanban-filter-btn { min-width: 44px; padding: 0 10px !important; }
  .kanban-filter-label { display: none; }
  .kanban-filter-icon { font-size: 16px; }
}

/* Kanban stage-jump dropdown — mobile-only. On desktop all columns are
   visible via horizontal scroll; on mobile each column is 86vw so users
   would have to swipe ~10x to reach the rightmost column otherwise. */
.kanban-stage-select {
  display: none;
  flex-shrink: 0;
  max-width: 140px;
  min-height: 44px;
  padding: 0 28px 0 10px;
  border-radius: 12px;
  border: 1.5px solid #e2e8f0;
  background: white;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23808080' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px 12px;
  outline: none;
}
.kanban-stage-select:focus { border-color: var(--accent); }
@media (max-width: 1023px) {
  .kanban-stage-select { display: inline-block; }
}

/* Desktop column width restored via CSS (the old inline
   width:min(calc(100vw - 56px), 300px) doesn't apply on mobile because the
   icon-sidebar isn't there). Mobile gets a wider column + less next-column
   peek so cards don't feel cropped. */
.kanban-col {
  width: 300px;
}
@media (max-width: 1023px) {
  .kanban-col {
    width: 86vw;
    min-width: 86vw;
    max-width: 86vw;
  }
  /* Board padding tightened on mobile so the first column isn't hiding
     behind a 20px left gutter. */
  .kanban-board {
    padding-left: 12px !important;
    padding-right: 12px !important;
    /* Scroll-snap each column into view — one column per swipe */
    scroll-snap-type: x mandatory;
  }
  .kanban-col { scroll-snap-align: start; }
}

/* Kanban card: allow content wrapping, reserve right padding for the
   absolute ⋮ button so the deadline text never collides with it. */
.kanban-card {
  position: relative;
  word-break: break-word;
  overflow-wrap: anywhere;
}
@media (max-width: 1023px) {
  .kanban-card { padding-right: 40px !important; }
}

/* Kanban card "⋮" move button — tap-to-move fallback for mobile.
   Hidden on desktop (drag-and-drop is reliable there). */
.kanban-move-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 2;
}
.kanban-move-btn:active { background: var(--bg-hover); }
@media (max-width: 1023px) {
  .kanban-move-btn { display: inline-flex; }
}

/* Move-stage modal */
.kanban-move-modal { padding: 4px; }
.kanban-move-current {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding: 0 4px;
}
.kanban-move-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 60vh;
  overflow-y: auto;
}
.kanban-move-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  min-height: 48px;
  background: var(--bg-primary);
  border: 0.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
}
.kanban-move-row:active { background: var(--bg-hover); }
.kanban-move-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.kanban-move-name { flex: 1; min-width: 0; }
.kanban-move-count {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-card-solid);
  border-radius: 10px;
  padding: 2px 8px;
}

/* ===== Apple-style global overrides ===== */
input, select, textarea, button {
  font-family: var(--font-family);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.25);
}

/* Selection color */
::selection {
  background: var(--accent-light);
  color: var(--text-primary);
}

/* ===== Blog page responsive ===== */
.blog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 10px;
}
.blog-gen-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.blog-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.blog-main-grid {
  display: grid;
  grid-template-columns: 1fr 460px;
  gap: 20px;
  align-items: start;
}
.blog-main-grid.blog-seo {
  grid-template-columns: 1fr;
}
.blog-article-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.blog-article-row .blog-article-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

@media (max-width: 1023px) {
  .blog-header { flex-wrap: wrap; }
  .blog-header button { width: 100%; justify-content: center; }
  .blog-gen-grid { grid-template-columns: 1fr !important; }
  .blog-gen-grid > div[style*="grid-column:span 2"],
  .blog-gen-grid > div[style*="grid-column: span 2"] { grid-column: span 1 !important; }
  .blog-main-grid { grid-template-columns: 1fr !important; }
  .blog-article-row { flex-wrap: wrap; }
  .blog-article-row .blog-article-actions { width: 100%; justify-content: flex-end; }
}


/* ============================================================
   Grants Module
   ============================================================ */
.grants-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin: 12px 0 20px; }
.grants-stat-card { background: var(--bg-card); border-radius: 12px; padding: 16px; text-align: center; border: 1px solid var(--border); }
.grants-stat-value { font-size: 28px; font-weight: 700; color: var(--accent); }
.grants-stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.grants-stat-new .grants-stat-value { color: #fd7e14; }
.grants-stat-urgent .grants-stat-value { color: #dc3545; }
.grants-stat-won .grants-stat-value { color: #198754; }

.grants-toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; padding: 0 12px; }
.grants-search { flex: 1; min-width: 200px; padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-card-solid, #fff); color: var(--text-primary, #1d1d1f); }
.grants-filter-select { padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-card-solid, #fff); color: var(--text-primary, #1d1d1f); }
.grants-btn { padding: 8px 16px; border-radius: 8px; border: none; cursor: pointer; font-size: 14px; font-weight: 600; }
.grants-btn-primary { background: var(--accent); color: #fff; }
.grants-btn-secondary { background: var(--bg-card); color: var(--text-primary, #1d1d1f); border: 1px solid var(--border); }

.grants-table { width: 100%; border-collapse: collapse; background: var(--bg-card); border-radius: 12px; overflow: hidden; }
.grants-table th { padding: 10px 12px; text-align: left; font-size: 12px;
  color: var(--text-muted); border-bottom: 1px solid var(--border); }
.grants-table td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.grants-row { cursor: pointer; transition: background 0.15s; }
.grants-row:hover { background: var(--accent-light); }
.grants-row-new { background: rgba(160,140,100,0.04); }
.grants-title-cell { max-width: 300px; font-weight: 500; }
.grant-new-dot { display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent); margin-right: 6px; vertical-align: middle; }

.grant-badge { padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.grant-badge-urgent { background: #dc354520; color: #dc3545; }
.grant-badge-soon { background: #fd7e1420; color: #fd7e14; }
.grant-badge-ok { background: #19875420; color: #198754; }
.grant-badge-expired { background: #6c757d20; color: #6c757d; }
.grant-status-badge { padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; white-space: nowrap; }

/* Grant cards (mobile) */
.grant-card { background: var(--bg-card); border-radius: 12px; padding: 14px;
  margin: 0 12px 10px; cursor: pointer; border: 1px solid var(--border); }
.grant-card-new { border-left: 3px solid var(--accent); }
.grant-card-header { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.grant-card-title { font-weight: 600; font-size: 14px; margin-bottom: 8px; line-height: 1.4; }
.grant-card-meta { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; flex-wrap: wrap; }

.grants-loading, .grants-empty { padding: 40px 20px; text-align: center; color: var(--text-muted); }

/* Detail panel */
.grants-detail { position: fixed; top: 0; right: -100%; width: min(480px, 100vw); height: 100vh;
  background: var(--bg-card-solid, #fff); z-index: 1001; overflow-y: auto; transition: right 0.3s ease;
  box-shadow: -4px 0 24px rgba(0,0,0,0.2); padding: 20px; }
.grants-detail-open { right: 0 !important; }
.grants-detail-header { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.grants-detail-close { background: none; border: none; font-size: 20px; cursor: pointer;
  color: var(--text-muted); padding: 4px; min-width: 32px; }
.grants-detail-header h2 { flex: 1; font-size: 16px; line-height: 1.4; margin: 0; }
.grants-detail-section { background: var(--bg-card); border-radius: 12px; padding: 16px; margin-bottom: 12px; border: 1px solid var(--border); }
.grants-detail-section h4 { margin: 0 0 10px; font-size: 13px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.grants-detail-row { display: flex; justify-content: space-between; padding: 8px 0;
  border-bottom: 1px solid var(--border); font-size: 13px; gap: 12px; }
.grants-detail-row:last-child { border-bottom: none; }
.grants-detail-label { color: var(--text-muted); }
.grants-link { color: var(--accent); text-decoration: none; }
.grants-description { font-size: 13px; line-height: 1.6; color: var(--text-primary, #1d1d1f); white-space: pre-wrap; margin: 0; }
.grants-status-buttons { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.grants-status-btn { padding: 6px 12px; border-radius: 20px; border: 1px solid var(--border);
  cursor: pointer; font-size: 12px; background: var(--bg-card-solid, #fff); color: var(--text-primary, #1d1d1f); transition: all 0.2s; }
.grants-status-btn.active { font-weight: 600; }
.grants-note-input { width: 100%; min-height: 80px; padding: 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-card-solid, #fff); color: var(--text-primary, #1d1d1f);
  font-size: 13px; resize: vertical; box-sizing: border-box; }
.grants-reminder-input { padding: 8px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-card-solid, #fff); color: var(--text-primary, #1d1d1f); }

#grants-new-badge { display: inline-block; background: var(--accent); color: #fff;
  border-radius: 10px; padding: 1px 7px; font-size: 11px; font-weight: 600; margin-left: 6px; }

@media (max-width: 768px) {
  .grants-stats { grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 12px; }
  .grants-table { display: none; }
}
@media (max-width: 480px) {
  .grants-stats { grid-template-columns: repeat(2, 1fr); }
}

.grants-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text-muted);
  transition: all 0.2s;
}
.grants-delete-btn:hover {
  background: #dc354520;
  color: #dc3545;
}

/* ── Delivery status dots (replaced emoji in getDeliveryIcon) ── */
.del-dot { display:inline-block;width:8px;height:8px;border-radius:50%;margin-right:4px;flex-shrink:0;vertical-align:middle; }
.del-dot-received  { background:#16a34a; }
.del-dot-paid      { background:#2563eb; }
.del-dot-transit   { background:#f97316; }
.del-dot-waiting   { background:#f59e0b; }
.del-dot-returned  { background:#dc2626; }
.del-dot-tracking  { background:#94a3b8; }

/* ── Social Media Module (Marketing → Соцмережі) ── */
.social-tabs { display:flex; gap:4px; padding:4px 0 12px; border-bottom:1px solid var(--border); margin-bottom:16px; }
.social-tab { padding:8px 16px; border-radius:8px; border:none; background:none; cursor:pointer; font-size:13px; color:var(--text-muted); }
.social-tab.active { background:var(--accent, #2563eb); color:#fff; font-weight:500; }

.social-accounts-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(220px,1fr)); gap:12px; margin-bottom:24px; }
.social-account-card { background:var(--bg-card, #fff); border:1px solid var(--border); border-radius:12px; padding:16px; }
.social-account-header { margin-bottom:12px; }
.social-platform-badge { display:inline-block; padding:2px 10px; border-radius:10px; font-size:11px; font-weight:600; text-transform:uppercase; }
.social-platform-badge.instagram { background:#E1306C20; color:#E1306C; }
.social-platform-badge.facebook  { background:#1877F220; color:#1877F2; }
.social-platform-badge.tiktok    { background:#00000020; color:#000; }
.social-account-name { font-weight:600; font-size:14px; margin-top:6px; }
.social-username { font-size:12px; color:var(--text-muted); }
.social-stats-row { display:flex; gap:16px; margin-top:8px; }
.social-stat-value { font-size:20px; font-weight:700; color:var(--accent, #2563eb); }
.social-stat-label { font-size:11px; color:var(--text-muted); }

.social-posts-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(180px,1fr)); gap:10px; }
.social-post-card { background:var(--bg-card, #fff); border-radius:10px; overflow:hidden; cursor:pointer; border:1px solid var(--border); transition:transform 0.15s; text-decoration:none; color:inherit; display:block; position:relative; }
.social-post-card:hover { transform:translateY(-2px); }
.social-post-media { aspect-ratio:1; overflow:hidden; background:var(--bg-primary, #f5f5f7); position:relative; }
.social-post-media img { width:100%; height:100%; object-fit:cover; }
.social-post-info { padding:8px; }
.social-post-caption { font-size:12px; line-height:1.4; margin-bottom:6px; }
.social-post-meta { font-size:11px; color:var(--text-muted); display:flex; gap:8px; flex-wrap:wrap; }
.social-post-video-badge { position:absolute; top:6px; right:6px; background:rgba(0,0,0,0.6); color:#fff; padding:2px 6px; border-radius:4px; font-size:10px; }

.social-create-form { max-width:600px; }
.social-form-field { margin-bottom:16px; }
.social-form-field label { display:block; font-size:13px; font-weight:500; margin-bottom:6px; }
.social-accounts-select { display:flex; flex-direction:column; gap:8px; }
.social-acc-checkbox { display:flex; align-items:center; gap:8px; font-size:13px; cursor:pointer; }
.social-media-upload { display:flex; gap:8px; align-items:center; }
.social-btn-primary { background:var(--accent, #2563eb); color:#fff; border:none; border-radius:8px; padding:8px 20px; cursor:pointer; font-size:13px; font-weight:500; }
.social-btn-secondary { background:var(--bg-card, #fff); color:var(--text-primary, #1d1d1f); border:1px solid var(--border); border-radius:8px; padding:8px 20px; cursor:pointer; font-size:13px; }

.social-scheduled-list { display:flex; flex-direction:column; gap:8px; }
.social-scheduled-item { display:flex; align-items:center; gap:12px; padding:12px; background:var(--bg-card, #fff); border-radius:10px; border:1px solid var(--border); }
.social-scheduled-content { flex:1; min-width:0; }
.social-scheduled-text { font-size:13px; margin-bottom:4px; word-break:break-word; }
.social-scheduled-time { font-size:11px; color:var(--text-muted); }
.social-status-badge { padding:2px 8px; border-radius:10px; font-size:11px; font-weight:500; white-space:nowrap; }
.social-status-badge.scheduled { background:#0d6efd20; color:#0d6efd; }
.social-status-badge.draft     { background:#6c757d20; color:#6c757d; }
.social-status-badge.published { background:#19875420; color:#198754; }
.social-status-badge.failed    { background:#dc354520; color:#dc3545; }
.social-status-badge.cancelled { background:#9ca3af20; color:#9ca3af; }

.social-cal-header { font-size:15px; font-weight:600; margin-bottom:12px; text-transform:capitalize; }
.social-cal-grid { display:grid; grid-template-columns:repeat(7,1fr); gap:4px; }
.social-cal-dow { text-align:center; font-size:11px; color:var(--text-muted); padding:4px; font-weight:600; }
.social-cal-day { min-height:60px; border:1px solid var(--border); border-radius:6px; padding:4px; font-size:12px; }
.social-cal-day.today { border-color:var(--accent, #2563eb); background:rgba(37,99,235,0.05); }
.social-cal-date { font-weight:500; display:block; margin-bottom:2px; }
.social-cal-post { font-size:10px; padding:2px 4px; border-radius:4px; margin-bottom:2px; text-transform:uppercase; }
.social-cal-post.instagram { background:#E1306C20; color:#E1306C; }
.social-cal-post.facebook  { background:#1877F220; color:#1877F2; }

@media (max-width:768px) {
  .social-accounts-grid { grid-template-columns:1fr 1fr; }
  .social-posts-grid { grid-template-columns:1fr 1fr 1fr; }
  .social-cal-day { min-height:40px; }
  .social-tabs { overflow-x:auto; }
  .social-tab { white-space:nowrap; }
}

/* ── Social file upload (drop zone, tabs, preview) ── */
.social-media-upload-wrap { display:flex; flex-direction:column; gap:8px; }
.social-upload-tabs { display:flex; gap:6px; align-items:center; }
.social-upload-tab { padding:6px 14px; border-radius:6px; border:1px solid var(--border); background:var(--bg-card, #fff); cursor:pointer; font-size:12px; color:var(--text-muted); }
.social-upload-tab.active { background:var(--accent, #2563eb); color:#fff; border-color:var(--accent, #2563eb); }
.social-drop-zone {
  border:2px dashed var(--border); border-radius:10px; padding:24px;
  text-align:center; cursor:pointer; transition:all 0.15s ease;
  min-height:140px; display:flex; align-items:center; justify-content:center;
  position:relative; background:var(--bg-card, #fff);
}
.social-drop-zone:hover, .social-drop-zone.dragover { border-color:var(--accent, #2563eb); background:rgba(37,99,235,0.04); }
.social-drop-zone p { margin:8px 0 0; font-size:13px; color:var(--text-muted); }
.social-drop-zone svg { color:var(--text-muted); }
.social-clear-media {
  display:inline-block; margin:8px auto 0; background:none;
  border:1px solid var(--border); border-radius:6px; padding:4px 12px;
  cursor:pointer; font-size:12px; color:var(--text-muted);
}
.social-clear-media:hover { background:#dc354515; color:#dc3545; border-color:#dc3545; }

/* ── Per-account language settings + multi-lang captions + post type ── */
.social-account-settings { margin-top:12px; border-top:1px solid var(--border); padding-top:10px; display:flex; flex-direction:column; gap:8px; }
.social-account-setting label { font-size:11px; color:var(--text-muted); display:block; margin-bottom:3px; }
.social-account-setting select {
  width:100%; padding:5px 8px; border:1px solid var(--border); border-radius:6px;
  background:var(--bg-input, #fff); color:var(--text-primary, #1d1d1f); font-size:12px;
}
.social-lang-caption { margin-bottom:12px; }
.social-lang-label { display:flex; align-items:center; gap:8px; margin-bottom:6px; }
.social-lang-badge {
  background:var(--accent, #2563eb); color:#fff;
  border-radius:4px; padding:2px 8px; font-size:11px; font-weight:700;
}
.social-caption-textarea {
  width:100%; padding:10px; border:1px solid var(--border); border-radius:8px;
  background:var(--bg-input, #fff); color:var(--text-primary, #1d1d1f);
  font-size:13px; resize:vertical; box-sizing:border-box;
}
.social-post-type-selector { display:flex; gap:6px; flex-wrap:wrap; }
.social-post-type-btn {
  padding:6px 14px; border-radius:6px; border:1px solid var(--border);
  background:var(--bg-card, #fff); cursor:pointer; font-size:12px; color:var(--text-muted);
}
.social-post-type-btn.active { background:var(--accent, #2563eb); color:#fff; border-color:var(--accent, #2563eb); }

/* ===== GENERAL MOBILE IMPROVEMENTS ===== */
@media (max-width: 1023px) {
  /* Prevent horizontal overflow */
  body, html {
    overflow-x: hidden;
    max-width: 100vw;
  }

  /* Improve text readability */
  * {
    word-wrap: break-word;
    overflow-wrap: break-word;
  }

  /* Make tables responsive */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Improve button sizing on mobile */
  .btn, button {
    min-height: 44px; /* Apple's recommended touch target size */
    touch-action: manipulation;
  }

  /* Improve form inputs */
  input, select, textarea {
    font-size: 16px; /* Prevent zoom on iOS */
    box-sizing: border-box;
    max-width: 100%;
  }

  /* Hide desktop-only elements */
  .desktop-only {
    display: none !important;
  }

  /* Show mobile-only elements */
  .mobile-only {
    display: block !important;
  }

  /* Improve spacing for small screens */
  .page {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }

  /* Prevent cards from being too wide */
  .card, .modal-content {
    max-width: 100%;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  /* Better overflow handling for tables */
  table {
    table-layout: auto;
    width: 100%;
  }

  /* Improve modal sizing */
  .modal-dialog {
    margin: 8px !important;
    max-width: calc(100vw - 16px) !important;
  }
}

/* ===== Finance mobile (Finmap-style) — < 768px ===== */
@media (max-width: 1023px) {
  /* When mobile shell renders, hide any leftover desktop layout */
  #page-finance .fin-layout { display:none !important; }
}

.fin-mobile-shell { display:flex; flex-direction:column; min-height:100vh; background:var(--bg-primary, #f5f5f7); }
.fin-mobile-header {
  background:#0a0a0a; color:#fff;
  padding:36px 20px 56px; text-align:center; flex-shrink:0;
}
.fin-mobile-total-amount { font-size:38px; font-weight:700; letter-spacing:-1px; }
.fin-mobile-total-label  { font-size:13px; opacity:.6; margin-top:4px; }

.fin-mobile-card {
  background:var(--bg-card, #fff);
  border-radius:20px 20px 0 0;
  margin-top:-24px; padding:18px 16px;
  padding-bottom:calc(96px + env(safe-area-inset-bottom));
  flex:1; min-height:60vh;
  position:relative; z-index:1;
}
.fin-mobile-card.fin-mobile-card-flat { margin-top:0; border-radius:0; min-height:100vh; padding-top:14px; }

.fin-mobile-section-header {
  display:flex; justify-content:space-between; align-items:center;
  margin:14px 0 10px; font-size:14px; font-weight:600; color:var(--text-primary, #1d1d1f);
}
.fin-mobile-section-header:first-child { margin-top:0; }
.fin-mobile-add-btn {
  width:30px; height:30px; border-radius:50%;
  border:1.5px solid var(--border, #e2e8f0); background:none;
  font-size:18px; line-height:1; cursor:pointer; color:var(--text-muted);
  display:flex; align-items:center; justify-content:center;
}

.fin-mobile-accounts-list { margin-bottom:6px; }
.fin-mobile-account-row {
  display:flex; align-items:center; gap:14px;
  padding:12px 0; border-bottom:1px solid rgba(0,0,0,0.06); cursor:pointer;
}
.fin-mobile-account-row:last-child { border-bottom:none; }
.fin-account-icon {
  width:42px; height:42px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  color:#fff; font-size:13px; font-weight:700; flex-shrink:0;
}
.fin-account-name    { font-size:15px; font-weight:400; color:var(--text-primary, #1d1d1f); }
.fin-account-balance { font-size:15px; font-weight:500; color:var(--text-primary, #1d1d1f); white-space:nowrap; }
.fin-account-balance.negative { color:#dc3545; }

/* Bottom tab bar */
.fin-mobile-tabs {
  position:fixed; bottom:0; left:0; right:0;
  background:var(--bg-card, #fff);
  border-top:1px solid var(--border, #e2e8f0);
  display:flex; align-items:center;
  padding:8px 0 calc(8px + env(safe-area-inset-bottom));
  z-index:100;
}
.fin-tab {
  flex:1; display:flex; flex-direction:column; align-items:center; gap:3px;
  background:none; border:none; cursor:pointer;
  color:var(--text-muted, #64748b); font-size:10px; padding:4px 0;
}
.fin-tab.active { color:var(--accent, #2563eb); }
.fin-tab svg    { width:22px; height:22px; }
.fin-tab-add {
  width:52px; height:52px; border-radius:50% !important;
  background:var(--accent, #2563eb) !important; color:#fff !important;
  margin-top:-16px; flex:none !important;
  box-shadow:0 4px 12px rgba(0,0,0,0.2);
  align-items:center; justify-content:center;
}
.fin-tab-add svg { width:24px; height:24px; }

/* Journal */
.fin-journal-date-group  { margin-bottom:16px; }
.fin-journal-date-header {
  display:flex; justify-content:space-between;
  padding:10px 0 6px; font-size:12px; color:var(--text-muted); font-weight:500;
}
.fin-journal-day-total.income  { color:#16a34a; font-weight:600; }
.fin-journal-day-total.expense { color:#dc3545; font-weight:600; }
.fin-journal-tx-row {
  display:flex; align-items:center; gap:12px;
  padding:10px 0; border-bottom:1px solid rgba(0,0,0,0.05);
}
.fin-tx-category-icon {
  width:38px; height:38px; border-radius:11px;
  display:flex; align-items:center; justify-content:center;
  flex-shrink:0; color:#fff; font-size:14px; font-weight:700;
}
.fin-tx-info { flex:1; min-width:0; }
.fin-tx-name { font-size:14px; font-weight:500; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; color:var(--text-primary, #1d1d1f); }
.fin-tx-meta { font-size:11px; color:var(--text-muted); margin-top:2px; }
.fin-tx-amount { font-size:14px; font-weight:600; white-space:nowrap; }
.fin-tx-amount.income   { color:#16a34a; }
.fin-tx-amount.expense  { color:var(--text-primary, #1d1d1f); }
.fin-tx-amount.transfer { color:#64748b; }

/* Quick-add modal */
.fin-add-backdrop {
  position:fixed; inset:0; background:rgba(0,0,0,0.4);
  z-index:199; opacity:0; pointer-events:none; transition:opacity 0.2s;
}
.fin-add-backdrop.open { opacity:1; pointer-events:auto; }
.fin-add-modal {
  position:fixed; bottom:0; left:0; right:0;
  background:var(--bg-card, #fff);
  border-radius:20px 20px 0 0;
  padding:12px 20px calc(20px + env(safe-area-inset-bottom));
  z-index:200;
  transform:translateY(100%); transition:transform 0.3s ease;
  box-shadow:0 -4px 24px rgba(0,0,0,0.15);
  max-height:90vh; overflow-y:auto;
}
.fin-add-modal.open { transform:translateY(0); }
.fin-add-modal-handle {
  width:36px; height:4px; background:var(--border, #cbd5e1);
  border-radius:2px; margin:0 auto 16px;
}
.fin-add-type-selector { display:flex; gap:8px; margin-bottom:18px; }
.fin-type-btn {
  flex:1; padding:8px; border-radius:8px;
  border:1px solid var(--border, #e2e8f0); background:var(--bg-primary, #f5f5f7);
  cursor:pointer; font-size:13px; color:var(--text-muted);
}
.fin-type-btn.active { background:var(--accent, #2563eb); color:#fff; border-color:var(--accent, #2563eb); }
.fin-add-amount-wrap {
  display:flex; align-items:center; gap:8px; margin-bottom:14px;
  padding:0 4px;
}
.fin-add-currency { font-size:30px; font-weight:300; color:var(--text-muted); }
.fin-add-amount-input {
  flex:1; font-size:36px; font-weight:600;
  border:none; background:none; color:var(--text-primary, #1d1d1f); outline:none;
  width:100%;
}
.fin-add-select, .fin-add-input {
  width:100%; padding:11px 14px;
  border:1px solid var(--border, #e2e8f0); border-radius:10px;
  background:var(--bg-input, #fff); color:var(--text-primary, #1d1d1f);
  font-size:14px; margin-bottom:8px; box-sizing:border-box;
}
.fin-add-submit-btn {
  width:100%; padding:13px;
  background:var(--accent, #2563eb); color:#fff;
  border:none; border-radius:12px;
  font-size:15px; font-weight:600; cursor:pointer; margin-top:6px;
}

/* Analytics mobile */
.fin-analytics-period-selector { display:flex; gap:6px; margin-bottom:16px; }
.fin-period-btn {
  flex:1; padding:8px; border-radius:8px;
  border:1px solid var(--border, #e2e8f0); background:var(--bg-primary, #f5f5f7);
  cursor:pointer; font-size:12px; color:var(--text-muted);
}
.fin-period-btn.active { background:var(--accent, #2563eb); color:#fff; border-color:var(--accent, #2563eb); }
.fin-analytics-summary { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-bottom:8px; }
.fin-summary-card { padding:14px; border-radius:12px; }
.fin-summary-card.income  { background:#19875410; }
.fin-summary-card.expense { background:#dc354510; }
.fin-summary-label  { font-size:12px; color:var(--text-muted); margin-bottom:4px; }
.fin-summary-amount { font-size:16px; font-weight:700; }
.fin-summary-card.income  .fin-summary-amount { color:#198754; }
.fin-summary-card.expense .fin-summary-amount { color:#dc3545; }
.fin-categories-list { margin-top:6px; }
.fin-category-row { display:flex; align-items:center; gap:10px; padding:8px 0; }
.fin-cat-icon { width:10px; height:10px; border-radius:50%; flex-shrink:0; }
.fin-cat-info { flex:1; }
.fin-cat-name { font-size:13px; display:block; margin-bottom:4px; color:var(--text-primary, #1d1d1f); }
.fin-cat-bar { height:3px; background:rgba(0,0,0,0.06); border-radius:2px; overflow:hidden; }
.fin-cat-bar-fill { height:100%; border-radius:2px; }
.fin-cat-amount { font-size:13px; font-weight:500; white-space:nowrap; }

/* Calendar mobile (grid) */
.fin-mobile-cal-nav {
  display:flex; align-items:center; justify-content:space-between;
  margin:6px 0 10px; gap:10px;
}
.fin-cal-nav-btn {
  width:34px; height:34px; border-radius:50%;
  border:1px solid var(--border, #e2e8f0); background:var(--bg-card, #fff);
  cursor:pointer; font-size:18px; line-height:1; color:var(--text-primary, #1d1d1f);
  display:flex; align-items:center; justify-content:center;
}
.fin-cal-month-label {
  flex:1; text-align:center; font-size:15px; font-weight:600;
  text-transform:capitalize; color:var(--text-primary, #1d1d1f);
}
.fin-cal-dow-row {
  display:grid; grid-template-columns:repeat(7, 1fr);
  gap:2px; margin-bottom:4px;
}
.fin-cal-dow {
  text-align:center; font-size:10px; color:var(--text-muted);
  text-transform:uppercase; font-weight:600; padding:2px 0;
}
.fin-cal-grid-mobile {
  display:grid; grid-template-columns:repeat(7, 1fr);
  gap:3px;
}
.fin-cal-cell {
  background:var(--bg-primary, #f5f5f7); border-radius:6px;
  padding:4px 3px; min-height:54px;
  display:flex; flex-direction:column; gap:1px;
  cursor:pointer; transition:transform 0.1s, background 0.15s;
  border:1px solid transparent;
}
.fin-cal-cell:hover { background:var(--bg-card, #fff); }
.fin-cal-cell.empty { background:transparent; cursor:default; }
.fin-cal-cell.today { border-color:var(--accent, #2563eb); background:rgba(37,99,235,0.06); }
.fin-cal-cell.future { opacity:0.65; }
.fin-cal-cell-num {
  font-size:11px; font-weight:600; color:var(--text-primary, #1d1d1f);
  display:flex; align-items:center; justify-content:space-between;
  line-height:1.1;
}
.fin-cal-cell-dot {
  width:5px; height:5px; border-radius:50%;
  background:var(--accent, #2563eb); display:inline-block;
}
.fin-cal-cell-line { font-size:9px; line-height:1.1; font-weight:600; }
.fin-cal-cell-line.inc { color:#16a34a; }
.fin-cal-cell-line.exp { color:#dc2626; }
.fin-cal-cell-bal {
  font-size:10px; font-weight:500; color:var(--text-muted);
  margin-top:auto; line-height:1.1;
}
.fin-cal-cell.neg .fin-cal-cell-bal { color:#dc2626; }

.fin-cal-day-detail {
  margin-top:18px; padding:14px;
  background:var(--bg-primary, #f5f5f7); border-radius:12px;
}

/* ===== Finance AI Agent ===== */
.fin-ai-layout {
  display:grid; grid-template-columns:190px 1fr 240px;
  height:calc(100vh - 200px); min-height:520px;
  border:1px solid var(--border); border-radius:12px;
  overflow:hidden; background:var(--bg-card, #fff);
}
.fin-ai-sidebar { display:flex; flex-direction:column; background:var(--bg-card, #fff); border-right:1px solid var(--border); min-width:0; }
.fin-ai-sidebar-header {
  padding:14px 12px; font-size:13px; font-weight:600;
  border-bottom:1px solid var(--border);
  display:flex; justify-content:space-between; align-items:center; gap:8px;
}
.fin-ai-new-chat-btn {
  width:26px; height:26px; border-radius:6px;
  border:1px solid var(--border); background:none; cursor:pointer;
  display:flex; align-items:center; justify-content:center; color:var(--text-muted);
}
.fin-ai-new-chat-btn:hover { background:var(--accent, #2563eb); color:#fff; border-color:var(--accent, #2563eb); }
.fin-ai-chat-list { flex:1; overflow-y:auto; padding:8px; }
.fin-ai-chat-item {
  display:flex; align-items:center; gap:8px;
  padding:8px 10px; border-radius:8px; cursor:pointer;
  font-size:13px; color:var(--text-muted);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.fin-ai-chat-item:hover { background:var(--bg-primary, #f5f5f7); }
.fin-ai-chat-item.active { background:var(--accent, #2563eb); color:#fff; }
.fin-ai-chat-item.active svg { stroke:#fff; }

.fin-ai-main { display:flex; flex-direction:column; background:var(--bg-primary, #f5f5f7); overflow:hidden; min-width:0; }
.fin-ai-chat-header {
  padding:12px 16px; border-bottom:1px solid var(--border);
  display:flex; justify-content:space-between; align-items:center; gap:8px;
  background:var(--bg-card, #fff);
}
.fin-ai-chat-title { font-size:14px; font-weight:600; color:var(--text-primary, #1d1d1f); }
.fin-ai-header-btn {
  padding:5px 12px; border-radius:6px;
  border:1px solid var(--border); background:none; cursor:pointer;
  font-size:12px; color:var(--text-muted);
  display:flex; align-items:center; gap:6px;
}
.fin-ai-badge {
  background:var(--accent, #2563eb); color:#fff;
  border-radius:10px; padding:1px 6px; font-size:10px; font-weight:700;
}

.fin-ai-messages {
  flex:1; overflow-y:auto; padding:16px;
  display:flex; flex-direction:column; gap:12px;
}
.fin-ai-welcome { text-align:center; padding:40px 20px; color:var(--text-muted); }
.fin-ai-welcome-icon {
  width:56px; height:56px; border-radius:50%;
  background:var(--bg-card, #fff); border:1px solid var(--border);
  display:flex; align-items:center; justify-content:center; margin:0 auto 12px;
}
.fin-ai-welcome h3 { font-size:16px; color:var(--text-primary, #1d1d1f); margin:0 0 6px; }
.fin-ai-welcome p { font-size:13px; margin:0; }

.fin-ai-message { display:flex; align-items:flex-start; gap:10px; }
.fin-ai-message.user { flex-direction:row-reverse; }
.fin-ai-avatar {
  width:30px; height:30px; border-radius:50%;
  background:var(--accent, #2563eb); color:#fff;
  display:flex; align-items:center; justify-content:center;
  font-size:11px; font-weight:700; flex-shrink:0;
}
.fin-ai-bubble {
  max-width:78%; padding:10px 14px; border-radius:12px;
  font-size:13px; line-height:1.6;
  background:var(--bg-card, #fff); border:1px solid var(--border);
  color:var(--text-primary, #1d1d1f); word-wrap:break-word;
}
.fin-ai-message.user .fin-ai-bubble {
  background:var(--accent, #2563eb); color:#fff; border-color:var(--accent, #2563eb);
}

.fin-ai-typing { display:flex; gap:4px; align-items:center; padding:4px 0; }
.fin-ai-typing span {
  width:6px; height:6px; border-radius:50%; background:var(--text-muted);
  animation:fin-ai-typing 1.2s infinite;
}
.fin-ai-typing span:nth-child(2) { animation-delay:0.2s; }
.fin-ai-typing span:nth-child(3) { animation-delay:0.4s; }
@keyframes fin-ai-typing { 0%,60%,100% { opacity:0.3; } 30% { opacity:1; } }

.fin-ai-input-wrap {
  padding:12px 16px; border-top:1px solid var(--border);
  display:flex; gap:8px; align-items:flex-end; background:var(--bg-card, #fff);
}
.fin-ai-input {
  flex:1; border:1px solid var(--border); border-radius:10px;
  padding:10px 14px; background:var(--bg-input, #fff);
  color:var(--text-primary, #1d1d1f); font-size:13px;
  resize:none; outline:none; font-family:inherit; line-height:1.5; max-height:120px;
}
.fin-ai-input:focus { border-color:var(--accent, #2563eb); }
.fin-ai-send-btn {
  width:38px; height:38px; border-radius:10px;
  background:var(--accent, #2563eb); color:#fff;
  border:none; cursor:pointer; flex-shrink:0;
  display:flex; align-items:center; justify-content:center;
}
.fin-ai-send-btn:disabled { opacity:0.5; cursor:not-allowed; }

.fin-ai-quick-prompts {
  padding:8px 16px 12px; border-top:1px solid var(--border);
  background:var(--bg-card, #fff);
}
.fin-ai-quick-label {
  font-size:10px; color:var(--text-muted); text-transform:uppercase;
  letter-spacing:0.05em; margin-bottom:6px; font-weight:600;
}
.fin-ai-quick-list { display:flex; flex-wrap:wrap; gap:6px; }
.fin-ai-quick-btn {
  padding:4px 12px; border-radius:20px;
  border:1px solid var(--border); background:var(--bg-primary, #f5f5f7);
  cursor:pointer; font-size:12px; color:var(--text-muted);
  white-space:nowrap; transition:all 0.15s;
}
.fin-ai-quick-btn:hover { border-color:var(--accent, #2563eb); color:var(--accent, #2563eb); background:rgba(37,99,235,0.05); }

.fin-ai-info-panel { background:var(--bg-card, #fff); border-left:1px solid var(--border); padding:16px; overflow-y:auto; }
.fin-ai-info-header { font-size:13px; font-weight:600; margin-bottom:16px; display:flex; justify-content:space-between; align-items:center; }
.fin-ai-info-items { display:flex; flex-direction:column; gap:14px; }
.fin-ai-info-item { display:flex; gap:10px; align-items:flex-start; }
.fin-ai-info-icon { width:32px; height:32px; border-radius:8px; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.fin-ai-info-icon.security { background:#0d6efd20; color:#0d6efd; }
.fin-ai-info-icon.shield   { background:#19875420; color:#198754; }
.fin-ai-info-icon.ai       { background:#dc354520; color:#dc3545; }
.fin-ai-info-icon.person   { background:#6f42c120; color:#6f42c1; }
.fin-ai-info-title { font-size:12px; font-weight:600; margin-bottom:3px; color:var(--text-primary, #1d1d1f); }
.fin-ai-info-desc  { font-size:11px; color:var(--text-muted); line-height:1.5; }

.fin-ai-modal { position:fixed; inset:0; background:rgba(0,0,0,0.5); display:flex; align-items:center; justify-content:center; z-index:1000; }
.fin-ai-modal-content { background:var(--bg-card, #fff); border-radius:12px; width:560px; max-width:95vw; max-height:80vh; overflow-y:auto; }
.fin-ai-modal-header { padding:14px 18px; font-size:15px; font-weight:600; border-bottom:1px solid var(--border); display:flex; justify-content:space-between; align-items:center; }

.fin-suggestion-item { padding:14px 18px; border-bottom:1px solid var(--border); display:flex; align-items:flex-start; gap:12px; }
.fin-suggestion-info { flex:1; min-width:0; }
.fin-suggestion-pattern { font-size:14px; font-weight:600; margin-bottom:4px; word-break:break-word; }
.fin-suggestion-meta { font-size:12px; color:var(--text-muted); margin-bottom:3px; }
.fin-suggestion-samples { font-size:11px; color:var(--text-muted); }
.fin-suggestion-actions { display:flex; flex-direction:column; gap:6px; }
.fin-suggestion-accept { padding:5px 14px; border-radius:6px; background:var(--accent, #2563eb); color:#fff; border:none; cursor:pointer; font-size:12px; white-space:nowrap; }
.fin-suggestion-reject { padding:5px 14px; border-radius:6px; background:none; color:var(--text-muted); border:1px solid var(--border); cursor:pointer; font-size:12px; }

@media (max-width: 900px) {
  .fin-ai-layout { grid-template-columns:1fr; height:auto; min-height:70vh; }
  .fin-ai-sidebar, .fin-ai-info-panel, .fin-ai-smart-panel { display:none; }
}

/* ── Smart panel ── */
.fin-ai-smart-panel { background:var(--bg-card,#fff); border-left:1px solid var(--border); overflow-y:auto; display:flex; flex-direction:column; min-width:0; }
.fin-smart-block { padding:14px 16px; border-bottom:1px solid var(--border); }
.fin-smart-block:last-child { border-bottom:none; flex:1; }
.fin-smart-block-title { font-size:12px; font-weight:700; text-transform:uppercase; letter-spacing:.5px; color:var(--text-muted); margin-bottom:10px; display:flex; align-items:center; gap:6px; }
.fin-smart-alert { background:#fef3cd; border:1px solid #fdd835; border-radius:8px; padding:10px 12px; font-size:13px; display:flex; flex-direction:column; gap:8px; }
.fin-smart-alert-num { font-size:22px; font-weight:700; color:#e65100; display:block; }
.fin-smart-run-btn { padding:6px 14px; background:#e65100; color:#fff; border:none; border-radius:6px; font-size:12px; font-weight:600; cursor:pointer; align-self:flex-start; }
.fin-smart-run-btn:hover { background:#bf360c; }
.fin-smart-ok { background:#e8f5e9; border:1px solid #a5d6a7; border-radius:8px; padding:10px 12px; font-size:13px; color:#2e7d32; }
.fin-smart-rule { padding:10px 0; border-bottom:1px solid var(--border); }
.fin-smart-rule:last-child { border-bottom:none; }
.fin-smart-rule-pattern { font-size:13px; font-weight:600; color:var(--text-primary,#1d1d1f); margin-bottom:3px; word-break:break-all; }
.fin-smart-rule-meta { font-size:12px; color:var(--text-muted); margin-bottom:2px; }
.fin-smart-rule-sample { font-size:11px; color:var(--text-muted); margin-bottom:6px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.fin-smart-rule-btns { display:flex; gap:6px; }
.fin-smart-accept { padding:4px 10px; background:var(--accent,#2563eb); color:#fff; border:none; border-radius:5px; font-size:11px; cursor:pointer; white-space:nowrap; }
.fin-smart-reject { padding:4px 10px; background:none; color:var(--text-muted); border:1px solid var(--border); border-radius:5px; font-size:11px; cursor:pointer; }
.fin-smart-accept:hover { background:#1d4ed8; }
.fin-smart-reject:hover { border-color:#dc3545; color:#dc3545; }
.fin-smart-empty { font-size:12px; color:var(--text-muted); line-height:1.5; }
.fin-smart-add-btn { display:flex; align-items:center; gap:7px; padding:8px 12px; background:var(--bg-primary,#f5f5f7); border:1px dashed var(--border); border-radius:7px; font-size:13px; color:var(--text-muted); cursor:pointer; width:100%; justify-content:center; }
.fin-smart-add-btn:hover { border-color:var(--accent,#2563eb); color:var(--accent,#2563eb); }
.fin-form-row { margin-bottom:8px; }
.fin-form-row label { display:block; font-size:11px; color:var(--text-muted); margin-bottom:4px; font-weight:500; }
.fin-form-row input, .fin-form-row select { width:100%; padding:7px 10px; border:1px solid var(--border); border-radius:6px; font-size:13px; background:#fff; box-sizing:border-box; }
.fin-form-row input:focus, .fin-form-row select:focus { border-color:var(--accent,#2563eb); outline:none; }
.fin-form-save { width:100%; padding:8px; background:var(--accent,#2563eb); color:#fff; border:none; border-radius:7px; font-size:13px; font-weight:600; cursor:pointer; margin-top:4px; }
.fin-form-save:hover { background:#1d4ed8; }

/* ── Welcome screen cards ── */
.fin-welcome-stats { display:flex; gap:10px; justify-content:center; margin:16px 0; flex-wrap:wrap; }
.fin-welcome-stat { background:var(--bg-card,#fff); border:1px solid var(--border); border-radius:10px; padding:10px 16px; text-align:center; min-width:80px; }
.fin-welcome-stat-val { font-size:18px; font-weight:700; color:var(--text-primary,#1d1d1f); }
.fin-welcome-stat-lbl { font-size:11px; color:var(--text-muted); margin-top:2px; }
.fin-welcome-stat-warn { border-color:#fdd835; background:#fffde7; }
.fin-welcome-stat-warn .fin-welcome-stat-val { color:#e65100; }
.fin-welcome-stat-accent { border-color:#bfdbfe; background:#eff6ff; }
.fin-welcome-stat-accent .fin-welcome-stat-val { color:var(--accent,#2563eb); }
.fin-welcome-cards { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-top:16px; }
.fin-welcome-card { background:var(--bg-card,#fff); border:1px solid var(--border); border-radius:12px; padding:14px; cursor:pointer; text-align:left; transition:all .15s; }
.fin-welcome-card:hover { border-color:var(--accent,#2563eb); box-shadow:0 2px 8px rgba(37,99,235,.1); transform:translateY(-1px); }
.fin-welcome-card-icon { font-size:22px; margin-bottom:8px; }
.fin-welcome-card-label { font-size:13px; font-weight:600; color:var(--text-primary,#1d1d1f); margin-bottom:3px; }
.fin-welcome-card-desc { font-size:11px; color:var(--text-muted); }

/* ===== INBOX (chat module) ===== */
.inbox-layout {
  display: grid;
  grid-template-columns: 320px 1fr 280px;
  /* svh = small viewport height — equals the viewport WITH the mobile URL
     bar visible. Using svh (instead of vh/dvh) keeps the chat input above
     the fold from the first paint, regardless of whether the URL bar is
     currently collapsed. Slight empty strip at the bottom when the URL bar
     does collapse is acceptable; jumping input is not. */
  height: calc(100svh - 60px);
  overflow: hidden;
}
.inbox-sidebar { border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; background: var(--bg-card-solid); }
.inbox-sidebar-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.inbox-sidebar-header h2 { font-size: 16px; font-weight: 600; margin: 0; color: var(--text-primary); }
.inbox-new-chat-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border); background: none; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-muted); }
.inbox-new-chat-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }

.inbox-search { padding: 8px 12px; }
.inbox-search input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-primary); color: var(--text-primary); font-size: 13px; outline: none; box-sizing: border-box; }
.inbox-search input:focus { border-color: var(--accent); }

.inbox-filters { display: flex; gap: 4px; padding: 4px 12px 8px; flex-wrap: wrap; }
.inbox-filter-btn { padding: 4px 10px; border-radius: 6px; border: 1px solid transparent; background: none; cursor: pointer; font-size: 12px; color: var(--text-muted); }
.inbox-filter-btn.active { background: var(--accent); color: white; }
.inbox-count-badge { background: #dc2626; color: white; border-radius: 10px; padding: 0 6px; font-size: 10px; font-weight: 700; margin-left: 4px; display: none; }

.inbox-chat-list { flex: 1; overflow-y: auto; }
.inbox-empty-list { padding: 40px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }

.inbox-chat-item { display: flex; gap: 10px; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--border); transition: background 0.1s; }
.inbox-chat-item:hover { background: rgba(0,0,0,0.03); }
.inbox-chat-item.active { background: rgba(99,102,241,0.08); border-left: 3px solid var(--accent); padding-left: 13px; }
.inbox-chat-item.unread .inbox-chat-name { font-weight: 700; color: var(--text-primary); }

.inbox-chat-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--bg-primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; position: relative; font-size: 16px; font-weight: 600; color: var(--text-muted); }
.inbox-platform-dot { position: absolute; bottom: -2px; right: -2px; width: 16px; height: 16px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 700; color: white; border: 2px solid var(--bg-card-solid); z-index: 1; }
.inbox-avatar-letter { z-index: 1; }

.inbox-chat-info { flex: 1; min-width: 0; }
.inbox-chat-top { display: flex; justify-content: space-between; gap: 6px; margin-bottom: 2px; }
.inbox-chat-name { font-size: 13px; font-weight: 500; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-chat-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.inbox-chat-preview { display: flex; align-items: center; gap: 6px; }
.inbox-preview-text { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-unread-badge { background: var(--accent); color: white; border-radius: 10px; padding: 1px 7px; font-size: 10px; font-weight: 700; flex-shrink: 0; }
.inbox-chat-assigned { font-size: 10px; color: var(--text-muted); margin-top: 2px; }

.inbox-main { display: flex; flex-direction: column; overflow: hidden; background: var(--bg-primary); }
.inbox-empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); gap: 12px; }

.inbox-conv-header { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--bg-card-solid); }
.inbox-back-btn { display: none; background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 4px; }
.inbox-conv-header-info { flex: 1; cursor: pointer; min-width: 0; }
.inbox-conv-name { font-size: 14px; font-weight: 600; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-conv-meta { font-size: 11px; color: var(--text-muted); }
.inbox-conv-actions { display: flex; gap: 6px; }
.inbox-conv-actions button { width: 32px; height: 32px; border-radius: 6px; border: 1px solid var(--border); background: none; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-muted); }
.inbox-conv-actions button:hover { background: var(--bg-primary); color: var(--accent); }

.inbox-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.inbox-no-messages { text-align: center; padding: 40px; color: var(--text-muted); }

.inbox-message { display: flex; }
.inbox-message.out { justify-content: flex-end; }
.inbox-msg-bubble { max-width: 70%; padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.5; background: var(--bg-card-solid); border: 1px solid var(--border); color: var(--text-primary); }
.inbox-message.out .inbox-msg-bubble { background: var(--accent); color: white; border-color: var(--accent); }
.inbox-msg-text a { color: inherit; text-decoration: underline; }
.inbox-msg-image { max-width: 240px; max-height: 240px; border-radius: 8px; cursor: zoom-in; display: block; transition: opacity 0.15s; }
.inbox-msg-image:hover { opacity: 0.85; }

/* Custom voice player — waveform + speed */
.inbox-voice-player { display: flex; align-items: center; gap: 8px; min-width: 220px; max-width: 300px; padding: 2px 0; }
.inbox-voice-play-btn { width: 34px; height: 34px; border-radius: 50%; border: none; background: rgba(15,23,42,0.08); color: var(--text-primary, #1e293b); display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; transition: background 0.15s; padding: 0; }
.inbox-voice-play-btn:hover { background: rgba(15,23,42,0.15); }
.inbox-message.out .inbox-voice-play-btn { background: rgba(255,255,255,0.22); color: white; }
.inbox-message.out .inbox-voice-play-btn:hover { background: rgba(255,255,255,0.35); }
.inbox-voice-wave-wrap { flex: 1; height: 32px; position: relative; cursor: pointer; border-radius: 4px; overflow: hidden; }
.inbox-voice-canvas { width: 100%; height: 100%; display: block; }
.inbox-voice-progress { position: absolute; top: 0; left: 0; height: 100%; width: 0%; background: rgba(160,140,100,0.30); pointer-events: none; transition: width 0.1s linear; }
.inbox-message.out .inbox-voice-progress { background: rgba(255,255,255,0.28); }
.inbox-voice-time { font-size: 11px; color: var(--text-muted, #64748b); min-width: 30px; text-align: center; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.inbox-message.out .inbox-voice-time { color: rgba(255,255,255,0.78); }
.inbox-voice-speed { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 10px; border: 1px solid rgba(15,23,42,0.12); background: none; color: var(--text-muted, #64748b); cursor: pointer; flex-shrink: 0; transition: all 0.15s; }
.inbox-voice-speed:hover { background: rgba(15,23,42,0.06); }
.inbox-message.out .inbox-voice-speed { border-color: rgba(255,255,255,0.32); color: rgba(255,255,255,0.85); }
.inbox-message.out .inbox-voice-speed:hover { background: rgba(255,255,255,0.15); }

/* Video circle bubble (Telegram-style) — inline playback + expand-on-play */
.inbox-video-bubble { width: 180px; height: 180px; border-radius: 50%; overflow: hidden; position: relative; cursor: pointer; background: #000; flex-shrink: 0; transition: width 0.3s ease, height 0.3s ease; }
.inbox-video-bubble.playing { width: 260px; height: 260px; }
.inbox-video-round { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 50%; }
.inbox-video-play-icon { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,0.28); border-radius: 50%; transition: background 0.15s; pointer-events: none; }
.inbox-video-bubble:hover .inbox-video-play-icon { background: rgba(0,0,0,0.15); }
@media (max-width: 768px) {
  .inbox-video-bubble { width: 150px; height: 150px; }
  .inbox-video-bubble.playing { width: 220px; height: 220px; }
}

/* Media-only bubbles: strip the rounded-card padding/border so circles
   and image thumbnails render cleanly without the wrap. */
.inbox-msg-bubble.naked { background: transparent !important; border: none !important; padding: 0 !important; }
.inbox-msg-bubble.naked .inbox-msg-meta { padding: 4px 4px 0; }

/* Flash highlight when scrolling to a message from media library */
.inbox-msg-flash .inbox-msg-bubble { box-shadow: 0 0 0 3px rgba(160,140,100,0.45); transition: box-shadow 0.4s ease; }

/* Reply quote (banner above content inside a bubble) */
.inbox-msg-reply { display: flex; gap: 8px; padding: 6px 8px; margin-bottom: 6px; cursor: pointer; border-radius: 6px; background: rgba(15,23,42,0.05); max-width: 100%; }
.inbox-message.out .inbox-msg-reply { background: rgba(255,255,255,0.14); }
.inbox-msg-reply-bar  { width: 3px; border-radius: 2px; background: var(--accent, #A08C64); flex-shrink: 0; }
.inbox-msg-reply-text { font-size: 12px; color: var(--text-muted, #64748b); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.4; }
.inbox-message.out .inbox-msg-reply-text { color: rgba(255,255,255,0.75); }

/* Hover action button (reply) */
.inbox-message { position: relative; }
.inbox-msg-actions { position: absolute; top: -10px; right: 8px; display: none; gap: 2px; z-index: 2; }
.inbox-message.out .inbox-msg-actions { right: auto; left: 8px; }
.inbox-message:hover .inbox-msg-actions { display: flex; }
.inbox-msg-action-btn { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border, #e2e8f0); background: var(--bg-card-solid, #fff); display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-muted, #64748b); box-shadow: 0 1px 3px rgba(0,0,0,0.10); padding: 0; }
.inbox-msg-action-btn:hover { background: var(--accent, #A08C64); color: #fff; border-color: var(--accent, #A08C64); }

/* Create-order form (KeyCRM-style sections, line items, totals) */
.co-form { padding: 4px 4px 0; max-width: 760px; }
.co-form .co-row { display: flex; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.co-form .co-section { flex: 1 1 200px; min-width: 0; }
.co-form .co-full { width: 100%; flex-basis: 100%; }
.co-form .co-section-title { font-size: 11px; font-weight: 700; color: var(--text-muted, #64748b); text-transform: uppercase; letter-spacing: 0.04em; margin: 0 0 8px; padding-bottom: 5px; border-bottom: 1px solid var(--border, #e2e8f0); }
.co-form .co-field { margin-bottom: 8px; }
.co-form .co-field label { display: block; font-size: 11px; color: var(--text-muted, #64748b); margin-bottom: 3px; }
.co-form .co-field input,
.co-form .co-field select,
.co-form .co-field textarea { width: 100%; padding: 7px 10px; border: 1px solid var(--border, #e2e8f0); border-radius: 6px; font-size: 13px; background: var(--bg-card-solid, #fff); color: var(--text-primary, #1e293b); box-sizing: border-box; }
.co-product-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.co-product-row .co-prod-name  { flex: 3; min-width: 0; }
.co-product-row .co-prod-qty   { width: 70px; }
.co-product-row .co-prod-price { width: 100px; }
.co-product-row input { padding: 7px 9px; border: 1px solid var(--border, #e2e8f0); border-radius: 6px; font-size: 13px; background: var(--bg-card-solid, #fff); box-sizing: border-box; }
.co-prod-remove { background: none; border: none; color: var(--text-muted, #64748b); cursor: pointer; font-size: 16px; padding: 4px 8px; flex-shrink: 0; }
.co-prod-remove:hover { color: #dc2626; }
.co-add-product { background: none; border: 1px dashed var(--accent, #A08C64); border-radius: 6px; padding: 7px 12px; font-size: 12px; color: var(--accent, #A08C64); cursor: pointer; margin-top: 4px; flex: 2; }
.co-add-product:hover { background: rgba(160,140,100,0.08); }
.co-add-row { display: flex; gap: 8px; margin-top: 4px; }
.co-add-manual { background: none; border: 1px dashed var(--border, #e2e8f0); border-radius: 6px; padding: 7px 12px; font-size: 12px; color: var(--text-muted, #64748b); cursor: pointer; flex: 1; }
.co-add-manual:hover { background: rgba(15,23,42,0.04); }
.co-catalog-btn { background: none; border: 1px solid var(--accent, #A08C64); border-radius: 6px; padding: 3px 9px; font-size: 11px; color: var(--accent, #A08C64); cursor: pointer; display: inline-flex; align-items: center; gap: 4px; text-transform: none; letter-spacing: 0; font-weight: 600; }
.co-catalog-btn:hover { background: var(--accent, #A08C64); color: #fff; }
.co-prod-thumb { width: 38px; height: 38px; border-radius: 6px; object-fit: cover; flex-shrink: 0; border: 1px solid var(--border, #e2e8f0); }
.co-prod-sku { font-size: 10px; color: var(--text-muted, #94a3b8); margin-top: 2px; }

/* Catalog slide-in panel */
.co-catalog-panel { position: fixed; top: 0; right: 0; width: 480px; max-width: 92vw; height: 100vh; background: var(--bg-card-solid, #fff); box-shadow: -4px 0 20px rgba(0,0,0,0.18); z-index: 10001; display: flex; flex-direction: column; animation: coCatalogIn 0.18s ease; }
@keyframes coCatalogIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.co-catalog-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border, #e2e8f0); }
.co-catalog-header h3 { font-size: 15px; font-weight: 700; margin: 0; color: var(--text-primary, #1e293b); }
.co-catalog-close { background: none; border: none; cursor: pointer; color: var(--text-muted, #64748b); padding: 4px; }
.co-catalog-close:hover { color: var(--text-primary, #1e293b); }
.co-catalog-search { display: flex; gap: 8px; padding: 12px 18px; border-bottom: 1px solid var(--border, #e2e8f0); }
.co-catalog-search input { flex: 1; padding: 8px 11px; border: 1px solid var(--border, #e2e8f0); border-radius: 8px; font-size: 13px; }
.co-catalog-search select { padding: 8px 10px; border: 1px solid var(--border, #e2e8f0); border-radius: 8px; font-size: 12px; min-width: 130px; background: #fff; }
.co-catalog-results { flex: 1; overflow-y: auto; padding: 8px 12px; }
.co-catalog-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border, #e2e8f0); border-radius: 8px; margin-bottom: 6px; cursor: pointer; transition: all 0.12s; }
.co-catalog-item:hover { border-color: var(--accent, #A08C64); background: rgba(160,140,100,0.04); }
.co-catalog-item-img { width: 48px; height: 48px; border-radius: 6px; object-fit: cover; flex-shrink: 0; background: var(--bg, #f8fafc); border: 1px solid var(--border, #e2e8f0); }
.co-catalog-no-img { border-style: dashed; }
.co-catalog-item-info { flex: 1; min-width: 0; }
.co-catalog-item-title { font-size: 12px; font-weight: 600; line-height: 1.3; color: var(--text-primary, #1e293b); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.co-catalog-item-meta { display: flex; gap: 6px; margin-top: 3px; }
.co-catalog-item-variant { font-size: 10px; color: var(--accent, #A08C64); background: rgba(160,140,100,0.10); padding: 1px 6px; border-radius: 8px; }
.co-catalog-item-sku { font-size: 10px; color: var(--text-muted, #94a3b8); }
.co-catalog-item-price { font-size: 12px; font-weight: 700; white-space: nowrap; flex-shrink: 0; color: var(--text-primary, #1e293b); }
@media (max-width: 768px) {
  .co-catalog-panel { width: 100vw; }
}
.co-totals { display: flex; flex-direction: column; justify-content: flex-end; }
.co-total-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13px; color: var(--text-muted, #64748b); }
.co-total-main { font-weight: 700; font-size: 15px; color: var(--text-primary, #1e293b); border-top: 1px solid var(--border, #e2e8f0); padding-top: 7px; margin-top: 4px; }
@media (max-width: 768px) { .co-form .co-row { flex-direction: column; gap: 10px; } .co-product-row { flex-wrap: wrap; } .co-product-row .co-prod-qty, .co-product-row .co-prod-price { width: 90px; } }

/* Contact panel — manager select + orders + action buttons */
.inbox-cp-manager-select { width: 100%; padding: 7px 10px; border: 1px solid var(--border, #e2e8f0); border-radius: 8px; background: var(--bg-card-solid, #fff); font-size: 13px; color: var(--text-primary, #1e293b); cursor: pointer; }
.inbox-cp-manager-select:hover { border-color: var(--accent, #A08C64); }

.inbox-cp-order-card { padding: 9px 10px; border: 1px solid var(--border, #e2e8f0); border-radius: 8px; margin-bottom: 6px; background: var(--bg-card-solid, #fff); }
.inbox-cp-order-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; gap: 8px; }
.inbox-cp-order-id { font-size: 13px; font-weight: 600; color: var(--accent, #A08C64); text-decoration: none; }
.inbox-cp-order-id:hover { text-decoration: underline; }
.inbox-cp-order-status { font-size: 10px; padding: 2px 8px; border-radius: 10px; background: rgba(160,140,100,0.12); color: var(--accent, #A08C64); font-weight: 600; white-space: nowrap; }
.inbox-cp-order-details { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted, #64748b); }
.inbox-cp-order-price { font-size: 13px; font-weight: 700; margin-top: 4px; color: var(--text-primary, #1e293b); }

.inbox-cp-actions { display: flex; flex-direction: column; gap: 6px; margin: 14px 0 16px; }
.inbox-cp-action-btn { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 12px; border: 1px solid var(--accent, #A08C64); border-radius: 8px; background: none; color: var(--accent, #A08C64); font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.15s; }
.inbox-cp-action-btn:hover { background: var(--accent, #A08C64); color: #fff; }

/* Assigned-manager badge in conversation header */
.inbox-header-assigned { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-muted, #64748b); padding: 1px 8px; background: rgba(160,140,100,0.12); border-radius: 10px; margin-left: 8px; }

/* Reply preview row above the input */
#inbox-reply-bar { padding: 0 16px; }
.inbox-reply-preview { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--bg, #f8fafc); border: 1px solid var(--border, #e2e8f0); border-radius: 10px; margin: 6px 0 0; }
.inbox-reply-preview-bar { width: 3px; height: 28px; border-radius: 2px; background: var(--accent, #A08C64); flex-shrink: 0; }
.inbox-reply-preview-content { flex: 1; min-width: 0; }
.inbox-reply-preview-sender { font-size: 11px; font-weight: 700; color: var(--accent, #A08C64); }
.inbox-reply-preview-text   { font-size: 12px; color: var(--text-muted, #64748b); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-reply-close { background: none; border: none; cursor: pointer; color: var(--text-muted, #64748b); padding: 4px; flex-shrink: 0; }
.inbox-reply-close:hover { color: #dc2626; }

/* File upload — attach button + preview */
.inbox-attach-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 8px; cursor: pointer; color: var(--text-muted, #64748b); transition: all 0.15s; flex-shrink: 0; }
.inbox-attach-btn:hover { color: var(--accent, #A08C64); background: rgba(160,140,100,0.10); }
.inbox-file-preview { padding: 6px 16px 0; }
.inbox-file-preview-inner { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; background: rgba(160,140,100,0.08); border: 1px solid var(--border, #e2e8f0); border-radius: 10px; }
.inbox-file-badge { font-size: 12px; color: var(--text-primary, #1e293b); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-file-remove { background: none; border: none; cursor: pointer; color: var(--text-muted, #64748b); font-size: 14px; padding: 2px 6px; border-radius: 4px; }
.inbox-file-remove:hover { background: rgba(0,0,0,0.05); color: #dc2626; }

/* Contact-panel tabs + media library */
.inbox-cp-tabs { display: flex; gap: 2px; margin: 0 0 12px; border-bottom: 1px solid var(--border, #e2e8f0); }
.inbox-cp-tab { padding: 7px 14px; border: none; background: none; cursor: pointer; font-size: 12px; color: var(--text-muted, #64748b); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.inbox-cp-tab.active { color: var(--accent, #A08C64); border-bottom-color: var(--accent, #A08C64); font-weight: 600; }
.inbox-cp-empty { color: var(--text-muted, #94a3b8); font-size: 12px; padding: 12px; text-align: center; }
.inbox-media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.inbox-media-thumb { aspect-ratio: 1; overflow: hidden; border-radius: 4px; cursor: pointer; position: relative; background: #000; transition: opacity 0.15s; }
.inbox-media-thumb img, .inbox-media-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.inbox-media-thumb:hover { opacity: 0.85; }
.inbox-media-video-badge { position: absolute; bottom: 4px; left: 4px; background: rgba(0,0,0,0.6); color: white; font-size: 10px; padding: 1px 6px; border-radius: 4px; }
.inbox-files-section { margin-bottom: 14px; }
.inbox-files-title { font-size: 10px; font-weight: 700; color: var(--text-muted, #64748b); text-transform: uppercase; margin-bottom: 6px; letter-spacing: 0.04em; }
.inbox-file-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 6px; border-bottom: 1px solid rgba(0,0,0,0.04); font-size: 12px; cursor: pointer; text-decoration: none; color: inherit; gap: 8px; }
.inbox-file-item:hover { background: rgba(0,0,0,0.02); }
.inbox-file-dir { color: var(--text-muted, #94a3b8); font-size: 11px; white-space: nowrap; }

/* Lightbox overlay for image/video preview */
.inbox-lightbox-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.92); z-index: 10000; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 14px; cursor: zoom-out; padding: 24px; box-sizing: border-box; }
.inbox-lightbox-content { cursor: default; display: flex; align-items: center; justify-content: center; }
.inbox-lightbox-close { position: absolute; top: 14px; right: 14px; background: rgba(255,255,255,0.18); border: none; border-radius: 50%; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: background 0.2s; }
.inbox-lightbox-close:hover { background: rgba(255,255,255,0.32); }
.inbox-lightbox-download { display: inline-flex; align-items: center; gap: 6px; color: white; text-decoration: none; font-size: 12px; padding: 7px 14px; border-radius: 8px; background: rgba(255,255,255,0.15); transition: background 0.2s; }
.inbox-lightbox-download:hover { background: rgba(255,255,255,0.32); }

.inbox-msg-file { display: inline-block; padding: 6px 10px; background: rgba(0,0,0,0.05); border-radius: 6px; text-decoration: none; color: inherit; font-size: 12px; }
.inbox-message.out .inbox-msg-file { background: rgba(255,255,255,0.15); }
.inbox-msg-meta { font-size: 10px; opacity: 0.7; margin-top: 4px; text-align: right; }
.inbox-message.in .inbox-msg-meta { color: var(--text-muted); opacity: 1; }
.inbox-msg-sender { font-weight: 600; }

.inbox-input-wrap { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: flex-end; background: var(--bg-card-solid); }
.inbox-input { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-primary); color: var(--text-primary); font-size: 13px; resize: none; outline: none; max-height: 100px; font-family: inherit; box-sizing: border-box; }
.inbox-input:focus { border-color: var(--accent); }
.inbox-send-btn { width: 36px; height: 36px; border-radius: 8px; background: var(--accent); color: white; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.inbox-send-btn:hover { opacity: 0.9; }

.inbox-contact-panel { border-left: 1px solid var(--border); padding: 16px; overflow-y: auto; background: var(--bg-card-solid); }
.inbox-cp-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.inbox-cp-header h3 { font-size: 14px; font-weight: 600; margin: 0; color: var(--text-primary); }
.inbox-cp-header button { background: none; border: none; cursor: pointer; color: var(--text-muted); }
.inbox-cp-avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: white; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; margin: 0 auto 10px; }
.inbox-cp-name { text-align: center; font-size: 15px; font-weight: 600; color: var(--text-primary); }
.inbox-cp-phone { text-align: center; font-size: 13px; color: var(--text-muted); margin: 4px 0; }
.inbox-cp-platform { text-align: center; font-size: 12px; color: var(--text-muted); margin-bottom: 16px; }
.inbox-cp-link { display: block; text-align: center; color: var(--accent); font-size: 13px; text-decoration: none; padding: 8px; border: 1px solid var(--accent); border-radius: 8px; margin-bottom: 8px; }
.inbox-cp-btn { display: block; width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: none; cursor: pointer; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.inbox-cp-btn:hover { background: var(--bg-primary); }
.inbox-cp-section { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.inbox-cp-section-title { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 6px; }
.inbox-cp-section div { font-size: 13px; margin-bottom: 3px; color: var(--text-primary); }

.inbox-platform-btn { padding: 6px 16px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg-card-solid); cursor: pointer; font-size: 13px; color: var(--text-muted); }
.inbox-platform-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

/* The inbox needs to reach the actual viewport bottom — global
   body { padding-bottom: 100px } and the mobile-only
   .main-content { padding-bottom: 80px + safe-area } reserve space for
   the bottom-nav and otherwise push the chat input ~80–100px above the
   real bottom edge. Cancel both while #page-inbox is the active page. */
body:has(#page-inbox.active) { padding-bottom: 0; }
body:has(#page-inbox.active) .main-content { padding-bottom: 0 !important; }
/* iOS notch / home indicator — keep the input row above the gesture bar. */
.inbox-input-wrap { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }

/* Reaction badges under message bubble (Viber 👍 / ❤ from customers) */
.inbox-msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.inbox-msg-reaction { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; padding: 1px 6px; background: rgba(15,23,42,0.06); border-radius: 10px; line-height: 18px; }
.inbox-message.out .inbox-msg-reaction { background: rgba(255,255,255,0.22); }

/* Mic button + recording bar */
.inbox-mic-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 8px; cursor: pointer; color: var(--text-muted, #64748b); border: none; background: none; transition: all 0.15s; flex-shrink: 0; }
.inbox-mic-btn:hover { color: var(--accent, #A08C64); background: rgba(160,140,100,0.10); }
.inbox-mic-btn.recording { color: #dc2626; background: rgba(220,38,38,0.10); }
.inbox-record-bar { display: none; align-items: center; gap: 10px; padding: 8px 16px; border-top: 1px solid var(--border, #e2e8f0); background: var(--bg-card-solid, #fff); }
.inbox-rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #dc2626; animation: inboxRecPulse 1s ease infinite; flex-shrink: 0; }
@keyframes inboxRecPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
.inbox-rec-time { font-size: 13px; font-weight: 600; color: var(--text-primary, #1e293b); font-variant-numeric: tabular-nums; min-width: 36px; }
.inbox-rec-hint { font-size: 12px; color: var(--text-muted, #94a3b8); flex: 1; }
.inbox-rec-cancel, .inbox-rec-send { width: 32px; height: 32px; border-radius: 50%; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.inbox-rec-cancel { background: rgba(15,23,42,0.06); color: var(--text-muted, #64748b); }
.inbox-rec-cancel:hover { background: rgba(220,38,38,0.10); color: #dc2626; }
.inbox-rec-send { background: var(--accent, #A08C64); color: #fff; }
.inbox-rec-send:hover { filter: brightness(1.1); }

@media (max-width: 768px) {
  /* 100svh = smallest stable viewport (URL bar visible). Avoids the
     "input below screen until first scroll" jump that 100dvh caused on
     iOS Safari fresh loads. */
  .inbox-layout { grid-template-columns: 1fr; grid-template-rows: 1fr; height: calc(100svh - 56px); }
  .inbox-main { display: none; }                       /* hidden until openChat() shows it */
  .inbox-back-btn { display: flex !important; }
  /* Contact panel becomes a full-screen slide-in overlay on mobile.
     Hidden by default; toggleContactPanel() flips display via JS — no
     !important so the inline override works. */
  .inbox-contact-panel {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 950;
    background: var(--bg-card-solid, #fff);
    overflow-y: auto;
    padding: 14px;
    width: auto;
    border-left: none;
  }
  /* Header gets sticky on mobile so the back button stays accessible
     while scrolling long threads. */
  .inbox-conv-header { position: sticky; top: 0; z-index: 5; }
}
@media (min-width: 769px) and (max-width: 1024px) {
  .inbox-layout { grid-template-columns: 280px 1fr; }
  .inbox-contact-panel { display: none !important; }
}

#sidebar-inbox-badge { background:#dc2626; color:white; border-radius:10px; padding:0 6px; font-size:10px; font-weight:700; margin-left:6px; display:none; vertical-align:middle; }

/* ===== E-chat channels (Settings → Інтеграції → Комунікації → E-chat) ===== */
.echat-channels-section { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }
.echat-channels-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.echat-add-channel-btn { padding: 4px 12px; border-radius: 6px; border: 1px solid var(--accent); background: none; color: var(--accent); cursor: pointer; font-size: 12px; font-weight: 500; }
.echat-add-channel-btn:hover { background: var(--accent); color: white; }

.echat-channel-item { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #f1f5f9; }
.echat-channel-item:last-child { border-bottom: none; }
.echat-channel-icon { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; flex-shrink: 0; }
.echat-channel-info { flex: 1; min-width: 0; }
.echat-channel-name { font-size: 13px; font-weight: 500; color: var(--text-primary); }
.echat-channel-phone { font-size: 11px; color: #94a3b8; }

.echat-channel-form { min-width: 360px; max-width: 520px; }
.echat-channel-tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.echat-tab { padding: 8px 16px; border: none; background: none; cursor: pointer; font-size: 13px; color: #64748b; border-bottom: 2px solid transparent; margin-bottom: -2px; font-weight: 500; }
.echat-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.echat-field { margin-bottom: 14px; }
.echat-field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: #64748b; }

.echat-auth-btn { display: inline-flex; align-items: center; gap: 8px; padding: 10px 24px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-card-solid); cursor: pointer; font-size: 14px; color: var(--text-primary); font-weight: 500; }
.echat-auth-btn:hover { background: var(--bg-primary); }
.echat-auth-btn:disabled { opacity: .6; cursor: not-allowed; }

/* ===== Google Ads Campaign Management page ===== */
.ac-page { padding: 18px 20px 40px; max-width: 1400px; margin: 0 auto; }
.ac-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.ac-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; color: var(--text-primary, #1e293b); }
.ac-sub { font-size: 13px; color: var(--text-muted, #64748b); }
.ac-header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ac-input { padding: 8px 12px; border: 1px solid var(--border, #e2e8f0); border-radius: 8px; font-size: 13px; background: var(--bg-card-solid, #fff); color: var(--text-primary, #1e293b); cursor: pointer; }
.ac-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border, #e2e8f0); background: var(--bg-card-solid, #fff); color: var(--text-primary, #1e293b); font-size: 13px; font-weight: 600; cursor: pointer; transition: all 0.15s; }
.ac-btn:hover { background: var(--bg, #f8fafc); }
.ac-btn-primary { background: var(--accent, #A08C64); color: #fff; border-color: var(--accent, #A08C64); }
.ac-btn-primary:hover { filter: brightness(1.1); }
.ac-btn-ghost { background: none; border: 1px solid var(--border, #e2e8f0); }
.ac-loading, .ac-empty, .ac-error { padding: 40px; text-align: center; color: var(--text-muted, #64748b); font-size: 14px; background: var(--bg-card-solid, #fff); border-radius: 10px; border: 1px solid var(--border, #e2e8f0); }
.ac-error { color: #dc2626; }

.ac-table { background: var(--bg-card-solid, #fff); border: 1px solid var(--border, #e2e8f0); border-radius: 10px; overflow: hidden; }
.ac-thead { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 0.7fr 0.8fr 0.7fr 1fr 1.2fr; gap: 10px; padding: 10px 14px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted, #64748b); background: var(--bg, #f8fafc); border-bottom: 1px solid var(--border, #e2e8f0); }
.ac-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 0.7fr 0.8fr 0.7fr 1fr 1.2fr; gap: 10px; padding: 12px 14px; align-items: center; font-size: 13px; border-bottom: 1px solid var(--border, #e2e8f0); transition: background 0.12s; }
.ac-row:hover { background: rgba(160,140,100,0.04); }
.ac-row:last-child { border-bottom: none; }
.ac-row .num { font-variant-numeric: tabular-nums; }
.ac-cname { min-width: 0; }
.ac-cname b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-primary, #1e293b); }
.ac-cid { font-size: 11px; color: var(--text-muted, #94a3b8); }

.ac-badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; text-transform: uppercase; letter-spacing: 0.02em; }
.ac-badge-green { background: rgba(22,163,74,0.12); color: #15803d; }
.ac-badge-amber { background: rgba(202,138,4,0.14); color: #a16207; }
.ac-badge-red   { background: rgba(220,38,38,0.12); color: #b91c1c; }
.ac-badge-gray  { background: rgba(100,116,139,0.12); color: #475569; }

.ac-actions { display: flex; gap: 4px; justify-content: flex-end; }
.ac-act { width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border, #e2e8f0); background: var(--bg-card-solid, #fff); color: var(--text-muted, #64748b); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0; transition: all 0.12s; }
.ac-act:hover { background: var(--accent, #A08C64); color: #fff; border-color: var(--accent, #A08C64); }
.ac-act-danger:hover { background: #dc2626; border-color: #dc2626; color: #fff; }

.ac-form { padding: 6px 4px 0; max-width: 520px; }
.ac-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.ac-form-grid label { display: block; font-size: 11px; font-weight: 600; color: var(--text-muted, #64748b); }
.ac-form-grid label input, .ac-form-grid label select { width: 100%; margin-top: 4px; padding: 9px 11px; border: 1px solid var(--border, #e2e8f0); border-radius: 8px; font-size: 13px; box-sizing: border-box; }
.ac-hint { font-size: 12px; color: var(--text-muted, #94a3b8); margin: 12px 0 0; }
.ac-form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

@media (max-width: 900px) {
  .ac-thead, .ac-row { grid-template-columns: 1.6fr 0.8fr 0.7fr 0.7fr 0.6fr 1fr; }
  .ac-thead > :nth-child(5), .ac-row > :nth-child(5),
  .ac-thead > :nth-child(6), .ac-row > :nth-child(6),
  .ac-thead > :nth-child(7), .ac-row > :nth-child(7) { display: none; }
  .ac-form-grid { grid-template-columns: 1fr; }
}

/* Ads campaigns — drilldown (ad groups) */
.ac-link { color: var(--accent, #A08C64); text-decoration: none; cursor: pointer; }
.ac-link:hover { text-decoration: underline; }
.ac-drill { background: var(--bg-card-solid, #fff); border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 16px; }
.ac-drill-top { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.ac-drill-info { flex: 1; min-width: 0; }
.ac-drill-name { font-size: 16px; font-weight: 700; color: var(--text-primary, #1e293b); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-drill-sub { font-size: 12px; color: var(--text-muted, #64748b); margin-top: 2px; }
.ac-pmax-note { font-size: 12px; color: #a16207; background: rgba(202,138,4,0.10); padding: 6px 10px; border-radius: 6px; }
.ac-adgroups { }
.ac-adg-table .ac-thead, .ac-adg-table .ac-row { grid-template-columns: 2fr 1fr 1fr 1fr 0.7fr 0.7fr 0.8fr 1fr 1.2fr; }
@media (max-width: 900px) {
  .ac-adg-table .ac-thead, .ac-adg-table .ac-row { grid-template-columns: 1.6fr 0.8fr 0.8fr 1fr 1fr; }
  .ac-adg-table .ac-thead > :nth-child(5), .ac-adg-table .ac-row > :nth-child(5),
  .ac-adg-table .ac-thead > :nth-child(6), .ac-adg-table .ac-row > :nth-child(6),
  .ac-adg-table .ac-thead > :nth-child(7), .ac-adg-table .ac-row > :nth-child(7) { display: none; }
}

/* Level-2 drilldown: ads + keywords side by side */
.ac-l2-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .ac-l2-grid { grid-template-columns: 1fr; } }
.ac-l2-section { background: var(--bg-card-solid, #fff); border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 14px; }
.ac-l2-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.ac-l2-head h3 { margin: 0; font-size: 14px; font-weight: 700; color: var(--text-primary, #1e293b); }
.ac-l2-actions { display: flex; gap: 6px; }
.ac-muted { color: var(--text-muted, #64748b); }

/* Ads list cards */
.ac-ads-box { display: flex; flex-direction: column; gap: 10px; }
.ac-ad-card { border: 1px solid var(--border, #e2e8f0); border-radius: 8px; padding: 10px 12px; position: relative; background: #fafbfc; }
.ac-ad-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.ac-ad-title { font-size: 13px; font-weight: 600; color: #1a73e8; line-height: 1.3; overflow: hidden; }
.ac-ad-desc { font-size: 12px; color: var(--text-secondary, #4b5563); line-height: 1.4; margin-bottom: 4px; }
.ac-ad-meta { font-size: 11px; display: flex; gap: 6px; flex-wrap: wrap; }
.ac-ad-actions { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.ac-ad-card:hover .ac-ad-actions { opacity: 1; }

/* Keywords */
.ac-kw-box { display: flex; flex-direction: column; gap: 14px; }
.ac-kw-group { }
.ac-kw-title { font-size: 12px; font-weight: 600; color: var(--text-muted, #64748b); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.ac-kw-list { display: flex; flex-direction: column; gap: 4px; }
.ac-kw-item { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border: 1px solid var(--border, #e2e8f0); border-radius: 6px; background: #fafbfc; }
.ac-kw-item.ac-kw-neg { background: #fef2f2; border-color: #fecaca; }
.ac-kw-text { flex: 1; font-size: 13px; display: flex; align-items: center; gap: 6px; min-width: 0; }
.ac-kw-text .ac-kw-match { color: var(--text-muted, #64748b); font-family: monospace; font-size: 11px; }
.ac-kw-badge { font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 3px; background: #e2e8f0; color: #475569; }
.ac-kw-metrics { display: flex; gap: 10px; font-size: 11px; color: var(--text-muted, #64748b); }
.ac-kw-item .ac-act { padding: 2px 6px; }

/* Campaign drill tabs */
.ac-tabs { display: flex; align-items: center; gap: 6px; border-bottom: 1px solid var(--border, #e2e8f0); margin-bottom: 14px; padding-bottom: 0; }
.ac-tab { background: none; border: none; padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--text-muted, #64748b); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.ac-tab:hover { color: var(--text-primary, #1e293b); }
.ac-tab.is-active { color: #1a73e8; border-bottom-color: #1a73e8; }
.ac-tabs-spacer { flex: 1; }
.ac-tab-action { margin-bottom: 6px; }

/* Criteria (targeting) grid */
.ac-crit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .ac-crit-grid { grid-template-columns: 1fr; } }
.ac-crit-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.ac-crit-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px; border: 1px solid var(--border, #e2e8f0); border-radius: 6px; background: #fafbfc; font-size: 13px; }
.ac-crit-item.ac-kw-neg { background: #fef2f2; border-color: #fecaca; }
.ac-crit-name { display: flex; align-items: center; gap: 8px; }
.ac-bid-mod { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 3px; background: #dbeafe; color: #1d4ed8; }

/* Geo picker */
.ac-geo-results { max-height: 240px; overflow-y: auto; border: 1px solid var(--border, #e2e8f0); border-radius: 6px; margin-bottom: 10px; }
.ac-geo-results:empty { display: none; }
.ac-geo-row { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--border, #e2e8f0); font-size: 13px; }
.ac-geo-row:last-child { border-bottom: 0; }
.ac-geo-row:hover { background: #eff6ff; }
.ac-geo-picked-title { font-size: 12px; font-weight: 600; color: var(--text-muted, #64748b); margin: 8px 0 4px; }
.ac-geo-picked-row { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border: 1px solid var(--border, #e2e8f0); border-radius: 6px; background: #f8fafc; font-size: 13px; margin-bottom: 4px; }
.ac-geo-picked-row > span:first-child { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-inline { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-secondary, #4b5563); white-space: nowrap; }

/* Language chips */
.ac-lang-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 6px; }
.ac-lang-chip { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border: 1px solid var(--border, #e2e8f0); border-radius: 6px; font-size: 13px; cursor: pointer; background: #fafbfc; }
.ac-lang-chip:has(input:checked) { background: #eff6ff; border-color: #93c5fd; }

/* Schedule grid */
.ac-sched-grid { display: flex; flex-direction: column; gap: 4px; }
.ac-sched-head { display: grid; grid-template-columns: 1.4fr 0.8fr 0.8fr 1fr; gap: 6px; font-size: 11px; font-weight: 600; color: var(--text-muted, #64748b); text-transform: uppercase; letter-spacing: .04em; padding: 0 8px; }
.ac-sched-row { display: grid; grid-template-columns: 1.4fr 0.8fr 0.8fr 1fr; gap: 6px; align-items: center; padding: 4px 8px; border: 1px solid var(--border, #e2e8f0); border-radius: 6px; }
.ac-sched-row input[type=number] { width: 100%; padding: 5px 6px; border: 1px solid var(--border, #e2e8f0); border-radius: 4px; font-size: 13px; }
.ac-sched-row label { display: flex; align-items: center; gap: 6px; font-size: 13px; }

/* Ads inline-SVG icons — align with text baseline, gentle muted color
   unless overridden by parent (buttons / badges inherit accent color). */
.ac-ic { display: inline-block; vertical-align: -2px; flex-shrink: 0; margin-right: 4px; opacity: 0.85; }
.ac-btn .ac-ic, .ac-tab .ac-ic, h3 .ac-ic, h4 .ac-ic { opacity: 1; }
.ac-act .ac-ic { margin-right: 0; opacity: 1; }
.ac-tile-label .ac-ic { vertical-align: -2px; margin-right: 4px; }

/* Campaigns table — extra leading column for bulk-select checkbox */
.ac-camp-table .ac-thead, .ac-camp-table .ac-row { grid-template-columns: 36px 2fr 1fr 1fr 1fr 0.7fr 0.8fr 0.8fr 0.7fr 1fr 1.2fr; }
.ac-row.is-selected { background: rgba(26,115,232,0.06); }
.ac-row-cb, #ac-sel-all { width: 16px; height: 16px; cursor: pointer; }

/* Bulk action bar */
.ac-bulk-bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #1e293b; color: #fff; border-radius: 8px; margin-bottom: 10px; box-shadow: 0 4px 12px rgba(0,0,0,.15); }
.ac-bulk-count { font-size: 13px; }
.ac-bulk-spacer { flex: 1; }
.ac-bulk-bar .ac-btn-ghost { background: rgba(255,255,255,0.10); color: #fff; border: 1px solid rgba(255,255,255,0.20); }
.ac-bulk-bar .ac-btn-ghost:hover { background: rgba(255,255,255,0.20); }
.ac-bulk-bar .ac-bulk-danger { color: #fca5a5; }
.ac-bulk-bar .ac-bulk-danger:hover { background: #b91c1c; color: #fff; border-color: #b91c1c; }
@media (max-width: 900px) {
  .ac-camp-table .ac-thead, .ac-camp-table .ac-row { grid-template-columns: 32px 1.6fr 0.8fr 0.7fr 0.7fr 0.6fr 0.6fr 1fr; }
  .ac-camp-table .ac-thead > :nth-child(4), .ac-camp-table .ac-row > :nth-child(4) { display: none; } /* Hide budget column */
}

/* Competitive insights (Impression Share) */
.ac-comp-accts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.ac-comp-summary { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.ac-comp-list { display: flex; flex-direction: column; gap: 10px; }
.ac-comp-card { background: var(--bg-card-solid, #fff); border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 14px 16px; border-left-width: 4px; }
.ac-comp-card.ac-comp-WINNING     { border-left-color: #16a34a; }
.ac-comp-card.ac-comp-RANK_LOSS   { border-left-color: #dc2626; }
.ac-comp-card.ac-comp-BUDGET_LOSS { border-left-color: #f59e0b; background: #fffbeb; }
.ac-comp-card.ac-comp-MIXED       { border-left-color: #94a3b8; }
.ac-comp-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.ac-comp-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 900px) { .ac-comp-grid { grid-template-columns: repeat(2, 1fr); } }
.ac-comp-metric { display: flex; flex-direction: column; gap: 4px; }
.ac-comp-label { font-size: 11px; font-weight: 600; color: var(--text-muted, #64748b); text-transform: uppercase; letter-spacing: .03em; }
.ac-comp-value { font-size: 13px; font-variant-numeric: tabular-nums; }
.ac-comp-value b { font-size: 14px; }
.ac-comp-action { margin-top: 10px; font-size: 12px; }
.ac-comp-hint { color: #1e40af; font-weight: 600; }
.ac-comp-card.ac-comp-BUDGET_LOSS .ac-comp-hint { color: #92400e; }
.ac-comp-card.ac-comp-RANK_LOSS .ac-comp-hint   { color: #991b1b; }

/* Generic progress bar */
.ac-bar { width: 100%; height: 6px; background: #e2e8f0; border-radius: 3px; overflow: hidden; }
.ac-bar-fill { height: 100%; transition: width .25s; }

/* A/B Experiments */
.ac-exp-table .ac-thead, .ac-exp-table .ac-row { grid-template-columns: 2fr 0.8fr 1.4fr 1fr 1fr 1.2fr; }
.ac-exp-lifecycle { display: flex; gap: 6px; flex-shrink: 0; }
.ac-exp-compare {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 0;
  background: var(--bg-card-solid, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  overflow: hidden;
}
.ac-exp-arm { padding: 14px 16px; border-bottom: 1px solid var(--border, #e2e8f0); background: var(--bg, #f8fafc); }
.ac-exp-arm:first-of-type { grid-column: 1 / span 1; visibility: hidden; }
.ac-exp-arm-title { font-size: 14px; font-weight: 700; color: var(--text-primary, #1e293b); }
.ac-exp-arm-meta { font-size: 12px; color: var(--text-muted, #64748b); margin-top: 2px; }
.ac-exp-control { border-right: 2px solid #cbd5e1; }
.ac-exp-trial { background: #eff6ff; }
.ac-exp-row-label { padding: 10px 16px; border-bottom: 1px solid var(--border, #e2e8f0); font-size: 12px; font-weight: 600; color: var(--text-muted, #64748b); text-transform: uppercase; letter-spacing: .04em; background: var(--bg, #f8fafc); }
.ac-exp-cell { padding: 10px 16px; border-bottom: 1px solid var(--border, #e2e8f0); font-size: 14px; font-variant-numeric: tabular-nums; }
.ac-exp-cell:nth-of-type(3n + 2) { border-right: 2px solid #cbd5e1; }
.ac-exp-cell .is-pos { color: #16a34a; font-weight: 600; }
.ac-exp-cell .is-neg { color: #dc2626; font-weight: 600; }

/* Anomaly alerts */
.ac-anom-list { display: flex; flex-direction: column; gap: 6px; }
.ac-anom-item { display: flex; align-items: flex-start; gap: 10px; padding: 8px 12px; border-radius: 8px; background: var(--bg-card-solid, #fff); border: 1px solid var(--border, #e2e8f0); font-size: 13px; }
.ac-anom-item.ac-anom-high   { background: #fef2f2; border-color: #fecaca; }
.ac-anom-item.ac-anom-medium { background: #fffbeb; border-color: #fde68a; }
.ac-anom-body { flex: 1; min-width: 0; }

/* Audit log */
.ac-audit-list { display: flex; flex-direction: column; gap: 6px; }
.ac-audit-item { background: var(--bg-card-solid, #fff); border: 1px solid var(--border, #e2e8f0); border-radius: 8px; padding: 10px 12px; }
.ac-audit-item.is-err { background: #fef2f2; border-color: #fecaca; }
.ac-audit-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12px; }
.ac-audit-time { color: var(--text-muted, #64748b); white-space: nowrap; min-width: 80px; }
.ac-audit-user { font-weight: 600; }
.ac-audit-rtype { color: var(--text-muted, #64748b); font-family: monospace; }
.ac-audit-rn { font-family: monospace; font-size: 11px; color: var(--text-muted, #64748b); margin-top: 4px; word-break: break-all; }
.ac-audit-details { font-size: 12px; margin-top: 4px; color: var(--text-secondary, #4b5563); }

/* Sortable column headers */
.ac-thead .ac-sortable { cursor: pointer; user-select: none; display: flex; align-items: center; gap: 4px; transition: color .12s; }
.ac-thead .ac-sortable:hover { color: var(--text-primary, #1e293b); }
.ac-thead .ac-sortable.is-active { color: #1a73e8; }
.ac-sort-arrow { font-size: 10px; opacity: 0.7; min-width: 8px; }
.ac-sortable.is-active .ac-sort-arrow { opacity: 1; }

/* Dashboard */
.ac-dash-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 20px; }
.ac-tile { background: var(--bg-card-solid, #fff); border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 14px 16px; }
.ac-tile-label { font-size: 11px; font-weight: 600; color: var(--text-muted, #64748b); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.ac-tile-value { font-size: 24px; font-weight: 700; color: var(--text-primary, #1e293b); }
.ac-dash-section { margin-bottom: 20px; }
.ac-dash-section h3 { font-size: 14px; font-weight: 700; margin: 0 0 8px; color: var(--text-primary, #1e293b); }
.ac-dash-acct-table .ac-thead, .ac-dash-acct-table .ac-row { grid-template-columns: 2fr 1.2fr 0.9fr 0.9fr 1.2fr 0.7fr; }
.ac-dash-chan-table .ac-thead, .ac-dash-chan-table .ac-row { grid-template-columns: 1.8fr 1fr 0.9fr 0.9fr 1.2fr; }
.ac-dash-top-table .ac-thead, .ac-dash-top-table .ac-row { grid-template-columns: 2.2fr 1.1fr 0.9fr 0.9fr 0.7fr; }
.ac-row-error { background: #fef2f2; }
@media (max-width: 900px) {
  .ac-dash-acct-table .ac-thead, .ac-dash-acct-table .ac-row { grid-template-columns: 1.6fr 1fr 0.8fr 0.6fr; }
  .ac-dash-acct-table .ac-thead > :nth-child(5), .ac-dash-acct-table .ac-row > :nth-child(5),
  .ac-dash-acct-table .ac-thead > :nth-child(3), .ac-dash-acct-table .ac-row > :nth-child(3) { display: none; }
}

/* Recommendations cards */
.ac-rec-list { display: flex; flex-direction: column; gap: 10px; }
.ac-rec-card { background: var(--bg-card-solid, #fff); border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 14px 16px; position: relative; }
.ac-rec-card.is-positive { border-left: 3px solid #16a34a; }
.ac-rec-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ac-rec-title { flex: 1; min-width: 0; }
.ac-rec-scope { font-size: 12px; margin-top: 3px; }
.ac-rec-actions { display: flex; gap: 6px; flex-shrink: 0; }
.ac-rec-detail { margin-top: 10px; padding: 8px 10px; background: #f8fafc; border-radius: 6px; font-size: 13px; }
.ac-rec-impact { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.ac-rec-metric { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 4px; background: #e2e8f0; color: #475569; }
.ac-rec-metric.is-pos { background: #dcfce7; color: #166534; }
.ac-rec-metric.is-neg { background: #fee2e2; color: #991b1b; }
.ac-rec-metric.is-warn { background: #fef3c7; color: #92400e; }

/* Headline (marginal ROAS) — single big number in the header row */
.ac-rec-headline { font-size: 14px; font-weight: 800; padding: 4px 10px; border-radius: 6px; white-space: nowrap; align-self: center; }
.ac-rec-headline.is-pos  { background: #dcfce7; color: #14532d; }
.ac-rec-headline.is-warn { background: #fef3c7; color: #78350f; }
.ac-rec-headline.is-neg  { background: #fee2e2; color: #7f1d1d; }

/* Details disclosure */
.ac-rec-details { margin-top: 12px; border-top: 1px solid var(--border, #e2e8f0); padding-top: 10px; }
.ac-rec-details > summary { cursor: pointer; font-size: 12px; font-weight: 700; color: var(--text-muted, #64748b); list-style: none; padding: 4px 0; user-select: none; }
.ac-rec-details > summary::-webkit-details-marker { display: none; }
.ac-rec-details > summary::before { content: '▸ '; transition: transform .15s; display: inline-block; margin-right: 4px; }
.ac-rec-details[open] > summary::before { content: '▾ '; }
.ac-rec-details[open] > summary { color: var(--text-primary, #1e293b); margin-bottom: 8px; }
.ac-rec-section { margin: 10px 0; font-size: 13px; line-height: 1.5; color: var(--text-secondary, #475569); }
.ac-rec-section-h { font-size: 11px; font-weight: 700; color: var(--text-muted, #64748b); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.ac-rec-disclaimer { margin-top: 8px; font-size: 11px; color: var(--text-muted, #94a3b8); font-style: italic; }
.ac-rec-risks ul { margin: 4px 0 0 18px; padding: 0; }
.ac-rec-risks li { font-size: 12px; color: #b45309; margin-bottom: 2px; }

/* Scenario grid */
.ac-rec-scenarios { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 6px; }
@media (max-width: 700px) { .ac-rec-scenarios { grid-template-columns: 1fr; } }
.ac-rec-sc { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border, #e2e8f0); }
.ac-rec-sc-cons { background: #f8fafc; }
.ac-rec-sc-base { background: #eff6ff; border-color: #bfdbfe; }
.ac-rec-sc-opt  { background: #f0fdf4; border-color: #bbf7d0; }
.ac-rec-sc-label { font-size: 11px; font-weight: 700; color: var(--text-muted, #64748b); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.ac-rec-sc-row { display: flex; justify-content: space-between; font-size: 12px; padding: 2px 0; }
.ac-rec-sc-row span { color: var(--text-muted, #64748b); }
.ac-rec-sc-row b { font-variant-numeric: tabular-nums; }
.ac-rec-sc-roas { border-top: 1px solid rgba(0,0,0,0.06); margin-top: 4px; padding-top: 4px; }
.ac-rec-sc-roas b { font-size: 14px; }

/* Period picker */
.ac-period-btn { white-space: nowrap; }
.ac-period-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; }
.ac-period-opt { padding: 8px 12px; border: 1px solid var(--border, #e2e8f0); border-radius: 6px; background: #fff; font-size: 13px; cursor: pointer; text-align: center; transition: .15s; }
.ac-period-opt:hover { background: #f1f5f9; }
.ac-period-opt.is-active { background: #1a73e8; color: #fff; border-color: #1a73e8; }
.ac-period-custom { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; padding-top: 12px; border-top: 1px solid var(--border, #e2e8f0); }
.ac-period-custom label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-muted, #64748b); }
.ac-period-custom input[type=date] { padding: 7px 10px; border: 1px solid var(--border, #e2e8f0); border-radius: 6px; font-size: 13px; }

/* Conversions table */
.ac-conv-header { margin-bottom: 14px; }
.ac-conv-header h3 { margin: 0 0 4px; font-size: 16px; }
.ac-conv-table .ac-thead, .ac-conv-table .ac-row {
  grid-template-columns: 2fr 1.2fr 1.2fr 0.9fr 0.7fr 0.7fr 0.9fr 0.5fr;
}
@media (max-width: 900px) {
  .ac-conv-table .ac-thead, .ac-conv-table .ac-row { grid-template-columns: 1.6fr 0.8fr 0.7fr 0.6fr 0.5fr; }
  .ac-conv-table .ac-thead > :nth-child(2), .ac-conv-table .ac-row > :nth-child(2),
  .ac-conv-table .ac-thead > :nth-child(3), .ac-conv-table .ac-row > :nth-child(3),
  .ac-conv-table .ac-thead > :nth-child(4), .ac-conv-table .ac-row > :nth-child(4) { display: none; }
}

/* iOS-style toggle switch */
.ac-switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.ac-switch input { opacity: 0; width: 0; height: 0; }
.ac-switch span { position: absolute; cursor: pointer; inset: 0; background: #cbd5e1; transition: .2s; border-radius: 22px; }
.ac-switch span::before { position: absolute; content: ''; height: 16px; width: 16px; left: 3px; top: 3px; background: #fff; transition: .2s; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.ac-switch input:checked + span { background: #16a34a; }
.ac-switch input:checked + span::before { transform: translateX(16px); }

/* PMax asset groups */
.ac-ag-table .ac-thead, .ac-ag-table .ac-row { grid-template-columns: 2fr 1fr 2fr 0.5fr; }
.ac-pmax-section { background: var(--bg-card-solid, #fff); border: 1px solid var(--border, #e2e8f0); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.ac-pmax-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.ac-pmax-section-head h4 { margin: 0; font-size: 13px; font-weight: 700; }
.ac-pmax-sections { margin-top: 14px; }

/* Search terms table */
.ac-st-section { margin-top: 14px; }
.ac-st-table .ac-thead, .ac-st-table .ac-row { grid-template-columns: 2.6fr 0.8fr 0.8fr 1fr 0.8fr 1fr 0.6fr; }
@media (max-width: 900px) {
  .ac-st-table .ac-thead, .ac-st-table .ac-row { grid-template-columns: 1.8fr 0.7fr 1fr 0.7fr 0.6fr; }
  .ac-st-table .ac-thead > :nth-child(3), .ac-st-table .ac-row > :nth-child(3),
  .ac-st-table .ac-thead > :nth-child(6), .ac-st-table .ac-row > :nth-child(6) { display: none; }
}

/* AI-negatives results */
.ac-aineg-summary { padding: 10px 12px; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 6px; font-size: 13px; color: #1e3a8a; margin-bottom: 12px; }
.ac-aineg-section { margin-bottom: 16px; }
.ac-aineg-title { font-size: 13px; font-weight: 700; color: var(--text-primary, #1e293b); margin-bottom: 6px; }
.ac-aineg-list { display: flex; flex-direction: column; gap: 4px; }
.ac-aineg-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--border, #e2e8f0); border-radius: 6px; background: #fafbfc; font-size: 13px; flex-wrap: wrap; }
.ac-aineg-item.ac-aineg-keep { background: #f0fdf4; border-color: #bbf7d0; }
.ac-aineg-text { font-weight: 600; }
.ac-aineg-reason { font-size: 12px; }

/* RSA form */
.ac-rsa-form { display: flex; flex-direction: column; gap: 14px; }
.ac-rsa-section { }
.ac-rsa-label { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; font-weight: 600; color: var(--text-secondary, #4b5563); margin-bottom: 6px; }
.ac-rsa-fields { display: flex; flex-direction: column; gap: 6px; }
.ac-rsa-h, .ac-rsa-d { width: 100%; padding: 7px 10px; border: 1px solid var(--border, #e2e8f0); border-radius: 6px; font-size: 13px; font-family: inherit; }
.ac-rsa-d { resize: vertical; min-height: 50px; }
.ac-rsa-add { font-size: 11px; padding: 3px 8px; }

/* ── UNIVERSAL FUNNEL ────────────────────── */
.uf-page { display:flex; flex-direction:column; height:100%; overflow:hidden; }
.uf-header { display:flex; justify-content:space-between; align-items:center; padding:12px 20px; border-bottom:1px solid var(--border); gap:12px; flex-wrap:wrap; }
.uf-header-left { display:flex; align-items:center; gap:12px; flex:1; }
.uf-header-right { display:flex; align-items:center; gap:8px; }
.uf-funnel-badge { padding:4px 12px; border-radius:20px; font-size:13px; font-weight:600; }
.uf-total-count { font-size:12px; color:var(--text-muted); }
.uf-search { padding:6px 12px; border:1px solid var(--border); border-radius:8px; font-size:13px; background:var(--bg); min-width:160px; }
.uf-view-toggle { display:flex; border:1px solid var(--border); border-radius:8px; overflow:hidden; }
.uf-view-btn { width:32px; height:32px; display:flex; align-items:center; justify-content:center; border:none; background:none; cursor:pointer; color:var(--text-muted); }
.uf-view-btn.active { background:var(--accent); color:white; }
.uf-btn-primary { padding:7px 16px; background:var(--accent); color:white; border:none; border-radius:8px; font-size:13px; font-weight:500; cursor:pointer; }
.uf-content { flex:1; overflow:hidden; }
.uf-kanban { display:flex; gap:12px; padding:16px 20px; overflow-x:auto; height:100%; align-items:flex-start; }
.uf-column { flex:0 0 270px; background:var(--bg); border-radius:10px; border:1px solid var(--border); max-height:calc(100vh - 160px); display:flex; flex-direction:column; transition:border-color 0.15s; }
.uf-column.drag-over { border-color:var(--accent); background:rgba(var(--accent-rgb,99,102,241),0.03); }
.uf-col-header { display:flex; align-items:center; gap:8px; padding:10px 12px; border-bottom:1px solid var(--border); position:sticky; top:0; background:var(--bg); border-radius:10px 10px 0 0; }
.uf-col-dot { width:10px; height:10px; border-radius:50%; flex-shrink:0; }
.uf-col-name { flex:1; font-size:13px; font-weight:600; }
.uf-col-count { font-size:11px; background:var(--bg-card); padding:2px 7px; border-radius:10px; color:var(--text-muted); }
.uf-col-add { width:22px; height:22px; border:1px solid var(--border); border-radius:6px; background:none; cursor:pointer; font-size:14px; color:var(--text-muted); display:flex; align-items:center; justify-content:center; line-height:1; }
.uf-col-add:hover { background:var(--accent); color:white; border-color:var(--accent); }
.uf-col-items { padding:8px; overflow-y:auto; display:flex; flex-direction:column; gap:6px; }
.uf-card { background:var(--bg-card); border:1px solid var(--border); border-radius:8px; padding:10px 12px; cursor:pointer; transition:all 0.15s; user-select:none; }
.uf-card:hover { border-color:var(--accent); box-shadow:0 2px 8px rgba(0,0,0,0.08); }
.uf-card.dragging { opacity:0.4; }
.uf-card-header { display:flex; justify-content:space-between; align-items:flex-start; gap:8px; margin-bottom:6px; }
.uf-card-name { font-size:13px; font-weight:500; line-height:1.3; }
.uf-prio-dot { width:8px; height:8px; border-radius:50%; flex-shrink:0; display:inline-block; }
.uf-card-row { display:flex; align-items:center; gap:5px; font-size:12px; color:var(--text-muted); margin-bottom:3px; }
.uf-card-footer { display:flex; justify-content:space-between; align-items:center; margin-top:8px; padding-top:6px; border-top:1px solid rgba(0,0,0,0.06); }
.uf-card-manager { font-size:11px; color:var(--text-muted); }
.uf-card-manager.unassigned { opacity:0.6; }
.uf-card-time { font-size:10px; color:var(--text-muted); }
.uf-card-notes { font-size:11px; color:var(--text-muted); margin-top:5px; font-style:italic; }
.uf-list { padding:16px 20px; overflow-y:auto; height:100%; }
.uf-list-header { display:grid; grid-template-columns:2fr 1fr 1fr 1fr 1fr 0.5fr 0.5fr; gap:8px; padding:8px 12px; font-size:11px; font-weight:600; color:var(--text-muted); text-transform:uppercase; letter-spacing:0.04em; border-bottom:1px solid var(--border); }
.uf-list-row { display:grid; grid-template-columns:2fr 1fr 1fr 1fr 1fr 0.5fr 0.5fr; gap:8px; padding:10px 12px; border-bottom:1px solid var(--border-light,rgba(0,0,0,0.04)); cursor:pointer; font-size:13px; transition:background 0.1s; }
.uf-list-row:hover { background:var(--bg); }
.uf-list-name { font-weight:500; }
.uf-list-muted { color:var(--text-muted); font-size:12px; }
.uf-stage-pill { padding:2px 8px; border-radius:10px; font-size:11px; font-weight:500; }
.uf-empty { text-align:center; padding:60px; color:var(--text-muted); }
.uf-modal-overlay { position:fixed; inset:0; background:rgba(0,0,0,0.4); z-index:9999; display:flex; align-items:center; justify-content:center; padding:20px; }
.uf-modal { background:var(--bg-card); border-radius:12px; width:100%; max-width:520px; max-height:90vh; display:flex; flex-direction:column; overflow:hidden; box-shadow:0 20px 60px rgba(0,0,0,0.15); }
.uf-modal-header { display:flex; justify-content:space-between; align-items:center; padding:16px 20px; border-bottom:1px solid var(--border); }
.uf-modal-title { font-size:16px; font-weight:600; }
.uf-modal-close { background:none; border:none; cursor:pointer; font-size:18px; color:var(--text-muted); }
.uf-modal-body { padding:20px; overflow-y:auto; }
.uf-form-row { margin-bottom:14px; }
.uf-form-row.two-col { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.uf-form-row label { display:block; font-size:12px; color:var(--text-muted); margin-bottom:4px; font-weight:500; }
.uf-form-row input,.uf-form-row select,.uf-form-row textarea { width:100%; padding:8px 10px; border:1px solid var(--border); border-radius:6px; font-size:13px; background:var(--bg); color:var(--text); }
.uf-form-footer { display:flex; justify-content:flex-end; gap:8px; padding-top:16px; margin-top:8px; border-top:1px solid var(--border); }
.uf-btn-submit { padding:8px 18px; background:var(--accent); color:white; border:none; border-radius:8px; font-size:13px; cursor:pointer; }
.uf-btn-cancel { padding:8px 18px; background:none; border:1px solid var(--border); border-radius:8px; font-size:13px; cursor:pointer; }
.uf-btn-danger { padding:8px 18px; background:#ef4444; color:white; border:none; border-radius:8px; font-size:13px; cursor:pointer; margin-right:auto; }
@media (max-width:768px) {
  .uf-kanban { padding:10px; gap:8px; }
  .uf-column { flex:0 0 260px; }
  .uf-form-row.two-col { grid-template-columns:1fr; }
  .uf-list-header,.uf-list-row { grid-template-columns:2fr 1fr 1fr; }
  .uf-list-header span:nth-child(n+4),.uf-list-row span:nth-child(n+4) { display:none; }
}

/* ── FUNNEL SWITCHER ─────────────────────── */
.uf-switcher {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  background: var(--bg-card);
  flex-shrink: 0;
}
.uf-sw-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid transparent;
  background: var(--bg);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  color: var(--text-muted);
  transition: all 0.15s;
}
.uf-sw-btn:hover {
  background: var(--bg-card);
  color: var(--text);
}
.uf-sw-btn.active {
  border-color: var(--sw-color, var(--accent));
  color: var(--sw-color, var(--accent));
  background: var(--bg-card);
  font-weight: 500;
}
.uf-sw-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.uf-sw-count {
  font-size: 11px;
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}
.uf-sw-new {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px dashed var(--border);
  background: none;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  margin-left: 4px;
}
.uf-sw-new:hover { border-color: var(--accent); color: var(--accent); border-style: solid; }

@media (max-width: 768px) {
  .uf-switcher { padding: 8px 12px; }
}

/* ── UNIVERSAL FUNNEL BULK OPERATIONS ─────── */
.uf-bulk-cb {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-radius: 3px;
  background: var(--bg-card-solid);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.uf-bulk-cb:hover {
  border-color: var(--accent);
}

.uf-bulk-cb-on {
  background: var(--accent);
  border-color: var(--accent);
}

.uf-bulk-cb-on::after {
  content: '✓';
  color: white;
  font-size: 10px;
  font-weight: bold;
}

.uf-col-bulk-cb {
  margin-right: 8px;
}

.uf-card-selected {
  background: var(--accent) !important;
  color: white !important;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3) !important;
}

.uf-card-selected * {
  color: white !important;
}

.uf-card-selected .uf-prio-dot {
  background: rgba(255, 255, 255, 0.7) !important;
}

.uf-card .uf-bulk-cb {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  background: var(--bg-card-solid);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ── UNIVERSAL FUNNEL FILTERS ─────────────── */
.uf-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.uf-filter {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card-solid);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  min-width: 120px;
  outline: none;
  transition: all 0.2s;
}

.uf-filter:hover,
.uf-filter:focus {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.uf-filter-clear {
  padding: 6px 10px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}

.uf-filter-clear:hover {
  background: var(--danger-hover);
}

/* ── UNIVERSAL FUNNEL HEADER ───────────────── */
.uf-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.uf-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.uf-btn,
.uf-btn-primary,
.uf-btn-secondary {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s;
  white-space: nowrap;
}

.uf-btn-primary {
  background: var(--primary);
  color: white;
}

.uf-btn-primary:hover {
  background: var(--primary-hover);
}

.uf-btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.uf-btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.uf-selected-count {
  color: var(--accent);
  font-weight: 600;
}

/* ── UNIVERSAL FUNNEL MODAL ENHANCEMENTS ──── */
.uf-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1300;
  display: flex;
  align-items: center;
  justify-content: center;
}

.uf-modal {
  background: var(--bg-card-solid);
  border-radius: 12px;
  max-width: 900px;
  max-height: 85vh;
  width: 90%;
  display: flex;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0,0,0,0.15);
}

@media (max-width: 768px) {
  .uf-modal-overlay {
    align-items: end;
  }
  .uf-modal {
    width: 100%;
    max-height: 85vh;
    border-radius: 20px 20px 0 0;
    flex-direction: column;
  }
}

/* ===== AUTOMATION ===== */
.automation-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.automation-header {
  background: var(--bg-card-solid);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 20px;
}

.automation-title h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.automation-title p {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0;
}

.automation-stats {
  display: flex;
  gap: 24px;
}

.stat-item {
  text-align: center;
  min-width: 80px;
}

.stat-number {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.automation-actions button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
}

/* Automation List */
.automation-list {
  background: var(--bg-card-solid);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.automation-list-header {
  padding: 16px 20px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.automation-list-header h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}

.automation-list-header button {
  font-size: 12px;
  padding: 6px 12px;
}

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

.triggers-table th,
.triggers-table td {
  padding: 12px 20px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.triggers-table th {
  background: var(--bg-secondary);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.triggers-table tbody tr:hover {
  background: var(--bg-hover);
}

.trigger-name {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.trigger-event {
  font-size: 12px;
  color: var(--text-muted);
}

.trigger-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 12px;
}

.trigger-status.active {
  background: rgba(34, 197, 94, 0.1);
  color: rgb(34, 197, 94);
}

.trigger-status.inactive {
  background: rgba(156, 163, 175, 0.1);
  color: rgb(156, 163, 175);
}

.trigger-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.trigger-actions button {
  padding: 4px 8px;
  font-size: 11px;
  min-width: auto;
}

.trigger-actions .u-btn-danger {
  background: rgba(239, 68, 68, 0.1);
  color: rgb(239, 68, 68);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.trigger-actions .u-btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

/* Empty State */
.automation-empty {
  background: var(--bg-card-solid);
  border-radius: var(--radius-lg);
  padding: 60px 40px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.automation-empty svg {
  width: 64px;
  height: 64px;
  color: var(--text-muted);
  margin-bottom: 16px;
  opacity: 0.6;
}

.automation-empty h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.automation-empty p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-container {
  background: var(--bg-card-solid);
  border-radius: 12px;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.modal-container.large {
  max-width: 800px;
}

.modal-container.trigger-modal {
  max-width: 800px;
  max-height: 90vh;
  position: relative;
}

@media (max-width: 768px) {
  .modal-container.trigger-modal {
    max-width: 100%;
    width: 100%;
    height: 100%;
    max-height: 100vh;
    margin: 0;
    border-radius: 0;
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 24px;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 6px;
  transition: all 0.2s;
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* Trigger Editor */
.trigger-editor {
  display: flex;
  flex-direction: column;
  min-height: 500px;
}

.step-nav {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 32px;
  padding: 0 20px;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 12px;
  border-radius: 8px;
  transition: all 0.2s;
  min-width: 80px;
}

.step:hover {
  background: var(--bg-hover);
}

.step.active {
  background: rgba(59, 130, 246, 0.1);
}

.step-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
  transition: all 0.2s;
}

.step.active .step-number {
  background: rgb(59, 130, 246);
  color: white;
}

.step-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-align: center;
}

.step.active .step-title {
  color: rgb(59, 130, 246);
}

.step-content {
  flex: 1;
  margin-bottom: 24px;
}

.step-section h3 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.step-section p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.form-group small {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-control {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  transition: all 0.2s;
}

.form-control:focus {
  outline: none;
  border-color: rgb(59, 130, 246);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
}

/* Conditions Builder */
.conditions-builder {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

#conditions-list {
  background: var(--bg);
}

.condition-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card-solid);
}

.condition-item:last-child {
  border-bottom: none;
}

.condition-operator,
.condition-field,
.condition-comparison {
  min-width: 120px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg);
}

.condition-value {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg);
}

.condition-remove {
  padding: 8px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 6px;
  color: rgb(239, 68, 68);
  cursor: pointer;
  transition: all 0.2s;
}

.condition-remove:hover {
  background: rgba(239, 68, 68, 0.2);
}

/* Actions Builder */
.actions-builder {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

#actions-list {
  background: var(--bg);
}

.action-item {
  border-bottom: 1px solid var(--border);
  background: var(--bg-card-solid);
}

.action-item:last-child {
  border-bottom: none;
}

.action-item > .action-type {
  padding: 16px;
  margin: 0;
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  font-size: 14px;
  font-weight: 600;
}

.action-config {
  padding: 16px;
}

.action-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.action-remove {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 6px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 4px;
  color: rgb(239, 68, 68);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 12px;
}

.action-item {
  position: relative;
}

.action-remove:hover {
  background: rgba(239, 68, 68, 0.2);
}

/* Step Actions */
.step-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.step-actions .spacer {
  flex: 1;
}

/* Logs */
.logs-container {
  max-height: 500px;
  overflow-y: auto;
}

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

.logs-table th,
.logs-table td {
  padding: 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.logs-table th {
  background: var(--bg-secondary);
  font-weight: 600;
  color: var(--text-muted);
  position: sticky;
  top: 0;
}

.logs-table tr.success {
  background: rgba(34, 197, 94, 0.05);
}

.logs-table tr.error {
  background: rgba(239, 68, 68, 0.05);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.status-badge.status-success {
  background: rgba(34, 197, 94, 0.1);
  color: rgb(34, 197, 94);
}

.status-badge.status-error {
  background: rgba(239, 68, 68, 0.1);
  color: rgb(239, 68, 68);
}

.status-badge.status-pending {
  background: rgba(249, 115, 22, 0.1);
  color: rgb(249, 115, 22);
}

/* Wide Trigger Editor */
.trigger-editor-wide {
  padding: 0;
}

.trigger-section {
  margin-bottom: 0;
}

.section-divider {
  height: 1px;
  background: var(--border);
  margin: 24px 0;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.section-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: white;
  font-weight: 600;
}

.section-icon-event {
  background: #3b82f6;
}

.section-icon-timing {
  background: #6b7280;
}

.section-icon-conditions {
  background: #8b5cf6;
}

.section-icon-actions {
  background: #f59e0b;
}

.section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.section-content {
  padding-left: 44px;
}

.form-control-lg {
  font-size: 16px;
  font-weight: 600;
  padding: 14px 16px;
}

.timing-selector {
  max-width: 400px;
}

.timing-options {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500;
}

.radio-option input[type="radio"] {
  margin: 0;
}

.delay-input {
  display: flex;
  gap: 12px;
  align-items: center;
  max-width: 300px;
}

.delay-input input {
  flex: 1;
  min-width: 80px;
}

.delay-input select {
  flex: 1;
  min-width: 100px;
}

/* Condition Groups */
.conditions-section {
  max-width: 600px;
}

.condition-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  margin-bottom: 16px;
  overflow: hidden;
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-secondary);
  font-weight: 600;
  font-size: 14px;
}

.group-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.group-operator {
  padding: 4px 8px;
  font-size: 12px;
  min-width: 80px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
}

.btn-icon {
  padding: 4px 6px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.1);
  color: rgb(239, 68, 68);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

.group-conditions {
  padding: 16px;
}

.condition-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #e0e7ff;
  color: #3730a3;
  padding: 4px 8px;
  border-radius: 16px;
  font-size: 13px;
  margin: 4px 6px 4px 0;
}

.chip-remove {
  background: none;
  border: none;
  color: #6b21a8;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  padding: 0;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chip-remove:hover {
  background: rgba(107, 33, 168, 0.1);
  border-radius: 50%;
}

.u-btn-add-condition {
  background: var(--bg-secondary);
  border: 1px dashed var(--border-strong);
  color: var(--text-muted);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.u-btn-add-condition:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Actions Section */
.actions-section {
  max-width: 600px;
}

.action-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  margin-bottom: 16px;
  overflow: hidden;
}

.action-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-secondary);
  font-weight: 600;
  font-size: 14px;
}

.action-content {
  padding: 16px;
}

.add-action-dropdown {
  position: relative;
}

.dropdown-toggle {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--bg-card-solid);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  min-width: 200px;
}

.dropdown-item {
  display: block;
  padding: 8px 12px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-item:hover {
  background: var(--bg-hover);
}

.trigger-editor-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding-top: 24px;
  margin-top: 24px;
  border-top: 1px solid var(--border);
}

/* Condition Drawer */
.condition-drawer {
  position: fixed;
  top: 0;
  right: -400px;
  width: 380px;
  height: 100vh;
  background: var(--bg-card-solid);
  border-left: 1px solid var(--border);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  transition: right 0.3s ease;
  box-shadow: -2px 0 12px rgba(0, 0, 0, 0.1);
}

.condition-drawer.open {
  right: 0;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
}

.drawer-header h3 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
}

.drawer-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
}

.drawer-close:hover {
  background: var(--bg-hover);
  border-radius: 4px;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.drawer-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  padding: 20px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
}

.condition-options {
  margin-bottom: 24px;
}

.condition-option {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.condition-option:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.condition-option.selected {
  background: rgba(59, 130, 246, 0.1);
  border-color: rgb(59, 130, 246);
}

.condition-option-name {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.condition-option-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.condition-form-section h4 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
}

.radio-group {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

/* Responsive */
@media (max-width: 768px) {
  .automation-header {
    flex-direction: column;
    text-align: center;
  }

  .automation-stats {
    justify-content: center;
  }

  .step-nav {
    flex-wrap: wrap;
    gap: 4px;
  }

  .step {
    min-width: 60px;
    padding: 8px;
  }

  .condition-item,
  .action-fields {
    flex-direction: column;
  }

  .modal-container {
    margin: 10px;
    max-height: calc(100vh - 20px);
  }

  .logs-table {
    font-size: 12px;
  }

  .logs-table th,
  .logs-table td {
    padding: 8px;
  }

  .condition-drawer {
    width: 100%;
    right: -100%;
  }

  .section-content {
    padding-left: 0;
  }

  .section-header {
    margin-bottom: 12px;
  }

  .timing-options {
    flex-direction: column;
    gap: 8px;
  }

  .delay-input {
    flex-direction: column;
    align-items: stretch;
  }
}
