/*
  Application Tracker styles.
  Keep this file focused on presentation: layout, spacing, colors, and responsive behavior.
*/

/* Design tokens and reset */
:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9e2ec;
  --soft: #eef3f8;
  --nav: #10233f;
  --blue: #2d6cdf;
  --blue-dark: #174ea6;
  --green: #1f7a4d;
  --red: #b42318;
  --amber: #9a6700;
  --violet: #6842a3;
  --shadow: 0 18px 48px rgba(31, 44, 71, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1722;
  --panel: #182231;
  --ink: #edf3fb;
  --muted: #a8b5c7;
  --line: #334155;
  --soft: #223044;
  --nav: #0b1525;
  --blue: #6aa4ff;
  --blue-dark: #9fc3ff;
  --green: #58c087;
  --red: #ff8a80;
  --amber: #f0b94f;
  --violet: #b898ff;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  line-height: 1.45;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.hidden {
  display: none !important;
}

.app {
  min-height: 100vh;
}

/* Top navigation, buttons, and dropdown menu */
.topbar {
  background: var(--nav);
  color: #fff;
  padding: 18px 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner,
main {
  width: min(1480px, 100%);
  margin: 0 auto;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.12;
  letter-spacing: 0;
  cursor: pointer;
}

.subtle {
  color: #c9d6e6;
  font-size: 13px;
  margin-top: 4px;
}

.top-actions,
.panel-actions,
.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  background: #e8eef8;
  color: var(--nav);
  font-weight: 750;
  white-space: nowrap;
}

.btn.primary {
  background: #6ee7d8;
  color: #062f2b;
}

.btn.danger {
  background: #fee4e2;
  color: var(--red);
}

.btn.ghost {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.notification-button {
  position: relative;
}

#opportunityWatchButton {
  position: relative;
}

.notification-count {
  min-width: 20px;
  min-height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 850;
}

.mobile-action-bar {
  display: none;
}

.menu-wrap {
  position: relative;
}

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  width: 210px;
  display: grid;
  gap: 4px;
  padding: 8px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.menu button,
.menu label {
  width: 100%;
  justify-content: flex-start;
  color: var(--ink);
  background: transparent;
  border-radius: 6px;
  padding: 9px 10px;
  font-weight: 700;
  font-size: 14px;
  min-height: 34px;
}

.menu label {
  display: flex;
  cursor: pointer;
}

main {
  padding: 18px 24px 36px;
  display: grid;
  gap: 16px;
}

.demo-banner {
  border: 1px solid color-mix(in srgb, var(--amber) 50%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--amber) 13%, var(--panel));
  color: var(--ink);
  padding: 12px 14px;
  font-weight: 700;
}

/* Dashboard filters, form controls, and summary stats */
.filters {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto 170px 170px 170px auto;
  gap: 10px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(45, 108, 223, 0.12);
}

label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.checkbox-line input {
  width: 18px;
  min-height: 18px;
  padding: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.stat,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(31, 44, 71, 0.04);
  scroll-margin-top: 92px;
}

.stat {
  padding: 12px;
}

.stat-label {
  color: var(--muted);
  display: block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.stat-value {
  display: block;
  margin-top: 4px;
  font-size: 23px;
  font-weight: 850;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-title {
  margin: 0;
  font-size: 18px;
}

.entries-toolbar,
.entries-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--soft) 42%, var(--panel));
}

.entries-pagination {
  border-top: 1px solid var(--line);
  border-bottom: 0;
}

.select-page-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.select-cell {
  width: 44px;
  text-align: center !important;
}

.select-cell input,
.select-page-control input {
  width: 18px;
  min-height: 18px;
  padding: 0;
}

.entries-page-status {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.notification-panel .empty {
  padding: 18px;
}

.notification-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.notification-group {
  display: grid;
  gap: 8px;
}

.notification-group-title {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.notification-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  background: color-mix(in srgb, var(--soft) 45%, var(--panel));
  color: var(--ink);
}

.notification-main {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--ink);
  text-align: left;
  background: transparent;
  padding: 0;
  font-weight: inherit;
}

