/* ============================================
   Dashboard Page Styles
   ============================================ */

.dashboard-page {
    display: flex;
    min-height: 100vh;
    background: #f9fafb;
}

/* ============================================
   Sidebar
   ============================================ */

.sidebar {
    width: 260px;
    background: white;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 100;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e5e7eb;
}

.sidebar-header .logo {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    padding: 1rem 0;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    color: #6b7280;
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: #f3f4f6;
    color: #374151;
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.1) 0%, transparent 100%);
    color: #667eea;
    border-left-color: #667eea;
    font-weight: 600;
}

.nav-item .icon {
    font-size: 1.25rem;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid #e5e7eb;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 8px;
    background: #f9fafb;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.user-details {
    flex: 1;
    min-width: 0;
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 0.75rem;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-logout {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 0.9rem;
}

.btn-logout:hover {
    background: #fef2f2;
    border-color: #ef4444;
    color: #ef4444;
}

/* ============================================
   Sidebar Bottom — Settings + Account
   ============================================ */

.sidebar-bottom {
  padding: 8px 0 12px;
  border-top: 1px solid #e5e7eb;
  position: relative;
}

.sb-bottom-item {
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  text-align: left;
}

/* Account toggle row */
.sb-account-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
}

.sb-account-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sb-chevron {
  font-size: 11px;
  opacity: 0.55;
  flex-shrink: 0;
  transition: transform 0.2s;
}

/* Account flyout panel */
.sb-account-menu {
  display: none;
  flex-direction: column;
  background: #f9fafb;
  border-top: 1px solid #e5e7eb;
  border-bottom: 1px solid #e5e7eb;
  padding: 6px 0;
  margin: 4px 0;
}
.sb-account-menu.open { display: flex; }

.sb-account-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 12px;
}

