:root{
  --charcoal:#212123; --red:#dd4531; --red-dim:#c33d2b;
  --bg:#f3f1ee; --card:#ffffff; --line:#e4e0da; --text:#212123; --text-dim:#6d6b68;
  --success:#2f9e6e; --amber:#c98a2c; --danger:#c62828;
  --radius:6px; --side:220px; --bar:58px; --nav-h:58px;
}
@media (prefers-color-scheme: dark){
  :root{ --bg:#17171a; --card:#212124; --line:#333335; --text:#efeeec; --text-dim:#a3a19d; }
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; font-family:'Vazirmatn',Tahoma,'Segoe UI',sans-serif; background:var(--bg); color:var(--text);
  -webkit-font-smoothing:antialiased; font-size:14px; line-height:1.7;
}
a{color:inherit; text-decoration:none}
button,input,select,textarea{font-family:inherit; font-size:inherit; color:inherit}
.ic{flex-shrink:0}
.muted{color:var(--text-dim)}
.inline{display:inline}

/* ---------- shell ---------- */
.app{display:flex; height:100vh; height:100dvh}
.sidebar{
  width:var(--side); flex-shrink:0; background:var(--charcoal); color:#efeeec;
  display:flex; flex-direction:column; padding:20px 14px; overflow-y:auto;
}
.side-brand{font-weight:800; font-size:21px; letter-spacing:.5px}
.side-brand span{color:var(--red)}
.side-company{font-size:11px; color:#9c9b98; margin-bottom:24px}
.nav-item{
  display:flex; align-items:center; gap:10px; padding:10px 12px; border-radius:var(--radius);
  font-size:13.5px; color:#d7d6d3; margin-bottom:4px; border-right:3px solid transparent;
}
.nav-item:hover{background:rgba(255,255,255,.06)}
.nav-item.active{background:rgba(221,69,49,.18); color:#fff; border-right-color:var(--red)}
.nav-badge{margin-right:auto; background:var(--red); color:#fff; font-size:10.5px; padding:0 7px; border-radius:10px; line-height:18px; min-width:18px; text-align:center}

.main{flex:1; display:flex; flex-direction:column; min-width:0; min-height:0}
.topbar{
  height:var(--bar); flex-shrink:0; display:flex; align-items:center; justify-content:space-between;
  padding:0 20px; background:var(--card); border-bottom:1px solid var(--line);
}
.topbar-title{font-size:15.5px; font-weight:700; line-height:1.3}
.topbar-date{font-size:11.5px; color:var(--text-dim)}
.topbar-user{display:flex; align-items:center; gap:10px}
.who{text-align:left}
.who-name{font-size:13px; font-weight:600; line-height:1.3}
.who-role{font-size:11px; color:var(--text-dim)}
.content{flex:1; overflow:auto; padding:22px; min-height:0}
.content.chat, .chat-page .content{padding:14px 18px; overflow:hidden}

.avatar{
  width:36px; height:36px; border-radius:50%; background:var(--charcoal); color:#fff; flex-shrink:0;
  display:flex; align-items:center; justify-content:center; font-size:14px; font-weight:700; position:relative;
}
.avatar.sm{width:30px; height:30px; font-size:12px}
.topbar .avatar{width:32px; height:32px; font-size:13px}
.avatar.online::after, .avatar .dot-online{
  content:''; position:absolute; bottom:0; left:0; width:10px; height:10px; border-radius:50%;
  background:var(--success); border:2px solid var(--card);
}
.icon-btn{
  background:none; border:1px solid var(--line); color:var(--text-dim); width:34px; height:34px;
  border-radius:var(--radius); display:inline-flex; align-items:center; justify-content:center; cursor:pointer;
}
.icon-btn:hover{border-color:var(--red); color:var(--red)}

/* ---------- common ---------- */
.flash{padding:10px 14px; border-radius:var(--radius); margin-bottom:16px; font-size:13px; border:1px solid}
.flash.ok{background:rgba(47,158,110,.12); color:var(--success); border-color:rgba(47,158,110,.3)}
.flash.err{background:rgba(198,40,40,.1); color:var(--danger); border-color:rgba(198,40,40,.3)}
.panel{background:var(--card); border:1px solid var(--line); border-radius:var(--radius); overflow:hidden; margin-bottom:22px}
.panel.pad{padding:20px}
.panel.narrow{max-width:520px}
.h2{font-size:15px; margin:0 0 14px}
.section-head{display:flex; align-items:center; justify-content:space-between; margin-bottom:10px}
.section-head h2{font-size:14.5px; margin:0}
.link{font-size:12.5px; color:var(--red)}
.empty-hint{padding:34px 20px; text-align:center; color:var(--text-dim); font-size:13px}
.kv{display:flex; justify-content:space-between; padding:8px 0; border-bottom:1px solid var(--line)}
.kv:last-child{border-bottom:0}
.kv span{color:var(--text-dim)}

.stat-grid{display:grid; grid-template-columns:repeat(auto-fit,minmax(140px,1fr)); gap:12px; margin-bottom:24px}
.stat-card{background:var(--card); border:1px solid var(--line); border-right:4px solid var(--red); border-radius:var(--radius); padding:14px 16px}
.stat-card.success{border-right-color:var(--success)}
.stat-card.amber{border-right-color:var(--amber)}
.stat-card.danger{border-right-color:var(--danger)}
.stat-card .num{font-size:26px; font-weight:800; line-height:1.3}
.stat-card .lbl{font-size:12.5px; color:var(--text-dim)}
.two-col{display:grid; grid-template-columns:1fr 1fr; gap:20px}

.item{display:flex; align-items:center; gap:12px; padding:12px 14px; border-bottom:1px solid var(--line); font-size:13.5px}
.item:last-child{border-bottom:0}
.item-link:hover{background:var(--bg)}
.item-title{flex:1; min-width:0}
.item-sub{font-size:11.5px; color:var(--text-dim); margin-top:1px}

.badge{font-size:11px; padding:1px 9px; border-radius:20px; font-weight:600; flex-shrink:0; white-space:nowrap}
.badge.pending{background:rgba(201,138,44,.15); color:var(--amber)}
.badge.doing{background:rgba(221,69,49,.12); color:var(--red)}
.badge.done{background:rgba(47,158,110,.15); color:var(--success)}
.overdue{color:var(--danger); font-weight:600}

.team-row{display:grid; grid-template-columns:2fr 1fr 1fr 1fr; gap:8px; padding:11px 14px; border-bottom:1px solid var(--line); align-items:center; font-size:13.5px}
.team-row:last-child{border-bottom:0}
.team-head{background:var(--bg); font-size:12px; color:var(--text-dim); font-weight:600}

/* ---------- forms & buttons ---------- */
.field{margin-bottom:12px}
.field label{display:block; font-size:12px; color:var(--text-dim); margin-bottom:4px}
.field input,.field select,.field textarea,.inline-form input,.room-search input{
  width:100%; padding:9px 11px; border:1px solid var(--line); border-radius:var(--radius); background:var(--bg); color:var(--text);
}
.field input:focus,.field select:focus,.field textarea:focus,.room-search input:focus,.chat-input-bar textarea:focus{outline:none; border-color:var(--red)}
.btn{display:inline-block; padding:9px 18px; border-radius:var(--radius); border:1px solid var(--line); background:var(--bg); font-weight:600; cursor:pointer}
.btn-primary{background:var(--red); border-color:var(--red); color:#fff}
.btn-primary:hover{background:var(--red-dim)}
.btn-block{width:100%; padding:11px}
.btn-sm{padding:5px 12px; font-size:12.5px}
.btn-link{background:none; border:0; padding:2px 4px; color:var(--text-dim); font-size:12.5px; cursor:pointer}
.btn-link:hover{color:var(--red)}
.btn-link.danger:hover{color:var(--danger)}

.add-panel summary{padding:12px 16px; cursor:pointer; font-weight:600; display:flex; align-items:center; gap:8px; list-style:none}
.add-panel summary::-webkit-details-marker{display:none}
.add-panel[open] summary{border-bottom:1px solid var(--line)}
.add-form{display:grid; grid-template-columns:repeat(auto-fit,minmax(200px,1fr)); gap:0 14px; padding:16px}
.add-form .wide{grid-column:1/-1}
.add-form .actions{align-self:end}

.chips{display:flex; flex-wrap:wrap; gap:8px; margin-bottom:14px}
.chip{border:1px solid var(--line); background:var(--card); padding:5px 14px; border-radius:20px; font-size:12.5px; color:var(--text-dim)}
.chip.active{background:var(--charcoal); border-color:var(--charcoal); color:#fff}

/* ---------- tasks ---------- */
.task-row{display:flex; align-items:flex-start; gap:14px; padding:14px 16px; border-bottom:1px solid var(--line); border-right:4px solid var(--amber)}
.task-row:last-child{border-bottom:0}
.task-row.st-doing{border-right-color:var(--red)}
.task-row.st-done{border-right-color:var(--success)}
.task-row.st-done .task-name{text-decoration:line-through; color:var(--text-dim)}
.task-main{flex:1; min-width:0}
.task-name{font-weight:600; font-size:14px}
.task-desc{font-size:12.5px; color:var(--text-dim); margin-top:2px; overflow-wrap:anywhere}
.task-meta{display:flex; flex-wrap:wrap; gap:4px 16px; font-size:11.5px; color:var(--text-dim); margin-top:6px}
.task-actions{display:flex; flex-direction:column; align-items:flex-end; gap:4px; flex-shrink:0}
.status-select{padding:4px 8px; border:1px solid var(--line); border-radius:20px; background:var(--bg); font-size:12px; cursor:pointer}
.status-select.done{color:var(--success)} .status-select.doing{color:var(--red)} .status-select.pending{color:var(--amber)}

/* ---------- users ---------- */
.user-item{display:flex; align-items:center; gap:14px; padding:14px 16px; border-bottom:1px solid var(--line); flex-wrap:wrap}
.user-item:last-child{border-bottom:0}
.user-item.inactive{opacity:.55}
.user-main{flex:1; min-width:200px}
.uname{font-weight:600}
.tag{font-size:10.5px; padding:0 8px; border-radius:20px; background:rgba(221,69,49,.12); color:var(--red); margin-right:6px; font-weight:600}
.tag.off{background:rgba(109,107,104,.18); color:var(--text-dim)}
.user-actions{display:flex; align-items:center; gap:6px; flex-wrap:wrap}
details.mini summary{cursor:pointer; font-size:12.5px; color:var(--text-dim); list-style:none; padding:2px 4px}
details.mini summary::-webkit-details-marker{display:none}
details.mini summary:hover{color:var(--red)}
.inline-form{display:flex; gap:6px; margin-top:6px}
.inline-form input{width:150px; padding:5px 8px}

/* ---------- chat ---------- */
.msg-layout{display:flex; height:100%; border:1px solid var(--line); border-radius:var(--radius); overflow:hidden; background:var(--card)}
.room-side{width:280px; flex-shrink:0; border-left:1px solid var(--line); display:flex; flex-direction:column; min-height:0}
.room-search{padding:10px; border-bottom:1px solid var(--line)}
.room-list{flex:1; overflow-y:auto}
.contact{display:flex; align-items:center; gap:10px; padding:11px 12px; cursor:pointer; border-bottom:1px solid var(--line)}
.contact:hover{background:var(--bg)}
.contact.active{background:rgba(221,69,49,.08); box-shadow:inset -3px 0 0 var(--red)}
.cinfo{flex:1; min-width:0}
.cname{font-size:13px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis}
.clast{font-size:11.5px; color:var(--text-dim); white-space:nowrap; overflow:hidden; text-overflow:ellipsis}
.room-label{padding:8px 12px 4px; font-size:11px; color:var(--text-dim); font-weight:600; background:var(--bg)}

.chat-area{flex:1; display:flex; flex-direction:column; min-width:0; min-height:0}
.chat-head{display:flex; align-items:center; gap:10px; padding:10px 16px; border-bottom:1px solid var(--line); flex-shrink:0}
.chat-head .back{display:none}
.chat-title{font-weight:700; font-size:14px; line-height:1.3}
.chat-sub{font-size:11.5px; color:var(--text-dim)}
.chat-body{flex:1; overflow-y:auto; padding:16px; display:flex; flex-direction:column; gap:8px; min-height:0; background:var(--bg)}
.chat-empty{margin:auto; color:var(--text-dim); font-size:13px}
.date-sep{align-self:center; font-size:11px; color:var(--text-dim); background:var(--card); border:1px solid var(--line); padding:0 12px; border-radius:20px; margin:6px 0}
.bubble{max-width:72%; padding:8px 13px; border-radius:12px; font-size:13.5px; line-height:1.8; overflow-wrap:anywhere}
.bubble .txt{white-space:pre-wrap}
.bubble .from{font-size:11.5px; font-weight:700; color:var(--red); margin-bottom:1px}
.bubble .meta{font-size:10px; opacity:.6; margin-top:2px; text-align:left}
.bubble.in{align-self:flex-end; background:var(--card); border:1px solid var(--line); border-bottom-left-radius:3px}
.bubble.out{align-self:flex-start; background:var(--red); color:#fff; border-bottom-right-radius:3px}
.chat-input-bar{display:flex; align-items:flex-end; gap:8px; padding:10px 12px; border-top:1px solid var(--line); flex-shrink:0; background:var(--card)}
.chat-input-bar textarea{
  flex:1; resize:none; max-height:120px; border:1px solid var(--line); border-radius:18px; padding:8px 15px;
  background:var(--bg); line-height:1.7;
}
.send-btn{background:var(--red); color:#fff; border:0; width:38px; height:38px; border-radius:50%; cursor:pointer; display:flex; align-items:center; justify-content:center; flex-shrink:0}
.send-btn .ic{transform:scaleX(-1)}
.send-btn:hover{background:var(--red-dim)}

/* ---------- login ---------- */
.login-body{background:linear-gradient(160deg,#212123 0%,#17171a 100%)}
.login-wrap{min-height:100vh; min-height:100dvh; display:flex; align-items:center; justify-content:center; padding:24px; position:relative; overflow:hidden}
.login-pattern{position:absolute; inset:0; width:100%; height:100%; opacity:.14; pointer-events:none}
.login-box{position:relative; z-index:1; width:100%; max-width:380px; background:var(--card); border:1px solid var(--line); border-radius:var(--radius); padding:34px 28px}
.brand-mark{font-weight:800; font-size:28px; text-align:center; letter-spacing:.5px}
.brand-mark span{color:var(--red)}
.login-sub{color:var(--text-dim); font-size:13px; text-align:center; margin:4px 0 22px}
.login-note{margin-top:16px; font-size:11.5px; color:var(--text-dim); text-align:center}
.login-body .flash{margin-bottom:14px}

::-webkit-scrollbar{width:8px; height:8px}
::-webkit-scrollbar-thumb{background:var(--line); border-radius:8px}

/* ---------- mobile ---------- */
@media (max-width:820px){
  .app{flex-direction:column-reverse}
  .sidebar{
    width:100%; height:calc(var(--nav-h) + env(safe-area-inset-bottom,0px)); flex-direction:row; padding:0 6px env(safe-area-inset-bottom,0px);
    justify-content:space-around; align-items:stretch; overflow:hidden; border-top:1px solid #000;
  }
  .side-brand,.side-company{display:none}
  .nav-item{flex-direction:column; justify-content:center; gap:2px; font-size:10.5px; padding:6px 4px; margin:0; flex:1; border-right:0; border-top:3px solid transparent; border-radius:0; position:relative}
  .nav-item.active{border-top-color:var(--red)}
  .nav-badge{position:absolute; top:4px; right:50%; margin:0 -22px 0 0}
  .topbar{padding:0 14px; padding-top:env(safe-area-inset-top,0px); height:calc(var(--bar) + env(safe-area-inset-top,0px))}
  .who{display:none}
  .content{padding:14px}
  .chat-page .content{padding:0}
  .two-col{grid-template-columns:1fr}
  .team-row{grid-template-columns:1.6fr 1fr 1fr 1fr; font-size:12.5px; padding:10px}
  .task-row{flex-direction:column; gap:8px}
  .task-actions{flex-direction:row; align-items:center; justify-content:space-between; width:100%}

  .msg-layout{border:0; border-radius:0}
  .room-side{width:100%; border-left:0}
  .chat-area{display:none; width:100%}
  .msg-layout.show-chat .room-side{display:none}
  .msg-layout.show-chat .chat-area{display:flex}
  .chat-head .back{display:inline-flex}
  .bubble{max-width:86%}
}
