:root {
  --brand-primary: #81272b;
  --brand-red: #a11e22;
  --brand-accent: #a03035;
  --brand-orange: #ff7607;
  --brand-blue: #066aab;
  --text-dark: #0a0a0a;
  --text-muted: #666666;
  --bg: #ffffff;
  --bg-soft: #f7f5f5;
  --border: #e2dede;
  --success: #1f7a3f;
  --error: #a11e22;
  --shadow: 0 1px 3px rgba(10, 10, 10, 0.08);
  --radius: 6px;
  --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--text-dark);
  background: var(--bg-soft);
  min-height: 100%;
}

a {
  color: var(--brand-primary);
  text-decoration: none;
}

a:hover {
  color: var(--brand-red);
}

.topbar {
  background: var(--bg);
  border-bottom: 3px solid var(--brand-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-link {
  display: flex;
  flex-direction: column;
  color: inherit;
  text-decoration: none;
}

.brand-name {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--brand-primary);
  letter-spacing: 0.02em;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
}

.nav a {
  color: var(--text-dark);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
}

.nav a.active,
.nav a:hover {
  color: var(--brand-red);
  border-bottom-color: var(--brand-red);
}

.user-chip {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: right;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-left: auto;
}

.btn-hard-refresh {
  background: var(--brand-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.4rem 0.75rem;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-hard-refresh:hover {
  background: var(--brand-red);
}

.company-logo {
  height: 46px;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  display: block;
}

.login-logo {
  display: block;
  height: 56px;
  width: auto;
  margin: 0 auto 0.85rem;
  object-fit: contain;
}

.container {
  width: min(1100px, calc(100% - 2rem));
  margin: 1.25rem auto 2rem;
}

.page-title {
  margin: 0 0 0.35rem;
  font-size: 1.5rem;
}

.page-sub {
  margin: 0 0 1.25rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

.card h2 {
  margin: 0 0 0.85rem;
  font-size: 1.1rem;
  color: var(--brand-primary);
}

.flash-wrap {
  margin-bottom: 1rem;
}

.flash {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.flash.success {
  background: #e8f6ec;
  color: var(--success);
  border: 1px solid #b7dfc3;
}

.flash.error {
  background: #fceaea;
  color: var(--error);
  border: 1px solid #efc0c2;
}

.btn {
  display: inline-block;
  border: none;
  border-radius: var(--radius);
  padding: 0.55rem 1rem;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.92rem;
  background: var(--brand-primary);
  color: #fff;
}

.btn:hover {
  background: var(--brand-red);
  color: #fff;
}

.btn-secondary {
  background: #fff;
  color: var(--brand-primary);
  border: 1px solid var(--brand-primary);
}

.btn-secondary:hover {
  background: var(--bg-soft);
  color: var(--brand-red);
}

.btn-small {
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.form-grid .full {
  grid-column: 1 / -1;
}

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.65rem;
  font: inherit;
  background: #fff;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(129, 39, 43, 0.25);
  border-color: var(--brand-primary);
}

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

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}

th,
td {
  text-align: left;
  padding: 0.65rem 0.55rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
  font-size: 0.92rem;
}

th {
  background: #f3ecec;
  color: var(--text-dark);
  font-weight: 700;
  white-space: nowrap;
}

tr:hover td {
  background: #faf7f7;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-on {
  background: #e8f6ec;
  color: var(--success);
}

.badge-off {
  background: #fceaea;
  color: var(--error);
}

.inline-form {
  display: grid;
  gap: 0.4rem;
}

.inline-form .row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.35rem;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
  background:
    linear-gradient(180deg, rgba(129, 39, 43, 0.08), rgba(255, 255, 255, 0.9)),
    var(--bg-soft);
}

.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--border);
  border-top: 4px solid var(--brand-primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.login-card h1 {
  margin: 0 0 0.25rem;
  color: var(--brand-primary);
}

.login-card p {
  margin: 0 0 1.1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-card .field {
  margin-bottom: 0.85rem;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.85rem;
}

.home-tile {
  display: block;
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand-primary);
  border-radius: var(--radius);
  padding: 1rem;
  color: inherit;
  box-shadow: var(--shadow);
}

.home-tile strong {
  display: block;
  margin-bottom: 0.25rem;
  color: var(--brand-primary);
}

.home-tile span {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.menu-toggle {
  display: none;
  background: var(--brand-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.45rem 0.7rem;
  font-weight: 700;
}

@media (max-width: 800px) {
  .topbar {
    flex-wrap: wrap;
  }

  .menu-toggle {
    display: inline-block;
    margin-left: auto;
  }

  .nav {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: flex-start;
  }

  .nav.open {
    display: flex;
  }

  .user-chip {
    width: 100%;
    text-align: left;
  }

  .topbar-right {
    width: 100%;
    justify-content: space-between;
    margin-left: 0;
  }

  .company-logo {
    height: 40px;
  }

  .form-grid,
  .inline-form .row {
    grid-template-columns: 1fr;
  }

  table {
    min-width: 560px;
  }
}

.actions-bar {
  margin-bottom: 1rem;
}

.muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.count-pill {
  display: inline-block;
  background: var(--brand-primary);
  color: #fff;
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  font-size: 0.75rem;
  margin-left: 0.35rem;
  vertical-align: middle;
}

.count-pill.soft {
  background: #f3ecec;
  color: var(--brand-primary);
}

.status-block {
  margin-top: 0.85rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.status-block h3 {
  margin: 0 0 0.45rem;
  font-size: 0.98rem;
  color: var(--text-dark);
}

.reminder-card {
  border-left: 4px solid var(--brand-orange);
}

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

.reminder-list li {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}

.inline-done {
  display: inline-block;
  margin-left: 0.5rem;
}

.lead-layout {
  display: grid;
  gap: 1rem;
}

.kv-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.kv-list .full {
  grid-column: 1 / -1;
}

.kv-list span {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.kv-list strong.pre {
  white-space: pre-wrap;
  font-weight: 500;
}

.spec-cell {
  max-width: 14rem;
  white-space: normal;
  font-size: 0.9em;
  color: #444;
}

.attach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}

.attach-item {
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.4rem;
  color: inherit;
  background: #fff;
}

.attach-item img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  border-radius: 4px;
  display: block;
}

.file-chip {
  display: block;
  padding: 1.2rem 0.4rem;
  text-align: center;
  font-weight: 600;
  color: var(--brand-primary);
  word-break: break-word;
}

.attach-item small {
  display: block;
  margin-top: 0.35rem;
  color: var(--text-muted);
  font-size: 0.72rem;
}

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

.timeline li {
  padding: 0.65rem 0 0.65rem 0.85rem;
  border-left: 3px solid var(--brand-primary);
  margin-bottom: 0.55rem;
}

.timeline-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.timeline-body {
  white-space: pre-wrap;
}

@media (max-width: 800px) {
  .kv-list {
    grid-template-columns: 1fr;
  }
}

.corr-title {
  margin: 1.25rem 0 0.75rem;
  font-size: 1rem;
  color: var(--brand-primary);
}

.email-thread {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.email-bubble {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  background: #fff;
}

.email-bubble.out {
  border-left: 4px solid var(--brand-primary);
  background: #faf6f6;
}

.email-bubble.in {
  border-left: 4px solid var(--brand-blue);
  background: #f5f9fc;
}

.email-bubble.needs-action {
  border-color: #c45c12;
  box-shadow: 0 0 0 2px rgba(255, 118, 7, 0.25);
}

.email-action-box {
  margin-top: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.email-action-box.pending {
  background: #fff6eb;
  border-color: #ff7607;
}

.email-action-box.done {
  background: #f3f8f3;
  border-color: #8cba8c;
}

.email-action-box .action-missing {
  color: #81272b;
  margin: 0 0 0.5rem;
}

.email-action-box .action-recorded {
  margin: 0 0 0.5rem;
}

.email-action-form {
  margin-top: 0.35rem;
}

.email-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
}

.email-headers {
  font-size: 0.88rem;
  margin-bottom: 0.55rem;
}

.email-headers span {
  display: inline-block;
  min-width: 3.5rem;
  color: var(--text-muted);
  font-weight: 600;
}

.email-body {
  white-space: pre-wrap;
  font-size: 0.92rem;
}

.email-body.pre {
  white-space: pre-wrap;
}

.btn-danger {
  background: var(--brand-red);
  color: #fff;
  border: none;
}

.btn-danger:hover {
  background: #7f171a;
  color: #fff;
}

.filter-bar {
  display: grid;
  grid-template-columns: 2fr 1.2fr auto;
  gap: 0.75rem;
  align-items: end;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.month-block {
  margin-top: 0.75rem;
}

.month-heading {
  margin: 0.35rem 0 0.5rem;
  font-size: 1.05rem;
  color: var(--brand-primary);
}

.status-block h4 {
  margin: 0.4rem 0;
  font-size: 0.92rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
}

.stat-box {
  background: #faf6f6;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  text-align: center;
}

.stat-box span {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.stat-box strong {
  font-size: 1.35rem;
  color: var(--brand-primary);
}

@media (max-width: 800px) {
  .filter-bar {
    grid-template-columns: 1fr;
  }
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.page-head.tight {
  margin-bottom: 0.35rem;
  align-items: center;
}

.page-head .page-title,
.page-head .page-sub {
  margin-bottom: 0.15rem;
}

.section-title {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  color: var(--brand-primary);
}

.mt-half {
  margin-top: 0.35rem;
}

.mt-1 {
  margin-top: 0.65rem;
}

.item-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem;
  margin-bottom: 0.85rem;
  background: #faf7f7;
}

.item-block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.65rem;
}

.searchable-select {
  display: grid;
  gap: 0.35rem;
}

.searchable-select .select-filter {
  width: 100%;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  background: #fff;
}

.searchable-select .select-filter:focus {
  outline: 2px solid color-mix(in srgb, var(--brand-primary) 35%, transparent);
  border-color: var(--brand-primary);
}

.link-danger {
  background: none;
  border: none;
  color: var(--error);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.attach-list {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.75rem;
}

.attach-row {
  display: grid;
  grid-template-columns: 1.2fr 1.4fr 0.8fr;
  gap: 0.45rem;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.kv-grid .full {
  grid-column: 1 / -1;
}

.kv-grid span {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.1rem;
}

.item-summary {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.item-summary:last-child {
  border-bottom: none;
}

.item-summary h3 {
  margin: 0 0 0.55rem;
  font-size: 0.98rem;
  color: var(--brand-primary);
}

.file-list {
  margin: 0;
  padding-left: 1.1rem;
}

.file-list li {
  margin-bottom: 0.35rem;
}

.badge-ok {
  background: #e8f6ec;
  color: var(--success);
}

.badge-soft {
  background: #f3ecec;
  color: var(--brand-primary);
}

.actions.inline {
  margin-top: 0;
}

.quote-group + .quote-group {
  margin-top: 0.25rem;
}

.data-table {
  min-width: 720px;
}

@media (max-width: 800px) {
  .attach-row,
  .kv-grid {
    grid-template-columns: 1fr;
  }
}
