/* =========================================================
   PM CRM — styles.css
   Полная, стабильная версия
   Улучшенная mobile UX версия без ломки desktop
   ========================================================= */

/* ---------- Тема ---------- */
:root{
  --bg:#0b1220;
  --panel:#0f1b31;
  --panel-soft:#0b1324;
  --text:#e7eefc;
  --muted:#9fb0d0;
  --stroke:rgba(255,255,255,.08);
  --accent:#6ea8ff;

  --ok1:#20c997;
  --ok2:#2ecc71;
  --warn:#ffcc66;

  --shadow:0 10px 30px rgba(0,0,0,.18);
  --shadow-soft:0 8px 24px rgba(0,0,0,.22);
}

*{ box-sizing:border-box; }

html{
  -webkit-text-size-adjust:100%;
}

body{
  margin:0;
  font-family:system-ui, Segoe UI, Roboto, Arial, sans-serif;
  background:var(--bg);
  color:var(--text);
  line-height:1.4;
}

img{
  max-width:100%;
  display:block;
}

/* =========================================================
   LAYOUT
   ========================================================= */
.layout{
  display:flex;
  min-height:100vh;
}

/* ---------- Sidebar ---------- */
.sidebar{
  width:250px;
  padding:16px;
  background:#0e1628;
  border-right:1px solid var(--stroke);
}

.brand{
  font-weight:800;
  margin-bottom:16px;
}

.brand-link{
  font-weight:800;
  margin-bottom:16px;
  text-decoration:none;
  color:var(--text);
  display:inline-block;
}
.brand-link:hover{ opacity:.85; }

