:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --ink: #1c2330;
  --muted: #6a7484;
  --line: #dfe4ec;
  --accent: #1f3a5f;
  --accent-soft: #e8eef7;
  --ok: #16794c;
  --err: #b4232b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Calibri, Arial, sans-serif;
  font-size: 14px;
}

/* ------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 60px;
  padding: 0 20px;
  background: var(--accent);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .12), 0 8px 20px rgba(15, 40, 80, .07);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding-right: 16px;
  border-right: 1px solid rgba(255, 255, 255, .22);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .3px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.nav {
  display: flex;
  gap: 4px;
}

.nav a {
  padding: 6px 12px;
  border-radius: 6px;
  color: #cfdcec;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.nav a:hover { background: rgba(255, 255, 255, .12); }

.nav a.active {
  background: #fff;
  color: var(--accent);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  margin-top: 1px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.brand small {
  font-weight: 400;
  font-size: 12px;
  opacity: .75;
  letter-spacing: 0;
}

.logo {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: #fff;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.status {
  font-size: 11.5px;
  padding: 5px 11px;
  border-radius: 20px;
  background: rgba(255, 255, 255, .12);
  color: #dfe8f5;
  min-width: 100px;
  text-align: center;
}

.status[data-state="ok"] { background: rgba(76, 217, 150, .18); color: #b9f5d7; }
.status[data-state="err"] { background: rgba(255, 120, 120, .2); color: #ffd2d2; }

/* ------------------------------------------------------------ button */

.btn {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 8px 14px;
  font: 600 13px "Segoe UI", Arial, sans-serif;
  cursor: pointer;
  background: #fff;
  color: var(--accent);
  transition: filter .15s ease, background .15s ease;
  white-space: nowrap;
}

.btn:hover { filter: brightness(.96); }

.btn.primary { background: #fff; color: var(--accent); }
.btn.ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, .4);
  color: #fff;
}
.btn.ghost:hover { background: rgba(255, 255, 255, .1); }

.btn.small { padding: 6px 11px; font-size: 12.5px; }
.btn.tiny { padding: 3px 9px; font-size: 11.5px; border-radius: 6px; }

.btn-preview,
.btn-print {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.btn-preview { padding-left: 12px; }

.btn-preview svg,
.btn-print svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn.danger {
  background: #fdeceb;
  color: var(--err);
  border-color: #f6cfcd;
}

/* ------------------------------------------------------------ layout */

.layout {
  display: grid;
  grid-template-columns: minmax(430px, 46%) 1fr;
  height: calc(100vh - 60px);
}

.editor-pane {
  overflow-y: auto;
  padding: 16px 16px 48px;
  border-right: 1px solid var(--line);
}

.preview-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #e6ebf2;
}

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: #f7f9fc;
  border-bottom: 1px solid var(--line);
}

#preview {
  flex: 1;
  width: 100%;
  border: 0;
  background: #e6ebf2;
}

/* ------------------------------------------------------------ block */

.block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px 16px;
  margin-bottom: 14px;
}

.block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.block-title {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.1px;
  color: var(--accent);
}

.block-head .block-title { margin: 0; }

/* ------------------------------------------------------------ field */

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

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field { display: block; }

.field > span {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

input[type="text"],
input[type="email"],
input:not([type]),
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfe;
  color: var(--ink);
  font: 400 13.5px "Segoe UI", Arial, sans-serif;
  line-height: 1.4;
  transition: border-color .15s ease, background .15s ease;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

.hint {
  margin: 7px 0 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
}

/* ------------------------------------------------------------ foto */

.foto-row {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.foto-thumb {
  flex: 0 0 auto;
  width: 78px;
  height: 104px;
  border: 1.5px dashed #c3ccdb;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: #f7f9fc;
  overflow: hidden;
}

.foto-thumb span {
  font-size: 10.5px;
  color: #94a0b3;
  text-align: center;
  padding: 0 6px;
  line-height: 1.3;
}

.foto-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.foto-actions { flex: 1; min-width: 0; }

.foto-buttons { display: flex; gap: 8px; margin-bottom: 2px; }

.foto-actions .btn.small {
  background: var(--accent-soft);
  color: var(--accent);
}

.foto-actions .btn.small.ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

/* ------------------------------------------------------------ list */

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

.card {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 11px 12px 13px;
  background: #fcfdff;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 9px;
}

.card-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

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

.card .field + .field { margin-top: 9px; }

.empty {
  margin: 0;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  background: #fafbfd;
}

.save-note {
  margin: 18px 0 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--muted);
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 1080px) {
  .layout {
    display: flex;
    flex-direction: column;
    height: auto;
  }
  .editor-pane {
    overflow: visible;
    border-right: 0;
  }
  .preview-pane {
    position: static;
    width: 100%;
    height: 60vh;
    min-height: 380px;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 720px) {
  .topbar {
    height: auto;
    padding: 8px 12px;
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .brand {
    padding-right: 0;
    border-right: 0;
    font-size: 14px;
    gap: 7px;
    flex-shrink: 0;
  }
  .logo { width: 27px; height: 27px; font-size: 11px; }
  .topbar-left {
    width: 100%;
    gap: 8px;
  }
  .nav {
    flex: 1;
    gap: 2px;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 5px 8px; font-size: 11.5px; }
  .topbar-actions {
    width: 100%;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: wrap;
  }
  .btn { padding: 7px 10px; font-size: 11.5px; }
  .btn-preview, .btn-print { padding-left: 9px; gap: 5px; }
}

@media (max-width: 560px) {
  .grid-2, .card-grid { grid-template-columns: 1fr; }
  .layout { height: auto; }
  .status { display: none; }
  .foto-row { flex-direction: column; }
  .preview-pane { height: 55vh; min-height: 340px; }
  .preview-head { padding: 8px 12px; }
  .preview-head .hint { display: none; }
  .block-head { flex-wrap: wrap; }
  .foto-buttons { flex-wrap: wrap; }
}
