* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.5;
}

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

.topbar {
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 24px;
}

.brand {
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.page {
  margin: 0 auto;
  max-width: 1180px;
  padding: 28px 20px;
}

.auth-layout {
  display: grid;
  min-height: calc(100vh - 128px);
  place-items: center;
}

.auth-panel,
.settings-panel,
.work-area,
.metric-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.auth-panel {
  max-width: 440px;
  padding: 28px;
  width: 100%;
}

.auth-panel.wide {
  max-width: 760px;
}

h1,
h2,
p {
  margin-top: 0;
}

form {
  display: grid;
  gap: 16px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 14px;
  gap: 6px;
}

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

.field-error {
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  min-height: 42px;
  padding: 9px 11px;
  width: 100%;
}

.check {
  align-items: center;
  display: flex;
  gap: 8px;
}

.check input {
  min-height: auto;
  width: auto;
}

.button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
  min-height: 42px;
  padding: 10px 14px;
}

.button.primary {
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 700;
}

.button.secondary {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  display: inline-grid;
  place-items: center;
}

.form-grid,
.metric-grid {
  display: grid;
  gap: 16px;
}

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

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

.metric-grid.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 18px;
}

.metric-card {
  padding: 18px;
}

.metric-card span {
  color: var(--muted);
  display: block;
  font-size: 14px;
}

.metric-card strong {
  display: block;
  font-size: 32px;
  margin-top: 8px;
}

.section-head {
  align-items: end;
  display: flex;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-head p,
.muted {
  color: var(--muted);
}

.work-area,
.settings-panel {
  margin-top: 20px;
  padding: 22px;
}

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

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

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

.admin-table th {
  background: #eef0f2;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.table-actions form {
  display: block;
}

.danger-link {
  color: var(--danger);
}

.config-snippet {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-top: 16px;
  overflow-x: auto;
  padding: 12px;
}

.config-snippet pre {
  margin: 0;
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.message {
  border: 1px solid var(--line);
  border-radius: 6px;
  margin: 0;
  padding: 10px 12px;
}

.message-error {
  color: var(--danger);
}

.message-success {
  color: var(--success);
}

.notes-layout {
  align-items: stretch;
  display: grid;
  gap: 18px;
  grid-template-columns: 220px minmax(0, 1fr);
}

.notes-actions {
  background: linear-gradient(180deg, #eef2f4, #dfe7ea);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 14px;
  padding: 18px;
}

.notes-actions a {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  display: block;
  font-weight: 700;
  padding: 10px 12px;
  text-align: center;
}

.notes-table,
.notes-form,
.record-detail {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.notes-toolbar {
  background: #d7dadd;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 18px;
  padding: 8px 12px;
}

.notes-table table {
  border-collapse: collapse;
  font-size: 14px;
  width: 100%;
}

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

.notes-table th {
  background: #eef0f2;
  color: var(--text);
}

.group-row td {
  background: #f6f8fa;
  color: #11645d;
  font-weight: 700;
}

.group-row span {
  color: var(--muted);
  margin-left: 8px;
}

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

.notes-form-page {
  max-width: 980px;
}

.notes-form {
  gap: 0;
  padding: 14px;
}

.notes-form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 22px;
}

.link-button {
  background: none;
  border: 0;
  color: var(--primary);
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.notes-band {
  background: linear-gradient(90deg, #74809d, #eef1f4);
  color: #ffd5bc;
  font-size: 20px;
  margin: 14px 0;
  padding: 4px 8px;
}

.notes-grid {
  display: grid;
  gap: 10px;
}

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

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

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

.notes-cell {
  align-items: center;
  border: 1px solid var(--line);
  display: grid;
  gap: 8px;
  grid-template-columns: 130px minmax(0, 1fr);
  min-height: 44px;
  padding: 8px;
}

textarea {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font: inherit;
  padding: 9px 11px;
  resize: vertical;
  width: 100%;
}

.notes-attachment {
  border: 1px dashed var(--line);
  color: var(--muted);
  display: grid;
  gap: 8px;
  padding: 14px;
}

.file-picker {
  align-items: center;
  color: var(--text);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.file-picker input {
  max-width: 360px;
}

.paperclip {
  display: inline-grid;
  font-size: 20px;
  height: 32px;
  place-items: center;
  width: 32px;
}

.editorial {
  margin-top: 18px;
}

.editorial summary {
  color: #11645d;
  cursor: pointer;
  font-weight: 700;
  margin-bottom: 10px;
}

.record-detail {
  padding: 22px;
}

.record-detail dl {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
}

.record-detail dt,
.record-detail dd {
  border-bottom: 1px solid var(--line);
  margin: 0;
  padding: 8px 0;
}

.record-detail dt {
  color: var(--muted);
  font-weight: 700;
}

.status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.status-actions form {
  display: block;
}

.comment-list,
.attachment-list {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.comment-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
}

.comment-item header {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 6px;
}

.comment-item p {
  margin-bottom: 0;
}

.inline-form {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  margin: 12px 0 22px;
  padding-top: 14px;
}

@media (max-width: 780px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 14px 18px;
  }

  .form-grid,
  .metric-grid,
  .metric-grid.compact,
  .notes-layout,
  .notes-grid.two,
  .notes-grid.form {
    grid-template-columns: 1fr;
  }
}
