/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1a202c;
  --text-muted: #718096;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --overdue-bg: #fef2f2;
  --overdue-border: #fca5a5;
  --done-bg: #f0fdf4;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
       background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Nav ---------- */
.nav {
  background: #1e293b; color: #e2e8f0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem; height: 52px; position: sticky; top: 0; z-index: 100;
}
.nav-brand { font-weight: 700; font-size: 1rem; color: #fff; }
.nav-brand-by { font-weight: 400; font-size: .8rem; opacity: .75; }
.nav-brand em { font-style: italic; }
.nav-links { display: flex; gap: .25rem; }
.nav-links a { color: #94a3b8; padding: .4rem .75rem; border-radius: var(--radius);
               font-size: .85rem; transition: background .15s, color .15s; }
.nav-links a:hover, .nav-links a.active { background: #334155; color: #fff; text-decoration: none; }
.nav-logout { margin-left: .5rem; }

/* ---------- Layout ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: 1.5rem; }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Page Header ---------- */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem; gap: 1rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; }
.page-meta { color: var(--text-muted); font-size: .85rem; margin-top: .2rem; }
.date-badge { background: #eff6ff; color: var(--primary); padding: .25rem .75rem;
              border-radius: 999px; font-size: .85rem; font-weight: 600; }
.header-actions { display: flex; gap: .5rem; align-items: center; }

/* ---------- Alerts ---------- */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem;
         font-size: .9rem; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-info { background: #dbeafe; color: #1e40af; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .45rem 1rem; border-radius: var(--radius); font-size: .875rem;
  font-weight: 500; cursor: pointer; border: none; transition: background .15s;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); color: var(--text); }
.btn-sm { padding: .25rem .6rem; font-size: .8rem; }
.btn-lg { padding: .65rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ---------- Stats ---------- */
.stats-row { display: flex; gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.5rem; flex: 1;
  text-align: center; box-shadow: var(--shadow);
}
.stat-number { font-size: 1.25rem; font-weight: 700; line-height: 1; }
.stat-label { color: var(--text-muted); font-size: .8rem; margin-top: .25rem; }
.stat-warning .stat-number { color: var(--warning); }
.stat-success .stat-number { color: var(--success); }

/* ---------- Section Header ---------- */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: .75rem;
}
.section-header h2 { font-size: 1rem; font-weight: 600; }

