:root{
  --bg:#f5f1ec;
  --card:#fff;
  --ink:#2b2a28;
  --muted:#8a8378;
  --accent:#1c1c1c;
  --line:#e4ddd2;
  --beige:#e9e1d4;
  --beige-dark:#cdbfa6;
  --green:#2f6f4e;
  --amber:#a9761f;
}

*{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif;
  background:var(--bg);
  color:var(--ink);
  min-height:100vh;
}

.hidden{display:none !important;}

.screen{min-height:100vh;}

/* ---------- Login ---------- */
#login-screen{
  display:flex;
  align-items:center;
  justify-content:center;
  padding:24px;
}
.login-card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:16px;
  padding:32px 24px;
  width:100%;
  max-width:360px;
  text-align:center;
}
.login-card h1{
  font-size:22px;
  margin:0 0 4px;
}
.login-card .sub{
  color:var(--muted);
  font-size:13px;
  margin:0 0 24px;
}
.login-card form{
  display:flex;
  flex-direction:column;
  gap:10px;
  text-align:left;
}
.login-card label{
  font-size:13px;
  color:var(--muted);
  margin-top:4px;
}
.login-card input{
  border:1px solid var(--line);
  border-radius:10px;
  padding:12px 14px;
  font-size:15px;
  background:var(--bg);
  color:var(--ink);
}
.pwd-wrap{
  position:relative;
  display:flex;
}
.pwd-wrap input{
  width:100%;
  padding-right:42px;
}
.pwd-eye{
  position:absolute;
  right:4px;
  top:50%;
  transform:translateY(-50%);
  background:none;
  border:none;
  font-size:17px;
  cursor:pointer;
  padding:6px 8px;
  opacity:.55;
}
.pwd-eye.active{opacity:1;}
.login-card button[type="submit"]{
  margin-top:14px;
  background:var(--accent);
  color:#fff;
  border:none;
  border-radius:10px;
  padding:13px;
  font-size:15px;
  font-weight:600;
  cursor:pointer;
}
.link-btn{
  background:none;
  border:none;
  color:var(--muted);
  font-size:13px;
  margin-top:16px;
  cursor:pointer;
  text-decoration:underline;
}
.error{
  color:#b43c3c;
  font-size:13px;
  margin-top:12px;
}

/* ---------- App ---------- */
.app-header{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  padding:20px 16px 12px;
  position:sticky;
  top:0;
  background:var(--bg);
  border-bottom:1px solid var(--line);
  z-index:5;
}
.app-header h1{
  font-size:19px;
  margin:0 0 2px;
}
.app-header .sub{
  color:var(--muted);
  font-size:12.5px;
  margin:0;
}
.icon-btn{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:10px;
  width:38px;
  height:38px;
  font-size:17px;
  cursor:pointer;
  color:var(--ink);
}
.logout-btn{
  width:auto;
  display:flex;
  align-items:center;
  gap:6px;
  padding:0 14px;
  font-size:13px;
  font-weight:600;
}
.header-actions{
  display:flex;
  align-items:center;
  gap:8px;
}

/* ---------- Выбор проекта (админ) ---------- */
.project-picker-list{
  display:flex;
  flex-direction:column;
  gap:10px;
  margin-top:18px;
}
.project-picker-item{
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  gap:2px;
  width:100%;
  background:var(--card);
  border:1px solid var(--line);
  border-radius:12px;
  padding:14px 16px;
  cursor:pointer;
  text-align:left;
  font-family:inherit;
}
.project-picker-item:hover{
  border-color:var(--amber);
}
.project-picker-item .ppi-title{
  font-size:15px;
  font-weight:700;
  color:var(--ink);
}
.project-picker-item .ppi-id{
  font-size:12px;
  color:var(--muted);
}
.ppi-badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:18px;
  height:18px;
  padding:0 5px;
  margin-left:8px;
  border-radius:999px;
  background:#b43c3c;
  color:#fff;
  font-size:11px;
  font-weight:700;
  vertical-align:middle;
}