.notification-item.read {
  opacity: 0.74;
}

.notification-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mini-btn {
  min-height: 30px;
  padding: 5px 8px;
  border-radius: 6px;
  background: var(--soft);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.notification-item.warning {
  border-left-color: var(--amber);
}

.notification-item.overdue {
  border-left-color: var(--red);
}

.notification-title {
  font-weight: 850;
}

.notification-meta {
  color: var(--muted);
  font-size: 12px;
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(11, 21, 37, 0.58);
}

.confirm-card {
  width: min(430px, 100%);
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.confirm-card h2,
.confirm-card p {
  margin: 0;
}

.confirm-card p {
  color: var(--muted);
}

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

/* Entry list and expanded application summary */
.entries-table th,
.entries-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
  min-width: 0;
}

.entries-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  background: var(--soft);
  white-space: nowrap;
}

.entries-table th:nth-child(2),
.entries-table td:nth-child(2) {
  width: 78px;
  min-width: 78px;
  max-width: 78px;
}

.entries-table th:nth-child(4),
.entries-table td:nth-child(4) {
  width: 140px;
  min-width: 120px;
  white-space: nowrap;
}

.entries-table th:nth-child(5),
.entries-table td:nth-child(5),
.entries-table th:nth-child(7),
.entries-table td:nth-child(7) {
  width: 130px;
  min-width: 118px;
  white-space: nowrap;
}

.entries-table th:nth-child(6),
.entries-table td:nth-child(6) {
  width: 150px;
  min-width: 128px;
}

.entry-row {
  cursor: pointer;
}

.entry-row:hover {
  background: color-mix(in srgb, var(--blue) 8%, transparent);
}

.entry-row.expanded {
  background: color-mix(in srgb, var(--blue) 12%, transparent);
}

.expand-cell {
  padding: 0 !important;
  background: var(--panel);
}

.entry-summary {
  display: grid;
  gap: 14px;
  padding: 16px;
  border-top: 1px solid var(--line);
  border-left: 4px solid var(--blue);
}