.sb-account-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg,#667eea,#764ba2);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sb-account-info { flex: 1; min-width: 0; }
.sb-account-full-name {
  font-size: 13px;
  font-weight: 600;
  color: #111;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-account-email {
  font-size: 11px;
  color: #9ca3af;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-account-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  color: #6b7280;
  text-decoration: none;
  font-size: 13.5px;
  transition: background 0.15s, color 0.15s;
}
.sb-account-item:hover { background: #f0f0f5; color: #374151; }
.sb-account-item.active { color: #667eea; font-weight: 600; }

.sb-account-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 6px 14px;
}

.sb-credits-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  font-size: 13px;
  color: #6b7280;
}
.sb-credits-badge {
  background: linear-gradient(135deg,#667eea,#764ba2);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 24px;
  text-align: center;
}

.sb-logout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 20px;
  background: none;
  border: none;
  color: #ef4444;
  font-size: 13.5px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 0.15s;
}
.sb-logout-btn:hover { background: #fef2f2; }

/* ── Dark mode for new sidebar-bottom ──────────────────────────────────── */
html[data-theme="dark"] .sidebar-bottom        { border-color: var(--border); }
html[data-theme="dark"] .sb-account-menu       { background: var(--surface2); border-color: var(--border); }
html[data-theme="dark"] .sb-account-full-name  { color: var(--text); }
html[data-theme="dark"] .sb-account-email      { color: var(--text-muted); }
html[data-theme="dark"] .sb-account-item       { color: var(--text-muted); }
html[data-theme="dark"] .sb-account-item:hover { background: rgba(99,102,241,0.12); color: #a5b4fc; }
html[data-theme="dark"] .sb-account-item.active{ color: #a5b4fc; }
html[data-theme="dark"] .sb-account-divider    { background: var(--border); }
html[data-theme="dark"] .sb-credits-row        { color: var(--text-muted); }
html[data-theme="dark"] .sb-logout-btn         { color: #f87171; }
html[data-theme="dark"] .sb-logout-btn:hover   { background: rgba(239,68,68,0.1); }

/* ============================================
   Main Content
   ============================================ */

.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 2rem;
    overflow-y: auto;
}

/* Top Header */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.header-left h2 {
    font-size: 1.75rem;
    margin: 0 0 0.25rem 0;
    color: #1f2937;
}

.header-left .subtitle {
    color: #6b7280;
    margin: 0;
    font-size: 0.95rem;
}

.header-right .btn {
    padding: 0.75rem 1.5rem;
}

/* ============================================
   Stats Grid
   ============================================ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    gap: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
}

.stat-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 10px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-details {
    flex: 1;
}

.stat-label {
    font-size: 0.85rem;
    color: #6b7280;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 0.25rem;
}

.stat-change {
    font-size: 0.8rem;
    color: #6b7280;
}

.stat-change.positive {
    color: #10b981;
}

.stat-change.negative {
    color: #ef4444;
}

/* ============================================
   Quick Actions
   ============================================ */

.quick-actions {
    margin-bottom: 2rem;
}

.quick-actions h3 {
    font-size: 1.25rem;
    margin: 0 0 1rem 0;
    color: #1f2937;
}

.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

.action-card {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.action-card:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
    transform: translateY(-2px);
}

.action-icon {
    font-size: 2rem;
}

.action-title {
    font-weight: 600;
    color: #1f2937;
    font-size: 0.95rem;
}

.action-desc {
    font-size: 0.85rem;
    color: #6b7280;
}

/* ============================================
   Sections
   ============================================ */

.recent-posts,
.upcoming-posts {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.section-header h3 {
    font-size: 1.25rem;
    margin: 0;
    color: #1f2937;
}

.section-header .link {
    color: #667eea;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
}

.section-header .link:hover {
    text-decoration: underline;
}

/* ============================================
   Posts Table
   ============================================ */

.posts-table {
    overflow-x: auto;
}

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

.posts-table th {
    text-align: left;
    padding: 0.75rem;
    border-bottom: 2px solid #e5e7eb;
    color: #6b7280;
    font-size: 0.85rem;
    font-weight: 600;
}

.posts-table td {
    padding: 1rem 0.75rem;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
    font-size: 0.9rem;
}

.posts-table tr:hover {
    background: #f9fafb;
}

/* ============================================
   Empty State
   ============================================ */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    color: #6b7280;
    margin: 0 0 1.5rem 0;
}

/* ============================================
   Timeline
   ============================================ */

.timeline {
    position: relative;
}

.timeline-item {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #e5e7eb;
}

.timeline-item:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.timeline-time {
    min-width: 80px;
    color: #6b7280;
    font-size: 0.85rem;
}

.timeline-content {
    flex: 1;
}

.timeline-title {
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 0.25rem;
}

.timeline-platforms {
    font-size: 0.85rem;
    color: #6b7280;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 968px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
    }

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

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

    .top-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .header-right .btn {
        width: 100%;
    }
}

@media (max-width: 640px) {
    .posts-table {
        font-size: 0.85rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

/* ============================================
   Buttons
   ============================================ */

.btn-secondary {
    background: white;
    color: #667eea;
    border: 2px solid #667eea;
}

.btn-secondary:hover {
    background: #667eea;
    color: white;
}

/* ============================================
   Chat History Page
   ============================================ */

.history-credits-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin: 1.5rem 2rem;
}

.hcb-card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    padding: 1.1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.hcb-icon {
    font-size: 1.8rem;
    line-height: 1;
}

.hcb-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #111827;
    line-height: 1;
}

.hcb-label {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 2px;
}

/* Table */
.history-table-wrap {
    margin: 0 2rem 2rem;
    background: #fff;
    border-radius: 14px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.history-table-header {
    display: grid;
    grid-template-columns: 40px 1fr 130px 120px 130px 160px;
    gap: 0;
    background: #f9fafb;
    border-bottom: 1.5px solid #e5e7eb;
    padding: 0.7rem 1.25rem;
}

.ht-col {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
}

.history-row {
    display: grid;
    grid-template-columns: 40px 1fr 130px 120px 130px 160px;
    gap: 0;
    padding: 0.9rem 1.25rem;
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.15s;
    align-items: center;
}

.history-row:last-child { border-bottom: none; }
.history-row:hover { background: #f9fafb; }

.ht-num { font-size: 0.8rem; color: #9ca3af; font-weight: 600; }

.ht-title {
    font-size: 0.875rem;
    color: #111827;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding-right: 1rem;
}

.type-badge {
    font-size: 0.75rem;
    background: #f3f4f6;
    color: #374151;
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-weight: 500;
    white-space: nowrap;
}

.platform-pill {
    font-size: 0.75rem;
    color: #6b7280;
    font-weight: 500;
}

.date-main {
    display: block;
    font-size: 0.8rem;
    color: #374151;
    font-weight: 500;
}

.date-time {
    display: block;
    font-size: 0.7rem;
    color: #9ca3af;
    margin-top: 1px;
}

.credit-breakdown {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cb-gen {
    font-size: 0.75rem;
    color: #6b7280;
}

.cb-post {
    font-size: 0.75rem;
    color: #ef4444;
}

.cb-total {
    font-size: 0.78rem;
    font-weight: 700;
    color: #b45309;
}

.history-empty-state {
    padding: 4rem 2rem;
    text-align: center;
    color: #9ca3af;
}

.history-empty-state .empty-icon {
    font-size: 3rem;
    margin-bottom: 0.75rem;
}

.history-empty-state p {
    margin-bottom: 1rem;
    font-size: 1rem;
}

/* ============================================
   History Page — Two-panel Layout
   ============================================ */

.history-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 0;
    height: calc(100vh - 220px);
    min-height: 500px;
    margin: 0 2rem 2rem;
    background: #fff;
    border-radius: 14px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

/* ── Left: Sessions Panel ── */
.history-sessions-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e5e7eb;
    overflow: hidden;
    background: #f9fafb;
}

.history-search-wrap {
    position: relative;
    padding: 0.75rem;
    border-bottom: 1px solid #e5e7eb;
    background: #fff;
    flex-shrink: 0;
}

.history-search-icon {
    position: absolute;
    left: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.85rem;
    pointer-events: none;
}

.history-search {
    width: 100%;
    padding: 0.55rem 0.75rem 0.55rem 2rem;
    border: 1.5px solid #e5e7eb;
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    background: #f9fafb;
    color: #374151;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.history-search:focus {
    border-color: #667eea;
    background: #fff;
}

#sessionList {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.history-sessions-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: #9ca3af;
}

.history-sessions-empty .empty-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    display: block;
}

.history-sessions-empty p {
    margin: 0 0 1rem 0;
    font-size: 0.9rem;
}

/* Session Cards */
.session-card {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.75rem 0.9rem;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s, border-left 0.15s;
    border-left: 3px solid transparent;
    margin-bottom: 2px;
}

.session-card:hover {
    background: #f3f4f6;
}

.session-card.active {
    background: rgba(102, 126, 234, 0.08);
    border-left-color: #667eea;
}

.session-card-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
    margin-top: 1px;
}

.session-card-body {
    flex: 1;
    min-width: 0;
}

.session-card-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.session-card-meta {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.session-card-date {
    font-size: 0.72rem;
    color: #9ca3af;
}

.session-credit-badge {
    font-size: 0.68rem;
    background: #fef3c7;
    color: #92400e;
    border-radius: 999px;
    padding: 1px 6px;
    font-weight: 600;
}

.session-msg-badge {
    font-size: 0.68rem;
    background: #f3f4f6;
    color: #6b7280;
    border-radius: 999px;
    padding: 1px 6px;
    font-weight: 500;
}

/* ── Right: Conversation Panel ── */
.history-conv-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
}

.history-empty-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
    color: #9ca3af;
}

.history-conv-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
    flex-shrink: 0;
}