/* ---------- Main tabs (Проект / Ход работ) ---------- */
.main-tabs{
  display:flex;
  gap:8px;
  padding:10px 12px 0;
  max-width:640px;
  margin:0 auto;
  position:sticky;
  top:71px;
  background:var(--bg);
  z-index:4;
}
.main-tab-btn{
  position:relative;
  flex:1;
  border:1px solid var(--line);
  background:var(--card);
  border-radius:10px;
  padding:10px;
  font-size:13.5px;
  font-weight:600;
  cursor:pointer;
  color:var(--muted);
}
.tab-badge{
  position:absolute;
  top:-6px;
  right:-6px;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width:18px;
  height:18px;
  padding:0 5px;
  border-radius:999px;
  background:#b43c3c;
  color:#fff;
  font-size:11px;
  font-weight:700;
}
.main-tab-btn.active{
  background:var(--accent);
  color:#fff;
  border-color:var(--accent);
}
.main-tab-panel{display:none;}
.main-tab-panel.active{display:block;}

/* ---------- Room tabs ---------- */
#overview-tab{
  padding:14px 12px 40px;
  max-width:640px;
  margin:0 auto;
}
.room-tabs{
  display:flex;
  gap:8px;
  margin-bottom:12px;
}
.room-tab-btn{
  flex:1;
  border:1px solid var(--line);
  background:var(--card);
  border-radius:10px;
  padding:9px;
  font-size:13px;
  cursor:pointer;
  color:var(--ink);
}
.room-tab-btn.active{
  background:var(--beige);
  border-color:var(--beige-dark);
  font-weight:600;
}
.room-panel{display:none;}
.room-panel.active{display:block;}

/* ---------- Hero / specs ---------- */
.hero{
  border-radius:14px;
  overflow:hidden;
  margin-bottom:14px;
  background:var(--card);
  border:1px solid var(--line);
}
.hero img{
  width:100%;
  display:block;
}
.hero-info{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:14px;
  padding:14px 16px;
  margin-bottom:14px;
}
.hero-info h2{
  font-size:17px;
  margin:0 0 4px;
}
.hero-info .dims{
  display:inline-block;
  font-size:12px;
  color:var(--muted);
  background:var(--beige);
  border-radius:999px;
  padding:3px 10px;
  margin-bottom:8px;
}
.hero-info .spec-hint{
  font-size:13px;
  color:var(--muted);
  margin:6px 0 10px;
}
.chips{
  display:flex;
  flex-wrap:wrap;
  gap:6px;
}
.chip{
  font-size:12px;
  background:var(--beige);
  border:1px solid var(--beige-dark);
  border-radius:999px;
  padding:5px 10px;
}

/* ---------- Budget ---------- */
.budget{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:14px;
  padding:16px;
  margin-bottom:14px;
}
.budget h3{
  margin:0 0 14px;
  font-size:16px;
}
.bars{
  display:flex;
  flex-direction:column;
  gap:8px;
}
.bar-row{
  display:grid;
  grid-template-columns:78px 1fr 80px;
  align-items:center;
  gap:8px;
  font-size:12.5px;
}
.bar-track{
  height:8px;
  background:var(--beige);
  border-radius:999px;
  overflow:hidden;
}
.bar-fill{
  height:100%;
  background:var(--accent);
  border-radius:999px;
}
.bar-amt{
  text-align:right;
  font-size:12.5px;
  white-space:nowrap;
}
.total{
  display:flex;
  justify-content:space-between;
  align-items:baseline;
  margin-top:14px;
  padding-top:12px;
  border-top:1px dashed var(--line);
  font-weight:600;
}
.total .amount{font-size:17px;}
.total .amount span{font-size:11px;color:var(--muted);font-weight:400;}
.timeline{
  margin-top:10px;
  font-size:12.5px;
  color:var(--muted);
}
.timeline .badge{
  background:var(--beige);
  color:var(--ink);
  border-radius:999px;
  padding:3px 9px;
  font-size:11px;
  font-weight:600;
  margin-right:6px;
}
.spec-table{
  width:100%;
  border-collapse:collapse;
  font-size:12.5px;
  margin-top:6px;
}
.spec-table th,.spec-table td{
  padding:7px 6px;
  border-bottom:1px solid var(--line);
  text-align:left;
}
.spec-table .num{text-align:right;white-space:nowrap;}
.spec-table .sum-row{font-weight:600;}
.spec-hint{font-size:12.5px;color:var(--muted);margin-top:10px;}

