/* ============================================================
   CSS Custom Properties
   ============================================================ */
:root {
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --surface-2:    #f8fafc;
  --border:       #e2e8f0;
  --text:         #0f172a;
  --text-muted:   #64748b;
  --accent:       #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff6ff;
  --danger:       #dc2626;
  --danger-light: #fef2f2;
  --success:      #16a34a;
  --success-light:#f0fdf4;
  --warn:         #d97706;
  --warn-light:   #fffbeb;
  --radius:       0.5rem;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:    0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
  --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --header-h:     56px;
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   Layout
   ============================================================ */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

.container-narrow {
  max-width: 680px;
}

/* ============================================================
   Header / Nav
   ============================================================ */
.impersonation-banner {
  background: #fef3c7;
  border-bottom: 1px solid #f59e0b;
  color: #92400e;
  font-size: .8rem;
  padding: .4rem 1rem;
  text-align: center;
}

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.app-logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.app-nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}

.nav-link {
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.9rem;
  text-decoration: none;
}

.nav-link:hover { background: var(--bg); color: var(--text); text-decoration: none; }

.app-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.user-email {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
  line-height: 1.4;
}

.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); text-decoration: none; color: #fff; }

.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--bg); text-decoration: none; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); text-decoration: none; }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; text-decoration: none; color: #fff; }

.btn-sm { padding: 0.25rem 0.625rem; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 0.25rem;
  line-height: 1;
}
.btn-icon:hover { color: var(--danger); }
.btn-icon-danger { font-size: 0.75rem; color: var(--text-muted); }
.btn-icon-danger:hover { color: var(--danger); }

/* ============================================================
   Forms
   ============================================================ */
.form-group { display: flex; flex-direction: column; gap: 0.375rem; margin-bottom: 1.25rem; }

label { font-size: 0.875rem; font-weight: 500; color: var(--text); }

.form-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}
.form-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }

.form-input-sm { padding: 0.3rem 0.5rem; font-size: 0.8rem; }

.form-select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  appearance: auto;
}
.form-select:focus { outline: none; border-color: var(--accent); }
.form-select-sm { padding: 0.3rem 0.5rem; font-size: 0.8rem; }

.form-file {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.form-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }

.form-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

.inline-form { display: flex; gap: 0.5rem; align-items: center; }

.required { color: var(--danger); }
.optional { color: var(--text-muted); font-weight: normal; font-size: .8rem; }

/* ============================================================
   Quill editor
   ============================================================ */
.quill-editor {
  min-height: 160px;
  background: var(--surface);
  border-radius: 0 0 var(--radius) var(--radius);
  font-family: var(--font);
}

.ql-toolbar.ql-snow {
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}

.ql-container.ql-snow {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  font-family: var(--font);
  font-size: 0.9rem;
}

.ql-editor { min-height: 140px; }

/* ============================================================
   Alerts
   ============================================================ */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #fca5a5; }