.nav{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.nav-item{
  color:var(--text);
  text-decoration:none;
  padding:10px 12px;
  border-radius:10px;
  transition:background .18s ease, opacity .18s ease;
}

.nav-item:hover{
  background:rgba(255,255,255,.04);
}

.nav-item.active{
  background:rgba(110,168,255,.15);
}

.logout{ margin-top:16px; }

/* ---------- Main ---------- */
.main{
  flex:1;
  padding:16px;
  display:flex;
  flex-direction:column;
  align-items:flex-start;
  min-width:0;
}

.topbar{
  display:flex;
  align-items:center;
  gap:10px;
  margin-bottom:10px;
}

.page-title{
  font-size:18px;
  font-weight:800;
  line-height:1.2;
}

.panel{
  background:var(--panel);
  padding:16px;
  border-radius:16px;
  box-shadow:var(--shadow);
  width:100%;
  max-width:950px;
  margin:0;
}

/* =========================================================
   BLOCKS
   ========================================================= */
.block{
  background:var(--panel-soft);
  border:1px solid var(--stroke);
  border-radius:14px;
  padding:14px;
  margin-bottom:14px;
}

.block:last-child{
  margin-bottom:0;
}

.block-head{
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
  margin-bottom:10px;
}

.block-title{
  font-size:20px;
  font-weight:800;
  line-height:1.2;
}

/* ---------- Метрика ---------- */
.block-metric{
  display:flex;
  align-items:center;
  gap:10px;
  width:320px;
  max-width:100%;
}

.metric-value{
  display:flex;
  align-items:center;
  gap:6px;
  font-weight:700;
  white-space:nowrap;
}

.metric-percent{
  min-width:46px;
  text-align:right;
  font-weight:700;
  white-space:nowrap;
}

.progress{
  flex:1;
  height:8px;
  background:rgba(255,255,255,.08);
  border-radius:999px;
  overflow:hidden;
}

.progress-bar{
  height:100%;
  background:linear-gradient(90deg,var(--ok1),var(--ok2));
}

/* =========================================================
   ROWS
   ========================================================= */
.rows{
  display:flex;
  flex-direction:column;
  gap:8px;
}

.row{
  display:flex;
  align-items:center;
  gap:12px;
  padding:10px;
  background:rgba(255,255,255,.03);
  border-radius:12px;
  min-width:0;
}

.avatar{
  width:36px;
  height:36px;
  border-radius:50%;
  object-fit:cover;
  flex:0 0 36px;
}

.avatar.fallback{
  background:var(--accent);
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:800;
  color:#0b1220;
}

.row-info{
  flex:1;
  margin-left:10px;
  min-width:0;
}

.row-name{
  font-weight:700;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}

.row-sub{
  font-size:12px;
  color:var(--muted);
  line-height:1.35;
  overflow:hidden;
  text-overflow:ellipsis;
}

/* ---------- Правая часть ---------- */
.row-right{
  display:flex;
  align-items:center;
  gap:10px;
  flex-shrink:0;
}

/* ===== ВРЕМЯ ЗАПУСКА БОТА ===== */
.row-time{
  display:inline-flex;
  align-items:center;
  gap:6px;
  font-size:13px;
  font-weight:700;
  color:var(--muted);
  line-height:1;
  white-space:nowrap;
}

.row-time::before{
  content:"🕒";
  font-size:12px;
  opacity:.8;
}

/* =========================================================
   TASK 1 — DESKTOP
   ========================================================= */
.row-right-task{
  display:flex;
  align-items:center;
  gap:12px;
  justify-content:flex-end;
}

.mini-progress{
  width:92px;
  height:8px;
  border-radius:999px;
  background:rgba(255,255,255,.1);
  overflow:hidden;
  border:1px solid rgba(255,255,255,.08);
  flex:0 0 92px;
}

.mini-progress-bar{
  height:100%;
  background:linear-gradient(90deg,#22c55e,#16a34a);
}

.mini-progress-text{
  min-width:42px;
  text-align:right;
  font-weight:800;
  font-size:13px;
  line-height:1;
  white-space:nowrap;
}

/* =========================================================
   BUTTONS
   ========================================================= */
.btn{
  border:1px solid var(--stroke);
  background:transparent;
  color:var(--text);
  padding:6px 10px;
  border-radius:10px;
  cursor:pointer;
  text-decoration:none;
  display:inline-flex;
  align-items:center;
  justify-content:center;
  transition:background .18s ease, border-color .18s ease, opacity .18s ease;
}

.btn.small{ font-size:12px; }

.btn:hover{
  background:rgba(255,255,255,.04);
}

.btn:active{
  transform:translateY(1px);
}

/* =========================================================
   COLLAPSIBLE
   ========================================================= */
.hidden{ display:none!important; }

.toggle-title{
  display:flex;
  align-items:flex-start;
  gap:8px;
  cursor:pointer;
}

.toggle-title .arrow{
  flex:0 0 auto;
  line-height:1;
  margin-top:6px;
}

.arrow{ transition:transform .2s; }

.toggle-title.open .arrow{ transform:rotate(90deg); }

/* =========================================================
   BURGER
   ========================================================= */
.burger{
  display:none;
  border:1px solid var(--stroke);
  background:transparent;
  color:var(--text);
  padding:8px 10px;
  border-radius:10px;
}

.overlay{
  display:none;
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.45);
  z-index:40;
}

.overlay.show{ display:block; }

/* =========================================================
   CHAT GLOBAL HELPERS
   ========================================================= */
.chat-grid{
  min-width:0;
}

.chat-left,
.chat-right,
.chat-messages,
.chat-dialogs{
  min-width:0;
}

/* =========================================================
   CRM KPI cards
   ========================================================= */
.kpi-grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(260px, 300px));
  gap:14px;
  justify-content:start;
}

.kpi-card{
  border-radius:16px;
  border:1px solid var(--stroke);
  background:rgba(255,255,255,.03);
  padding:14px;
  box-shadow:var(--shadow);
}

.kpi-title{
  color:var(--muted);
  font-weight:800;
  font-size:13px;
}

.kpi-value{
  margin-top:6px;
  font-size:34px;
  font-weight:900;
  line-height:1.1;
}