.summary-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.summary-title {
  margin: 0;
  font-size: 18px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.summary-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.summary-value {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.summary-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.summary-note {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.key {
  color: var(--blue-dark);
  display: inline-block;
  font-weight: 850;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: bottom;
  white-space: nowrap;
}

.job-name {
  font-weight: 820;
}

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

.badge {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  min-height: 26px;
  align-items: center;
  overflow: hidden;
  padding: 4px 9px;
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-not-started {
  background: #667085;
}

/* Status color mapping */
.status-not-submitted {
  background: #667085;
}

.status-submitted {
  background: var(--blue);
}

.status-interview {
  background: var(--violet);
}

.status-waiting {
  background: var(--amber);
}

.status-accepted {
  background: var(--green);
}

.status-rejected {
  background: var(--red);
}

.empty {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.section {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
}

/* Editor form sections and document rows */
.section-title {
  background: var(--soft);
  padding: 10px 12px;
  font-weight: 850;
}

.section-body {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.two-col,
.three-col {
  display: grid;
  gap: 12px;
}

.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.three-col {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.ai-box {
  display: grid;
  gap: 12px;
}

.utility-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  scroll-margin-top: 92px;
}

.ai-thread {
  display: grid;
  gap: 12px;
  max-height: min(58vh, 620px);
  min-height: 220px;
  overflow-y: auto;
  padding: 4px;
  scroll-behavior: smooth;
}

.ai-composer {
  display: grid;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.ai-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.ai-message {
  display: grid;
  gap: 6px;
}

.ai-role {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.ai-bubble {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ai-message.user .ai-bubble {
  background: color-mix(in srgb, #6ee7d8 16%, var(--panel));
  border-color: color-mix(in srgb, #6ee7d8 50%, var(--line));
}

.ai-output {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--soft) 45%, var(--panel));
  overflow-wrap: anywhere;
}

.ai-output > *:first-child {
  margin-top: 0;
}

.ai-output > *:last-child {
  margin-bottom: 0;
}

.ai-output h3,
.ai-output h4 {
  margin: 16px 0 8px;
  line-height: 1.25;
}

.ai-output p {
  margin: 0 0 12px;
}

.ai-output ul,
.ai-output ol {
  margin: 0 0 14px 22px;
  padding: 0;
}

.ai-output li {
  margin: 5px 0;
}

.ai-output code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.ai-output pre {
  overflow: auto;
  padding: 10px;
  border-radius: 6px;
  background: #111827;
  color: #f9fafb;
}

.ai-output blockquote {
  margin: 0 0 14px;
  padding-left: 12px;
  border-left: 3px solid var(--line);
  color: var(--muted);
}

.ai-settings {
  flex: 1 1 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel);
}

.ai-settings summary {
  cursor: pointer;
  color: var(--ink);
  font-weight: 850;
}

.ai-settings[open] summary {
  margin-bottom: 12px;
}

.status-picker {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.status-toggle {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 850;
  padding: 7px 8px;
}

.status-toggle.selected {
  color: #fff;
  background: var(--nav);
  border-color: var(--nav);
}

.form-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  scroll-margin-top: 92px;
}

.form-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  background: var(--soft);
}

.form-body {
  padding: 16px;
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.doc-list {
  display: grid;
  gap: 8px;
}

.doc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--soft) 45%, var(--panel));
}

.doc-row .panel-actions {
  flex: 0 0 auto;
}

.doc-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.status-date-fields.disabled input {
  background: var(--soft);
  color: var(--muted);
  pointer-events: none;
}

.saved {
  color: var(--muted);
  font-size: 12px;
}

/* Opportunity Watch keeps discovered listings separate from active applications. */
.opportunity-watch {
  overflow: hidden;
}

.opportunity-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px 0;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--soft) 55%, var(--panel));
  overflow-x: auto;
}

.opportunity-tab {
  min-height: 42px;
  padding: 8px 14px;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.opportunity-tab.selected {
  border-bottom-color: var(--blue);
  color: var(--ink);
}

.opportunity-view {
  min-width: 0;
}

.opportunity-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.opportunity-results {
  display: grid;
}

.opportunity-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(190px, 230px);
  gap: 18px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.opportunity-card:last-child {
  border-bottom: 0;
}

.opportunity-card-main {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 14px;
  min-width: 0;
}

.opportunity-score {
  align-self: start;
  display: grid;
  place-items: center;
  min-height: 68px;
  padding: 8px;
  border: 1px solid color-mix(in srgb, var(--green) 45%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--green) 12%, var(--panel));
  color: var(--green);
  font-size: 20px;
  font-weight: 900;
}

.opportunity-score span {
  font-size: 10px;
  text-transform: uppercase;
}

.opportunity-card h3 {
  margin: 3px 0 4px;
  overflow-wrap: anywhere;
}

.opportunity-card p {
  margin: 0;
}

.opportunity-card-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.opportunity-description {
  margin-top: 9px !important;
  color: var(--muted);
}

.opportunity-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
}

.opportunity-reasons span {
  padding: 4px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--green) 13%, var(--panel));
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
}

.opportunity-concern {
  margin-top: 9px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 700;
}

.opportunity-card-side {
  display: grid;
  align-content: start;
  gap: 4px;
  text-align: right;
}

.opportunity-card-side .panel-actions {
  display: grid;
  margin-top: 8px;
}

.opportunity-card-side .btn {
  width: 100%;
}

.opportunity-diagnostics {
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.opportunity-diagnostics summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 900;
}

.opportunity-diagnostic-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
}

.opportunity-diagnostic-reasons span {
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--soft);
  font-size: 11px;
  font-weight: 800;
}

.opportunity-diagnostic-list {
  display: grid;
  gap: 8px;
}

.opportunity-diagnostic-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 260px);
  gap: 12px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.opportunity-diagnostic-row strong,
.opportunity-diagnostic-row span,
.opportunity-diagnostic-row small {
  display: block;
  overflow-wrap: anywhere;
}

.opportunity-diagnostic-row small {
  color: var(--amber);
  font-weight: 800;
}

