:root {
  --bg: #e6ecf3;
  --bg-2: #eef3f8;
  --shadow-dark: #c3cbd6;
  --shadow-light: #ffffff;
  --accent: #6a8dff;
  --accent-2: #9d7bff;
  --text: #2a3244;
  --text-soft: #6a7285;
  --success: #4dd18b;
  --danger: #ff6b81;
  --warn: #ffb547;
  --radius: 22px;
  --modal-bg: rgba(20,25,35,.35);
}
[data-theme="dark"] {
  --bg: #1c1f26;
  --bg-2: #24282f;
  --shadow-dark: #12151a;
  --shadow-light: #262b33;
  --text: #e6ecf3;
  --text-soft: #8a92a3;
  --modal-bg: rgba(0,0,0,.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro", "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  transition: background .2s, color .2s;
}

/* ========= NEO ========= */
.neo { background: var(--bg); border-radius: var(--radius);
  box-shadow: 6px 6px 14px var(--shadow-dark), -6px -6px 14px var(--shadow-light); }
.neo-in { background: var(--bg); border-radius: var(--radius);
  box-shadow: inset 5px 5px 10px var(--shadow-dark), inset -5px -5px 10px var(--shadow-light); }
.neo-btn { background: var(--bg); border: none; border-radius: 16px; padding: 10px 16px;
  font-weight: 600; color: var(--text); cursor: pointer;
  box-shadow: 4px 4px 10px var(--shadow-dark), -4px -4px 10px var(--shadow-light);
  transition: all .15s ease; font-family: inherit; display: inline-flex;
  align-items: center; gap: 6px; justify-content: center; }
.neo-btn:hover { transform: translateY(-1px); }
.neo-btn:active, .neo-btn.active {
  box-shadow: inset 4px 4px 10px var(--shadow-dark), inset -4px -4px 10px var(--shadow-light);
  transform: none; }
.neo-btn.primary { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 6px 6px 14px rgba(106,141,255,.35), -4px -4px 10px var(--shadow-light); }
.neo-btn.danger  { color: #fff; background: linear-gradient(135deg, #ff7a8a, #ff5b71); }
.neo-btn.ghost   { background: transparent; box-shadow: none; color: var(--text-soft); }
.neo-btn svg { width: 16px; height: 16px; }

input, textarea, select {
  border: none; outline: none; background: var(--bg); border-radius: 14px;
  padding: 12px 14px; font: inherit; color: var(--text); width: 100%;
  box-shadow: inset 4px 4px 10px var(--shadow-dark), inset -4px -4px 10px var(--shadow-light);
  transition: box-shadow .15s;
}
input:focus, textarea:focus, select:focus { box-shadow: inset 4px 4px 10px var(--shadow-dark), inset -4px -4px 10px var(--shadow-light), 0 0 0 2px var(--accent); }

/* ========= AUTH ========= */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(106,141,255,.08), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 440px; padding: 32px; }
.auth-card h1 { font-size: 26px; margin-bottom: 8px; }
.auth-card p.sub { color: var(--text-soft); margin-bottom: 20px; font-size: 14px; }
.auth-card .field { margin-bottom: 14px; }

/* ========= APP LAYOUT ========= */
.app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; gap: 18px; padding: 18px; }
.sidebar { padding: 20px; display: flex; flex-direction: column; gap: 8px;
  position: sticky; top: 18px; height: fit-content; max-height: calc(100vh - 36px); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.brand-dot { width: 12px; height: 12px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 0 14px var(--accent); }
.brand h2 { font-size: 18px; }

.nav-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-radius: 14px; cursor: pointer; color: var(--text-soft);
  font-weight: 600; font-size: 14px; transition: all .15s ease; }
.nav-item:hover { color: var(--text); }
.nav-item.active { color: var(--text); background: var(--bg);
  box-shadow: inset 4px 4px 10px var(--shadow-dark), inset -4px -4px 10px var(--shadow-light); }
