*, *::before, *::after { box-sizing: border-box; }
:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --ok: #16a34a;
  --ok-bg: #f0fdf4;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 1px 3px rgba(0,0,0,.04);
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px;
}

.hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.hdr h1 { font-size: 18px; margin: 0; }
.hdr .deal-info { color: var(--muted); font-size: 13px; }
.hdr .deal-info b { color: var(--text); }

.grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
}
@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.card h2 { font-size: 14px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.field { margin-bottom: 10px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}
.field input, .field select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font: inherit;
  color: inherit;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.row2 { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 6px 0 2px; }
.checkbox input { width: auto; }

.actions {
  display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px;
}
.btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 7px 12px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.btn:hover { background: #f3f4f6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.success:hover { background: #15803d; border-color: #15803d; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); padding: 4px 6px; }
.btn.ghost:hover { background: #eff6ff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

table.schedule {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.schedule th, table.schedule td {
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
  vertical-align: middle;
}
table.schedule th {
  background: #f9fafb;
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
table.schedule td.n { width: 44px; color: var(--muted); }
table.schedule td.kind { width: 90px; }
table.schedule td.actions-cell { width: 100px; text-align: right; white-space: nowrap; }
table.schedule input[type="text"],
table.schedule input[type="date"],
table.schedule input[type="number"],
table.schedule select {
  border: 1px solid transparent;
  background: transparent;
  padding: 4px 6px;
  width: 100%;
  border-radius: 4px;
  font: inherit;
  color: inherit;
}
table.schedule input:hover, table.schedule select:hover { border-color: var(--border); background: #fff; }
table.schedule input:focus, table.schedule select:focus {
  outline: none;
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}
table.schedule tr.down { background: #fefce8; }
table.schedule tr.down td.kind { color: #a16207; font-weight: 500; }
table.schedule td .badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 11px;
  background: #eef2ff;
  color: #4338ca;
}
table.schedule tr.down td .badge { background: #fef3c7; color: #92400e; }

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  line-height: 1.4;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
}
.status-badge.muted { background: #f3f4f6; color: var(--muted); border-color: var(--border); }
.status-badge:hover { text-decoration: none; filter: brightness(.95); }

.totals {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.totals .cell {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fafafa;
}
.totals .cell .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.totals .cell .v { font-size: 14px; font-weight: 500; margin-top: 2px; }
.totals .cell.diff.bad { background: var(--danger-bg); border-color: #fecaca; color: var(--danger); }
.totals .cell.diff.ok  { background: var(--ok-bg);     border-color: #bbf7d0; color: var(--ok); }

@media (max-width: 720px) { .totals { grid-template-columns: repeat(2, 1fr); } }

.toast {
  position: fixed; right: 16px; bottom: 16px;
  background: #111827; color: #fff;
  padding: 10px 14px; border-radius: 6px;
  box-shadow: 0 10px 24px rgba(0,0,0,.2);
  opacity: 0; transform: translateY(10px);
  transition: opacity .18s, transform .18s;
  z-index: 100;
  max-width: 420px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--danger); }
.toast.ok  { background: var(--ok); }

.preview {
  margin-top: 10px;
  padding: 10px;
  background: #f9fafb;
  border: 1px dashed var(--border);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  white-space: pre;
  overflow-x: auto;
  color: #374151;
  display: none;
}
.preview.show { display: block; }

.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .35);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 20px 40px rgba(0,0,0,.2);
  max-width: 520px;
  width: calc(100% - 32px);
  overflow: hidden;
  border: 1px solid var(--border);
}
.modal-h {
  padding: 12px 16px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.modal-b {
  padding: 14px 16px;
  font-size: 13px;
  max-height: 50vh;
  overflow-y: auto;
}
.modal-f {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: #f9fafb;
}
