:root {
  color-scheme: light;
  --ink: #18211d;
  --muted: #627169;
  --line: #d9e1dc;
  --panel: #ffffff;
  --panel-soft: #f4f7f5;
  --field: #fbfcfb;
  --nav: #17211d;
  --nav-2: #223129;
  --brand: #2f6f5e;
  --brand-dark: #214e43;
  --amber: #b06d19;
  --red: #b73d31;
  --blue: #376986;
  --shadow: 0 16px 42px rgba(24, 33, 29, 0.09);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #eef3f0;
}

body:not(.is-authenticated) .app-shell {
  display: none;
}

body.is-authenticated .auth-screen {
  display: none;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(23, 33, 29, 0.92), rgba(47, 111, 94, 0.86)),
    #17211d;
}

.auth-card {
  width: min(430px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border-radius: var(--radius);
  background: #ffffff;
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.auth-card h1 {
  margin: 0 0 4px;
  font-size: 2rem;
}

.auth-card .brand-mark {
  background: #e6f1ec;
  color: var(--brand-dark);
  border-color: #cbd7d1;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  color: #eef7f2;
  background: linear-gradient(180deg, var(--nav), var(--nav-2));
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  font-weight: 800;
}

.brand-block strong {
  display: block;
  font-size: 1rem;
}

.brand-block span:last-child {
  display: block;
  color: #aebdb5;
  font-size: 0.82rem;
  margin-top: 2px;
}

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

.nav-link {
  color: #c8d6ce;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
}

.nav-link:hover,
.nav-link.active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.14);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
  color: #aebdb5;
  font-size: 0.82rem;
}

.sidebar-footer span {
  padding: 9px 10px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.main-content {
  padding: 28px;
  min-width: 0;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.section-heading h1 {
  font-size: clamp(2rem, 3vw, 3.2rem);
  line-height: 1;
  margin: 0;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand-dark);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
}

.panel,
.filters-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.02rem;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  min-height: 106px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.metric strong {
  display: block;
  font-size: 2rem;
  margin: 8px 0 6px;
}

.metric.hot {
  border-color: rgba(183, 61, 49, 0.4);
  background: #fff6f4;
}

.metric.warn {
  border-color: rgba(176, 109, 25, 0.42);
  background: #fff9ef;
}

.filters-panel {
  display: grid;
  grid-template-columns: 2fr repeat(3, minmax(150px, 1fr));
  gap: 12px;
  padding: 14px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cbd7d1;
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  padding: 10px 11px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(47, 111, 94, 0.14);
}

.log-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(340px, 0.6fr);
  gap: 16px;
  align-items: start;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 0.9rem;
}

.data-table th {
  color: #f8fbf9;
  background: #314139;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.data-table tr {
  transition: background 0.15s ease;
}

.data-table tbody tr:hover,
.data-table tbody tr.selected {
  background: #eff6f2;
}

.clickable-row {
  cursor: pointer;
}

.count-pill,
.status-pill,
.priority-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.count-pill {
  color: var(--brand-dark);
  background: #e6f1ec;
}

.status-pill {
  color: #234037;
  background: #e6f1ec;
}

.status-open,
.status-in-review {
  color: #234037;
  background: #e6f1ec;
}

.status-waiting-on-others,
.status-at-risk {
  color: #75480f;
  background: #fff1d9;
}

.status-resolved,
.status-closed {
  color: #53635a;
  background: #ecf0ed;
}

.priority-pill {
  color: #264157;
  background: #e7f1f7;
}

.priority-critical {
  color: #8f241b;
  background: #ffe4df;
}

.priority-high {
  color: #75480f;
  background: #fff0d7;
}

.priority-medium {
  color: #28516b;
  background: #e4f2fb;
}

.priority-low {
  color: #53635a;
  background: #edf1ee;
}

.detail-panel {
  position: sticky;
  top: 28px;
}

.detail-panel h2,
.detail-panel h3 {
  margin: 0;
}

.detail-title {
  display: grid;
  gap: 10px;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-section {
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.detail-section strong {
  display: block;
  margin-bottom: 6px;
}

.detail-section p {
  margin: 0;
  color: #34423b;
  line-height: 1.5;
  white-space: pre-wrap;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.detail-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-soft);
}

.detail-item span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 3px;
}

.detail-item strong {
  font-size: 0.92rem;
}

.empty-detail,
.empty-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
}

.empty-icon {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  border-radius: 8px;
  background: #e6f1ec;
  color: var(--brand-dark);
  font-weight: 900;
}

.entry-form {
  max-width: 1120px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.wide {
  grid-column: 1 / -1;
}

.form-actions,
.action-row,
.export-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.form-actions {
  justify-content: flex-end;
  margin-top: 16px;
}

.primary-button,
.secondary-button,
.text-button,
.danger-button {
  border: 0;
  border-radius: 8px;
  font-weight: 800;
  min-height: 40px;
  padding: 10px 14px;
}

.primary-button {
  color: #ffffff;
  background: var(--brand);
}

.primary-button:hover {
  background: var(--brand-dark);
}

.secondary-button {
  color: var(--ink);
  background: #e9efec;
  border: 1px solid #cfdad4;
}

.text-button {
  color: var(--brand-dark);
  background: transparent;
  min-height: 32px;
  padding: 6px 8px;
}

.danger-button {
  color: var(--red);
}

.export-grid,
.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}

.user-panel {
  grid-column: 1 / -1;
}

.user-table {
  min-width: 700px;
}

.export-panel {
  min-height: 170px;
}

.report-preview {
  margin-top: 16px;
}

#emailPreview {
  margin: 0;
  padding: 14px;
  border-radius: 8px;
  color: #203028;
  background: #f3f7f5;
  border: 1px solid var(--line);
  white-space: pre-wrap;
  line-height: 1.5;
  overflow-x: auto;
}

.stack-form {
  display: grid;
  gap: 14px;
}

.admin-only {
  display: none;
}

.is-admin .admin-only {
  display: table-cell;
}

.is-admin th.admin-only {
  display: table-cell;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  color: #ffffff;
  background: #17211d;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1180px) {
  .metric-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .log-grid,
  .export-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    position: static;
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }

  .nav-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nav-link {
    text-align: center;
    padding: 10px 6px;
    font-size: 0.84rem;
  }

  .sidebar-footer {
    display: none;
  }

  .main-content {
    padding: 18px;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid,
  .filters-panel,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }
}