/* ---------- Action Cards ---------- */
.action-list { display: flex; flex-direction: column; gap: .5rem; }
.action-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem 1rem; box-shadow: var(--shadow);
}
.action-card.overdue { background: var(--overdue-bg); border-color: var(--overdue-border); }
.action-card.done { background: var(--done-bg); opacity: .75; }
.action-top { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.action-desc { flex: 1; font-size: .9rem; line-height: 1.4; }
.action-desc.strike { text-decoration: line-through; color: var(--text-muted); }
.action-desc-link { color: inherit; text-decoration: none; }
.action-desc-link:hover { text-decoration: underline; }
.action-buttons { display: flex; gap: .35rem; flex-shrink: 0; }
.action-meta { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .5rem; }
.action-notes { font-size: .8rem; color: var(--text-muted); margin-top: .4rem;
                padding-top: .4rem; border-top: 1px solid var(--border); }

/* ---------- Tags ---------- */
.tag {
  display: inline-block; padding: .15rem .5rem; border-radius: 999px;
  font-size: .75rem; background: #f1f5f9; color: #475569;
}
.tag-project { background: #eff6ff; color: #1d4ed8; }
.tag-class { background: #f0fdf4; color: #166534; }
.tag-org { background: #fef9c3; color: #854d0e; }
.tag-date { background: #f5f3ff; color: #6d28d9; }
.tag-overdue { background: #fee2e2; color: #991b1b; }
.tag-source { background: #f8fafc; color: var(--text-muted); }
.tag-source a { color: inherit; }
a.tag { text-decoration: none; cursor: pointer; }
a.tag:hover { filter: brightness(.92); }
.tag-row { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: 1rem; }

/* ---------- Summary Card ---------- */
.summary-card {
  background: #eff6ff; border: 1px solid #bfdbfe;
  border-radius: var(--radius); padding: 1rem; margin-bottom: 1.5rem;
}
.summary-card h3 { font-size: .85rem; font-weight: 600; color: #1e40af; margin-bottom: .4rem; }
.summary-card p { font-size: .9rem; color: #1e3a5f; line-height: 1.6; }

/* ---------- Transcripts List ---------- */
.transcript-list { list-style: none; }
.transcript-list li {
  border-bottom: 1px solid var(--border); padding: .6rem 0;
}
.transcript-link { display: flex; justify-content: space-between; align-items: baseline; }
.transcript-title { font-weight: 500; }
.transcript-date { font-size: .8rem; color: var(--text-muted); }
.transcript-tags { font-size: .75rem; color: var(--text-muted); margin-top: .15rem; }

/* ---------- Data Table ---------- */
.data-table { width: 100%; border-collapse: collapse; background: var(--surface);
              border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.data-table th { text-align: left; padding: .65rem 1rem; font-size: .8rem; font-weight: 600;
                 color: var(--text-muted); border-bottom: 1px solid var(--border); background: #f8fafc; }
.data-table td { padding: .65rem 1rem; border-bottom: 1px solid var(--border); font-size: .875rem; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8fafc; }
.tag-cell { max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link { font-weight: 500; }

/* ---------- Filter Bar ---------- */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: .5rem; align-items: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem;
}
.filter-bar select, .filter-bar input {
  padding: .35rem .6rem; border: 1px solid var(--border); border-radius: 6px;
  font-size: .85rem; background: var(--bg);
}

/* ---------- Forms ---------- */
.form-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow);
  max-width: 860px;
}
.form-group { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.form-group label { font-size: .85rem; font-weight: 500; color: var(--text); }
.form-group input, .form-group textarea, .form-group select {
  padding: .55rem .75rem; border: 1px solid var(--border); border-radius: 6px;
  font-size: .9rem; font-family: inherit; background: var(--bg);
  transition: border-color .15s;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  outline: none; border-color: var(--primary); background: #fff;
}
.form-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.form-group-sm { grid-column: span 1; }
.form-footer { display: flex; align-items: center; justify-content: space-between;
               margin-top: .5rem; flex-wrap: wrap; gap: .75rem; }
.form-hint { font-size: .8rem; color: var(--text-muted); }

/* ---------- Query ---------- */
.query-examples { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; align-items: center; }
.query-hint { font-size: .85rem; color: var(--text-muted); }
.query-pill {
  background: #eff6ff; color: var(--primary); border: 1px solid #bfdbfe;
  border-radius: 999px; padding: .3rem .9rem; font-size: .82rem; cursor: pointer;
  transition: background .15s;
}
.query-pill:hover { background: #dbeafe; }
.query-form { margin-bottom: 1.5rem; }
.query-input-row { display: flex; gap: .5rem; }
.query-input {
  flex: 1; padding: .65rem 1rem; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 1rem; background: var(--surface);
}
.query-input:focus { outline: none; border-color: var(--primary); }
.query-results h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: .75rem;
                    color: var(--text-muted); }

/* ---------- Projects ---------- */
.class-header { font-size: 1rem; font-weight: 700; margin: 1.5rem 0 .75rem;
                color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .75rem; }
.project-card { background: var(--surface); border: 1px solid var(--border);
                border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); }
.project-card.proj-red    { background: #fff0f0; border-color: #fca5a5; }
.project-card.proj-yellow { background: #fffbeb; border-color: #fcd34d; }
.project-card.proj-green  { background: #f0fdf4; border-color: #86efac; }
.project-top { display: flex; justify-content: space-between; align-items: baseline;
               gap: .5rem; margin-bottom: .3rem; }
.project-name { font-weight: 600; font-size: .9rem; }
.project-desc { font-size: .8rem; color: var(--text-muted); line-height: 1.4; }
.badge-open { background: #eff6ff; color: var(--primary); border-radius: 999px;
              padding: .1rem .5rem; font-size: .75rem; font-weight: 600; }
.color-legend { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1.25rem;
                font-size: .8rem; color: var(--text-muted); }
.legend-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px;
                 margin-right: .3rem; vertical-align: middle; }

/* ---------- Project status table (dashboard) ---------- */
.proj-status-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.proj-status-table th { text-align: left; padding: .4rem .6rem; color: var(--text-muted);
                        font-size: .75rem; font-weight: 600; border-bottom: 2px solid var(--border); }
.proj-status-table td { padding: .4rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.proj-status-table tr:last-child td { border-bottom: none; }
.proj-status-table tr.row-red    td { background: #fff0f0; }
.proj-status-table tr.row-yellow td { background: #fffbeb; }
.proj-status-table tr.row-green  td { background: #f0fdf4; }
.proj-status-table tr.cls-divider td { background: #f8fafc; font-weight: 700;
                                        font-size: .72rem; text-transform: uppercase;
                                        letter-spacing: .06em; color: var(--text-muted);
                                        padding: .35rem .6rem; }
.count-pill { display: inline-block; border-radius: 999px; padding: .1rem .45rem;
              font-size: .72rem; font-weight: 700; margin-left: .2rem; }
.count-red    { background: #fee2e2; color: #991b1b; }
.count-yellow { background: #fef3c7; color: #92400e; }
.count-future { background: #eff6ff; color: #1d4ed8; }
.count-zero   { background: #f1f5f9; color: var(--text-muted); }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center;
              min-height: 100vh; background: #1e293b; }
.login-card { background: var(--surface); border-radius: 12px; padding: 2rem 2.5rem;
              width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-title { font-size: 1.5rem; font-weight: 700; text-align: center; margin-bottom: .25rem; }
.login-subtitle { text-align: center; color: var(--text-muted); font-size: .85rem;
                  margin-bottom: 1.5rem; }
.login-form { display: flex; flex-direction: column; gap: .5rem; }
.login-form label { font-size: .85rem; font-weight: 500; }
.login-form input { padding: .65rem .75rem; border: 1px solid var(--border); border-radius: 6px;
                    font-size: 1rem; }
.login-form input:focus { outline: none; border-color: var(--primary); }

/* ---------- Raw Transcript ---------- */
.raw-transcript { margin-top: 2rem; }
.raw-transcript summary { cursor: pointer; color: var(--text-muted); font-size: .85rem;
                           padding: .5rem 0; }
.raw-transcript pre { margin-top: .75rem; background: #f8fafc; border: 1px solid var(--border);
                      border-radius: var(--radius); padding: 1rem; font-size: .8rem;
                      white-space: pre-wrap; word-break: break-word; max-height: 400px;
                      overflow-y: auto; }

/* ---------- Empty State ---------- */
.empty-state { color: var(--text-muted); text-align: center; padding: 2rem; font-size: .9rem; }

/* ---------- Admin grid ---------- */
.admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; max-width: 900px; }
.admin-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; text-decoration: none; color: var(--text); transition: border-color .15s, box-shadow .15s; }
.admin-card:hover { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.1); }
.admin-card-title { font-weight: 700; font-size: .95rem; color: var(--primary); margin-bottom: .4rem; }
.admin-card-desc { font-size: .82rem; color: var(--text-muted); line-height: 1.5; }

/* ---------- Email ---------- */
.email-section { margin-bottom: 2rem; }
.synopsis-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.synopsis-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; text-decoration: none; color: var(--text); transition: border-color .15s, box-shadow .15s; }
.synopsis-card:hover { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.1); }
.synopsis-card-header { display: flex; gap: .5rem; align-items: baseline; margin-bottom: .5rem; flex-wrap: wrap; }
.synopsis-classification { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--primary); }
.synopsis-project { font-weight: 600; font-size: .88rem; }
.synopsis-card-body { font-size: .82rem; color: var(--text-muted); line-height: 1.5; margin-bottom: .5rem; }
.synopsis-card-meta { font-size: .75rem; color: var(--text-muted); }
.synopsis-text { line-height: 1.7; white-space: pre-wrap; }
.synopsis-full { padding: 1.25rem 1.5rem; }
.email-thread-list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.email-thread-row { display: block; padding: .75rem 1rem; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text); transition: background .12s; }
.email-thread-row:last-child { border-bottom: none; }
.email-thread-row:hover { background: var(--surface-hover, #f8fafc); }
.email-thread-subject { font-weight: 500; font-size: .9rem; margin-bottom: .25rem; }
.email-thread-meta { display: flex; gap: 1rem; font-size: .78rem; color: var(--text-muted); flex-wrap: wrap; }
.email-messages-list { display: flex; flex-direction: column; gap: 1rem; }
.email-message-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; }
.email-message-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: .75rem; flex-wrap: wrap; gap: .5rem; }
.email-message-from { font-size: .88rem; }
.email-message-date { font-size: .78rem; color: var(--text-muted); white-space: nowrap; }
.email-message-headers { background: var(--surface-muted, #f8fafc); border-bottom: 1px solid var(--border); padding: .6rem 1rem; margin: -.75rem -1rem .75rem; border-radius: var(--radius) var(--radius) 0 0; font-size: .82rem; }
.email-header-row { display: flex; gap: .5rem; margin-bottom: .15rem; }
.email-header-label { font-weight: 600; color: var(--text-muted); min-width: 3.5rem; flex-shrink: 0; }
.email-message-body { font-size: .88rem; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.email-message-attachments { margin-top: .75rem; font-size: .8rem; }
.attachment-badge { display: inline-block; background: var(--border); border-radius: 4px; padding: .1rem .45rem; margin-right: .35rem; }
.email-thread-meta-bar { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1.25rem; font-size: .88rem; }
.email-thread-project-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.email-thread-project-row .label { font-weight: 600; color: var(--text-muted); }

/* ---------- Date quick-filter pills ---------- */
.date-quick-filters { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: 1rem; }
.dqf-pill { font-size: .75rem; padding: .2rem .65rem; border-radius: 99px; border: 1px solid var(--border); color: var(--text-muted); text-decoration: none; background: var(--surface); transition: background .15s, color .15s, border-color .15s; white-space: nowrap; }
.dqf-pill:hover { border-color: var(--primary); color: var(--primary); }
.dqf-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Tags (pills) ---------- */
.tag-pill {
  display: inline-block; padding: .12rem .5rem; border-radius: 999px;
  font-size: .7rem; color: #fff; font-weight: 600; line-height: 1.4;
}
.filter-tags {
  display: flex; flex-wrap: nowrap; gap: .4rem; overflow-x: auto;
  padding: .5rem 0; margin-bottom: .75rem;
}
.filter-tags .filter-tag {
  flex-shrink: 0; cursor: pointer; padding: .25rem .7rem; border-radius: 999px;
  font-size: .78rem; border: 2px solid transparent; background: #f1f5f9;
  color: #475569; user-select: none; transition: opacity .15s;
}
.filter-tags .filter-tag.selected { color: #fff; }
.filter-tags .filter-tag:not(.selected) { opacity: .8; }

/* ---------- Source badge ---------- */
.source-badge {
  display: inline-block; padding: .1rem .45rem; border-radius: 4px;
  font-size: .65rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .03em; margin-left: .35rem;
}
.source-badge.manual { background: #ffedd5; color: #9a3412; }
.source-badge.recurring { background: #ede9fe; color: #6d28d9; }

/* ---------- Bulk toolbar ---------- */
.bulk-toolbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
  background: #1e293b; color: #fff; display: none;
  align-items: center; gap: .6rem; padding: .75rem 1.5rem;
  box-shadow: 0 -2px 12px rgba(0,0,0,.2); flex-wrap: wrap;
}
.bulk-toolbar.active { display: flex; }
.bulk-toolbar .bulk-count { font-weight: 700; margin-right: .5rem; }
.bulk-toolbar select {
  padding: .3rem .5rem; border-radius: 6px; border: 1px solid #475569;
  background: #334155; color: #fff; font-size: .8rem;
}

/* ---------- Checkbox column ---------- */
.checkbox-col { width: 28px; flex-shrink: 0; padding-top: .15rem; }
.action-card.with-check { display: flex; gap: .6rem; align-items: flex-start; }
.action-card.with-check .action-body { flex: 1; }

/* ---------- Archived item ---------- */
.archived-item { opacity: .6; }
.archived-item .action-desc { text-decoration: line-through; color: var(--text-muted); }
.badge-archived {
  display: inline-block; padding: .1rem .45rem; border-radius: 4px;
  font-size: .65rem; font-weight: 700; background: #e5e7eb; color: #4b5563;
  text-transform: uppercase; margin-left: .35rem;
}

/* ---------- 2-column form row ---------- */
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 600px) { .form-row-2 { grid-template-columns: 1fr; } }

/* ---------- Tag color swatches ---------- */
.tag-swatch-row { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .35rem; }
.tag-swatch {
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer;
  border: 3px solid transparent; transition: transform .1s;
}
.tag-swatch:hover { transform: scale(1.1); }
.tag-swatch.selected { border-color: #1e293b; }

/* ---------- Action archived/manual checkbox row ---------- */
.checkbox-inline { display: flex; align-items: center; gap: .4rem; font-size: .85rem; }
.checkbox-inline input { width: auto; }

/* ---------- Export page ---------- */
.export-section { margin-bottom: 1.25rem; }
.export-section h3 { font-size: .9rem; font-weight: 600; margin-bottom: .5rem; }
.export-projects {
  max-height: 260px; overflow-y: auto; border: 1px solid var(--border);
  border-radius: var(--radius); padding: .75rem; background: var(--bg);
}
.export-projects .proj-class { font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; font-size: .72rem; margin: .5rem 0 .25rem; }
.export-check { display: flex; align-items: center; gap: .4rem; padding: .15rem 0; font-size: .85rem; }
.export-check input { width: auto; }

/* ---------- Tags table ---------- */
.tag-swatch-display { display: inline-block; width: 18px; height: 18px;
  border-radius: 4px; vertical-align: middle; margin-right: .4rem; }
.inline-form { display: inline-flex; gap: .35rem; align-items: center; }
.inline-form input, .inline-form select {
  padding: .25rem .5rem; border: 1px solid var(--border); border-radius: 6px; font-size: .8rem;
}

/* ---------- Report (export HTML) ---------- */
.report-group { margin-bottom: 1.5rem; }
.report-group h2 { font-size: 1.1rem; border-bottom: 2px solid var(--border);
  padding-bottom: .3rem; margin-bottom: .5rem; }
@media print {
  .nav, .no-print { display: none !important; }
  body { background: #fff; }
}

/* Summary boxes */
.summary-boxes { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px,1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.summary-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.summary-box-header { display: flex; align-items: center; justify-content: space-between; padding: .65rem 1rem; background: #1e293b; color: #fff; }
.summary-box-title { font-weight: 600; font-size: .9rem; }
.summary-box-meta { font-size: .75rem; color: #94a3b8; }
.summary-box-body { padding: 1rem; font-size: .875rem; line-height: 1.6; color: var(--text); min-height: 80px; word-wrap: break-word; overflow-wrap: break-word; }
.summary-box-body.placeholder { color: var(--text-muted); font-style: italic; }
.summary-spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid #94a3b8; border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Upload zone */
.upload-zone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 2rem; text-align: center; background: #f8fafc; cursor: pointer; transition: border-color .15s, background .15s; }
.upload-zone:hover, .upload-zone.dragover { border-color: var(--primary); background: #eff6ff; }
.upload-zone-icon { font-size: 2rem; margin-bottom: .5rem; }
.upload-zone-text { color: var(--text-muted); font-size: .9rem; }
.file-list { margin-top: .75rem; display: flex; flex-direction: column; gap: .25rem; }
.file-item { display: flex; align-items: center; gap: .5rem; font-size: .85rem; background: #f1f5f9; padding: .3rem .6rem; border-radius: 4px; }

/* Tab toggle */
.tab-bar { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 1.25rem; }
.tab-btn { padding: .5rem 1.25rem; font-size: .875rem; font-weight: 500; color: var(--text-muted); background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -2px; cursor: pointer; transition: color .15s, border-color .15s; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Per-project notes ---------- */
.proj-notes-section { margin-bottom: 1.5rem; }
.proj-notes-heading { font-size: 1rem; font-weight: 600; margin-bottom: .75rem; }
.proj-note-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: .6rem; box-shadow: var(--shadow);
}
.proj-note-summary {
  display: flex; align-items: center; gap: .5rem;
  padding: .65rem 1rem; cursor: pointer; list-style: none; font-weight: 500;
}
.proj-note-summary::-webkit-details-marker { display: none; }
.proj-note-body { padding: .75rem 1rem; border-top: 1px solid var(--border); }
.proj-note-row { display: grid; grid-template-columns: 140px 1fr; gap: .5rem;
                 margin-bottom: .6rem; align-items: start; }
.proj-note-label { font-size: .78rem; font-weight: 700; color: var(--text-muted);
                   text-transform: uppercase; letter-spacing: .04em; padding-top: .1rem; }
.proj-note-text { font-size: .875rem; line-height: 1.55; color: var(--text); }

/* ---------- Chat layout ---------- */
.chat-layout {
  display: flex; gap: 0; height: calc(100vh - 52px - 5rem);
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.chat-sidebar {
  width: 260px; flex-shrink: 0; border-right: 1px solid var(--border);
  background: var(--surface); display: flex; flex-direction: column;
  overflow: hidden;
}
.chat-sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1rem; border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.chat-sidebar-title { font-weight: 600; font-size: .875rem; }
.chat-session-list { flex: 1; overflow-y: auto; padding: .4rem 0; }
.chat-session-item {
  display: flex; align-items: center; gap: .25rem;
  padding: .1rem .5rem; border-radius: 6px; margin: .15rem .4rem;
  transition: background .1s;
}
.chat-session-item:hover { background: #f1f5f9; }
.chat-session-item.active { background: #eff6ff; }
.chat-session-link {
  flex: 1; display: flex; flex-direction: column; padding: .35rem .25rem;
  color: var(--text); text-decoration: none; overflow: hidden;
}
.chat-session-link:hover { text-decoration: none; }
.chat-session-name { font-size: .82rem; font-weight: 500; white-space: nowrap;
                     overflow: hidden; text-overflow: ellipsis; }
.chat-session-date { font-size: .72rem; color: var(--text-muted); }
.chat-size-pill {
  display: inline-block; font-size: .62rem; font-weight: 600;
  padding: .05rem .32rem; border-radius: 8px; margin-left: .3rem;
  vertical-align: middle; letter-spacing: .02em;
}
.chat-size-sm { background: #d4edda; color: #1a6b30; }
.chat-size-md { background: #fff3cd; color: #7a5300; }
.chat-size-lg { background: #fde8d8; color: #8c3b00; }
.chat-size-xl { background: #f8d7da; color: #7a1a20; }
@media (prefers-color-scheme:dark) {
  .chat-size-sm { background: #1a3d24; color: #6fe09a; }
  .chat-size-md { background: #3d2e00; color: #f5c842; }
  .chat-size-lg { background: #3d1800; color: #ff9a5c; }
  .chat-size-xl { background: #3d0a0d; color: #ff7b82; }
}
:root[data-theme="dark"] .chat-size-sm { background: #1a3d24; color: #6fe09a; }
:root[data-theme="dark"] .chat-size-md { background: #3d2e00; color: #f5c842; }
:root[data-theme="dark"] .chat-size-lg { background: #3d1800; color: #ff9a5c; }
:root[data-theme="dark"] .chat-size-xl { background: #3d0a0d; color: #ff7b82; }
:root[data-theme="light"] .chat-size-sm { background: #d4edda; color: #1a6b30; }
:root[data-theme="light"] .chat-size-md { background: #fff3cd; color: #7a5300; }
:root[data-theme="light"] .chat-size-lg { background: #fde8d8; color: #8c3b00; }
:root[data-theme="light"] .chat-size-xl { background: #f8d7da; color: #7a1a20; }
.chat-del-form { flex-shrink: 0; }
.chat-del-btn {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 1rem; padding: .2rem .4rem; border-radius: 4px; line-height: 1;
}
.chat-del-btn:hover { background: #fee2e2; color: var(--danger); }
.chat-empty-sidebar { font-size: .82rem; color: var(--text-muted);
                      padding: 1rem; text-align: center; }
.chat-main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg);
}
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .75rem 1.25rem; background: var(--surface);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.chat-title { font-weight: 600; font-size: .9rem; }
.chat-archived-toggle { display: flex; align-items: center; gap: .4rem;
                        font-size: .8rem; color: var(--text-muted); }
.chat-archived-toggle input { width: auto; }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 1rem 1.25rem;
  display: flex; flex-direction: column; gap: .75rem;
  max-height: 60vh;
}
.chat-msg { display: flex; }
.chat-msg-user { justify-content: flex-end; }
.chat-msg-assistant { justify-content: flex-start; }
.chat-bubble {
  max-width: 75%; padding: .65rem 1rem; border-radius: 12px;
  font-size: .875rem; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
}
.chat-msg-user .chat-bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 3px; }
.chat-msg-assistant .chat-bubble { background: var(--surface); border: 1px solid var(--border);
                                    color: var(--text); border-bottom-left-radius: 3px; }
.chat-input-area {
  padding: .75rem 1.25rem; background: var(--surface);
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.chat-input-row { display: flex; gap: .5rem; align-items: flex-end; }
.chat-input {
  flex: 1; padding: .6rem .85rem; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .9rem; font-family: inherit;
  resize: none; background: var(--bg); transition: border-color .15s;
}
.chat-input:focus { outline: none; border-color: var(--primary); background: #fff; }
.chat-send-btn { align-self: flex-end; }
.chat-error { background: #fee2e2; color: #991b1b; border-radius: 6px;
              padding: .4rem .75rem; font-size: .82rem; margin-bottom: .4rem; }
.chat-welcome { text-align: center; margin: auto; padding: 2rem; }
.chat-welcome p { color: var(--text-muted); margin-bottom: 1rem; }
.chat-starters { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; }
.chat-empty-main {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; text-align: center; padding: 2rem; gap: 1rem;
}
.chat-empty-icon { font-size: 3rem; }
.chat-empty-main h2 { font-size: 1.4rem; font-weight: 700; }
.chat-empty-main p { color: var(--text-muted); max-width: 380px; }

/* Source badge on transcripts */
.source-tag { display: inline-block; padding: .1rem .4rem; border-radius: 4px; font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.source-tag.pasted { background: #f1f5f9; color: #64748b; }
.source-tag.uploaded { background: #dbeafe; color: #1e40af; }
.source-tag.folder { background: #d1fae5; color: #065f46; }

/* ---------- Project Detail ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}

.status-pill {
  display: inline-block;
  padding: .15rem .65rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .03em;
}
.status-pill.proj-red    { background: #fee2e2; color: #991b1b; }
.status-pill.proj-yellow { background: #fef3c7; color: #92400e; }
.status-pill.proj-green  { background: #dcfce7; color: #14532d; }

.ai-status-body { font-size: .9rem; line-height: 1.65; }
.risk-block { background: #fff7ed; border-left: 3px solid #f59e0b; padding: .6rem .9rem; border-radius: 0 6px 6px 0; }

/* Transcript accordion rows on project detail */
.transcript-row-detail {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: .5rem;
  background: var(--surface);
  overflow: hidden;
}
.transcript-row-detail summary {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem 1rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.transcript-row-detail summary::-webkit-details-marker { display: none; }
.transcript-row-detail summary:hover { background: #f8fafc; }
.transcript-row-detail[open] summary { border-bottom: 1px solid var(--border); }
.transcript-title-text { font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transcript-proj-notes { padding: .75rem 1rem 1rem; }

/* Forecast highlight row */
.proj-note-row-forecast { background: #f0fdf4; border-radius: 6px; }
.proj-note-row-forecast .proj-note-label { color: #15803d; }

/* Compact markdown rendering in chat bubbles and dashboard summaries */
.chat-bubble p, .summary-box-body p { margin: 0 0 .2em; }
.chat-bubble p:last-child, .summary-box-body p:last-child { margin-bottom: 0; }
.chat-bubble li br, .summary-box-body li br { display: none; }
.chat-bubble ul, .chat-bubble ol, .summary-box-body ul, .summary-box-body ol { margin: .1em 0 .2em 1.2em; padding: 0; }
.chat-bubble li, .summary-box-body li { margin-bottom: .1em; }
.chat-bubble li p, .summary-box-body li p { display: inline; margin: 0; }
.chat-bubble h1,.chat-bubble h2,.chat-bubble h3,
.summary-box-body h1,.summary-box-body h2,.summary-box-body h3 { margin: .4em 0 .15em; font-size: 1em; }

/* Copy button on assistant chat bubbles */
.chat-bubble { position: relative; }
.chat-copy-btn {
  position: absolute;
  bottom: .4rem;
  right: .4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s, background .15s, color .15s;
}
.chat-msg-assistant .chat-bubble:hover .chat-copy-btn { opacity: 1; }
.chat-copy-btn:hover { background: var(--border); color: var(--text); }

/* Defer popover option buttons */
.defer-option-btn {
  width: 100%;
  text-align: left;
  padding: .3rem .5rem;
  border: none;
  border-radius: 5px;
  background: transparent;
  font-size: .85rem;
  color: var(--text);
  cursor: pointer;
}
.defer-option-btn:hover { background: var(--border); }

/* Chat source buttons */
.chat-source-btn {
  display: inline-block;
  margin-top: .4rem;
  margin-right: .4rem;
  padding: .2rem .6rem;
  font-size: .75rem;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  text-decoration: none;
  border: 1px solid #bfdbfe;
}
.chat-source-btn:hover { background: #dbeafe; }

/* ---------- Action item kebab menu ---------- */
.action-menu { position: relative; flex-shrink: 0; display: flex; align-items: center; gap: .3rem; }
.quick-complete-btn {
  background: none; border: 1px solid #22c55e; border-radius: var(--radius);
  cursor: pointer; font-size: .85rem; font-weight: 600; line-height: 1; padding: .2rem .45rem;
  color: #22c55e; transition: background .15s, color .15s; white-space: nowrap;
}
.quick-complete-btn:hover { background: #22c55e; color: #fff; }
.quick-complete-btn.undo-mode { background: #22c55e; color: #fff; border-color: #22c55e; }
.action-menu-btn {
  background: none; border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; font-size: 1.1rem; line-height: 1; padding: .2rem .5rem;
  color: var(--text-muted); transition: background .1s;
}
.action-menu-btn:hover { background: var(--border); color: var(--text); }
.action-menu-dropdown {
  display: none; position: fixed; z-index: 1500;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,.12);
  min-width: 150px; padding: .3rem 0;
}
.action-menu-dropdown.open { display: block; }
.action-menu-item {
  display: block; width: 100%; text-align: left; padding: .45rem .9rem;
  background: none; border: none; font-size: .875rem; color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.action-menu-item:hover { background: #f1f5f9; text-decoration: none; }
.action-menu-item.danger { color: var(--danger); }
.action-menu-item.success { color: var(--success); font-weight: 600; }

/* ---------- Priority Contacts ---------- */
.contacts-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: .6rem;
}
.contacts-item {
  display: flex; flex-direction: column; gap: .15rem;
  padding: .5rem .65rem;
  background: #f8fafc; border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.contacts-name {
  font-weight: 600; font-size: .875rem; color: var(--primary); text-decoration: none;
}
.contacts-name:hover { text-decoration: underline; }
.contacts-rationale {
  font-size: .825rem; color: var(--text-muted); line-height: 1.45;
}

/* ---------- Hamburger (hidden on desktop) ---------- */
.nav-hamburger {
  display: none;
  background: none; border: none; cursor: pointer;
  padding: .4rem; color: #e2e8f0;
}
.nav-hamburger span {
  display: block; width: 22px; height: 2px; background: currentColor;
  margin: 4px 0; border-radius: 2px; transition: transform .2s, opacity .2s;
}

/* ---------- Scrollable table wrapper ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ============================================================
   MOBILE  (≤ 640px)
   ============================================================ */
@media (max-width: 640px) {

  /* --- Nav --- */
  .nav { padding: 0 1rem; position: relative; flex-wrap: wrap; height: auto; min-height: 52px; }
  .nav-hamburger { display: flex; flex-direction: column; justify-content: center; margin-left: auto; }
  .nav-links {
    display: none; flex-direction: column; gap: 0;
    width: 100%; padding: .5rem 0 .75rem;
    border-top: 1px solid #334155;
  }
  .nav-links.open { display: flex; }
  .nav-links a { padding: .6rem .75rem; font-size: .9rem; border-radius: 6px; }
  .nav-logout { margin-left: 0; }

  /* --- Layout --- */
  .container { padding: 1rem .75rem; }
  .page-header { flex-wrap: wrap; }
  .page-header h1 { font-size: 1.2rem; }
  .header-actions { flex-wrap: wrap; }

  /* --- Stats --- */
  .stats-row { flex-wrap: wrap; }
  .stat-card { flex: 1 1 calc(50% - .5rem); min-width: 0; }

  /* --- Summary boxes --- */
  .summary-boxes { grid-template-columns: 1fr; }

  /* --- Data tables: scroll horizontally --- */
  .data-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; white-space: nowrap; }
  .data-table td, .data-table th { white-space: normal; min-width: 120px; }

  /* --- Filter bar --- */
  .filter-bar { gap: .4rem; }
  .filter-bar select, .filter-bar input { font-size: .82rem; max-width: 100%; }

  /* --- Buttons: bigger tap targets --- */
  .btn { padding: .55rem 1rem; font-size: .875rem; }
  .btn-sm { padding: .4rem .75rem; font-size: .82rem; }

  /* --- Action cards --- */
  .action-buttons { flex-wrap: wrap; }

  /* --- Forms --- */
  .form-row { grid-template-columns: 1fr; }
  .form-card { padding: 1rem; }

  /* --- Chat: stack sidebar above messages --- */
  .chat-layout {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 52px - 2rem);
  }
  .chat-sidebar {
    width: 100%; flex-shrink: 0;
    border-right: none; border-bottom: 1px solid var(--border);
    max-height: 200px;
  }
  .chat-main { flex: 1; min-height: 0; }
  .chat-messages { min-height: 300px; }
  .chat-bubble { max-width: 90%; }

  /* --- Project grid --- */
  .project-grid { grid-template-columns: 1fr; }

  /* --- Proj notes label/value: stack --- */
  .proj-note-row { grid-template-columns: 1fr; }
  .proj-note-label { padding-bottom: 0; }

  /* --- AI settings cards --- */
  .card > .card-body > div[style*="display:flex"] { flex-direction: column !important; }
}

/* ============================================================
   TABLET  (641px – 900px)
   ============================================================ */
@media (min-width: 641px) and (max-width: 900px) {
  .summary-boxes { grid-template-columns: 1fr; }
  .stats-row { flex-wrap: wrap; }
  .stat-card { flex: 1 1 calc(50% - .5rem); }
  .chat-sidebar { width: 200px; }
  .chat-bubble { max-width: 85%; }
}