.kpi-card--paid .kpi-value{ color:var(--ok2); }

.kpi-sum{
  margin-top:10px;
  display:flex;
  align-items:baseline;
  justify-content:space-between;
  gap:10px;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.035);
}

.kpi-sum__label{
  color:var(--muted);
  font-weight:800;
  font-size:12px;
  text-transform:uppercase;
}

.kpi-sum__value{
  font-weight:900;
  font-size:18px;
  color:var(--accent);
}

.kpi-sum--paid .kpi-sum__value{ color:var(--ok2); }

@media (max-width:720px){
  .kpi-grid{ grid-template-columns:1fr; }
}

/* =========================================================
   HOME (главная): карточки разделов + разные цвета
   ========================================================= */
.home-grid{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:14px;
}

.home-card{
  border-radius:16px;
  border:1px solid var(--stroke);
  background:rgba(255,255,255,.03);
  padding:14px;
  display:flex;
  gap:12px;
  align-items:flex-start;
  box-shadow:var(--shadow);
}

.home-card__icon{
  width:42px;
  height:42px;
  border-radius:14px;
  background:rgba(255,255,255,.05);
  border:1px solid rgba(255,255,255,.08);
  display:flex;
  align-items:center;
  justify-content:center;
  flex:0 0 42px;
  color:var(--accent);
}

.home-card__body{ min-width:0; }

.home-card__title{
  font-weight:900;
  font-size:16px;
  line-height:1.2;
}

.home-card__desc{
  margin-top:6px;
  color:var(--muted);
  font-size:13px;
  line-height:1.45;
}

.home-card__btn{
  margin-top:12px;
  width:max-content;
}

.home-card--chats{
  background:rgba(110,168,255,.18);
  border-color:rgba(110,168,255,.45);
}

.home-card--stats{
  background:rgba(32,201,151,.14);
  border-color:rgba(32,201,151,.35);
}

.home-card--crm{
  background:rgba(255,204,102,.14);
  border-color:rgba(255,204,102,.35);
}

.home-card--auto{
  background:rgba(167,139,250,.14);
  border-color:rgba(167,139,250,.35);
}

@media (max-width:900px){
  .home-grid{
    grid-template-columns:1fr;
  }
}

/* =========================================================
   MOBILE ≤ 900px
   ========================================================= */
@media (max-width:900px){

  .layout{
    display:block;
  }

  .main{
    padding:14px;
    align-items:stretch;
  }

  .topbar{
    gap:10px;
    margin-bottom:12px;
  }

  .page-title{
    font-size:20px;
  }

  .panel{
    max-width:100%;
    padding:14px;
    border-radius:18px;
  }

  .block{
    padding:14px;
    border-radius:16px;
  }

  .block-head{
    flex-direction:column;
    align-items:flex-start;
    gap:10px;
  }

  .block-title{
    font-size:21px;
  }

  .block-metric{
    width:100%;
  }

  .metric-value{
    font-size:15px;
  }

  .metric-percent{
    min-width:42px;
    font-size:14px;
  }

  .progress{
    height:10px;
  }

  .burger{
    display:inline-flex;
  }

  .sidebar{
    position:fixed;
    inset:0 auto 0 0;
    width:260px;
    transform:translateX(-110%);
    transition:.25s;
    z-index:50;
    box-shadow:var(--shadow-soft);
  }

  .sidebar.open{ transform:none; }

  .row{
    padding:12px;
    border-radius:14px;
  }

  .row-name{
    font-size:15px;
  }

  .row-sub{
    font-size:13px;
  }

  .btn{
    min-height:38px;
    padding:8px 12px;
    border-radius:12px;
  }

  .avatar{
    width:40px;
    height:40px;
    flex:0 0 40px;
  }

  .home-card{
    padding:16px;
    border-radius:18px;
    gap:14px;
  }

  .home-card__icon{
    width:44px;
    height:44px;
    border-radius:14px;
    flex:0 0 44px;
  }

  .home-card__title{
    font-size:18px;
  }

  .home-card__desc{
    font-size:14px;
    line-height:1.5;
  }
}

