:root {
  --bg: #f4f2ea;
  --ink: #111613;
  --muted: #5f665f;
  --line: #d8d4c7;
  --panel: #fffdf7;
  --panel-2: #ebe7db;
  --green: #16643a;
  --green-2: #21834e;
  --lime: #b7dc67;
  --amber: #d88b26;
  --red: #b84538;
  --blue: #236b8e;
  --shadow: 0 18px 50px rgba(17, 22, 19, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(22, 100, 58, 0.09), transparent 32%),
    linear-gradient(315deg, rgba(216, 139, 38, 0.13), transparent 30%),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

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

button {
  border: 0;
}

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

a {
  color: inherit;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #111613;
  color: #f7f4ec;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.side-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 850;
  font-size: 1.03rem;
}

.side-logo span:first-child {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--green-2);
  color: white;
}

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

.nav a,
.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 13px;
  text-align: left;
  text-decoration: none;
  border-radius: 8px;
  color: #dcd6c7;
  background: transparent;
  cursor: pointer;
}

.nav a:hover,
.nav button:hover,
.nav button.active {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.side-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #d9d4c5;
  line-height: 1.45;
  font-size: 0.9rem;
}

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

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(1.85rem, 3vw, 3.05rem);
  line-height: 1;
}

.subtle {
  color: var(--muted);
  line-height: 1.5;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 10px 13px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 850;
  text-decoration: none;
  cursor: pointer;
}

.btn.secondary {
  background: #e5e0d1;
  color: var(--ink);
}

.btn.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn.compact {
  min-height: 32px;
  padding: 6px 9px;
  font-size: 0.84rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(380px, 1.05fr);
  gap: 18px;
}

.panel {
  background: rgba(255, 253, 247, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(17, 22, 19, 0.07);
}

.panel-head {
  padding: 18px 18px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.panel-body {
  padding: 18px;
}

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

.field {
  display: grid;
  gap: 7px;
  color: #343b35;
  font-size: 0.88rem;
  font-weight: 750;
}

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

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

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green-2);
  box-shadow: 0 0 0 3px rgba(33, 131, 78, 0.16);
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric strong {
  display: block;
  margin-bottom: 4px;
  font-size: 2rem;
}

.search {
  position: sticky;
  top: 16px;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-bottom: 18px;
}

.rule-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.rule-card {
  display: grid;
  gap: 12px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
}

.rule-card.active {
  border-color: var(--green-2);
  box-shadow: inset 4px 0 0 var(--green-2);
}

.rule-number {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #111613;
  color: #fff;
  font-weight: 900;
}

.rule-title-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.rule-title-row h3 {
  font-size: 1rem;
  line-height: 1.25;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffefa;
  color: #333a33;
  font-size: 0.84rem;
  font-weight: 750;
}

.viewer {
  min-height: calc(100vh - 48px);
  display: grid;
  grid-template-rows: auto minmax(560px, 1fr);
}

.standalone-viewer {
  min-height: calc(100vh - 48px);
}

.viewer-frame {
  width: 100%;
  height: 100%;
  min-height: 560px;
  border: 0;
  border-top: 1px solid var(--line);
  background: #ebe7db;
}

.focus-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.focus-list li {
  padding: 10px 11px;
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  background: #fff8e6;
  line-height: 1.45;
}

.notes-panel {
  margin-top: 0;
}

.notes-grid {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 18px;
}

.item-list {
  display: grid;
  gap: 10px;
}

.list-item {
  width: 100%;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.list-item.active {
  border-color: var(--green-2);
  box-shadow: inset 4px 0 0 var(--green-2);
}

.list-item strong,
.list-item span {
  display: block;
}

.list-item span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.86rem;
}

.match-editor {
  display: grid;
  gap: 18px;
}

.entry-form {
  display: grid;
  grid-template-columns: 90px minmax(110px, 1fr) minmax(160px, 1fr) minmax(140px, 0.8fr);
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.entry-form .btn {
  align-self: end;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
}

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

.table th,
.table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.table th {
  color: #343b35;
  font-size: 0.86rem;
}

.table tr:last-child td {
  border-bottom: 0;
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

.danger-row {
  justify-content: flex-end;
}

.calendar-layout {
  display: grid;
  gap: 18px;
  align-items: start;
}

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

.calendar-weekday {
  padding: 8px 6px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 850;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.calendar-cell {
  min-height: 142px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
}

.calendar-cell strong {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.muted-cell {
  background: rgba(235, 231, 219, 0.55);
}

.calendar-events {
  display: grid;
  gap: 6px;
}

.calendar-event {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 7px;
  border-radius: 8px;
  background: #e7f3df;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.calendar-event span {
  color: var(--green);
  font-size: 0.74rem;
  font-weight: 850;
}

.calendar-event b {
  overflow-wrap: anywhere;
  font-size: 0.82rem;
  line-height: 1.25;
}

.quick-match-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.quick-match-form .btn {
  grid-column: 1 / -1;
}

.upcoming-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17, 22, 19, 0.58);
}

.modal-panel {
  width: min(760px, 100%);
  max-height: min(820px, calc(100vh - 40px));
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e5e0d1;
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.empty {
  padding: 28px;
  border: 1px dashed #bdb7aa;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.source-note {
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.76);
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 1120px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

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

  .viewer {
    min-height: auto;
  }
}

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

  .sidebar {
    position: static;
    height: auto;
  }

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

  .main {
    padding: 16px;
  }

  .topbar,
  .panel-head,
  .search {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .metric-row,
  .form-grid,
  .entry-form,
  .quick-match-form,
  .rule-grid {
    grid-template-columns: 1fr;
  }

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

  .calendar-weekday {
    display: none;
  }

  .calendar-cell {
    min-height: auto;
  }

  .viewer-frame {
    min-height: 440px;
  }
}

@media (max-width: 520px) {
  .nav {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #fff;
  }

  .sidebar,
  .topbar,
  .metric-row,
  .dashboard-grid,
  .source-note,
  .entry-form,
  .danger-row,
  .screen-only {
    display: none !important;
  }

  .app-shell,
  .main,
  .notes-grid {
    display: block;
  }

  .main {
    padding: 0;
  }

  .panel {
    border: 0;
    box-shadow: none;
  }

  .panel-head,
  .panel-body {
    padding: 0 0 14px;
  }

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

  input,
  textarea {
    border-color: #999;
  }

  .table {
    min-width: 0;
  }
}