.history-conv-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #1f2937;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    margin-right: 1rem;
}

.history-conv-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.history-conv-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* User message bubble */
.hcm-user {
    display: flex;
    justify-content: flex-end;
}

.hcm-user .hcm-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-radius: 18px 18px 4px 18px;
    padding: 0.75rem 1rem;
    max-width: 70%;
    word-break: break-word;
}

.hcm-user .hcm-bubble p {
    margin: 0 0 0.4rem 0;
    font-size: 0.9rem;
    line-height: 1.5;
}

/* Assistant message bubble */
.hcm-assistant {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
}

.hcm-avatar {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.hcm-assistant .hcm-bubble {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 4px 18px 18px 18px;
    padding: 0.75rem 1rem;
    max-width: 75%;
    word-break: break-word;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.hcm-assistant .hcm-bubble p {
    margin: 0 0 0.4rem 0;
    font-size: 0.9rem;
    color: #1f2937;
    line-height: 1.6;
}

.hcm-image {
    max-width: 300px;
    width: 100%;
    border-radius: 10px;
    margin-top: 0.5rem;
    display: block;
}

.hcm-hashtags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.4rem;
}

.hcm-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.5rem;
}

.hcm-time {
    font-size: 0.7rem;
    color: rgba(0,0,0,0.35);
}

