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

:root {
  --sidebar-bg: #3D2275;
  --sidebar-hover: rgba(255,255,255,0.09);
  --sidebar-active: #5B35A8;
  --sidebar-text: #EDE8F8;
  --sidebar-muted: #b8a8d4;
  --main-bg: #F5F4F0;
  --card-bg: #ffffff;
  --text: #2C2825;
  --text-muted: #6B6560;
  --border: #E8E5DE;
  --accent: #5B35A8;
  --accent-hover: #3D2275;
  --accent-light: #EDE8F8;
  --danger: #ef4444;
  --success: #22c55e;
  --font: 'DM Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-heading: 'Playfair Display', Georgia, serif;
  --font-mono: 'DM Mono', 'Courier New', monospace;
}

body {
  font-family: var(--font);
  background: var(--main-bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Auth Overlay ─────────────────────────────────────────────────────────── */

#auth-overlay {
  position: fixed; inset: 0;
  background: rgba(61, 34, 117, 0.88);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

.auth-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 2.5rem 2rem;
  max-width: 440px; width: 90%;
  text-align: center;
}

.auth-logo { height: 48px; width: auto; margin-bottom: 1rem; }
.auth-card p { color: var(--text-muted); margin-bottom: 1.5rem; line-height: 1.5; }
.auth-card a { color: var(--accent); }

.device-code {
  font-family: 'Courier New', monospace;
  font-size: 2rem; font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--accent);
  background: var(--accent-light);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin: 0.75rem 0 1rem;
}

.auth-waiting { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 0; }
.auth-card a.btn-primary { display: inline-block; text-decoration: none; color: #fff; }

/* ── Layout ───────────────────────────────────────────────────────────────── */

#app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */

#sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 1.1rem 1.25rem 0.9rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  display: flex; align-items: center; gap: 0.5rem;
}

.sidebar-header-link {
  margin-left: auto;
  color: var(--sidebar-muted);
  font-size: 0.95rem;
  text-decoration: none;
  padding: 0.15rem 0.3rem;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}
.sidebar-header-link:hover { color: #fff; background: rgba(255,255,255,0.1); }

.sidebar-logo-text {
  font-family: var(--font-heading);
  font-size: 1.1rem; font-weight: 700;
  color: #ffffff; letter-spacing: 0.02em;
}

.logo-sub {
  font-size: 0.75rem; color: var(--sidebar-muted);
  font-weight: 400; letter-spacing: 0.02em;
}

.sidebar-user {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 1.25rem 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sidebar-user-name {
  font-size: 0.72rem; color: var(--sidebar-muted);
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.btn-sign-out {
  background: none; border: none; cursor: pointer;
  color: var(--sidebar-muted); font-size: 0.8rem; padding: 0.1rem 0.25rem;
  border-radius: 3px; transition: color 0.15s;
}
.btn-sign-out:hover { color: #fff; }

.team-sources {
  font-size: 0.75rem; color: var(--text-muted);
  padding: 0.3rem 0 0.6rem;
  font-style: italic;
}
.team-sources.hidden { display: none; }

.search-wrap {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

#search {
  width: 100%;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: #e2e8f0;
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
#search::placeholder { color: var(--sidebar-muted); }
#search:focus { border-color: rgba(91,53,168,0.5); }

.folder-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.folder-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 1.25rem;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.1s;
  gap: 0.5rem;
}
.folder-item:hover { background: var(--sidebar-hover); }
.folder-item.active { background: var(--sidebar-active); }

.folder-name {
  font-size: 0.83rem;
  color: var(--sidebar-text);
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.folder-count {
  font-size: 0.72rem;
  color: var(--sidebar-muted);
  flex-shrink: 0;
}
.folder-item.active .folder-name { color: #fff; }
.folder-item.active .folder-count { color: rgba(255,255,255,0.6); }

.folder-item.cached .folder-name::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--success);
  margin-right: 5px;
  vertical-align: middle;
  position: relative; top: -1px;
  flex-shrink: 0;
}

/* Watched clients section */
.watched-section-label {
  padding: 0.55rem 1.25rem 0.2rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--sidebar-muted);
  opacity: 0.7;
  margin-top: 0.25rem;
}

.folder-item-watched { opacity: 0.88; }
.folder-item-watched .folder-name { font-style: italic; }

.watch-remove-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.3);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0.15rem;
  flex-shrink: 0;
  transition: color 0.12s;
}
.folder-item-watched:hover .watch-remove-btn { color: rgba(255,255,255,0.7); }

/* Watch search panel (above sidebar footer) */
.watch-search-wrap {
  padding: 0.5rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  position: relative;
}

.watch-search-input {
  width: 100%;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 0.38rem 0.65rem;
  font-size: 0.82rem;
  font-family: var(--font);
  color: var(--sidebar-text);
  outline: none;
  transition: border-color 0.15s;
}
.watch-search-input:focus { border-color: rgba(255,255,255,0.4); }
.watch-search-input::placeholder { color: var(--sidebar-muted); }

.watch-search-dropdown {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 1rem;
  right: 1rem;
  background: var(--card-bg);
  border: 1px solid var(--accent);
  border-radius: 7px;
  box-shadow: 0 -4px 20px rgba(61,34,117,0.18);
  z-index: 600;
  max-height: 220px;
  overflow-y: auto;
}

.watch-drop-item {
  padding: 0.42rem 0.75rem;
  font-size: 0.83rem;
  font-family: var(--font);
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.08s;
}
.watch-drop-item:last-child { border-bottom: none; }
.watch-drop-item:hover { background: var(--accent-light); color: var(--accent); }

.watch-drop-empty {
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
}

.loading-folders {
  padding: 1.5rem 1.25rem;
  color: var(--sidebar-muted);
  font-size: 0.85rem;
}

.sidebar-footer {
  padding: 0.6rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem;
}

#folder-count {
  font-size: 0.75rem; color: var(--sidebar-muted);
  flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}

