:root {
  --bg: #f2f7f7;
  --surface: #ffffff;
  --surface2: #e8f3f3;
  --border: #c5d9d9;
  --text: #1a2e2e;
  --muted: #5a7373;
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --accent-contrast: #ffffff;
  --success: #059669;
  --error: #dc2626;
  --mark: #0f766e;
  --shadow: 0 8px 24px rgba(15, 60, 60, 0.12);
  --shadow-lg: 0 20px 50px rgba(15, 60, 60, 0.16);

  /*
   * Header chrome tokens, mirrored from the extranet app so this header reads
   * as the same product. Source: extranet/main/src/app/globals.css (@theme) and
   * components/extranet-header.tsx + components/user-avatar.tsx.
   */
  --font-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
  --app-header-height: 3.5rem; /* extranet `h-14` */
  --app-chrome: linear-gradient(90deg, hsl(214 46% 12%), hsl(208 44% 14%) 55%, hsl(192 45% 16%));
  --header-bg: hsl(214 46% 12%);
  --header-foreground: hsl(0 0% 98%);
  --brand-teal-deep: hsl(175 84% 26%);
  --primary: var(--brand-teal-deep);
  --primary-foreground: hsl(0 0% 98%);
  --popover: hsl(0 0% 100%);
  --popover-foreground: hsl(240 10% 3.9%);
  --token-border: hsl(240 4.8% 93%);
  --muted-foreground: hsl(240 3.8% 40%);
  --token-accent: hsl(173 45% 94%);
  --token-accent-foreground: hsl(175 60% 18%);
  --destructive: hsl(0 84.2% 60.2%);
  --radius-lg: 0.5rem;
  --radius-md: calc(0.5rem - 2px);
  --radius-sm: calc(0.5rem - 4px);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  color-scheme: light;
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--app-header-height);
  flex-shrink: 0;
  padding: 0 1rem;
  background: var(--app-chrome);
  color: var(--header-foreground);
  font-family: var(--font-sans);
  gap: 0.75rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  min-width: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

header h1 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.app-branding {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.app-subtitle {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 400;
  color: currentColor;
  opacity: 0.7;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.menubar {
  display: flex;
  align-items: center;
}

.menu {
  position: relative;
}

.menu-btn {
  background: none;
  border: none;
  color: currentColor;
  font: inherit;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.menu-btn:hover,
.menu-btn[aria-expanded="true"] {
  background: rgb(255 255 255 / 0.12);
}

.menu-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 180px;
  background: var(--popover);
  color: var(--popover-foreground);
  border: 1px solid var(--token-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 0.25rem;
  z-index: 50;
}

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  padding: 0.375rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.menu-item:hover {
  background: var(--token-accent);
  color: var(--token-accent-foreground);
}

.stats {
  font-size: 0.8rem;
  color: currentColor;
  opacity: 0.75;
  white-space: nowrap;
}

.user-menu {
  position: relative;
  flex-shrink: 0;
}

/* Avatar + menu mirroring extranet's user-avatar.tsx (ring-2 ring-current/25
   trigger, bg-primary fallback, popover dropdown with accent-hover items). */
.avatar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: 9999px;
  outline: none;
  box-shadow: 0 0 0 2px rgb(255 255 255 / 0.25);
}

.avatar-btn:focus-visible {
  box-shadow:
    0 0 0 2px var(--header-bg),
    0 0 0 4px rgb(255 255 255 / 0.5);
}

.avatar-circle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  background: var(--primary);
  color: var(--primary-foreground);
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 500;
}

.avatar-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 18rem;
  max-width: calc(100vw - 2rem);
  background: var(--popover);
  color: var(--popover-foreground);
  font-family: var(--font-sans);
  border: 1px solid var(--token-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 0.25rem;
  z-index: 60;
}

.avatar-dropdown-header {
  padding: 0.375rem 0.5rem;
}

.avatar-dropdown-name {
  font-size: 0.875rem;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.avatar-dropdown-email,
.avatar-dropdown-principal {
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--muted-foreground);
  overflow-wrap: anywhere;
}

.avatar-dropdown-sep {
  height: 1px;
  margin: 0.25rem -0.25rem;
  background: var(--token-border);
}

.avatar-dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  padding: 0.375rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.avatar-dropdown-item:hover,
.avatar-dropdown-item:focus-visible {
  background: var(--token-accent);
  color: var(--token-accent-foreground);
  outline: none;
}

.avatar-dropdown-item.sign-out {
  color: var(--destructive);
}

.avatar-dropdown-item.sign-out:hover,
.avatar-dropdown-item.sign-out:focus-visible {
  background: hsl(0 84.2% 60.2% / 0.1);
  color: var(--destructive);
}

.notice-screen {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.5rem;
  text-align: center;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--popover-foreground);
}

.notice-screen .notice-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.notice-screen button {
  background: var(--primary);
  color: var(--primary-foreground);
  border: none;
  border-radius: var(--radius-md);
  padding: 0.5rem 1.25rem;
  font: inherit;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  cursor: pointer;
}

.notice-screen button:hover {
  filter: brightness(1.08);
}

main {
  display: grid;
  grid-template-columns: 300px 220px minmax(0, 1fr);
  height: calc(100vh - var(--app-header-height));
}

.panel {
  border-right: 1px solid var(--border);
  overflow: hidden;
  min-height: 0;
}

.criteria-panel,
.results-panel,
.detail-panel {
  display: flex;
  flex-direction: column;
}