.nav-item .icon { width: 22px; height: 22px; display: grid; place-items: center; }
.nav-item .icon svg { width: 18px; height: 18px; }
.nav-item .badge { margin-left: auto; background: var(--danger); color: #fff;
  border-radius: 10px; padding: 2px 8px; font-size: 10px; font-weight: 700; }

.profile-mini { margin-top: auto; padding: 12px; display: flex; align-items: center;
  gap: 10px; border-radius: 16px; }
.avatar { width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; color: #fff; font-weight: 700; flex-shrink: 0; }
.profile-mini .meta { overflow: hidden; min-width: 0; }
.profile-mini .meta .name { font-weight: 700; font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-mini .meta .role { color: var(--text-soft); font-size: 11px; }
.sig-badges { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.sig-badges img, .sig-badges span { width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; font-size: 10px; background: var(--bg);
  box-shadow: 3px 3px 6px var(--shadow-dark), -3px -3px 6px var(--shadow-light); }

/* ========= MAIN BENTO ========= */
.main { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; align-content: start; min-width: 0; }
.bento { padding: 20px; grid-column: span 12; min-width: 0; }
.bento.span-4 { grid-column: span 4; }
.bento.span-6 { grid-column: span 6; }
.bento.span-8 { grid-column: span 8; }
.bento.span-3 { grid-column: span 3; }

.page-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.page-title h1 { font-size: 22px; }
.page-title p { color: var(--text-soft); font-size: 13px; }

/* ========= TASKS ========= */
.board { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.board-col { padding: 14px; min-height: 300px; }
.board-col h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-soft); margin-bottom: 12px; }
.task-card { padding: 14px; margin-bottom: 10px; border-radius: 16px; cursor: pointer;
  background: var(--bg); box-shadow: 4px 4px 10px var(--shadow-dark), -4px -4px 10px var(--shadow-light);
  transition: transform .15s ease; word-break: break-word; }
.task-card:hover { transform: translateY(-2px); }
.task-card .ttl { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.task-card .desc { font-size: 12px; color: var(--text-soft); margin-bottom: 8px; }
.task-card .meta { display: flex; justify-content: space-between; font-size: 11px;
  color: var(--text-soft); flex-wrap: wrap; gap: 4px; }
.pill { padding: 3px 8px; border-radius: 10px; font-size: 10px; font-weight: 700; }
.pill.green { background: rgba(77,209,139,.15); color: var(--success); }
.pill.warn  { background: rgba(255,181,71,.15); color: var(--warn); }
.pill.red   { background: rgba(255,107,129,.15); color: var(--danger); }
.pill.blue  { background: rgba(106,141,255,.15); color: var(--accent); }

.list-task { padding: 14px 18px; border-radius: 16px; margin-bottom: 10px; background: var(--bg);
  box-shadow: 4px 4px 10px var(--shadow-dark), -4px -4px 10px var(--shadow-light);
  word-break: break-word; }
.list-task .head { display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; gap: 10px; }
.list-task .body { margin-top: 12px; display: none; }
.list-task.open .body { display: block; }
.list-task .actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ========= WALL ========= */
.post { padding: 16px; margin-bottom: 14px; word-break: break-word; }
.post .head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.post .head .name { font-weight: 700; font-size: 14px; }
.post .head .time { color: var(--text-soft); font-size: 11px; }
.post .content { margin: 8px 0; white-space: pre-wrap; }
.post img { max-width: 100%; border-radius: 14px; margin-top: 8px; }

/* ========= MESSENGER ========= */
.messenger { display: grid; grid-template-columns: 300px 1fr; gap: 14px;
  height: calc(100vh - 150px); min-height: 400px; }
.chat-sidebar { display: flex; flex-direction: column; padding: 14px; overflow: hidden; min-width: 0; }
.chat-sidebar .top { display: flex; gap: 6px; margin-bottom: 10px; }
.chat-sidebar .top input { flex: 1; }
.chat-list { flex: 1; overflow-y: auto; margin-top: 6px; }
.chat-item { padding: 10px 12px; border-radius: 14px; cursor: pointer; margin-bottom: 4px;
  display: flex; align-items: center; gap: 10px; transition: all .1s; min-width: 0; }
.chat-item:hover { background: rgba(106,141,255,.06); }
.chat-item.active { background: var(--bg);
  box-shadow: inset 3px 3px 8px var(--shadow-dark), inset -3px -3px 8px var(--shadow-light); }
.chat-item .avatar { width: 40px; height: 40px; font-size: 14px; flex-shrink: 0; }
.chat-item .info { flex: 1; min-width: 0; overflow: hidden; }
.chat-item .info .name { font-weight: 700; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .info .last { font-size: 12px; color: var(--text-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .meta { display: flex; flex-direction: column; align-items: flex-end;
  gap: 4px; flex-shrink: 0; }
.chat-item .meta .time { font-size: 10px; color: var(--text-soft); }
.chat-item .meta .unread { background: var(--accent); color: #fff;
  border-radius: 10px; padding: 2px 8px; font-size: 11px; font-weight: 700; min-width: 20px;
  text-align: center; }

.chat-window { display: flex; flex-direction: column; padding: 14px; overflow: hidden; min-width: 0; }
.chat-header { display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px; gap: 10px; min-width: 0; }
.chat-header .title { font-weight: 700; font-size: 16px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.messages { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 8px; display: flex;
  flex-direction: column; gap: 6px; }
.msg { max-width: 70%; padding: 10px 14px; border-radius: 16px; font-size: 14px;
  word-break: break-word; overflow-wrap: anywhere; min-width: 0; }
.msg.me { margin-left: auto; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff; border-bottom-right-radius: 4px; }
.msg.other { background: var(--bg); border-bottom-left-radius: 4px;
  box-shadow: 3px 3px 8px var(--shadow-dark), -3px -3px 8px var(--shadow-light); }
.msg .who { font-size: 10px; opacity: .8; margin-bottom: 4px; font-weight: 600; }
.msg .time { font-size: 10px; opacity: .7; text-align: right; margin-top: 4px; }
.msg a { color: inherit; text-decoration: underline; word-break: break-all; }
.msg audio { outline: none; max-width: 100%; }
.msg img { max-width: 100%; border-radius: 10px; cursor: zoom-in; display: block; }
.msg-input { display: flex; gap: 6px; margin-top: 10px; align-items: center; }
.msg-input input { flex: 1; min-width: 0; }
.msg-input button { padding: 10px; width: 42px; height: 42px; }
#emojiBar { display: none; flex-wrap: wrap; gap: 4px; margin-top: 8px;
  padding: 8px; border-radius: 12px; max-height: 160px; overflow-y: auto;
  background: var(--bg); box-shadow: inset 3px 3px 8px var(--shadow-dark), inset -3px -3px 8px var(--shadow-light); }
#emojiBar.show { display: flex; }
#emojiBar button { padding: 4px 8px; font-size: 18px; min-width: unset; width: auto; height: auto; }

/* ========= ANALYTICS ========= */
.dept-card { padding: 18px; word-break: break-word; }
.dept-card h3 { margin-bottom: 12px; }
.emp-row { display: flex; justify-content: space-between; padding: 8px 0;
  border-bottom: 1px dashed var(--shadow-dark); font-size: 13px; gap: 8px; align-items: center; }
.emp-row:last-child { border-bottom: none; }
.progress { height: 6px; border-radius: 3px; background: var(--shadow-dark);
  overflow: hidden; margin-top: 4px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* ========= MODAL ========= */
.modal-bg { position: fixed; inset: 0; background: var(--modal-bg); backdrop-filter: blur(6px);
  display: none; place-items: center; z-index: 100; padding: 20px; }
.modal-bg.show { display: grid; }
.modal { padding: 24px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  overflow-x: hidden; }
.modal h2 { margin-bottom: 14px; font-size: 18px; word-break: break-word; }
.modal .field { margin-bottom: 12px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }

/* ========= TOAST ========= */
.toast { position: fixed; bottom: 24px; right: 24px; padding: 14px 20px; border-radius: 14px;
  background: var(--bg); box-shadow: 6px 6px 14px var(--shadow-dark), -6px -6px 14px var(--shadow-light);
  z-index: 200; display: none; max-width: 90vw; word-break: break-word; }
.toast.show { display: block; animation: toast-in .2s ease; }
@keyframes toast-in { from { transform: translateY(20px); opacity: 0 } }

/* ========= LIGHTBOX ========= */
.lightbox-bg { position: fixed; inset: 0; background: rgba(0,0,0,.9);
  display: grid; place-items: center; z-index: 999; cursor: zoom-out; padding: 20px; }
.lightbox-img { max-width: 95vw; max-height: 95vh; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }

/* ========= TABS ========= */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--shadow-dark); margin-bottom: 8px; }
.tab { padding: 8px 14px; background: transparent; border: none;
  border-bottom: 2px solid transparent; cursor: pointer; font-family: inherit;
  font-weight: 600; font-size: 13px; color: var(--text-soft); transition: all .15s; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ========= EDITOR ========= */
.editor-toolbar { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; padding: 6px;
  border-radius: 12px; background: var(--bg);
  box-shadow: inset 2px 2px 6px var(--shadow-dark), inset -2px -2px 6px var(--shadow-light); }
.editor-toolbar button { padding: 6px 10px; font-size: 14px; min-width: 36px; }
.editor-area { min-height: 240px; max-height: 50vh; overflow-y: auto; padding: 14px;
  border-radius: 14px; background: var(--bg); outline: none;
  box-shadow: inset 4px 4px 10px var(--shadow-dark), inset -4px -4px 10px var(--shadow-light);
  line-height: 1.5; word-break: break-word; }
.editor-area:empty::before { content: attr(placeholder); color: var(--text-soft); pointer-events: none; }
.editor-area img { max-width: 100%; border-radius: 8px; margin: 6px 0; display: block; }
.editor-area a { color: var(--accent); text-decoration: underline; word-break: break-all; }
.editor-area ul, .editor-area ol { margin-left: 22px; margin-top: 6px; margin-bottom: 6px; }
.editor-area h2 { font-size: 20px; margin: 12px 0 8px; }
.editor-area p { margin: 6px 0; }

/* ========= MOBILE ========= */
.mobile-header { display: none; }
.burger { display: none; }
.overlay { display: none; }

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
  .sidebar { position: fixed; top: 0; left: 0; height: 100vh; width: 290px;
    z-index: 90; border-radius: 0 22px 22px 0; transform: translateX(-110%);
    transition: transform .25s ease; overflow-y: auto; max-height: 100vh; }
  .sidebar.open { transform: translateX(0); }
  .mobile-header { display: flex; align-items: center; justify-content: space-between;
    gap: 10px; padding: 10px 14px; margin-bottom: 4px; grid-column: span 12 !important;
    border-radius: 16px; position: sticky; top: 0; z-index: 40; }
  .mobile-header .burger { display: grid; padding: 8px 12px; }
  .mobile-header .title { font-weight: 700; font-size: 16px; }
  .overlay.show { display: block; position: fixed; inset: 0;
    background: rgba(20,25,35,.45); z-index: 80; backdrop-filter: blur(3px); }

  .bento.span-4, .bento.span-6, .bento.span-8, .bento.span-3 { grid-column: span 12; }
  .board { grid-template-columns: 1fr; }

  /* Мессенджер: показываем либо список, либо чат */
  .messenger { grid-template-columns: 1fr; height: auto; min-height: 0; }
  .messenger .chat-sidebar { display: flex; min-height: 60vh; }
  .messenger .chat-window { display: none; min-height: 80vh; }
  .messenger.show-chat .chat-sidebar { display: none; }
  .messenger.show-chat .chat-window { display: flex; }
  .msg { max-width: 85%; }
}

@media (max-width: 480px) {
  .bento { padding: 14px; border-radius: 18px; }
  .page-title h1 { font-size: 18px; }
  .msg { max-width: 92%; }
  .modal { padding: 18px; border-radius: 18px; }
  .msg-input button { padding: 8px; width: 38px; height: 38px; }
}