.sidebar-footer-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }

.sidebar-icon-btn {
  background: none; border: none; cursor: pointer;
  color: var(--sidebar-muted); font-size: 1rem;
  padding: 0.2rem 0.4rem; border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  line-height: 1; text-decoration: none; display: inline-flex; align-items: center;
}
.sidebar-icon-btn:hover { color: #fff; background: rgba(255,255,255,0.1); }
.sidebar-icon-btn:disabled { opacity: 0.4; cursor: default; }

/* ── Main ─────────────────────────────────────────────────────────────────── */

#main {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 2.5rem;
  display: flex;
  flex-direction: column;
}

/* Welcome */
.welcome {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  color: var(--text-muted);
}
.welcome-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.4; }
.welcome h1 { font-family: var(--font-heading); font-size: 1.5rem; color: var(--accent); margin-bottom: 0.5rem; font-weight: 700; }
.welcome p { font-size: 0.95rem; }

/* Status panel */
#status-panel { flex: 1; display: flex; flex-direction: column; gap: 1rem; }

#status-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  flex-wrap: wrap; gap: 0.75rem;
}

#status-client-name {
  font-family: var(--font-heading);
  font-size: 1.4rem; font-weight: 700; color: #1A1714;
}

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

.timestamp {
  font-size: 0.78rem; color: var(--text-muted);
  margin-right: 0.25rem;
}
.timestamp.cached { color: var(--success); }

.model-select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.28rem 0.5rem;
  font-size: 0.78rem;
  font-family: var(--font);
  color: var(--text-muted);
  background: var(--card-bg);
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.model-select:hover { border-color: #cbd5e1; color: var(--text); }
.model-select:focus { border-color: var(--accent); }

/* Preferences popover */
.prefs-wrap { position: relative; }

.prefs-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 200;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: 0.75rem 1rem;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.prefs-group { display: flex; flex-direction: column; gap: 0.3rem; }

.prefs-group-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.prefs-note { font-weight: 400; text-transform: none; letter-spacing: 0; }

.prefs-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  padding: 0.15rem 0;
}
.prefs-item input[type=checkbox] { accent-color: var(--accent); cursor: pointer; }

