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

  :root {
    --navy:        #1B2D3E;
    --navy-hover:  #243D52;
    --brass:       #B5893A;
    --brass-light: #F5EDD8;
    --bg:          #EFECE7;
    --white:       #FFFFFF;
    --card-bg:     #FAFAF8;
    --border:      rgba(0,0,0,0.10);
    --text:        #1A1A1A;
    --text-mid:    #555;
    --text-light:  #717171;
    --radius:      8px;
    --success:     #2E7D52;
    --danger:      #C0392B;
    --shadow-card: 0 1px 3px rgba(0,0,0,0.07), 0 0 0 1px rgba(0,0,0,0.05);
  }

  html.dark {
    --bg:          #1A1A1E;
    --white:       #242428;
    --card-bg:     #2A2A2E;
    --border:      rgba(255,255,255,0.10);
    --text:        #E8E8E8;
    --text-mid:    #B0B0B0;
    --text-light:  #909090;
    --shadow-card: 0 1px 3px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.05);
  }

  body {
    font-family: 'DM Sans', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
  }

  /* ── HEADER ── */
  .app-header {
    background: var(--navy);
    color: white;
    padding: 0 32px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  }
  .app-header-left {
    display: flex;
    align-items: center;
    gap: 16px;
  }
  .app-header-logo {
    display: flex;
    align-items: center;
  }
  .app-header-logo img {
    height: 40px;
    width: 40px;
    display: block;
    border-radius: 6px;
  }
  .app-header-divider {
    width: 1px;
    height: 20px;
    background: rgba(255,255,255,0.15);
  }
  .app-header h1 {
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.3px;
    color: rgba(255,255,255,0.85);
  }
  .app-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
  }
  .back-link {
    font-size: 12px;
    color: rgba(255,255,255,0.5);
    text-decoration: none;
    transition: color 0.15s;
  }
  .back-link:hover { color: white; }
  .theme-toggle {
    background: none;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 5px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    transition: border-color 0.15s;
    color: rgba(255,255,255,0.6);
  }
  .theme-toggle:hover { border-color: rgba(255,255,255,0.35); color: white; }

  /* ── LAYOUT ── */
  .container {
    max-width: 1080px;
    margin: 0 auto;
    padding: 28px 24px 80px;
  }

  /* ── LOADING ── */
  .loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 120px 0;
    gap: 12px;
    color: var(--text-light);
    font-size: 13px;
  }
  .spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--brass);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* ── KPI CARDS ── */
  .kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 28px;
  }
  .kpi-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 20px 22px;
  }
  .kpi-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-light);
    margin-bottom: 6px;
  }
  .kpi-value {
    font-family: 'DM Mono', monospace;
    font-size: 28px;
    font-weight: 500;
    color: var(--text);
    line-height: 1.2;
  }
  .kpi-sub {
    font-size: 11px;
    color: var(--text-light);
    margin-top: 4px;
  }
  .analytics-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
  }
  .analytics-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    background: var(--card-bg);
  }
  .analytics-card-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-light);
    margin-bottom: 6px;
  }
  .analytics-card-value {
    font-family: 'DM Mono', monospace;
    font-size: 22px;
    color: var(--text);
  }
  .analytics-card-sub {
    font-size: 12px;
    color: var(--text-mid);
    margin-top: 6px;
    line-height: 1.45;
  }

  /* ── SECTION CARD ── */
  .section {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    padding: 24px 28px;
    margin-bottom: 20px;
  }
  .section-title {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    color: var(--text-light);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
  }

  /* ── TABLE ── */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
  }
  th {
    text-align: left;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--text-light);
    padding: 0 12px 10px 0;
    white-space: nowrap;
  }
  td {
    padding: 10px 12px 10px 0;
    border-top: 1px solid var(--border);
    white-space: nowrap;
    vertical-align: middle;
  }
  tr.clickable { cursor: pointer; }
  tr.clickable:hover td { background: var(--card-bg); }
  .td-client {
    font-weight: 500;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .td-address {
    color: var(--text-mid);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .td-total {
    font-family: 'DM Mono', monospace;
    font-weight: 500;
  }
  .td-views {
    text-align: center;
    color: var(--text-mid);
  }
  .td-date {
    color: var(--text-light);
    font-size: 12px;
  }

  /* ── STATUS BADGES ── */
  .lib-status {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 3px 8px;
    border-radius: 3px;
  }
  .lib-status-draft    { background: #F0EDE6; color: #8A7A5A; }
  .lib-status-sent     { background: #E3F0FF; color: #2B6CB0; }
  .lib-status-viewed   { background: #EBF5EE; color: #2E7D52; }
  .lib-status-accepted { background: #D4EDDA; color: #155724; }
  .lib-status-expired  { background: #F5E6E6; color: #943030; }

  html.dark .lib-status-draft    { background: #333; color: #B0A080; }
  html.dark .lib-status-sent     { background: #1A2A40; color: #6EA8D8; }
  html.dark .lib-status-viewed   { background: #1A2E1F; color: #5CB87A; }
  html.dark .lib-status-accepted { background: #1A301A; color: #5CB87A; }
  html.dark .lib-status-expired  { background: #301A1A; color: #D06060; }

  .crm-sync-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
  }
  .crm-sync-copy {
    font-size: 13px;
    color: var(--text-mid);
  }
  .sync-pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
  }
  .sync-synced { background: rgba(46,125,82,0.14); color: #2E7D52; }
  .sync-pending { background: rgba(181,137,58,0.14); color: #8A641D; }
  .sync-failed { background: rgba(192,57,43,0.12); color: #C0392B; }
  .sync-disabled { background: rgba(0,0,0,0.08); color: var(--text-mid); }
  .sync-unknown { background: rgba(91,155,213,0.12); color: #2B6CB0; }

  /* ── STATUS BREAKDOWN BARS ── */
  .status-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
  }
  .status-label {
    width: 80px;
    font-size: 12px;
    font-weight: 500;
    text-transform: capitalize;
    flex-shrink: 0;
  }
  .status-bar-track {
    flex: 1;
    height: 24px;
    background: var(--card-bg);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border);
  }
  .status-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.6s ease;
    min-width: 0;
  }
  .status-bar-fill.draft    { background: #D4CFC4; }
  .status-bar-fill.sent     { background: #5B9BD5; }
  .status-bar-fill.viewed   { background: #5CB87A; }
  .status-bar-fill.accepted { background: #2E7D52; }
  .status-bar-fill.expired  { background: #D06060; }
  .status-count {
    width: 36px;
    text-align: right;
    font-family: 'DM Mono', monospace;
    font-size: 13px;
    font-weight: 500;
    flex-shrink: 0;
  }

  /* ── QUESTIONS ── */
  .question-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
  }
  .question-item:last-child { border-bottom: none; }
  .question-meta {
    font-size: 11px;
    color: var(--text-light);
    margin-bottom: 4px;
    display: flex;
    gap: 8px;
  }
  .question-meta .q-name { font-weight: 600; color: var(--text-mid); }
  .question-text {
    font-size: 13px;
    color: var(--text);
    line-height: 1.5;
  }
  .empty-state {
    color: var(--text-light);
    font-size: 13px;
    padding: 16px 0;
    text-align: center;
  }

  /* ── MONTHLY TREND ── */
  .trend-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
  }
  .trend-month {
    width: 56px;
    font-size: 12px;
    font-weight: 500;
    flex-shrink: 0;
  }
  .trend-bar-track {
    flex: 1;
    height: 28px;
    background: var(--card-bg);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border);
    position: relative;
  }
  .trend-bar-fill {
    height: 100%;
    background: var(--brass);
    border-radius: 3px;
    transition: width 0.6s ease;
    opacity: 0.85;
  }
  .trend-stats {
    width: 130px;
    font-size: 12px;
    color: var(--text-mid);
    text-align: right;
    flex-shrink: 0;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
  }
  .trend-stats .t-count {
    font-family: 'DM Mono', monospace;
    font-weight: 500;
    color: var(--text);
    min-width: 32px;
    text-align: right;
  }
  .trend-stats .t-val {
    font-family: 'DM Mono', monospace;
    color: var(--text-mid);
    min-width: 72px;
    text-align: right;
  }

  /* ── TWO-COL GRID ── */
  .grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
  }
  .queue-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  .queue-item {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    background: var(--card-bg);
  }
  .queue-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
  }
  .queue-item-title {
    font-weight: 600;
    color: var(--text);
  }
  .queue-item-meta {
    font-size: 12px;
    color: var(--text-light);
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 8px;
  }
  .queue-item-body {
    font-size: 13px;
    color: var(--text-mid);
    line-height: 1.55;
  }
  .queue-item-actions {
    margin-top: 10px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
  }
  .queue-link {
    font-size: 12px;
    color: var(--navy);
    text-decoration: none;
    font-weight: 600;
  }
  .queue-link:hover { color: var(--brass); }
  .queue-button {
    font-size: 12px;
    color: var(--navy);
    text-decoration: none;
    font-weight: 600;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-family: inherit;
  }
  .queue-button:hover { color: var(--brass); }
  .queue-button--active {
    color: var(--brass);
    border-bottom: 2px solid var(--brass);
  }

  /* ── RESPONSIVE ── */
  @media (max-width: 768px) {
    .app-header { padding: 0 16px; }
    .container { padding: 16px 12px 60px; }
    .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .analytics-grid { grid-template-columns: 1fr 1fr; }
    .kpi-value { font-size: 22px; }
    .grid-2 { grid-template-columns: 1fr; }
    .section { padding: 16px 18px; }
    .trend-stats { width: auto; }
  }
  @media (max-width: 480px) {
    .kpi-row { grid-template-columns: 1fr; }
    .analytics-grid { grid-template-columns: 1fr; }
    .app-header { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
    .app-header .nav-links { order: 3; flex-basis: 100%; justify-content: flex-start; overflow-x: auto; }
    .section { padding: 12px 14px; }
    .section-title { font-size: 14px; }
    .queue-item { padding: 10px; }
    .queue-item-title { font-size: 13px; }
    .queue-item-body { font-size: 11px; word-break: break-word; }
    .queue-item-actions { flex-wrap: wrap; gap: 6px; }
    .queue-item-actions .queue-button,
    .queue-item-actions .queue-link { flex: 1 1 auto; min-width: 120px; text-align: center; font-size: 12px; }
    .sync-filter-bar,
    .audit-filter-bar { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .sync-filter-bar .queue-button,
    .audit-filter-bar .queue-button { white-space: nowrap; }
    .trend-row { flex-wrap: wrap; }
    .trend-bar-wrap { min-width: 140px; }
    table { font-size: 12px; }
    th, td { padding: 6px 4px; }
    /* Horizontal scroll for wide data tables on tiny screens */
    .section > table,
    .section > div > table { display: block; overflow-x: auto; white-space: nowrap; }
  }

  /* ── Audit filter buttons share the same active treatment ── */
  .audit-filter-btn.queue-button--active,
  .sync-filter-btn.queue-button--active {
    color: var(--brass, #c6a868);
    border-bottom: 2px solid var(--brass, #c6a868);
  }