/* =========================================================
   TASK 1 — MOBILE ≤ 560px
   ========================================================= */
@media (max-width:560px){

  .main{
    padding:12px;
  }

  .panel{
    padding:12px;
    border-radius:18px;
  }

  .block{
    padding:14px;
  }

  .page-title{
    font-size:22px;
    line-height:1.2;
  }

  .block-title{
    font-size:22px;
    line-height:1.2;
  }

  #task1-list .row{
    display:grid;
    grid-template-columns:36px minmax(0, 1fr) max-content;
    grid-template-areas:
      "avatar info btn"
      "avatar bar  bar";
    column-gap:12px;
    row-gap:10px;
    align-items:center;
  }

  #task1-list .row .avatar{ grid-area:avatar; }

  #task1-list .row .row-info{
    grid-area:info;
    margin-left:0;
    min-width:0;
    overflow:hidden;
  }

  #task1-list .row .row-right-task{ display:contents; }

  #task1-list .row .btn-chat{
    grid-area:btn;
    justify-self:end;
    white-space:nowrap;
  }

  #task1-list .row .mini-progress{
    grid-area:bar;
    width:100%;
    height:7px;
    border-radius:999px;
    background:rgba(255,255,255,.1);
    overflow:hidden;
    border:1px solid rgba(255,255,255,.08);
    flex:none;
    position:relative;
    z-index:1;
  }

  #task1-list .row .mini-progress-bar{
    height:100%;
    border-radius:999px;
  }

  #task1-list .row .mini-progress-text{
    grid-area:bar;
    justify-self:end;
    align-self:center;
    min-width:42px;
    text-align:right;
    font-size:13px;
    font-weight:700;
    line-height:1;
    white-space:nowrap;
    z-index:2;
    pointer-events:none;
    padding:2px 6px;
    border-radius:10px;
    background:rgba(11,18,32,.75);
    border:1px solid rgba(255,255,255,.08);
  }
}

/* =========================================================
   EXTRA SMALL ≤ 420px
   ========================================================= */
@media (max-width:420px){

  .main{
    padding:10px;
  }

  .topbar{
    margin-bottom:10px;
  }

  .page-title{
    font-size:21px;
  }

  .panel{
    padding:10px;
    border-radius:16px;
  }

  .block{
    padding:12px;
    border-radius:14px;
  }

  .block-title{
    font-size:20px;
  }

  .row{
    gap:10px;
    padding:10px;
  }

  .row-right{
    gap:8px;
  }

  .btn{
    min-height:36px;
    padding:8px 10px;
    font-size:13px;
  }

  .metric-percent{
    min-width:38px;
    font-size:13px;
  }
}

/* =========================================================
   COMMON UI HELPERS FOR NEW PAGES
   ========================================================= */

.card{
  background:var(--panel);
  border:1px solid var(--stroke);
  box-shadow:var(--shadow);
}

.input{
  width:100%;
  min-height:42px;
  padding:10px 12px;
  border-radius:12px;
  border:1px solid var(--stroke);
  background:rgba(255,255,255,.03);
  color:var(--text);
  outline:none;
  transition:border-color .18s ease, background .18s ease, box-shadow .18s ease;
}

.input::placeholder{
  color:var(--muted);
  opacity:1;
}

.input:focus{
  border-color:rgba(110,168,255,.55);
  background:rgba(255,255,255,.05);
  box-shadow:0 0 0 3px rgba(110,168,255,.12);
}

select.input{
  appearance:none;
  -webkit-appearance:none;
  -moz-appearance:none;
}

textarea.input{
  min-height:110px;
  resize:vertical;
}

.btn.ghost{
  background:transparent;
  border:1px solid var(--stroke);
  color:var(--text);
}

.btn.ghost:hover{
  background:rgba(255,255,255,.04);
}