/* Progress bar */
.progress-bar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--accent-light);
  border-radius: 8px;
  border: 1px solid #c9b8e8;
}

.progress-fill {
  width: 18px; height: 18px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

#progress-msg { font-size: 0.85rem; color: var(--accent); }

/* Status content */
.status-content {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.75rem 2rem;
  flex: 1;
  min-height: 400px;
  line-height: 1.65;
  font-size: 0.92rem;
}

/* Markdown styling */
.status-content h2 {
  font-family: var(--font-heading);
  font-size: 1.3rem; font-weight: 700;
  margin-bottom: 0.25rem;
  color: #1A1714;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--accent);
}

.status-content h3 {
  font-size: 0.95rem; font-weight: 600;
  font-style: italic;
  margin: 1.4rem 0 0.5rem;
  color: var(--accent);
  text-transform: uppercase; letter-spacing: 0.04em;
}

.status-content p { margin-bottom: 0.75rem; color: var(--text); }

.status-content strong { color: var(--text); }

.status-content ul {
  padding-left: 1.25rem;
  margin-bottom: 0.75rem;
}
.status-content li { margin-bottom: 0.25rem; }

.status-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}
.status-content th {
  text-align: left;
  padding: 0.45rem 0.75rem;
  background: var(--main-bg);
  border: 1px solid var(--border);
  font-weight: 600; color: var(--text-muted);
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em;
}
.status-content td {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  vertical-align: top;
}
.status-content tr:nth-child(even) td { background: var(--main-bg); }

/* Buttons */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none; border-radius: 8px;
  padding: 0.65rem 1.5rem;
  font-size: 0.95rem; font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem; color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-ghost:hover { background: var(--main-bg); color: var(--text); border-color: #cbd5e1; }
.btn-ghost:disabled { opacity: 0.4; cursor: default; }

/* Dots animation */
.dots::after {
  content: '';
  animation: dots 1.5s steps(4, end) infinite;
}
@keyframes dots {
  0%  { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* ── Calendar ─────────────────────────────────────────────────────────────── */

#calendar-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
}

.calendar-reauth-banner {
  display: flex; align-items: center; gap: 0.75rem;
  font-size: 0.85rem; color: var(--text-muted);
  padding: 0.25rem 0;
}

.calendar-loading, .calendar-empty {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.25rem 0;
}

.cal-event {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.cal-event:last-child { border-bottom: none; }

.cal-date {
  flex-shrink: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  border-radius: 5px;
  padding: 0.2rem 0.5rem;
  white-space: nowrap;
  margin-top: 0.1rem;
}

.cal-detail {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

a.cal-subject {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
a.cal-subject:hover { color: var(--accent); text-decoration: underline; }
span.cal-subject {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

.cal-location {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ── Q&A ──────────────────────────────────────────────────────────────────── */

#qa-section {
  border-bottom: 2px solid var(--border);
  padding-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#qa-history {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.qa-entry {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.qa-question {
  background: var(--accent-light);
  border-bottom: 1px solid #c9b8e8;
  padding: 0.6rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent);
}

.qa-answer {
  padding: 0.85rem 1rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
}

.qa-answer p { margin-bottom: 0.5rem; }
.qa-answer p:last-child { margin-bottom: 0; }
.qa-answer ul { padding-left: 1.25rem; margin-bottom: 0.5rem; }

.qa-stale {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  display: block;
  margin-bottom: 0.5rem;
}

.prolaw-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  padding: 0.35rem 0;
}

.prolaw-since-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.prolaw-since-input {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--card-bg);
  outline: none;
  transition: border-color 0.15s;
}
.prolaw-since-input:focus { border-color: var(--accent); }

.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
}

.qa-input-row {
  display: flex;
  gap: 0.5rem;
  position: sticky;
  bottom: 0;
  background: var(--main-bg);
  padding: 0.75rem 0 0.25rem;
  z-index: 10;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}

#ask-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font-size: 0.9rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--card-bg);
  outline: none;
  transition: border-color 0.15s;
}
#ask-input:focus { border-color: var(--accent); }
#ask-input::placeholder { color: var(--text-muted); }

#ask-btn { flex-shrink: 0; padding: 0.55rem 1.25rem; font-size: 0.88rem; }
#ask-btn:disabled { opacity: 0.5; cursor: default; }

/* ── Documents section ────────────────────────────────────────────────────── */

#documents-section {
  border-bottom: 2px solid var(--border);
  padding-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.documents-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  padding: 0.35rem 0;
}