.criteria-body {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.results-panel .message-list {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.results-panel .pagination {
  flex-shrink: 0;
}

.detail-panel .detail {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.panel:last-child {
  border-right: none;
}

.panel-header {
  padding: 0.75rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 1;
}

.job-status {
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-sm);
  background: rgb(255 255 255 / 0.12);
  font-size: 0.78rem;
  display: none;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-status.visible {
  display: block;
}

.job-status.running {
  border-left: 3px solid var(--accent);
}

.job-status.done {
  border-left: 3px solid var(--success);
}

.job-status.error {
  border-left: 3px solid var(--error);
}

.message-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.message-item {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.message-output {
  flex-shrink: 0;
  padding-top: 0.15rem;
  cursor: pointer;
}

.message-output input[type="checkbox"] {
  accent-color: var(--accent);
  width: 0.9rem;
  height: 0.9rem;
  cursor: pointer;
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-item.active {
  background: var(--surface2);
  border-left: 3px solid var(--accent);
  padding-left: calc(0.65rem - 3px);
}

.message-item:hover {
  background: var(--surface2);
}

.message-subject {
  font-weight: 500;
  font-size: 0.8rem;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.search-bar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.search-bar input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.5rem 0.75rem;
  font: inherit;
}

.search-bar input:focus {
  outline: none;
  border-color: var(--accent);
}

.search-bar button {
  width: 100%;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font: inherit;
  cursor: pointer;
}

.search-bar button:hover {
  background: var(--accent-hover);
}

.filter-bar {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.filter-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.filter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.filter-actions button {
  flex: 1 1 auto;
  min-width: 0;
}

.filter-bar label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  min-width: 0;
}

.filter-bar input[type="date"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.45rem 0.5rem;
  font: inherit;
  font-size: 0.8rem;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
}

.filter-bar input[type="date"]:focus {
  outline: none;
  border-color: var(--accent);
}

.filter-bar button {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 6px;
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

.filter-bar button:hover {
  background: var(--accent-hover);
}

.filter-bar button.secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.filter-bar button.secondary:hover {
  border-color: var(--accent);
}

.analytics {
  padding: 0.75rem 1rem 1rem;
  background: var(--surface);
  font-size: 0.82rem;
  color: var(--muted);
}

.analytics-empty {
  color: var(--muted);
}

.analytics-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.analytics-stat strong {
  display: block;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 500;
  margin-top: 0.15rem;
}

.analytics-section h4 {
  margin: 0 0 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.analytics-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.5rem;
}

.analytics-tag {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  font-size: 0.78rem;
  color: var(--text);
}

.analytics-tag span {
  color: var(--muted);
}

.detail {
  padding: 1rem;
}

.detail h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  line-height: 1.4;
}

.detail-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
  line-height: 1.6;
}

.detail-meta strong {
  color: var(--text);
}

.detail-body {
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.attachments {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.attachments h3 {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.attachments a {
  display: block;
  color: var(--accent);
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
  text-decoration: none;
}

.attachments a:hover {
  text-decoration: underline;
}

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

mark {
  background: rgba(13, 148, 136, 0.18);
  color: var(--mark);
  padding: 0 2px;
  border-radius: 2px;
}

.pagination {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.5rem 0.65rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--surface);
}

.pagination-nav {
  display: flex;
  justify-content: space-between;
  gap: 0.35rem;
}

.pagination button {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 4px;
  padding: 0.25rem 0.4rem;
  cursor: pointer;
  font: inherit;
  font-size: 0.72rem;
}

#page-info {
  text-align: center;
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 46, 46, 0.35);
}

.modal-dialog {
  position: relative;
  width: min(560px, 100%);
  max-height: min(80vh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.modal-close:hover {
  color: var(--text);
}

.modal-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-search {
  flex: 1;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.45rem 0.6rem;
  font: inherit;
  font-size: 0.85rem;
}

.modal-search:focus {
  outline: none;
  border-color: var(--accent);
}

.participant-list {
  overflow: auto;
  padding: 0.5rem 1rem;
  flex: 1;
  min-height: 200px;
}

.participant-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.25rem;
  font-size: 0.85rem;
}

.participant-row:hover {
  background: var(--surface2);
  border-radius: 4px;
}

.participant-row input[type="checkbox"] {
  accent-color: var(--accent);
  flex-shrink: 0;
}

.participant-info {
  flex: 1;
  min-width: 0;
}

.participant-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.participant-email {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.participant-count {
  color: var(--muted);
  font-size: 0.78rem;
  flex-shrink: 0;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover {
  text-decoration: underline;
}

.folder-tree {
  overflow: auto;
  padding: 0.75rem 1rem;
  flex: 1;
  min-height: 200px;
}

.folder-tree-node {
  user-select: none;
}

.folder-tree-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0;
  font-size: 0.85rem;
}

.folder-tree-row:hover {
  background: var(--surface2);
  border-radius: 4px;
}

.folder-tree-toggle {
  width: 1rem;
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  font-size: 0.7rem;
  line-height: 1;
}

.folder-tree-toggle.hidden-toggle {
  visibility: hidden;
}

.folder-tree-row input[type="checkbox"] {
  accent-color: var(--accent);
  flex-shrink: 0;
}

.folder-tree-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-tree-count {
  color: var(--muted);
  font-size: 0.78rem;
  flex-shrink: 0;
}

.folder-tree-children {
  margin-left: 1.25rem;
}

.folder-tree-children.collapsed {
  display: none;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1.25rem;
  border-top: 1px solid var(--border);
}

.modal-footer button {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font: inherit;
  cursor: pointer;
}

.modal-footer button.secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.modal-footer button:hover {
  filter: brightness(1.08);
}