/* ---------- Gantt ---------- */
.gantt-sub{font-size:12.5px;color:var(--muted);margin:0 0 14px;}
.gantt-head{
  display:grid;
  grid-template-columns:120px 1fr;
  margin-bottom:6px;
}
.gantt-weeks{
  display:grid;
  grid-template-columns:repeat(8,1fr);
  font-size:11px;
  color:var(--muted);
  text-align:center;
}
.gantt-row{
  display:grid;
  grid-template-columns:120px 1fr;
  align-items:center;
  gap:6px;
  margin-bottom:5px;
}
.gantt-label{font-size:11.5px;color:var(--ink);}
.gantt-track{
  position:relative;
  height:14px;
  background:var(--beige);
  border-radius:4px;
}
.gantt-seg{
  position:absolute;
  top:0;
  height:100%;
  border-radius:4px;
}
.gantt-seg.work{background:#2f6f4e;}
.gantt-seg.wait{background:#e7d9b8;}
.gantt-legend{
  display:flex;
  gap:16px;
  margin-top:10px;
  font-size:11.5px;
  color:var(--muted);
}
.gantt-legend .dot{
  display:inline-block;
  width:9px;
  height:9px;
  border-radius:50%;
  margin-right:5px;
}
.gantt-legend .dot.work{background:#2f6f4e;}
.gantt-legend .dot.wait{background:#e7d9b8;}

/* ---------- Notice card ---------- */
.notice-list{
  margin:0;
  padding-left:0;
  list-style:none;
}
.notice-list li{
  display:flex;
  gap:10px;
  padding:8px 0;
  font-size:13.5px;
  color:#4a463f;
  border-bottom:1px dashed var(--line);
}
.notice-list li:last-child{border-bottom:none;}
.notice-list li::before{content:"•";color:var(--muted);font-weight:700;flex-shrink:0;}

/* ---------- Подробная смета (details) ---------- */
details.spec{
  margin-top:14px;
  background:var(--bg);
  border:1px solid var(--line);
  border-radius:14px;
  padding:4px 16px;
}
details.spec summary{
  cursor:pointer;
  padding:14px 0;
  font-size:14.5px;
  font-weight:600;
  list-style:none;
  display:flex;
  align-items:center;
  justify-content:space-between;
}
details.spec summary::-webkit-details-marker{display:none;}
details.spec summary::after{
  content:"+";
  font-size:20px;
  font-weight:400;
  color:var(--muted);
}
details.spec[open] summary::after{content:"–";}
details.spec .spec-sub{
  font-size:12px;
  color:var(--muted);
  font-weight:400;
  margin-top:2px;
}
.spec-block{padding-bottom:16px;}
.spec-block h4{
  font-size:12.5px;
  text-transform:uppercase;
  letter-spacing:.04em;
  color:var(--muted);
  margin:16px 0 8px;
}
table.spec-table{
  width:100%;
  border-collapse:collapse;
  font-size:12.5px;
}
table.spec-table th{
  text-align:left;
  font-weight:600;
  color:var(--muted);
  padding:7px 5px;
  border-bottom:1px solid var(--line);
  font-size:10.5px;
  text-transform:uppercase;
  letter-spacing:.03em;
}
table.spec-table td{
  padding:8px 5px;
  border-bottom:1px dashed var(--line);
  vertical-align:top;
}
table.spec-table td a{color:var(--ink);text-decoration:underline;}
table.spec-table tr:last-child td{border-bottom:none;}
table.spec-table td.num{
  text-align:right;
  white-space:nowrap;
  font-variant-numeric:tabular-nums;
}
table.spec-table td.cond{
  color:var(--muted);
  font-size:11.5px;
}
table.spec-table tr.sum-row td{
  font-weight:700;
  border-top:2px solid var(--ink);
  border-bottom:none;
  padding-top:10px;
}
table.spec-table tr.cat-row td{
  font-weight:700;
  font-size:10.5px;
  text-transform:uppercase;
  letter-spacing:.04em;
  color:var(--amber);
  background:var(--beige);
  border-bottom:1px solid var(--line);
  padding-top:9px;
  padding-bottom:9px;
}
@media (max-width:420px){
  table.spec-table td.cond{display:none;}
}

/* ---------- Акты приёмки ---------- */
.acts-hint{font-size:12px;color:var(--muted);margin:-6px 0 14px;}
.act-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:12px 13px;
  border:1px solid var(--line);
  border-radius:12px;
  margin-bottom:9px;
  cursor:pointer;
  background:var(--bg);
}
.act-row:last-child{margin-bottom:0;}
.act-row:hover{border-color:var(--ink);}
.act-row:focus-visible{outline:2px solid var(--ink);outline-offset:2px;}
.act-row-main{display:flex;flex-direction:column;gap:3px;}
.act-row-title{font-size:13.5px;font-weight:600;color:var(--ink);}
.act-row-sub{font-size:11.5px;color:var(--muted);}
.act-row-status{
  font-size:11.5px;
  font-weight:600;
  color:var(--muted);
  white-space:nowrap;
  flex-shrink:0;
}
.act-row-status.signed{color:#2f6f4e;}

.act-modal-overlay{
  display:none;
  position:fixed;inset:0;
  background:rgba(28,28,28,0.55);
  align-items:center;
  justify-content:center;
  padding:16px;
  z-index:1000;
}
.act-modal-overlay.open{display:flex;}
.act-modal{
  background:var(--card);
  border-radius:18px;
  padding:22px;
  max-width:520px;
  width:100%;
  max-height:88vh;
  overflow-y:auto;
  position:relative;
  box-shadow:0 20px 60px rgba(0,0,0,0.25);
}
.act-modal-close{
  position:absolute;top:14px;right:14px;
  background:none;border:none;
  font-size:22px;line-height:1;
  color:var(--muted);
  cursor:pointer;
  padding:4px;
}
.act-modal h3{margin:0 0 2px;font-size:17px;}
.act-modal-sub{margin:0 0 14px;font-size:13px;color:var(--muted);}
.act-modal-items{margin:0 0 18px;padding-left:18px;font-size:13px;line-height:1.5;}
.act-modal-items li{margin-bottom:8px;}
.act-modal-form label{
  display:block;
  font-size:12px;
  color:var(--muted);
  font-weight:600;
  margin:12px 0 6px;
}
.act-modal-form input[type="text"],.act-modal-form input[type="date"]{
  width:100%;
  box-sizing:border-box;
  padding:9px 12px;
  border:1px solid var(--line);
  border-radius:8px;
  font-size:14px;
  font-family:inherit;
  background:var(--bg);
}
#act-sign-canvas{
  width:100%;
  height:140px;
  border:1px dashed var(--beige-dark);
  border-radius:8px;
  background:#fff;
  touch-action:none;
  cursor:crosshair;
}
.act-modal-form-foot{
  display:flex;
  justify-content:flex-end;
  margin-top:6px;
}
.act-link-btn{
  background:none;border:none;
  font-size:12px;
  color:var(--muted);
  text-decoration:underline;
  cursor:pointer;
  padding:4px 0;
}
.act-modal-actions{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
  margin-top:18px;
}
.act-modal-actions button{
  flex:1 1 auto;
  padding:12px 14px;
  border-radius:10px;
  border:none;
  font-size:13px;
  font-weight:600;
  cursor:pointer;
  font-family:inherit;
}
#act-download-plain{background:var(--beige);color:var(--ink);}
#act-sign-confirm{background:var(--ink);color:#fff;}

#stages-list{
  padding:14px 12px 40px;
  display:flex;
  flex-direction:column;
  gap:10px;
  max-width:640px;
  margin:0 auto;
}

/* ---------- Stage card ---------- */
.stage-card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:14px;
  padding:14px 16px;
}
.stage-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
}
.stage-name{
  font-size:15px;
  font-weight:600;
}
.stage-num{
  color:var(--muted);
  font-weight:400;
  margin-right:6px;
}
.badge{
  font-size:11.5px;
  padding:4px 10px;
  border-radius:999px;
  white-space:nowrap;
  font-weight:600;
}
.badge.not_started{background:var(--beige);color:var(--muted);}
.badge.in_progress{background:#fbe9d0;color:var(--amber);}
.badge.done{background:#ddeee2;color:var(--green);}

.stage-meta{
  font-size:12px;
  color:var(--muted);
  margin-top:4px;
}
.stage-comment{
  font-size:13.5px;
  margin-top:8px;
  color:var(--ink);
}

.photo-grid{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-top:10px;
}
.photo-thumb{
  width:76px;
  height:76px;
  object-fit:cover;
  border-radius:8px;
  border:1px solid var(--line);
  cursor:pointer;
}
.photo-wrap{position:relative;}
.photo-del{
  position:absolute;
  top:-6px;
  right:-6px;
  background:#b43c3c;
  color:#fff;
  border:none;
  border-radius:50%;
  width:20px;
  height:20px;
  font-size:12px;
  line-height:20px;
  cursor:pointer;
}

/* ---------- Admin controls ---------- */
.admin-box{
  margin-top:12px;
  padding-top:12px;
  border-top:1px dashed var(--line);
}
.status-btns{
  display:flex;
  gap:6px;
  flex-wrap:wrap;
}
.status-btn{
  flex:1;
  min-width:90px;
  border:1px solid var(--line);
  background:var(--bg);
  border-radius:8px;
  padding:7px 6px;
  font-size:12px;
  cursor:pointer;
  color:var(--ink);
}
.status-btn.active{
  background:var(--accent);
  color:#fff;
  border-color:var(--accent);
}
.comment-row{
  display:flex;
  gap:6px;
  margin-top:8px;
}
.comment-row input{
  flex:1;
  border:1px solid var(--line);
  border-radius:8px;
  padding:8px 10px;
  font-size:13px;
  background:var(--bg);
}
.comment-row button{
  border:1px solid var(--line);
  background:var(--card);
  border-radius:8px;
  padding:8px 12px;
  font-size:12.5px;
  cursor:pointer;
}
.upload-label{
  display:inline-block;
  margin-top:10px;
  background:var(--beige);
  border:1px solid var(--beige-dark);
  border-radius:8px;
  padding:8px 12px;
  font-size:12.5px;
  cursor:pointer;
}
.upload-label input{display:none;}

/* ---------- Lightbox ---------- */
.lightbox{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.9);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:50;
  padding:20px;
}
.lightbox img{
  max-width:100%;
  max-height:100%;
  border-radius:6px;
}
.lightbox-close{
  position:absolute;
  top:16px;
  right:20px;
  background:none;
  border:none;
  color:#fff;
  font-size:32px;
  cursor:pointer;
}

/* ---------- Обратная связь ---------- */
.messages-list{
  display:flex;
  flex-direction:column;
  gap:10px;
  padding:4px 4px 16px;
  min-height:120px;
}
.msg{
  max-width:82%;
  padding:9px 12px;
  border-radius:14px;
  background:var(--card);
  border:1px solid var(--line);
}
.msg-meta{
  font-size:11px;
  color:var(--muted);
  margin-bottom:3px;
}
.msg-text{
  font-size:14px;
  line-height:1.4;
  white-space:pre-wrap;
  word-break:break-word;
}
.msg.client{
  align-self:flex-start;
  background:var(--card);
}
.msg.admin{
  align-self:flex-end;
  background:var(--accent);
  border-color:var(--accent);
}
.msg.admin .msg-meta{color:#d8d4cc;}
.msg.admin .msg-text{color:#fff;}
.msg-delete-btn{
  border:none;
  background:none;
  padding:0;
  margin-left:6px;
  font-size:11px;
  cursor:pointer;
  opacity:0.6;
  vertical-align:middle;
}
.msg-delete-btn:hover{opacity:1;}
.payment-card{margin-bottom:14px;}
.payment-progress{display:flex;flex-direction:column;gap:8px;}
.payment-bar-track{
  height:14px;
  background:var(--beige);
  border-radius:999px;
  overflow:hidden;
}
.payment-bar-fill{
  height:100%;
  background:var(--accent);
  border-radius:999px;
  transition:width 0.3s ease;
}
.payment-summary{
  font-size:15px;
  font-weight:600;
}
.payment-summary span:last-child{font-weight:400;color:var(--muted);}
.payment-history{
  margin-top:12px;
  display:flex;
  flex-direction:column;
  gap:6px;
}
.payment-row{
  display:flex;
  align-items:center;
  gap:8px;
  font-size:12.5px;
  padding:6px 0;
  border-top:1px dashed var(--line);
}
.payment-row-date{color:var(--muted);white-space:nowrap;}
.payment-row-amount{font-weight:600;white-space:nowrap;}
.payment-row-comment{color:var(--muted);flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.payment-del-btn{
  border:none;
  background:none;
  padding:0;
  font-size:12px;
  cursor:pointer;
  opacity:0.6;
  margin-left:auto;
}
.payment-del-btn:hover{opacity:1;}
.payment-empty{
  color:var(--muted);
  font-size:12.5px;
  margin:8px 0 0;
}
.payment-admin{
  margin-top:14px;
  padding-top:12px;
  border-top:1px dashed var(--line);
  display:flex;
  flex-direction:column;
  gap:10px;
}
.payment-admin-row{
  display:flex;
  flex-wrap:wrap;
  align-items:center;
  gap:8px;
}
.payment-admin-row label{
  font-size:12.5px;
  color:var(--muted);
  width:100%;
}
.payment-admin-row input{
  flex:1;
  min-width:90px;
  padding:7px 9px;
  border:1px solid var(--line);
  border-radius:8px;
  font-size:13px;
}
.payment-admin-row button{
  padding:7px 14px;
  border:none;
  border-radius:8px;
  background:var(--accent);
  color:#fff;
  font-size:13px;
  font-weight:600;
  cursor:pointer;
}
.messages-empty{
  color:var(--muted);
  font-size:13px;
  text-align:center;
  padding:20px 0;
}
.message-form{
  display:flex;
  gap:8px;
  position:sticky;
  bottom:0;
  background:var(--bg);
  padding:10px 0 4px;
  border-top:1px solid var(--line);
}
.message-form input{
  flex:1;
  border:1px solid var(--line);
  border-radius:10px;
  padding:11px 12px;
  font-size:14px;
  background:var(--card);
}
.message-form button{
  border:none;
  background:var(--accent);
  color:#fff;
  border-radius:10px;
  padding:0 18px;
  font-size:13.5px;
  font-weight:600;
  cursor:pointer;
}
.msg-photo-btn{
  display:flex;
  align-items:center;
  justify-content:center;
  width:40px;
  flex-shrink:0;
  border:1px solid var(--line);
  border-radius:10px;
  background:var(--card);
  font-size:18px;
  cursor:pointer;
}
.message-photo-preview{
  position:relative;
  display:inline-block;
  margin:0 0 8px;
}
.message-photo-preview img{
  max-height:90px;
  border-radius:8px;
  display:block;
  border:1px solid var(--line);
}
.msg-photo-remove{
  position:absolute;
  top:-8px;
  right:-8px;
  width:22px;
  height:22px;
  border-radius:50%;
  border:none;
  background:var(--accent);
  color:#fff;
  font-size:13px;
  line-height:1;
  cursor:pointer;
}
.msg-photo{
  display:block;
  max-width:100%;
  max-height:220px;
  border-radius:8px;
  margin-top:6px;
  cursor:pointer;
}
.enable-push-btn{
  display:block;
  width:100%;
  padding:10px;
  margin-bottom:10px;
  border:1px solid var(--line);
  border-radius:10px;
  background:var(--card);
  font-size:14px;
  cursor:pointer;
}