.documents-bar-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.documents-matter-select {
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--card-bg);
  outline: none;
  transition: border-color 0.15s;
  max-width: 260px;
}
.documents-matter-select:focus { border-color: var(--accent); }

.documents-status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.doc-search-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.25rem;
}

.doc-search-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.doc-search-row input[type="text"],
.doc-search-row input[type="date"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.65rem;
  font-size: 0.83rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--card-bg);
  outline: none;
  transition: border-color 0.15s;
}
.doc-search-row input[type="text"]:focus,
.doc-search-row input[type="date"]:focus { border-color: var(--accent); }
.doc-search-row input[type="text"]::placeholder { color: var(--text-muted); }
#doc-search-keyword { flex: 2; min-width: 160px; }
#doc-search-class   { flex: 1; min-width: 120px; }
.doc-search-date-label { font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; }

.doc-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.85rem;
  background: var(--accent-light);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}

.doc-select-all-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}

.doc-selected-count {
  font-size: 0.78rem;
  color: var(--text-muted);
}

#documents-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  font-size: 0.85rem;
}

.doc-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
}
.doc-row:last-child { border-bottom: none; }
.doc-row:hover { background: var(--accent-light); }
.doc-row.selected { background: var(--accent-light); }

.doc-check { accent-color: var(--accent); cursor: pointer; width: 15px; height: 15px; }

.doc-name {
  font-size: 0.83rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-name-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}
