:root {
  --bg: #e8ebe8;
  --panel: #f7f7f4;
  --ink: #1a1d1a;
  --muted: #667066;
  --line: #2a2e2a;
  --accent: #1f5c45;
  --accent-2: #8a4b1f;
  --danger: #8b2e2e;
  --sidebar: #1c2420;
  --sidebar-text: #dce6df;
  --focus: #2f6fed;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", "Consolas", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  transition: grid-template-columns .2s ease;
}

.app.sidebar-collapsed {
  grid-template-columns: 56px 1fr;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 20px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
  min-width: 0;
}

.sidebar-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.sidebar-toggle {
  appearance: none;
  margin-top: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
  color: var(--sidebar-text);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.sidebar-toggle:hover {
  background: rgba(255,255,255,0.12);
}
.toggle-icon {
  font-size: 18px;
  line-height: 1;
  font-weight: 700;
}

.app.sidebar-collapsed .sidebar {
  padding: 12px 8px;
}
.app.sidebar-collapsed .sidebar-body {
  display: none;
}
.app.sidebar-collapsed .sidebar-toggle {
  padding: 12px 0;
}
.app.sidebar-collapsed .toggle-label {
  display: none;
}
.app.sidebar-collapsed .toggle-icon {
  transform: scaleX(-1);
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-sub {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 2px;
}

.history-label {
  margin-top: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.55;
}

.history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.history-item {
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  background: rgba(255,255,255,0.04);
  border: 1px solid transparent;
}

.history-item:hover,
.history-item.active {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.15);
}

.history-title {
  font-size: 13px;
  font-weight: 600;
  word-break: break-word;
}

.history-meta {
  margin-top: 4px;
  font-size: 11px;
  opacity: 0.65;
}

.history-empty {
  font-size: 13px;
  opacity: 0.55;
  padding: 8px 2px;
}

.main {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.drop-view {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 32px;
}

.dropzone {
  width: min(640px, 100%);
  min-height: 280px;
  border: 2px dashed #9aa39a;
  border-radius: 16px;
  background: #f4f6f4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  text-align: center;
  padding: 32px;
  transition: border-color .15s, background .15s;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: #eef6f1;
}

.drop-icon {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.04em;
}

.drop-title { font-size: 20px; font-weight: 650; }
.drop-sub { color: var(--muted); font-size: 14px; max-width: 36ch; }

.busy {
  position: absolute;
  inset: 0;
  background: rgba(232,235,232,0.86);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  font-size: 16px;
  z-index: 5;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #c5cdc5;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.editor-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  background: #f0f2f0;
  border-bottom: 1px solid #d5dad5;
}

.toolbar-left { min-width: 0; }
.doc-title {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.save-state {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.save-state.dirty { color: var(--accent-2); }
.save-state.ok { color: var(--accent); }

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.btn {
  appearance: none;
  border: 1px solid #b7beb7;
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 14px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover {
  background: #eef1ee;
  border-color: #9aa39a;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover {
  background: #174a37;
  border-color: #174a37;
  color: #fff;
}
.btn-accent {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}
.btn-accent:hover {
  background: #6e3a16;
  border-color: #6e3a16;
  color: #fff;
}
.btn-block { width: 100%; }
.btn-icon {
  border: none;
  background: transparent;
  color: var(--danger);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.blank-scroll {
  flex: 1;
  overflow: auto;
  padding: 18px;
}

.upd-blank {
  background: var(--panel);
  border: 1px solid var(--line);
  min-width: 1180px;
  padding: 14px 16px 20px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.06);
}

.upd-top {
  display: grid;
  grid-template-columns: 90px 1fr 220px;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.upd-status-box {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: center;
}
.upd-name {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}
.upd-sf-line {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 4px;
  font-size: 13px;
}
.upd-law {
  font-size: 11px;
  line-height: 1.35;
  text-align: right;
}

.upd-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  margin-bottom: 12px;
}

.party-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid #c9cfc9;
  padding: 8px;
}

.row {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 8px;
  align-items: start;
  font-size: 12px;
}
.row span i {
  font-style: normal;
  color: var(--muted);
}

.split {
  display: flex;
  gap: 6px;
  min-width: 0;
}

.inp {
  width: 100%;
  border: 1px solid #b9c0b9;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 2px;
  min-width: 0;
}
.inp:focus {
  outline: 2px solid color-mix(in srgb, var(--focus) 45%, transparent);
  border-color: var(--focus);
}
textarea.inp {
  resize: vertical;
  min-height: 38px;
  font-family: inherit;
}
.inp.narrow { width: 48px; text-align: center; margin: 0 auto; display: block; }
.inp.short { width: 110px; }
.inp.mid { width: 150px; }
.inp.grow { width: 100%; }

.muted { color: var(--muted); font-size: 11px; }

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
}

.upd-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 11px;
}

.upd-table th,
.upd-table td {
  border: 1px solid #9aa19a;
  padding: 2px;
  vertical-align: top;
}

.upd-table th {
  background: #ecefec;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
  padding: 4px 2px;
}

.upd-table th.wide { width: 180px; }
.upd-table .inp {
  border: none;
  background: transparent;
  padding: 3px 4px;
  border-radius: 0;
}
.upd-table .inp:focus {
  outline: none;
  background: #fff8e8;
}

.upd-table col,
.upd-table th:nth-child(1),
.upd-table td:nth-child(1) { width: 70px; }
.upd-table th:nth-child(2),
.upd-table td:nth-child(2) { width: 36px; }
.upd-table th:nth-child(3),
.upd-table td:nth-child(3) { width: 180px; }
.upd-table th:nth-child(4),
.upd-table td:nth-child(4) { width: 56px; }
.upd-table th:nth-child(5),
.upd-table td:nth-child(5) { width: 42px; }
.upd-table th:nth-child(6),
.upd-table td:nth-child(6) { width: 42px; }
.upd-table th:nth-child(7),
.upd-table td:nth-child(7) { width: 58px; }
.upd-table th:nth-child(8),
.upd-table td:nth-child(8) { width: 70px; }
.upd-table th:nth-child(9),
.upd-table td:nth-child(9) { width: 78px; }
.upd-table th:nth-child(10),
.upd-table td:nth-child(10) { width: 70px; }
.upd-table th:nth-child(11),
.upd-table td:nth-child(11) { width: 52px; }
.upd-table th:nth-child(12),
.upd-table td:nth-child(12) { width: 64px; }
.upd-table th:nth-child(13),
.upd-table td:nth-child(13) { width: 78px; }
.upd-table th:nth-child(14),
.upd-table td:nth-child(14) { width: 56px; }
.upd-table th:nth-child(15),
.upd-table td:nth-child(15) { width: 70px; }
.upd-table th:nth-child(16),
.upd-table td:nth-child(16) { width: 90px; }
.upd-table th:nth-child(17),
.upd-table td:nth-child(17) { width: 28px; }

.totals-row td {
  background: #f3f5f3;
  font-weight: 600;
}
.totals-label {
  text-align: right;
  padding-right: 8px !important;
}
.center { text-align: center; }

.table-actions {
  margin: 8px 0 14px;
}

.transfer-block {
  border: 1px solid #c9cfc9;
  padding: 8px 10px 12px;
}
.transfer-block summary {
  cursor: pointer;
  font-weight: 650;
  margin-bottom: 8px;
}
.transfer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
}

.hidden { display: none !important; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #1c2420;
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  max-width: 360px;
  z-index: 50;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { max-height: 220px; }
}