.hcm-user .hcm-time {
    color: rgba(255,255,255,0.65);
}

.btn-hcm-copy {
    font-size: 0.72rem;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 0.2rem 0.55rem;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.15s;
    font-family: inherit;
}

.btn-hcm-copy:hover {
    background: #667eea;
    color: #fff;
    border-color: #667eea;
}

/* History view banner (in chat.html when viewing a session) */
.history-view-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 10px;
    padding: 0.6rem 1rem;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    color: #92400e;
    flex-shrink: 0;
}

.history-banner-new {
    font-size: 0.8rem;
    background: #667eea;
    color: #fff;
    padding: 0.3rem 0.7rem;
    border-radius: 6px;
    text-decoration: none;
    font-weight: 500;
    white-space: nowrap;
}

.history-banner-new:hover {
    background: #4f46e5;
}

/* Historical message subtle styling */
.chat-message.historical .message-bubble {
    opacity: 0.88;
}

/* ── Responsive ── */
@media (max-width: 900px) {
    .history-layout {
        grid-template-columns: 260px 1fr;
        margin: 0 1rem 1rem;
    }
}

@media (max-width: 640px) {
    .history-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    .history-sessions-panel {
        border-right: none;
        border-bottom: 1px solid #e5e7eb;
        max-height: 40vh;
    }

    .history-conv-panel {
        min-height: 50vh;
    }

    .history-credits-bar {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ══════════════════════════════════════════════════════════════
   DARK MODE — dashboard, history, all shared sidebar/layout
   ══════════════════════════════════════════════════════════════ */
html[data-theme="dark"] .dashboard-page     { background: #0f172a; }
html[data-theme="dark"] .main-content       { background: #0f172a; }

/* Sidebar */
html[data-theme="dark"] .sidebar            { background: #1e293b; border-color: #334155; }
html[data-theme="dark"] .sidebar-header     { border-color: #334155; }
html[data-theme="dark"] .sidebar-footer     { border-color: #334155; }
html[data-theme="dark"] .nav-item           { color: #94a3b8; }
html[data-theme="dark"] .nav-item:hover     { background: rgba(99,102,241,0.12); color: #c7d2fe; }
html[data-theme="dark"] .nav-item.active    { background: rgba(99,102,241,0.18); color: #a5b4fc; border-left-color: #818cf8; }
html[data-theme="dark"] .user-info          { background: #0f172a; }
html[data-theme="dark"] .user-name          { color: #f1f5f9; }
html[data-theme="dark"] .user-email         { color: #64748b; }
html[data-theme="dark"] .btn-logout         { background: #1e293b; border-color: #334155; color: #94a3b8; }
html[data-theme="dark"] .btn-logout:hover   { background: #2d1a1a; border-color: #ef4444; color: #ef4444; }

/* Header */
html[data-theme="dark"] .top-header         { background: #1e293b; }
html[data-theme="dark"] .header-left h2     { color: #f1f5f9; }
html[data-theme="dark"] .header-left .subtitle { color: #94a3b8; }

/* Stat cards */
html[data-theme="dark"] .stat-card          { background: #1e293b; box-shadow: 0 1px 3px rgba(0,0,0,0.4); }
html[data-theme="dark"] .stat-label         { color: #94a3b8; }
html[data-theme="dark"] .stat-value         { color: #f1f5f9; }
html[data-theme="dark"] .stat-change        { color: #64748b; }

/* Quick actions */
html[data-theme="dark"] .quick-actions h3   { color: #f1f5f9; }
html[data-theme="dark"] .action-card        { background: #1e293b; border-color: #334155; }
html[data-theme="dark"] .action-card:hover  { background: #253047; border-color: #6366f1; }
html[data-theme="dark"] .action-title       { color: #f1f5f9; }
html[data-theme="dark"] .action-desc        { color: #64748b; }

/* Sections */
html[data-theme="dark"] .recent-posts,
html[data-theme="dark"] .upcoming-posts     { background: #1e293b; box-shadow: none; }
html[data-theme="dark"] .section-header h3  { color: #f1f5f9; }

/* Table */
html[data-theme="dark"] .posts-table th     { color: #64748b; border-color: #334155; }
html[data-theme="dark"] .posts-table td     { color: #cbd5e1; border-color: #1e293b; }
html[data-theme="dark"] .posts-table tr:hover { background: #253047; }

/* Timeline */
html[data-theme="dark"] .timeline-item      { border-color: #334155; }
html[data-theme="dark"] .timeline-time      { color: #818cf8; }
html[data-theme="dark"] .timeline-title     { color: #f1f5f9; }
html[data-theme="dark"] .timeline-platforms { color: #94a3b8; }

/* Empty states */
html[data-theme="dark"] .empty-state p      { color: #64748b; }

/* History credits bar */
html[data-theme="dark"] .hcb-card           { background: #1e293b; border-color: #334155; }
html[data-theme="dark"] .hcb-value          { color: #f1f5f9; }
html[data-theme="dark"] .hcb-label          { color: #64748b; }

/* History layout */
html[data-theme="dark"] .history-layout     { background: #1e293b; border-color: #334155; }
html[data-theme="dark"] .history-sessions-panel { background: #151f30; border-color: #334155; }
html[data-theme="dark"] .history-search-wrap { background: #1e293b; border-color: #334155; }
html[data-theme="dark"] .history-search     { background: #151f30; border-color: #334155; color: #f1f5f9; }
html[data-theme="dark"] .history-search:focus { border-color: #6366f1; background: #1e293b; }
html[data-theme="dark"] .session-card:hover { background: #253047; }
html[data-theme="dark"] .session-card.active { background: rgba(99,102,241,0.12); border-left-color: #6366f1; }
html[data-theme="dark"] .session-card-title { color: #f1f5f9; }
html[data-theme="dark"] .session-card-date  { color: #64748b; }
html[data-theme="dark"] .history-conv-panel { background: #1e293b; }
html[data-theme="dark"] .history-conv-header { background: #151f30; border-color: #334155; }
html[data-theme="dark"] .history-conv-title { color: #f1f5f9; }
html[data-theme="dark"] .hcm-assistant .hcm-bubble { background: #253047; border-color: #334155; }
html[data-theme="dark"] .hcm-assistant .hcm-bubble p { color: #e2e8f0; }
html[data-theme="dark"] .btn-hcm-copy       { background: #334155; border-color: #475569; color: #94a3b8; }

/* History table */
html[data-theme="dark"] .history-table-wrap { background: #1e293b; border-color: #334155; }
html[data-theme="dark"] .history-table-header { background: #151f30; border-color: #334155; }
html[data-theme="dark"] .ht-col             { color: #64748b; }
html[data-theme="dark"] .history-row        { border-color: #253047; }
html[data-theme="dark"] .history-row:hover  { background: #253047; }
html[data-theme="dark"] .ht-title           { color: #f1f5f9; }
html[data-theme="dark"] .ht-num             { color: #475569; }
html[data-theme="dark"] .date-main          { color: #cbd5e1; }
html[data-theme="dark"] .date-time          { color: #475569; }
html[data-theme="dark"] .type-badge         { background: #334155; color: #cbd5e1; }

/* Nav history section */
html[data-theme="dark"] .nav-history-section    { border-color: #334155; }
html[data-theme="dark"] .nav-history-header     { color: #64748b; }
html[data-theme="dark"] .nav-history-header:hover { background: #253047; color: #94a3b8; }
html[data-theme="dark"] .sidebar-history-list   { background: #151f30; border-color: #334155; }
html[data-theme="dark"] .sidebar-history-item   { border-color: #253047; }
html[data-theme="dark"] .sidebar-history-item:hover { background: #253047; }
html[data-theme="dark"] .sidebar-history-title  { color: #cbd5e1; }
html[data-theme="dark"] .sidebar-history-time   { color: #475569; }

/* Credits display */
html[data-theme="dark"] .credits-display    { background: #1c1a0f; border-color: #78350f; }
html[data-theme="dark"] .credits-label      { color: #d97706; }
html[data-theme="dark"] .credits-value      { color: #fbbf24; }

/* Btn-secondary */
html[data-theme="dark"] .btn-secondary      { background: #1e293b; color: #818cf8; border-color: #4f46e5; }
html[data-theme="dark"] .btn-secondary:hover { background: #4f46e5; color: white; }