.opportunity-diagnostic-action {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.opportunity-refresh-report {
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.opportunity-refresh-report summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 900;
}

.opportunity-refresh-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.opportunity-refresh-row {
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--soft) 35%, var(--panel));
}

.opportunity-refresh-row strong,
.opportunity-refresh-row span {
  overflow-wrap: anywhere;
}

.opportunity-refresh-row.ok strong {
  color: var(--green);
}

.opportunity-refresh-row.warn strong {
  color: var(--amber);
}

.opportunity-settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
  gap: 14px;
}

.watch-profile-row {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
}

.watch-profile-row.active {
  border-left: 4px solid var(--blue);
  background: color-mix(in srgb, var(--blue) 8%, var(--panel));
}

.watch-profile-row span,
.watch-source-row small {
  color: var(--muted);
  font-size: 12px;
}

.source-pack-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.watch-source-list {
  display: grid;
  gap: 6px;
}

.watch-source-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: color-mix(in srgb, var(--soft) 35%, var(--panel));
}

.watch-source-row .checkbox-line {
  align-items: flex-start;
  min-width: 0;
}

.watch-source-row .checkbox-line span {
  display: grid;
  min-width: 0;
}

.watch-source-row strong,
.watch-source-row small {
  overflow-wrap: anywhere;
}