.alert-info  { background: var(--accent-light); color: var(--accent); border: 1px solid #bfdbfe; }

/* ============================================================
   Badges
   ============================================================ */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.badge-priority-low    { background: transparent; color: #15803d; border: 1px solid currentColor; }
.badge-priority-medium { background: transparent; color: #a16207; border: 1px solid currentColor; }
.badge-priority-high   { background: transparent; color: #c2410c; border: 1px solid currentColor; }
.badge-priority-urgent { background: transparent; color: #b91c1c; border: 1px solid currentColor; }

.badge-status-open      { background: transparent; color: var(--accent);      border: 1px solid currentColor; }
.badge-status-pending   { background: transparent; color: var(--warn);        border: 1px solid currentColor; }
.badge-status-on_hold   { background: transparent; color: var(--text-muted);  border: 1px solid currentColor; }
.badge-status-completed { background: transparent; color: var(--success);     border: 1px solid currentColor; }
.badge-status-cancelled { background: transparent; color: var(--danger);      border: 1px solid currentColor; }

/* ============================================================
   Pill button groups — status / priority selectors
   ============================================================ */
.pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.1rem;
}

.pill-btn {
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  border: 1.5px solid;
  background: transparent;
  transition: background .12s, color .12s;
  white-space: nowrap;
  line-height: 1.5;
}

/* Status pills */
.pill-btn.pill-status-open      { border-color: #d97706; color: #d97706; }
.pill-btn.pill-status-pending   { border-color: #2563eb; color: #2563eb; }
.pill-btn.pill-status-on_hold   { border-color: #6b7280; color: #6b7280; }
.pill-btn.pill-status-completed { border-color: #16a34a; color: #16a34a; }
.pill-btn.pill-status-cancelled { border-color: #dc2626; color: #dc2626; }

.pill-btn.pill-status-open.pill-active      { background: #d97706; color: #fff; }
.pill-btn.pill-status-pending.pill-active   { background: #2563eb; color: #fff; }
.pill-btn.pill-status-on_hold.pill-active   { background: #6b7280; color: #fff; }
.pill-btn.pill-status-completed.pill-active { background: #16a34a; color: #fff; }
.pill-btn.pill-status-cancelled.pill-active { background: #dc2626; color: #fff; }

/* Priority pills */
.pill-btn.pill-priority-urgent { border-color: #dc2626; color: #dc2626; }
.pill-btn.pill-priority-high   { border-color: #ea580c; color: #ea580c; }
.pill-btn.pill-priority-medium { border-color: #2563eb; color: #2563eb; }
.pill-btn.pill-priority-low    { border-color: #6b7280; color: #6b7280; }

.pill-btn.pill-priority-urgent.pill-active { background: #dc2626; color: #fff; }
.pill-btn.pill-priority-high.pill-active   { background: #ea580c; color: #fff; }
.pill-btn.pill-priority-medium.pill-active { background: #2563eb; color: #fff; }
.pill-btn.pill-priority-low.pill-active    { background: #6b7280; color: #fff; }

/* Flat solid-colour dots used in filter tabs (replaces shaded emoji circles) */
.flat-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  vertical-align: middle;
  margin-bottom: 1px;
  flex-shrink: 0;
}
.flat-dot-open      { background: #fbbf24; }
.flat-dot-pending   { background: #3b82f6; }
.flat-dot-on_hold   { background: #6b7280; }
.flat-dot-completed { background: #16a34a; }
.flat-dot-cancelled { background: #dc2626; }

.badge-role  { background: #f1f5f9; color: var(--text-muted); font-size: .68rem; }
.badge-email { background: #e0e7ff; color: #4338ca; font-size: .68rem; }

/* ============================================================
   Ticket list
   ============================================================ */
.page-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  flex: 1;
}

/* Filter bar */
.filter-bar {
  margin-bottom: 1rem;
}

.filter-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.filter-tab {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  font-family: var(--font);
  transition: background .1s, color .1s;
}
.filter-tab:hover  { background: var(--bg); color: var(--text); }
.filter-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.filter-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.filter-controls .form-select { width: auto; font-size: .8rem; padding: 0.3rem 0.5rem; }
.search-wrap { flex: 1; min-width: 140px; position: relative; }
.search-wrap .form-input { width: 100%; padding-right: 1.75rem; }
.search-clear {
  position: absolute; right: .4rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 1rem; line-height: 1;
  color: var(--text-muted); padding: 0 .15rem;
}
.search-clear:hover { color: var(--text); }

/* Ticket list column headers */
.ticket-list-header {
  display: flex;
  align-items: center;
  padding-bottom: 0.375rem;
  border-bottom: 2px solid var(--border);
  margin-bottom: 0.375rem;
}

.tlh-inner {
  display: grid;
  grid-template-columns: 64px 140px 1fr 140px 80px;
  grid-template-areas: "num creator subject org updated";
  align-items: center;
  gap: 0.625rem;
  padding: 0 1rem 0 calc(1rem + 4px); /* +4px aligns with card content past border-left */
  flex: 1;
  min-width: 0;
}

.tlh-col {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.tlh-sort-btn {
  background: none;
  border: none;
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  text-align: left;
  white-space: nowrap;
}
.tlh-sort-btn:hover { color: var(--accent); }
.tlh-sort-btn.tlh-active { color: var(--text); }

.tlh-checkbox-spacer { width: 3.5rem; flex-shrink: 0; }

/* Ticket cards */
.ticket-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Floating bulk action bar */
.bulk-bar {
  display: none;
  position: fixed;
  top: calc(var(--header-h) + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
}

.bulk-bar.bulk-bar-visible { display: flex; }

.bulk-count {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
}

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

/* Scroll-to-top button */
.scroll-top-btn {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 150;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: background .15s, color .15s;
  line-height: 1;
}
.scroll-top-btn:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.scroll-top-btn.visible { display: flex; align-items: center; justify-content: center; }

.ticket-card {
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid transparent;
  border-radius: var(--radius);
  overflow: hidden;
  transition: box-shadow .15s;
}
.ticket-card:hover { box-shadow: var(--shadow-md); }

/* Single-row grid inside the card link */
.ticket-card-link {
  display: grid;
  grid-template-columns: 64px 140px 1fr 140px 80px;
  grid-template-areas: "num creator subject org updated";
  align-items: center;
  gap: 0.625rem;
  padding: 0.6rem 1rem;
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  overflow: hidden;
}
.ticket-card-link:hover { text-decoration: none; }

/* Grid cell classes */
.tc-num {
  grid-area: num;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

/* Priority dot — colored circle encoding ticket priority */
.priority-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  cursor: help;
}
.priority-dot-low    { background: #9ca3af; }
.priority-dot-medium { background: #3b82f6; }
.priority-dot-high   { background: #f97316; }
.priority-dot-urgent { background: #ef4444; animation: urgent-pulse 1s ease-in-out infinite; }

@keyframes urgent-pulse {
  0%, 100% { background: #ef4444; }
  50%       { background: #fca5a5; }
}
@keyframes spin { to { transform: rotate(360deg); } }

.tc-creator {
  grid-area: creator;
  font-size: 0.8rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tc-subject {
  grid-area: subject;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ticket-card .tc-subject {
  font-size: 0.9rem;
  font-weight: 500;
}

.tc-org {
  grid-area: org;
  font-size: 0.78rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tc-updated {
  grid-area: updated;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  text-align: right;
  cursor: default;
}

/* Checkbox column on the right */
.ticket-card-checkbox {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 1rem;
  border-left: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  flex-shrink: 0;
}
.ticket-card-checkbox:hover { background: var(--accent-light); }

.ticket-checkbox {
  width: 1.25rem;
  height: 1.25rem;
  cursor: pointer;
  accent-color: var(--accent);
}

/* Left border = ticket status */
.ticket-card.status-open      { border-left-color: #fbbf24; }
.ticket-card.status-pending   { border-left-color: #3b82f6; }
.ticket-card.status-on_hold   { border-left-color: #6b7280; }
.ticket-card.status-completed { border-left-color: #16a34a; }
.ticket-card.status-cancelled { border-left-color: #d1d5db; opacity: 0.65; }

.ticket-card-left {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  align-items: flex-start;
  min-width: 90px;
}

.ticket-num { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }

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

.ticket-subject {
  font-weight: 500;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.25rem;
}

.ticket-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.meta-item { white-space: nowrap; }
.overdue { color: var(--danger); font-weight: 500; }

/* CSS tooltip — reveals email address when hovering a name in the ticket list */
.name-tip {
  position: relative;
  cursor: default;
}
.name-tip::after {
  content: attr(data-email);
  position: absolute;
  bottom: calc(100% + 5px);
  left: 0;
  background: #1e293b;
  color: #f8fafc;
  padding: 0.2rem 0.5rem;
  border-radius: 0.3rem;
  font-size: 0.72rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 50;
}
.name-tip:hover::after { opacity: 1; }

.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* ============================================================
   Ticket detail
   ============================================================ */
.ticket-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.ticket-header-top {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.ticket-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.ticket-layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 1rem;
  align-items: start;
}

.ticket-main {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.ticket-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  min-height: 80px;
  overflow-x: auto;
}

/* Quill editor input widget padding */
.ql-container .ql-editor { padding: 8px 12px !important; }

/* Rich content display — used for stored ticket/comment HTML, no Quill classes */
.rich-content {
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  font-size: 0.9rem;
}
.rich-content p { margin: 0 0 0.6em; }
.rich-content p:last-child { margin-bottom: 0; }
.rich-content ul, .rich-content ol { padding-left: 1.5em; margin: 0 0 0.6em; }
.rich-content li { margin-bottom: 0.15em; }
.rich-content h1, .rich-content h2, .rich-content h3 { margin: 0.75em 0 0.4em; font-weight: 600; line-height: 1.3; }
.rich-content h1 { font-size: 1.25em; }
.rich-content h2 { font-size: 1.1em; }
.rich-content h3 { font-size: 1em; }
.rich-content blockquote {
  border-left: 3px solid var(--border);
  padding-left: 0.9em;
  color: var(--text-muted);
  margin: 0.5em 0;
}
.rich-content pre {
  background: var(--bg);
  padding: 0.6em 0.9em;
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 0.85em;
  white-space: pre-wrap;
}
.rich-content code { font-size: 0.85em; background: var(--bg); padding: 0.1em 0.35em; border-radius: 3px; }
.rich-content pre code { background: none; padding: 0; }
.rich-content a { color: var(--accent); }
.rich-content img { max-width: 100%; height: auto; border-radius: var(--radius); }
.rich-content strong, .rich-content b { font-weight: 600; }
.rich-content em, .rich-content i { font-style: italic; }
.rich-content del, .rich-content s { text-decoration: line-through; }

/* Compact auto-expanding comment editor */
.quill-compact { min-height: 0 !important; }
.quill-compact .ql-editor {
  height: auto !important;
  min-height: 3.5em !important;
  max-height: 50vh !important;
  overflow-y: auto !important;
}

/* Comments */
.comments-section { display: flex; flex-direction: column; gap: 0.75rem; }

.section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.comment {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.comment-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.625rem;
  flex-wrap: wrap;
}

.comment-author { font-weight: 500; font-size: 0.875rem; line-height: 1.3; }
.comment-author-sub { display: block; font-size: 0.72rem; color: var(--text-muted); font-weight: 400; }
.comment-time   { font-size: 0.78rem; color: var(--text-muted); margin-left: auto; }
.comment-body   { font-size: 0.9rem; }

.comment-form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

/* Attachments */
.attachments-section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.attachment-list { list-style: none; display: flex; flex-direction: column; gap: 0.25rem; margin-top: 0.5rem; }
.attachment-link { font-size: 0.875rem; }

/* Sidebar */
.ticket-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: sticky;
  top: calc(var(--header-h) + 1rem);
}

.sidebar-section {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-section:last-child { border-bottom: none; }

.sidebar-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* Parties */
.party-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }

.party-item {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.85rem;
}

.party-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.party-name {
  display: block;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
}

.party-email-link {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}
.party-email-link:hover { color: var(--accent); text-decoration: underline; }

.add-party-details { margin-top: 0.75rem; }
.add-party-details summary { font-size: 0.8rem; cursor: pointer; color: var(--accent); list-style: none; }
.add-party-details summary::-webkit-details-marker { display: none; }

.add-party-form {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-top: 0.5rem;
}

.link-btn { color: var(--accent); cursor: pointer; font-size: 0.85rem; background: none; border: none; font-family: var(--font); }

/* ============================================================
   Admin tables
   ============================================================ */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.875rem;
}

.data-table th {
  text-align: left;
  padding: 0.75rem 1rem;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table .row-blocked td { color: var(--text-muted); opacity: 0.6; }
.actions-cell { display: flex; gap: 0.25rem; }

/* ============================================================
   Auth pages
   ============================================================ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--bg);
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 2);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
}

.auth-logo    { text-align: center; font-size: 1.5rem; font-weight: 700; margin-bottom: 1.5rem; }
.auth-title   { font-size: 1.3rem; font-weight: 700; text-align: center; margin-bottom: 0.5rem; }
.auth-subtitle { font-size: 0.875rem; color: var(--text-muted); text-align: center; margin-bottom: 1.5rem; }
.auth-form    { display: flex; flex-direction: column; gap: 0; }

.otp-input {
  text-align: center;
  font-size: 1.75rem;
  letter-spacing: 0.2em;
  font-weight: 700;
}

.link-muted { color: var(--text-muted); font-size: 0.875rem; }
.link-muted:hover { color: var(--text); }

/* ============================================================
   Card
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

/* Ticket form */
.ticket-form { display: flex; flex-direction: column; gap: 0; }

/* ============================================================
   <dialog> modal
   ============================================================ */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 0;
  width: 520px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  margin: auto;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
dialog::backdrop { background: rgba(0,0,0,.45); }

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.dialog-header h2 { font-size: 1rem; font-weight: 600; margin: 0; }

.dialog-body { padding: 1.25rem; }
.dialog-body .form-group { margin-bottom: 1rem; }

.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle, #f9fafb);
}

.dialog-section-divider {
  margin: 1rem 0;
  border: none;
  border-top: 1px solid var(--border);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 700px) {
  .ticket-layout {
    grid-template-columns: 1fr;
  }

  /* Move sidebar above comments on mobile, disable sticky */
  .ticket-sidebar { order: -1; position: static; }

  /* 2-row card layout on mobile */
  .ticket-card-link {
    grid-template-columns: auto 1fr auto;
    grid-template-areas:
      "num creator updated"
      "subject subject org";
    gap: 0.2rem 0.5rem;
    padding: 0.625rem 0.75rem;
  }
  .tc-subject { font-size: 0.85rem; }
  .tc-org     { font-size: 0.72rem; }
  .tc-updated { font-size: 0.72rem; text-align: right; }

  .ticket-list-header { display: none; }
  .filter-controls { flex-direction: column; align-items: stretch; }
  .search-wrap { min-width: unset; }

  .form-row { flex-direction: column; gap: 0; }

  .app-header-inner { gap: 0.75rem; }
  .user-email { display: none; }

  .auth-card { padding: 1.5rem; }
  .page-toolbar { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .app-logo { font-size: 1rem; }
  .page-title { font-size: 1.2rem; }
}
