@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@500;700;800&family=Inter:wght@400;500;600&display=swap');

:root{
  --bg: #0F1720;
  --panel: #16212C;
  --panel-2: #1C2A37;
  --border: #263341;
  --text: #E7EDF3;
  --muted: #8DA0B3;
  --accent: #3FE08F;
  --accent-dim: #23483A;
  --warn: #E8B339;
  --warn-dim: #453A20;
  --info: #4FA8E8;
  --info-dim: #1F3A4D;
  --danger: #E8615D;
  --danger-dim: #452427;
  --radius: 10px;
  --font-head: 'Manrope', 'Segoe UI', sans-serif;
  --font-body: 'Inter', 'Segoe UI', sans-serif;
}

*{ box-sizing: border-box; }

@media (prefers-reduced-motion: reduce){
  *{ animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

html, body{
  margin:0; padding:0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

a{ color: inherit; }

.layout{
  display: grid;
  grid-template-columns: 236px 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar{
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.sidebar .brand{ display:block; }
.sidebar nav{ display:flex; flex-direction:column; gap: 2px; flex:1; }
.sidebar nav a{
  display:flex;
  align-items:center;
  gap: 10px;
  text-decoration:none;
  color: var(--muted);
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 14px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border-left: 3px solid transparent;
}
.sidebar nav a .nav-icon{ flex-shrink:0; }
.sidebar nav a:hover{ color: var(--text); background: var(--panel-2); }
.sidebar nav a.active{
  color: var(--text);
  background: var(--panel-2);
  border-left-color: var(--accent);
}
.sidebar .user-box{
  border-top: 1px solid var(--border);
  padding-top: 14px;
  font-size: 13px;
  color: var(--muted);
}
.sidebar .user-box strong{ color: var(--text); display:block; font-family: var(--font-head); }
.sidebar .user-box .role-tag{
  display:inline-block; margin-top:4px;
  font-size: 11px; letter-spacing: .02em;
  color: var(--accent);
}
.sidebar .logout-link{ display:inline-block; margin-top: 10px; color: var(--muted); font-size: 13px; text-decoration: underline; }

/* ---------- Main ---------- */
.main{ padding: 30px 36px 60px; max-width: 1100px; }
.topbar{ display:flex; align-items:baseline; justify-content:space-between; margin-bottom: 26px; gap: 16px; flex-wrap: wrap; }
.topbar h1{ font-family: var(--font-head); font-size: 24px; margin: 0; }
.topbar .sub{ color: var(--muted); font-size: 13px; margin-top: 4px; }

.panel{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
}
.panel + .panel{ margin-top: 18px; }

/* ---------- Buttons ---------- */
.btn{
  display:inline-flex; align-items:center; gap:8px;
  font-family: var(--font-head); font-weight: 700; font-size: 13.5px;
  padding: 9px 16px; border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer; text-decoration:none;
}
.btn:hover{ border-color: #35485a; }
.btn-accent{ background: var(--accent); border-color: var(--accent); color: #08331F; }
.btn-accent:hover{ filter: brightness(1.05); }
.btn-danger{ background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover{ background: var(--danger-dim); }
.btn-ghost{ background: transparent; }
.btn-sm{ padding: 6px 11px; font-size: 12.5px; }

/* ---------- Forms ---------- */
form .field{ margin-bottom: 15px; }
label{ display:block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; font-family: var(--font-head); font-weight: 700; letter-spacing: .01em; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], textarea, select{
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: var(--font-body);
}
input:focus, textarea:focus, select:focus{
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea{ resize: vertical; min-height: 70px; }
.form-grid{ display:grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.form-section-title{ font-family: var(--font-head); font-weight: 800; font-size: 13px; color: var(--accent); margin: 22px 0 12px; padding-top: 14px; border-top: 1px solid var(--border); }
.form-section-title:first-child{ border-top: none; padding-top: 0; margin-top: 0; }
.checkbox-row{ display:flex; align-items:center; gap: 8px; }
.checkbox-row input{ width:auto; }
.checkbox-row label{ margin:0; }
.hint{ color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---------- Tables / lists ---------- */
table{ width:100%; border-collapse: collapse; }
th{ text-align:left; font-family: var(--font-head); font-size: 11.5px; text-transform: none; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
td{ padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td{ border-bottom: none; }
.row-actions{ display:flex; gap: 8px; justify-content:flex-end; }
.empty-state{ color: var(--muted); padding: 30px 10px; text-align:center; }
.client-link{ font-weight:600; text-decoration:none; }
.client-link:hover{ text-decoration:underline; }
.muted{ color: var(--muted); }

/* ---------- Stat cards ---------- */
.stat-grid{ display:grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat-card{ background: var(--panel); border:1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.stat-card .num{ font-family: var(--font-head); font-size: 28px; font-weight: 800; }
.stat-card .label{ color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.stat-card.accent .num{ color: var(--accent); }
.stat-card.warn .num{ color: var(--warn); }
.stat-card.danger .num{ color: var(--danger); }

/* ---------- Клиенты: карточки, сгруппированные по фирме ---------- */
/* ---------- Панель поиска/фильтров (Клиенты) ---------- */
.filter-bar{
  display:flex; gap: 10px; align-items:center; flex-wrap:wrap;
  margin-bottom: 18px; padding: 14px 16px;
}
.filter-bar input[type=text], .filter-bar select{ width:auto; }

.company-block{ margin-bottom: 22px; }
.company-header{
  display:flex; align-items:baseline; gap:10px;
  font-family: var(--font-head); font-size: 14px;
  padding: 4px 2px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.client-card-grid{
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.client-card{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display:flex; flex-direction:column; gap: 10px;
}
.client-card-id .account-number{ font-family: var(--font-head); font-weight:800; font-size: 15px; }
.client-card-id .client-fio{ color: var(--muted); font-size: 12.5px; margin-top:2px; }
.client-card-id .tag{ margin-top: 6px; margin-right:0; }
.client-card-money{ display:flex; flex-direction:column; gap: 4px; font-size: 13.5px; border-top:1px solid var(--border); border-bottom:1px solid var(--border); padding: 8px 0; }
.money-row{ display:flex; justify-content:space-between; gap: 10px; }
.client-card-status{ display:flex; flex-direction:column; gap: 6px; align-items:flex-start; }
.client-card-status .mark-paid-form{ width:100%; }
.client-card-status .mark-paid-form button{ width:100%; justify-content:center; }
.client-card-actions{ display:flex; gap:8px; margin-top:auto; padding-top: 4px; }
.client-card-actions .btn{ flex:1; justify-content:center; }

/* ---------- Диалог с тех. данными (нативный <dialog>) ---------- */
dialog.tech-dialog{
  border:none; border-radius: var(--radius);
  background: var(--panel); color: var(--text);
  padding: 20px 22px; max-width: 420px; width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
dialog.tech-dialog:not([open]){ display: none; }
dialog.tech-dialog::backdrop{ background: rgba(4,8,12,.6); }
dialog.tech-dialog h3{ margin:0 0 14px; font-family: var(--font-head); }

/* ---------- Лента дел (дашборд) ---------- */
.feed-list{ display:flex; flex-direction:column; gap: 10px; }
.feed-item{
  display:flex; align-items:center; justify-content:space-between; gap: 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  flex-wrap: wrap;
}
.feed-item.feed-danger{ border-left-color: var(--danger); }
.feed-item.feed-warning{ border-left-color: var(--warn); }
.feed-item-text{ min-width: 220px; flex: 1; }
.feed-item-title{ font-family: var(--font-head); font-weight:700; font-size: 14px; text-decoration:none; color: var(--text); }
.feed-item-title:hover{ text-decoration:underline; }
.feed-item-subtitle{ font-size: 12.5px; margin-top: 3px; }
.feed-item-actions{ display:flex; gap:8px; flex-shrink:0; }

.progress-bar{
  width:100%; height:8px; border-radius:999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  overflow:hidden;
}
.progress-fill{
  height:100%;
  background: linear-gradient(90deg, var(--warn), var(--accent));
  border-radius: 999px;
  transition: width .4s ease;
}

/* ---------- Signal-bar status indicator ----------
   Вместо цветных точек статус показывается кластером столбиков,
   как индикатор уровня сигнала: чем "хуже" статус, тем меньше столбиков активно. */
.signal{
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
  vertical-align: middle;
}
.signal i{
  display:block;
  width: 4px;
  background: var(--border);
  border-radius: 1px;
}
.signal i:nth-child(1){ height: 40%; }
.signal i:nth-child(2){ height: 65%; }
.signal i:nth-child(3){ height: 100%; }
.status-label{ display:inline-flex; align-items:center; gap:8px; font-weight:600; font-size: 13px; }

.status-paid .signal i{ background: var(--accent); }
.status-paid .status-text{ color: var(--accent); }

.status-pending .signal i:nth-child(1),
.status-pending .signal i:nth-child(2){ background: var(--warn); }
.status-pending .status-text{ color: var(--warn); }

.status-overdue .signal i:nth-child(1){ background: var(--danger); }
.status-overdue .status-text{ color: var(--danger); }

/* Момент подтверждения оплаты: столбики "дозаполняются" и появляется галочка. */
.status-just-paid .signal i{
  animation: fillBar 0.5s ease forwards;
}
.status-just-paid .signal i:nth-child(2){ animation-delay: .08s; }
.status-just-paid .signal i:nth-child(3){ animation-delay: .16s; }
@keyframes fillBar{
  from{ background: var(--border); transform: scaleY(.4); transform-origin: bottom; }
  to{ background: var(--accent); transform: scaleY(1); }
}
.check-pop{
  display:inline-block; width:16px; height:16px; margin-left: 2px;
}
.check-pop path{
  stroke: var(--accent);
  stroke-width: 3;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 20;
  stroke-dashoffset: 20;
  animation: drawCheck .35s ease forwards .3s;
}
@keyframes drawCheck{ to{ stroke-dashoffset: 0; } }

/* ---------- Flash toasts ----------
   Один согласованный момент появления — выезжают сверху один раз при загрузке страницы. */
.toast-stack{
  position: fixed; top: 18px; right: 18px; z-index: 50;
  display:flex; flex-direction:column; gap: 10px;
  max-width: 340px;
}
.toast{
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 13.5px;
  animation: toastIn .35s cubic-bezier(.2,.8,.3,1);
}
.toast.error, .toast.warning{ border-left-color: var(--danger); }
.toast.info{ border-left-color: var(--warn); }
@keyframes toastIn{
  from{ opacity:0; transform: translateY(-10px); }
  to{ opacity:1; transform: translateY(0); }
}

/* ---------- Auth pages ---------- */
.auth-wrap{
  min-height: 100vh; display:flex; align-items:center; justify-content:center;
  padding: 20px;
}
.auth-card{ width: 100%; max-width: 380px; }
.auth-card .brand{ display:flex; justify-content:center; margin-bottom: 22px; }
.auth-card h1{ font-family: var(--font-head); font-size: 19px; text-align:center; margin: 0 0 20px; }
.auth-card .switch{ text-align:center; margin-top: 16px; font-size: 13px; color: var(--muted); }
.auth-card .switch a{ color: var(--accent); text-decoration:none; }

.badge-pill{
  display:inline-block; font-size: 11px; font-family: var(--font-head); font-weight:700;
  padding: 3px 9px; border-radius: 999px; background: var(--warn-dim); color: var(--warn);
}

/* ---------- Тип работы с фирмой ---------- */
.tag{
  display:inline-block; font-size: 11.5px; font-family: var(--font-head); font-weight:700;
  padding: 3px 10px; border-radius: 999px; margin-right: 4px; white-space: nowrap;
}
.tag-service{ background: var(--accent-dim); color: var(--accent); }
.tag-one_time{ background: var(--info-dim); color: var(--info); }
.tag-project-awaiting{ background: var(--warn-dim); color: var(--warn); }
.tag-project-active{ background: var(--info-dim); color: var(--info); }
.tag-project-declined{ background: var(--danger-dim); color: var(--danger); }
.tag-project-done{ background: var(--accent-dim); color: var(--accent); }

/* ---------- Технические данные: быстро открыть при ремонте ---------- */
.tech-panel{
  background: var(--panel);
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  padding: 4px 18px;
  margin-bottom: 18px;
}
.tech-panel summary{
  cursor: pointer;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 13.5px;
  color: var(--warn);
  padding: 12px 0;
  list-style: none;
}
.tech-panel summary::-webkit-details-marker{ display:none; }
.tech-notes{
  white-space: pre-wrap;
  font-family: 'Inter', monospace;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 0 0 14px;
}

@media (max-width: 820px){
  .layout{ grid-template-columns: 1fr; }
  .sidebar{ flex-direction:row; align-items:center; overflow-x:auto; }
  .sidebar nav{ flex-direction:row; }
  .sidebar .user-box{ display:none; }
  .form-grid{ grid-template-columns: 1fr; }
  .stat-grid{ grid-template-columns: 1fr 1fr; }
  .main{ padding: 20px; }
}
