/* ------- базовые переменные ------- */
:root{
  --bg:#f6f7fb;
  --card:#fff;
  --text:#111827;
  --muted:#6b7280;
  --line:#e5e7eb;
  --brand:#2563eb;
  --brand-2:#1d4ed8;
  --ghost:#eef2ff;
}

/* ------- базовые стили ------- */
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font:15px/1.45 Inter,system-ui,-apple-system,Segoe UI,Roboto,Arial;
}

/* ------- верхняя панель ------- */
.bar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:10px 14px;
  background:#fff;
  border-bottom:1px solid var(--line);
}
.brand{display:flex;align-items:center;gap:10px}
.logo{font-size:22px;line-height:1}
.brand h1{font-size:18px;margin:0}
#invoiceNumber{color:var(--muted);font-size:12px}

.actions{display:flex;gap:8px;flex-wrap:wrap}
.actions button{
  display:inline-flex;align-items:center;justify-content:center;
  height:34px;padding:0 12px;border-radius:8px;border:0;
  background:var(--brand);color:#fff;font-weight:600;cursor:pointer
}
.actions button:hover{background:var(--brand-2)}
.actions .ghost{background:var(--ghost);color:#1f2937}
.actions .ghost:hover{background:#e0e7ff}

/* ------- карточка инвойса (узкая) ------- */
#invoice{
  max-width:820px;
  margin:22px auto;
  background:var(--card);
  border:1px solid var(--line);
  border-radius:14px;
  padding:16px 16px 18px;
  box-shadow:0 10px 22px rgba(0,0,0,.04);
}

/* ------- сетки и поля ------- */
h3{margin:.2rem 0 .6rem}
label{display:block;font-weight:600;margin:.6rem 0 .25rem}

input,textarea,select{
  width:100%;padding:.58rem .65rem;border:1px solid var(--line);
  border-radius:10px;background:#fff;outline:none;font:inherit;
}
textarea{resize:vertical}

.grid{display:grid;gap:12px;margin:10px 0}
.grid.two{grid-template-columns:1fr 1fr}
.grid.three{grid-template-columns:repeat(3,1fr)}
.meta input,.meta select{margin-top:.25rem}

/* ------- таблица позиций ------- */
.items{
  width:100%;border-collapse:collapse;margin-top:.3rem;
  border:1px solid var(--line);border-radius:10px;overflow:hidden
}
.items th,.items td{border-bottom:1px solid var(--line);padding:.55rem .5rem}
.items th{background:#fafafa;font-weight:700}
.items td:last-child,.items th:last-child{text-align:center}
.items input{border:0;width:100%;padding:.35rem .2rem;background:transparent}

/* ------- суммы ------- */
.totals .numbers{
  display:grid;gap:.35rem;border:1px solid var(--line);
  border-radius:10px;padding:.7rem .9rem;background:#fafafa
}
.numbers>div{display:flex;align-items:center;justify-content:space-between}
.numbers .row{display:flex;align-items:center;gap:.6rem}
.numbers .grand{font-size:1.05rem;font-weight:800}

/* ------- утилиты ------- */
.row{margin:.4rem 0}
.small{font-size:.85rem;color:var(--muted)}
.center{text-align:center}

/* ===== Modal ===== */
.modal{position:fixed;inset:0;display:none}
.modal[aria-hidden="false"]{display:block}
.modal__backdrop{position:absolute;inset:0;background:rgba(0,0,0,.35)}
.modal__dialog{
  position:relative;max-width:980px;width:92%;margin:5vh auto;background:#fff;
  border:1px solid var(--line);border-radius:12px;box-shadow:0 15px 40px rgba(0,0,0,.25)
}
.modal__head{display:flex;align-items:center;justify-content:space-between;padding:12px 16px;border-bottom:1px solid var(--line)}
.modal__body{padding:12px 16px}
.modal__close{border:0;background:#eef2ff;color:#111;border-radius:8px;height:32px;width:32px;cursor:pointer}
.table-wrap{overflow:auto;max-height:70vh}
.list{width:100%;border-collapse:collapse}
.list th,.list td{border-bottom:1px solid var(--line);padding:.55rem .6rem;text-align:left;vertical-align:middle}
.list .muted{color:var(--muted);text-align:center}
.badge{display:inline-block;padding:.2rem .5rem;border-radius:999px;font-size:.8rem}
.badge.paid{background:#e8fff2;color:#0a7a30;border:1px solid #bff0d3}
.badge.unpaid{background:#fff4e5;color:#8a4b00;border:1px solid #f7d9ad}
.row-actions{display:flex;gap:6px;flex-wrap:wrap}
.row-actions button{
  background:#2563eb;color:#fff;border:0;border-radius:8px;height:30px;padding:0 10px;cursor:pointer;font-weight:600
}
.row-actions button.ghost{background:#eef2ff;color:#1f2937}
.row-actions button.danger{background:#ef4444}

/* ------- адаптив ------- */
@media (max-width:900px){
  #invoice{max-width:680px}
}
@media (max-width:760px){
  .grid.two,.grid.three{grid-template-columns:1fr}
  .actions{justify-content:flex-start}
}
