:root {
  --ink: #1c2733;
  --ink-soft: #4a5a6a;
  --line: #d8dee3;
  --paper: #f6f4f0;
  --card: #ffffff;
  --accent: #c2481f;
  --accent-soft: #f3e2da;
  --accent-ink: #7a2e11;
  --focus: #2f6f8f;
  --ok: #2e7d4f;
  --radius: 8px;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
}

h1, h2, legend { font-family: Georgia, "Times New Roman", serif; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  background: var(--ink);
  color: #fff;
  padding: 18px 28px;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  font-size: 28px;
  color: var(--accent);
  line-height: 1;
}
.brand h1 { margin: 0; font-size: 1.35rem; letter-spacing: 0.01em; }
.brand p { margin: 2px 0 0; font-size: 0.82rem; color: #cfd8de; }

.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.25);
  color: #e7ecef;
  padding: 9px 18px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
}
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

main { max-width: 980px; margin: 0 auto; padding: 28px 20px 60px; }

.view { display: none; }
.view.active { display: block; }

fieldset {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 22px;
  margin: 0 0 18px;
}
legend {
  padding: 0 8px;
  font-size: 1.02rem;
  color: var(--accent-ink);
}

.top-fields { margin-bottom: 18px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 14px; }
@media (max-width: 720px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field.grow { grid-column: span 1; }
.field label { font-size: 0.8rem; color: var(--ink-soft); font-weight: 600; letter-spacing: 0.01em; }
.field-hint { font-size: 0.76rem; color: var(--ink-soft); }

input[type=text], input[type=number], input[type=date], select, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  border-color: var(--focus);
}
textarea { resize: vertical; font-family: inherit; }

.hidden { display: none !important; }

.radio-row, .checkbox-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}
.radio-col { display: flex; flex-direction: column; gap: 8px; }
.radio-row label, .radio-col label, .checkbox-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.radio-row input:checked + span, .checkbox-row input:checked + span { font-weight: 600; }
.radio-row label:has(input:checked), .radio-col label:has(input:checked), .checkbox-row label:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.leziune-field { display: flex; flex-direction: column; gap: 5px; }

.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 6px;
}
.status-msg { margin-right: auto; font-size: 0.88rem; color: var(--ok); min-height: 1.2em; }
.status-msg.error { color: var(--accent); }

.btn {
  font: inherit;
  border-radius: 999px;
  padding: 10px 20px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { border-color: var(--ink-soft); }

.list-toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
#search-box {
  flex: 1;
  min-width: 220px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.table-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; min-width: 760px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: var(--paper); color: var(--ink-soft); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
tbody tr:hover { background: #fbfaf8; }
td.actions { display: flex; gap: 6px; }
td.actions button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 5px 9px;
  cursor: pointer;
  font-size: 0.82rem;
}
td.actions button:hover { border-color: var(--focus); }
.empty-state { padding: 30px; text-align: center; color: var(--ink-soft); }

#table-cazuistica th, #table-cazuistica td { text-align: right; white-space: normal; min-width: 92px; }
#table-cazuistica th:first-child, #table-cazuistica td:first-child { text-align: left; white-space: nowrap; min-width: 110px; position: sticky; left: 0; background: var(--card); }
#table-cazuistica thead th { vertical-align: bottom; font-size: 0.68rem; line-height: 1.25; text-transform: none; letter-spacing: 0; cursor: help; }
#table-cazuistica tfoot tr { font-weight: 700; background: var(--accent-soft); }
#table-cazuistica tfoot td:first-child { background: var(--accent-soft); }

.cazuistica-note {
  margin-top: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}
.cazuistica-note p { margin: 4px 0; }

.modal {
  position: fixed; inset: 0;
  background: rgba(20, 26, 32, 0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-card {
  background: #fff;
  border-radius: var(--radius);
  max-width: 720px;
  width: 100%;
  padding: 28px 30px;
  position: relative;
}
.modal-close {
  position: absolute; top: 14px; right: 14px;
  border: none; background: transparent; font-size: 1.1rem; cursor: pointer; color: var(--ink-soft);
}
.modal-actions { margin-top: 20px; display: flex; justify-content: flex-end; }

.printable h2 { margin-top: 0; }
.printable dl { display: grid; grid-template-columns: 200px 1fr; gap: 6px 14px; margin: 0; }
.printable dt { color: var(--ink-soft); font-size: 0.82rem; }
.printable dd { margin: 0; }
.printable .section-title {
  margin: 18px 0 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-ink);
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}
.btn-print-section {
  font: inherit;
  font-size: 0.72rem;
  text-transform: none;
  letter-spacing: 0;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 3px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-print-section:hover { border-color: var(--focus); color: var(--focus); }

@media print {
  .topbar, .tabs, main > *:not(#view-list), .no-print, .modal-close { display: none !important; }
  .modal { position: static; background: none; padding: 0; }
  .modal-card { box-shadow: none; max-width: none; }
  /* cand se apasa "Print sectiune", ascundem toate sectiunile in afara celei alese */
  body.print-one-section .section-block { display: none; }
  body.print-one-section .section-block.print-only-this { display: block; }
}
