:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --ink: #17201d;
  --muted: #68736f;
  --line: #d8dfdc;
  --primary: #156f5b;
  --primary-dark: #0f5747;
  --warn: #9b5d00;
  --danger: #b3261e;
  --ok: #237245;
  --soon: #b7791f;
  --soft: #eef5f2;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button, input, select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 7px;
  padding: 9px 12px;
  cursor: pointer;
}

button:hover { background: #eef2f0; }
button.primary { background: var(--primary); border-color: var(--primary); color: white; }
button.primary:hover { background: var(--primary-dark); }
button.danger { border-color: #e3b7b2; color: var(--danger); }
button.danger:hover { background: #fff0ee; }

.topbar {
  min-height: 74px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar h1, h2 { margin: 0; }
.topbar h1 { font-size: 24px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-icon { width: 42px; height: 42px; flex: 0 0 auto; border-radius: 10px; }
.eyebrow { margin: 0 0 2px; color: var(--primary); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  min-height: calc(100vh - 74px);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.profile-panel h2 { font-size: 17px; margin-bottom: 12px; }
label { display: block; color: var(--muted); font-size: 13px; }
input, select {
  width: 100%;
  margin-top: 5px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  background: white;
  color: var(--ink);
}

.check-grid { display: grid; gap: 9px; margin-top: 12px; }
.check-grid label { display: grid; grid-template-columns: 18px 1fr; gap: 8px; align-items: start; color: var(--ink); }
.check-grid input { width: auto; margin: 2px 0 0; }

.tabs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tab.active { background: var(--primary); border-color: var(--primary); color: white; font-weight: 700; }

.side-note {
  margin-top: auto;
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: 8px;
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.side-note strong { display: block; color: var(--ink); margin-bottom: 4px; }

.workspace { padding: 22px; overflow: auto; }
.tab-content { display: none; }
.tab-content.active { display: block; }

.toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.toolbar h2 { font-size: 22px; }
.muted { color: var(--muted); margin: 4px 0 0; }
.compact { min-width: 150px; }

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.status-card, .record-item, .rule-item {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.status-card { display: grid; gap: 9px; border-left-width: 6px; }
.status-card.ok { border-left-color: var(--ok); }
.status-card.soon { border-left-color: var(--soon); }
.status-card.due, .status-card.missing { border-left-color: var(--danger); }
.status-card.optional { border-left-color: #7b8794; }
.status-head { display: flex; align-items: start; justify-content: space-between; gap: 8px; }
.status-title { font-size: 16px; font-weight: 800; }
.badge { border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge.ok { background: #e5f6ed; color: var(--ok); }
.badge.soon { background: #fff4db; color: var(--soon); }
.badge.due, .badge.missing { background: #ffebe8; color: var(--danger); }
.badge.optional { background: #eef1f4; color: #54606b; }
.status-meta { color: var(--muted); font-size: 13px; line-height: 1.45; }

.entry-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  align-items: end;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.component-fieldset {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px 12px;
  margin: 0;
}
.component-fieldset legend {
  color: var(--muted);
  font-size: 13px;
  padding: 0 5px;
}
.component-options { display: flex; flex-wrap: wrap; gap: 10px; }
.component-options label {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 10px;
  background: var(--soft);
}
.component-options input {
  width: auto;
  margin: 0;
}
.form-actions { display: flex; gap: 8px; align-items: center; }
.form-actions button { width: 100%; }

.list-tools {
  margin: 16px 0 10px;
  display: flex;
  gap: 10px;
}
.list-tools input { margin: 0; max-width: 380px; }

.record-list, .rule-list { display: grid; gap: 10px; }
.record-item { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: start; }
.record-item.editing { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(21,111,91,.12); }
.record-summary { min-width: 0; }
.record-title { font-weight: 800; }
.record-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.record-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.record-details {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin: 2px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.record-details div { min-width: 0; }
.record-details dt { color: var(--muted); font-size: 12px; margin-bottom: 3px; }
.record-details dd { margin: 0; font-size: 14px; overflow-wrap: anywhere; }
.record-edit-form {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-top: 2px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.record-edit-form label { min-width: 0; }
.record-edit-form input,
.record-edit-form select { margin-top: 5px; }
.record-edit-form .component-fieldset { background: rgba(238,245,242,.65); }

.rule-item { display: grid; grid-template-columns: minmax(180px, 1fr) repeat(4, minmax(100px, 140px)) auto; gap: 10px; align-items: end; }
.rule-item label { min-width: 0; }
.rule-item input[type="checkbox"] { width: auto; }
.rule-toggle { display: flex; align-items: center; gap: 8px; color: var(--ink); padding-bottom: 9px; }

.data-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.data-preview {
  margin: 0;
  background: #16201d;
  color: #edf7f3;
  border-radius: 8px;
  padding: 14px;
  overflow: auto;
  max-height: 50vh;
  font-size: 12px;
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 22px;
  color: var(--muted);
  background: rgba(255,255,255,.6);
}

@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .topbar, .toolbar { align-items: stretch; flex-direction: column; }
  .topbar-actions { justify-content: flex-start; }
  .entry-form, .rule-item, .record-item { grid-template-columns: 1fr; }
  .record-actions { justify-content: flex-start; }
  .list-tools { flex-direction: column; }
  .list-tools input { max-width: none; }
}

@media print {
  .sidebar, .topbar-actions, .entry-form, .list-tools, .data-actions { display: none; }
  .layout { grid-template-columns: 1fr; }
  .workspace { padding: 0; }
  body { background: white; }
}