/* Responsive layout */
@media (max-width: 1100px) {
  .filters,
  .summary-grid,
  .summary-columns,
  .two-col,
  .three-col {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  body {
    font-size: 15px;
  }

  .app {
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }

  .topbar,
  main {
    padding-left: 12px;
    padding-right: 12px;
  }

  .topbar {
    padding-top: 12px;
    padding-bottom: 12px;
    position: static;
  }

  .panel,
  .form-panel,
  .utility-panel {
    scroll-margin-top: 12px;
  }

  main {
    gap: 12px;
    padding-top: 12px;
  }

  h1 {
    font-size: 22px;
  }

  .panel-head,
  .summary-head,
  .form-footer,
  .ai-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-actions,
  .form-actions {
    width: 100%;
    justify-content: stretch;
  }

  .top-actions {
    width: auto;
    display: flex;
    justify-content: flex-end;
  }

  #newEntry,
  #moreButton,
  #opportunityWatchButton {
    display: none;
  }

  #notificationsButton {
    display: inline-flex;
    min-height: 38px;
    flex: 0 0 auto;
    padding: 7px 10px;
  }

  .notification-button {
    position: relative;
  }

  .menu-wrap {
    position: static;
  }

  .menu {
    position: fixed;
    left: 12px;
    right: 12px;
    top: auto;
    bottom: calc(74px + env(safe-area-inset-bottom));
    width: auto;
    max-height: min(70vh, 360px);
    overflow-y: auto;
    padding: 10px;
  }

  .btn {
    flex: 1;
    min-height: 44px;
    min-width: 0;
    white-space: normal;
  }

  .filters {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 0;
  }

  input,
  select,
  textarea {
    min-height: 44px;
    font-size: 16px;
  }

  .stats,
  .status-picker {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mobile-action-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: color-mix(in srgb, var(--panel) 94%, transparent);
    box-shadow: 0 -10px 28px rgba(17, 24, 39, 0.12);
  }

  body[data-mode="edit"] .mobile-action-bar,
  body[data-mode="new"] .mobile-action-bar {
    display: none;
  }

  .mobile-action {
    min-height: 46px;
    border-radius: 8px;
    background: var(--soft);
    color: var(--ink);
    font-size: 13px;
    font-weight: 850;
  }

  .mobile-action.primary {
    background: #6ee7d8;
    color: #062f2b;
  }

  .stat {
    padding: 10px;
  }

  .stat-value {
    font-size: 22px;
  }

  .panel-head {
    padding: 12px;
  }

  .panel-title {
    font-size: 17px;
  }

  #dashboardHint {
    font-size: 12px;
  }

  .entries-table,
  .entries-table thead,
  .entries-table tbody,
  .entries-table tr,
  .entries-table td {
    display: block;
    width: 100%;
  }

  .entries-table thead {
    display: none;
  }

  .entries-table {
    border-collapse: separate;
    border-spacing: 0;
  }

  .entry-row {
    position: relative;
    display: grid;
    gap: 8px;
    margin: 10px 10px 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
  }

  .entry-row:hover {
    background: var(--panel);
  }

  .entry-row.expanded {
    border-color: var(--blue);
    background: color-mix(in srgb, var(--blue) 8%, var(--panel));
  }

  .entries-table td {
    display: grid;
    grid-template-columns: minmax(92px, 36%) minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    padding: 0;
    border-bottom: 0;
    white-space: normal;
  }

  .entries-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 850;
    text-transform: uppercase;
  }

  .entries-table .select-cell {
    position: absolute;
    top: 12px;
    right: 12px;
    width: auto;
    display: block;
    text-align: right !important;
  }

  .entries-table .select-cell::before {
    content: "";
  }

  .entry-row td:nth-child(2) {
    padding-right: 38px;
  }

  .entry-row td:nth-child(3) {
    grid-template-columns: 1fr;
    padding-right: 38px;
  }

  .entry-row td:nth-child(3)::before {
    display: none;
  }

  .entry-row td:nth-child(3) .job-name {
    font-size: 17px;
    line-height: 1.25;
  }

  .entry-row td:nth-child(7) {
    display: none;
  }

  .summary-row {
    display: block;
  }

  .expand-cell {
    display: block !important;
    padding: 0 !important;
  }

  .entry-summary {
    margin: 0 10px 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--blue);
    border-radius: 0 0 8px 8px;
  }

  .summary-title {
    font-size: 17px;
  }

  .entries-toolbar,
  .entries-pagination {
    align-items: stretch;
    flex-direction: column;
    padding: 10px;
  }

  .select-page-control {
    min-height: 38px;
  }

  .entries-page-status {
    margin-left: 0;
  }

  .entries-toolbar .entries-page-status {
    display: none;
  }

  .summary-grid,
  .summary-columns,
  .two-col,
  .three-col {
    grid-template-columns: 1fr;
  }

  .summary-note,
  .summary-card {
    padding: 10px;
  }

  .summary-head .panel-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-body {
    padding: 12px;
    gap: 12px;
  }

  .section-body {
    padding: 10px;
  }

  .status-picker {
    gap: 6px;
  }

  .status-toggle {
    min-height: 42px;
    padding: 7px;
  }

  .doc-row {
    align-items: stretch;
    flex-direction: column;
  }

  .doc-row .panel-actions {
    width: 100%;
  }

  .notification-item {
    grid-template-columns: 1fr;
  }

  .notification-actions {
    justify-content: stretch;
  }

  .mini-btn {
    flex: 1;
    min-height: 38px;
  }

  .confirm-card .panel-actions {
    width: 100%;
  }

  .ai-thread {
    max-height: 52vh;
    min-height: 180px;
  }

  .ai-settings {
    flex-basis: auto;
    width: 100%;
  }

  .ai-toolbar > .panel-actions {
    order: -1;
  }

  .opportunity-toolbar,
  .opportunity-card,
  .opportunity-card-main,
  .opportunity-settings-grid,
  .watch-source-row {
    grid-template-columns: 1fr;
  }

  .opportunity-toolbar,
  .watch-source-row {
    align-items: stretch;
    flex-direction: column;
  }

  .opportunity-card-main {
    display: grid;
  }

  .opportunity-score {
    min-height: 48px;
    grid-template-columns: auto auto;
    justify-content: start;
    gap: 5px;
  }

  .opportunity-card-side {
    text-align: left;
  }

  .opportunity-diagnostic-row {
    grid-template-columns: 1fr;
  }

  .opportunity-diagnostic-action {
    justify-items: start;
  }
}

@media (max-width: 430px) {
  .entries-table td {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .entries-table td::before {
    margin-top: 2px;
  }

  .entry-row td:nth-child(2),
  .entry-row td:nth-child(3) {
    padding-right: 34px;
  }

}

@media (max-width: 340px) {
  .stats,
  .status-picker,
  .summary-head .panel-actions {
    grid-template-columns: 1fr;
  }
}