.doc-date {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.doc-class {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

#document-ask-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#document-ask-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font-size: 0.9rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--card-bg);
  outline: none;
  transition: border-color 0.15s;
}
#document-ask-input:focus { border-color: var(--accent); }
#document-ask-input::placeholder { color: var(--text-muted); }

#document-ask-btn { flex-shrink: 0; padding: 0.55rem 1.25rem; font-size: 0.88rem; }
#document-ask-btn:disabled { opacity: 0.5; cursor: default; }

#document-qa-history {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ── Sync folder names modal ──────────────────────────────────────────────── */

.sync-modal {
  position: fixed; inset: 0;
  background: rgba(61, 34, 117, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
}

.sync-modal-card {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 1.5rem;
  width: 680px; max-width: 96vw;
  max-height: 85vh;
  display: flex; flex-direction: column; gap: 1rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.sync-modal-card h3 { font-size: 1rem; font-weight: 700; color: var(--text); }

#sync-preview {
  flex: 1; overflow-y: auto;
  font-size: 0.85rem; color: var(--text);
  display: flex; flex-direction: column; gap: 0.5rem;
}

#sync-preview ul { padding-left: 1.25rem; display: flex; flex-direction: column; gap: 0.2rem; }
#sync-preview li { line-height: 1.5; }

.sync-section-label { font-weight: 600; color: var(--text); margin-top: 0.25rem; }
.sync-section-label.sync-warn { color: #d97706; }
.sync-from { color: var(--text-muted); }
.sync-to   { color: var(--accent); font-weight: 500; }
.sync-summary { color: var(--text-muted); font-size: 0.78rem; margin-top: 0.25rem; }
.sync-none { color: var(--text-muted); }
.sync-loading { color: var(--text-muted); }

.sync-modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; flex-wrap: wrap; }

/* Sync domain/address input table */
.sync-domain-table { width: 100%; border-collapse: collapse; font-size: 0.83rem; margin: 0.35rem 0 0; }
.sync-domain-table td { padding: 0.3rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.sync-domain-table tr:last-child td { border-bottom: none; }
.sync-col-domain { color: var(--text); font-family: var(--font-mono); font-size: 0.8rem; }
.sync-col-count  { text-align: right; color: var(--text-muted); width: 50px; }
.sync-col-input  { min-width: 200px; }
.sync-folder-input {
  width: 100%; background: var(--main-bg); border: 1px solid var(--border);
  border-radius: 5px; padding: 0.22rem 0.45rem;
  font-size: 0.83rem; font-family: var(--font); color: var(--text);
  outline: none; transition: border-color 0.15s;
}
.sync-folder-input:focus { border-color: var(--accent); }
.sync-folder-input::placeholder { color: var(--text-muted); }
.sync-folder-input.has-value  { border-color: #10b981; background: rgba(16,185,129,0.06); }
.sync-folder-input.suggested  { border-color: #f59e0b; background: rgba(245,158,11,0.06); }
.sync-generic-header td { color: var(--text-muted); font-size: 0.77rem; padding-top: 0.5rem; background: none; }
.sync-generic-sub .sync-col-domain { padding-left: 1.25rem; color: var(--text-muted); }
.sync-matched-toggle { background: none; border: none; cursor: pointer; font-size: 0.78rem; color: var(--text-muted); padding: 0; margin-left: auto; }
.sync-matched-toggle:hover { color: var(--accent); }
.sync-domain-table th {
  text-align: left; padding: 0.25rem 0.5rem;
  font-size: 0.7rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border); background: var(--main-bg);
}
.sync-col-action { width: 1%; white-space: nowrap; text-align: right; }
.sync-col-action .btn-row + .btn-row { margin-left: 0.25rem; }
.sync-ignored-text { color: var(--text-muted); font-style: italic; font-size: 0.83rem; }
.sync-badge-src {
  display: inline-block; font-size: 0.68rem; font-weight: 600;
  padding: 0.1rem 0.35rem; border-radius: 4px; vertical-align: middle; white-space: nowrap;
}
.sync-badge-prolaw   { background: rgba(59,130,246,0.12); color: #60a5fa; }
.sync-badge-global   { background: rgba(16,185,129,0.12); color: #10b981; }
.sync-badge-override { background: rgba(245,158,11,0.12);  color: #f59e0b; }

/* Custom combobox dropdown */
.sync-combobox-dropdown {
  position: fixed;
  background: var(--card-bg);
  border: 1px solid var(--accent);
  border-radius: 7px;
  box-shadow: 0 6px 24px rgba(61,34,117,0.15);
  z-index: 700;
  max-height: 240px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.sync-combobox-option {
  padding: 0.42rem 0.75rem;
  font-size: 0.83rem;
  font-family: var(--font);
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.08s;
}
.sync-combobox-option:last-child { border-bottom: none; }
.sync-combobox-option:hover,
.sync-combobox-option.active {
  background: var(--accent-light);
  color: var(--accent);
}
.sync-combobox-ignore {
  color: var(--text-muted);
  font-style: italic;
  border-bottom: 2px solid var(--border);
}
.sync-combobox-ignore:hover,
.sync-combobox-ignore.active {
  background: #fef2f2;
  color: var(--danger);
}
.sync-combobox-empty {
  padding: 0.42rem 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
}

.sync-conflict-list li, .sync-nomatch-list li {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.2rem 0; flex-wrap: wrap;
}
.sync-conflict-list .merge-status { font-size: 0.78rem; color: var(--text-muted); }
.sync-nomatch-list { columns: 2; gap: 1rem; }
.sync-nomatch-list li { font-size: 0.82rem; color: var(--text-muted); display: block; padding: 0.1rem 0; }
.sync-link { color: var(--accent); font-size: 0.85rem; }

/* ── Organize inbox progress bar ──────────────────────────────────────────── */
.organize-progress-bar {
  width: 100%; height: 7px;
  background: var(--border); border-radius: 4px;
  overflow: hidden; margin-top: 0.4rem;
}
.organize-progress-fill {
  height: 100%;
  background: var(--accent); border-radius: 4px;
  width: 0%; transition: width 0.35s ease;
}
.organize-progress-fill.done { background: #10b981; }
.organize-progress-fill.indeterminate {
  width: 38%;
  animation: org-slide 1.5s ease-in-out infinite;
}
@keyframes org-slide {
  0%   { transform: translateX(-200%); }
  100% { transform: translateX(370%); }
}

/* ── Label enrichment ─────────────────────────────────────────────────────── */

#status-name-wrap {
  display: flex; flex-direction: column; gap: 0.1rem;
  min-width: 0;
}

.client-name-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

.btn-edit-label {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted);
  font-size: 0.75rem;
  padding: 0 0.3rem;
  margin-left: 0.25rem;
  opacity: 0.45;
  transition: opacity 0.15s;
  vertical-align: middle;
}
.btn-edit-label:hover { opacity: 1; }

.label-edit-row {
  display: inline-flex; align-items: center; gap: 0.4rem;
}

.label-edit-input {
  border: 1px solid var(--accent);
  border-radius: 5px;
  padding: 0.2rem 0.5rem;
  font-size: 1.2rem;
  font-weight: 700;
  font-family: var(--font);
  color: var(--text);
  background: var(--card-bg);
  outline: none;
  width: 280px;
}

/* ── AI Skills ────────────────────────────────────────────────────────────── */

#skills-section {
  border-bottom: 2px solid var(--border);
  padding-bottom: 1.25rem;
  margin-bottom: 0.25rem;
}

.skills-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
  padding: 0.75rem 0 0.25rem;
}

.skill-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.skill-card-name {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

.skill-card-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
  flex: 1;
}

.skill-run-btn { align-self: flex-start; margin-top: 0.5rem; }

.skill-result-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.skill-result-name {
  font-weight: 600;
  font-size: 0.9rem;
  flex: 1;
  color: var(--accent);
}

.skill-progress {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.25rem 0;
}

.skill-output {
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text);
}

.skill-output p { margin-bottom: 0.6rem; }
.skill-output ul, .skill-output ol { margin: 0.4rem 0 0.6rem 1.25rem; }
.skill-output li { margin-bottom: 0.25rem; }
.skill-output strong { color: var(--text); }

/* ── Global search panel ──────────────────────────────────────────────────── */

#global-search-panel {
  padding: 2rem;
  overflow-y: auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.gsearch-header h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  color: var(--text);
}

.gsearch-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

#gsearch-keyword {
  width: 100%;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 0.95rem;
  background: var(--card-bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}
#gsearch-keyword:focus { border-color: var(--accent); }
#gsearch-keyword::placeholder { color: var(--text-muted); }

.gsearch-dates-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.gsearch-dates-row label { font-size: 0.85rem; color: var(--text-muted); }
.gsearch-dates-row input[type="date"] {
  padding: 0.38rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 0.875rem;
  background: var(--card-bg);
  color: var(--text);
  outline: none;
}
.gsearch-dates-row input[type="date"]:focus { border-color: var(--accent); }

.gsearch-status { font-size: 0.85rem; color: var(--text-muted); }

.gsearch-results { display: flex; flex-direction: column; gap: 0.75rem; }

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

.gsearch-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.9rem;
  background: var(--accent-light);
  cursor: pointer;
}
.gsearch-group-header:hover { background: #ddd6f3; }
.gsearch-group-name { font-weight: 600; color: var(--accent); }
.gsearch-group-count {
  font-size: 0.75rem;
  background: var(--accent);
  color: #fff;
  border-radius: 99px;
  padding: 0.1rem 0.5rem;
}

.gsearch-msg {
  padding: 0.55rem 0.9rem;
  border-top: 1px solid var(--border);
  cursor: pointer;
}
.gsearch-msg:hover { background: var(--main-bg); }

.gsearch-msg-subject { font-size: 0.88rem; font-weight: 500; margin-bottom: 0.15rem; }
.gsearch-msg-meta {
  display: flex;
  gap: 0.75rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}
.gsearch-msg-preview {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gsearch-more {
  padding: 0.35rem 0.9rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  font-style: italic;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }
