/* Палитра в духе Битрикс24: тёмное боковое меню, светло-серая рабочая
   область, голубые кнопки действий, лаймовый для успеха. */
:root {
  --bg: #eef2f4;
  --card: #ffffff;
  --text: #333333;
  --muted: #828b95;
  --border: #e0e5e8;
  --sidebar-bg: #505f6f;
  --sidebar-bg-dark: #46535f;
  --sidebar-text: #cfd8dd;
  --primary: #d4a017;      /* фирменный золотой */
  --primary-dark: #b8871b;
  --deep-blue: #2067b0;
  --red: #ff5752;
  --red-bg: #ffe3e2;
  --yellow: #d68a00;
  --yellow-accent: #ffa900;
  --yellow-bg: #fff2d4;
  --green: #7ba800;
  --green-accent: #9dcf00;
  --green-bg: #f0f7d8;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Helvetica Neue", Helvetica, Arial, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: var(--deep-blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 26px; font-weight: 400; margin: 0 0 6px; color: #333; }
h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; text-transform: uppercase; color: #6b7683; letter-spacing: .3px; }
.muted { color: var(--muted); }

/* --- боковое меню, как в Битрикс24 --- */
body.with-sidebar { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--sidebar-bg);
  display: flex; flex-direction: column; position: sticky; top: 0;
  height: 100vh; height: 100dvh;
}
.sidebar .logo {
  color: #fff; font-size: 20px; font-weight: 700; padding: 18px 20px 16px;
  letter-spacing: .2px;
}
.sidebar .logo:hover { text-decoration: none; }
.logo-accent { color: var(--primary); }
.sidebar nav { flex: 1; padding-top: 6px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  color: var(--sidebar-text); padding: 11px 20px; font-size: 14px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: var(--sidebar-bg-dark); text-decoration: none; color: #fff; }
.sidebar nav a.active {
  background: var(--sidebar-bg-dark); color: #fff;
  border-left-color: var(--primary);
}
.nav-ico { width: 20px; text-align: center; }
.counter {
  margin-left: auto; background: var(--red); color: #fff;
  min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.sidebar-user {
  padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.12);
}
.sidebar-user-name {
  display: flex; align-items: center; gap: 10px; color: #fff; margin-bottom: 8px;
}
.sidebar-user-name:hover { text-decoration: none; color: var(--primary); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--primary);
  color: #fff; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; flex-shrink: 0;
}
.sidebar-logout {
  color: var(--sidebar-text); font-size: 13px; font-family: inherit;
  background: none; border: 0; padding: 0; cursor: pointer;
}
.sidebar-logout:hover { text-decoration: underline; }

.container { flex: 1; max-width: 1200px; margin: 0 auto; padding: 26px 30px; min-width: 0; }
body.no-sidebar .container { max-width: none; padding: 0; }

@media (max-width: 800px) {
  body.with-sidebar { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar .logo { padding: 12px 16px 8px; font-size: 18px; }
  /* меню — горизонтальная лента со скроллом, а не столбик */
  .sidebar nav {
    display: flex; flex-wrap: nowrap; overflow-x: auto; padding: 0 6px;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .sidebar nav a {
    border-left: none; border-bottom: 3px solid transparent;
    padding: 10px 12px; white-space: nowrap; flex: 0 0 auto;
  }
  .sidebar nav a.active { border-bottom-color: var(--primary); }
  .counter { margin-left: 4px; }
  .sidebar-user {
    padding: 8px 16px; display: flex; align-items: center;
    justify-content: space-between; gap: 10px;
  }
  .sidebar-user-name { margin-bottom: 0; }
  /* в колоночном flex margin:auto сжимает контейнер под широкий контент */
  .container { padding: 16px 14px; width: 100%; }
  /* 16px, иначе iOS Safari зумит страницу при фокусе в поле */
  input, textarea, select { font-size: 16px; }
}

.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { min-width: 0; overflow-wrap: anywhere; }
.page-head form { margin-left: auto; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 6px; padding: 20px; margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(50,58,70,.06);
}
.card h3:not(:first-child) { margin-top: 20px; }
.empty { text-align: center; color: var(--muted); padding: 40px; }

/* --- вкладки и фильтры --- */
.tabs {
  display: flex; flex-wrap: wrap; gap: 14px 22px; margin-bottom: 14px;
  border-bottom: 1px solid var(--border); width: 100%;
}
.tab {
  padding: 8px 2px 10px; border: none; background: transparent;
  color: var(--muted); cursor: pointer; font-size: 14px;
  border-bottom: 3px solid transparent; margin-bottom: -1px;
  text-transform: uppercase; letter-spacing: .3px;
}
.tab:hover { text-decoration: none; color: var(--text); }
.tab.active { color: var(--text); font-weight: 600; border-bottom-color: var(--primary); }
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters select, .filters .search {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 4px; background: #fff; font-size: 14px;
}
.filters .search { flex: 1 1 220px; min-width: 0; }
.filter-date {
  display: flex; align-items: center; gap: 6px; margin: 0;
  font-weight: 400; color: var(--muted); font-size: 14px;
}
.filter-date input { width: auto; margin: 0; }

/* --- таблицы --- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 6px; }
/* видимая полоса прокрутки: иначе на macOS обрезанная колонка выглядит как баг */
.table-wrap::-webkit-scrollbar { height: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: #c6cdd3; border-radius: 4px; }
.table-wrap::-webkit-scrollbar-track { background: transparent; }
.task-table {
  width: 100%; border-collapse: collapse; background: #fff;
  border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
  box-shadow: 0 1px 2px rgba(50,58,70,.06);
}
.task-table th, .task-table td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.task-table th {
  background: #fff; font-size: 12px; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .4px; border-bottom: 2px solid var(--border);
}
.task-table tr:last-child td { border-bottom: none; }
/* компактный вариант для широких таблиц (KPI: 12 колонок) */
.table-compact th, .table-compact td { padding: 9px 8px; font-size: 13px; }
.table-compact th { font-size: 11px; letter-spacing: .2px; }
.table-compact .load-cell { min-width: 120px; }
.task-table tbody tr:hover { background: #f5f9fa; }
.row-overdue { background: #fff1f0; }
.row-overdue:hover { background: #ffe8e6 !important; }
.row-soon { background: #fffaec; }
.row-closed { opacity: .55; }
.task-link { font-weight: 600; color: var(--deep-blue); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* --- таблицы-карточки: на телефоне строки превращаются в карточки --- */
@media (max-width: 700px) {
  .cards-on-mobile { overflow-x: visible; }
  .cards-on-mobile table { display: block; border: none; box-shadow: none; background: none; }
  .cards-on-mobile thead { display: none; }
  .cards-on-mobile tbody { display: block; }
  .cards-on-mobile tr {
    display: block; background: #fff; border: 1px solid var(--border);
    border-radius: 6px; margin-bottom: 10px; padding: 12px 14px;
    box-shadow: 0 1px 2px rgba(50,58,70,.06);
  }
  .cards-on-mobile td {
    display: flex; gap: 8px; padding: 3px 0; border: none;
    align-items: baseline; flex-wrap: wrap;
  }
  .cards-on-mobile td[data-label]::before {
    content: attr(data-label); flex: 0 0 105px;
    color: var(--muted); font-size: 12.5px;
  }
  .cards-on-mobile td.card-title { display: block; font-size: 15px; padding-bottom: 7px; }
  .cards-on-mobile td:empty, .cards-on-mobile .hide-mobile { display: none; }
  .cards-on-mobile .actions { padding-top: 9px; }
  .cards-on-mobile tbody tr:hover { background: #fff; }
  .cards-on-mobile tr.row-overdue { background: #fff1f0; }
  .cards-on-mobile tr.row-soon { background: #fffaec; }
  /* полоса загрузки в KPI-карточке: тянется на остаток строки */
  .cards-on-mobile .load-cell { align-items: center; }
  .cards-on-mobile .load-bar { flex: 1 1 60px; margin-bottom: 0; }
}

/* --- бейджи и статусы --- */
.badge { padding: 3px 10px; border-radius: 12px; font-size: 12.5px; white-space: nowrap; }
.badge-red { background: var(--red-bg); color: var(--red); font-weight: 600; }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); font-weight: 600; }
.status {
  padding: 3px 10px; border-radius: 12px; font-size: 12px; white-space: nowrap;
  text-transform: uppercase; letter-spacing: .3px; font-weight: 600;
}
.status-new { background: #e2f6fd; color: #1793c1; }
.status-in_progress { background: var(--yellow-bg); color: var(--yellow); }
.status-review { background: #ece5fb; color: #7d5bbe; }
.status-done { background: var(--green-bg); color: var(--green); }
.status-cancelled { background: #edf0f2; color: var(--muted); }

/* --- KPI --- */
.kpi-good { color: var(--green); }
.kpi-mid { color: var(--yellow); }
.kpi-bad { color: var(--red); }

.load-cell { min-width: 150px; }
.load-bar {
  height: 7px; border-radius: 4px; background: #e6ebee; overflow: hidden; margin-bottom: 5px;
}
.load-fill { height: 100%; background: var(--green-accent); border-radius: 4px; }
.load-high .load-fill { background: var(--yellow-accent); }
.load-over .load-fill { background: var(--red); }
.load-label { font-size: 12.5px; white-space: nowrap; }

/* --- формы --- */
label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: #6b7683; }
input, textarea, select {
  display: block; width: 100%; margin-top: 6px; padding: 9px 12px;
  border: 1px solid #c6cdd3; border-radius: 4px; font-size: 14px;
  font-family: inherit; background: #fff; color: var(--text); font-weight: 400;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(212,160,23,.28);
}
.form-card { max-width: 760px; }
.form-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
/* без нижнего отступа у подписей — иначе кнопки в строке «проваливаются» ниже полей */
.form-row label { flex: 1; min-width: 170px; margin-bottom: 0; }
.form-row .btn { margin-bottom: 1px; }
.form-actions { display: flex; gap: 10px; margin-top: 8px; }
.checkline { display: flex; align-items: center; gap: 8px; }
.checkline input { width: auto; margin: 0; }

.btn {
  display: inline-block; padding: 9px 20px; border-radius: 4px;
  border: 1px solid #c6cdd3; background: #fff; color: var(--text);
  font-size: 13px; cursor: pointer; text-decoration: none !important;
  text-transform: uppercase; letter-spacing: .4px; font-weight: 600;
}
.btn:hover { background: #f3f6f8; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-green { background: var(--green-accent); border-color: var(--green-accent); color: #fff; }
.btn-green:hover { background: #8bb900; border-color: #8bb900; }
.btn-muted { color: var(--muted); }
.btn-small { padding: 5px 12px; font-size: 12px; }

.btn:focus-visible, .tab:focus-visible, .sidebar nav a:focus-visible,
.check-toggle:focus-visible, .check-remove:focus-visible, .sidebar-logout:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}

.alert { padding: 12px 16px; border-radius: 4px; margin-bottom: 16px; }
.alert-red { background: var(--red-bg); color: var(--red); }
.alert-green { background: var(--green-bg); color: var(--green); }

/* --- вход: золотой градиент --- */
.login-wrap {
  display: flex; justify-content: center; align-items: flex-start;
  min-height: 100vh; min-height: 100dvh; padding-top: 12vh;
  background: linear-gradient(135deg, #8a6410 0%, #b8871b 55%, #e0b53c 100%);
}
.login-card { width: 380px; border: none; box-shadow: 0 8px 30px rgba(10,40,80,.35); }
.login-card h1 { text-align: center; }
.login-card p { text-align: center; margin-top: 0; }
.login-card .btn { width: 100%; margin-top: 4px; }

/* --- карточка задачи --- */
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .two-cols { grid-template-columns: 1fr; } }
.task-desc { white-space: pre-wrap; margin-top: 0; }
.props { display: grid; grid-template-columns: minmax(110px, 150px) 1fr; gap: 7px 12px; margin: 0; }
.props dt { color: var(--muted); }
.props dd { margin: 0; }
.status-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
details.card summary { cursor: pointer; font-weight: 600; color: var(--deep-blue); }
details.card[open] summary { margin-bottom: 14px; }

.comment { border-top: 1px solid var(--border); padding: 10px 0; }
.comment:first-of-type { border-top: none; }
.comment-head { font-size: 13px; margin-bottom: 4px; }
.comment-text { white-space: pre-wrap; }
.comment-form textarea { margin-bottom: 8px; }
.history { padding-left: 18px; font-size: 13px; }
.history li { margin-bottom: 6px; }
.bindcode {
  display: inline-block; background: #edf1f3; padding: 8px 14px;
  border-radius: 4px; font-size: 16px; user-select: all;
}

/* --- чипы проектов --- */
.chip {
  display: inline-block; background: #e2f6fd; color: #1793c1;
  padding: 2px 9px; border-radius: 10px; font-size: 12px; white-space: nowrap;
}

/* --- чек-лист --- */
.checklist { list-style: none; padding: 0; margin: 0 0 10px; }
.checklist li { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.inline-form { display: inline; }
.check-toggle {
  width: 24px; height: 24px; border: 2px solid #c6cdd3; border-radius: 4px;
  background: #fff; cursor: pointer; color: #fff; font-size: 13px; line-height: 1;
  padding: 0; flex-shrink: 0;
}
.check-toggle.checked { background: var(--green-accent); border-color: var(--green-accent); }
.check-done { text-decoration: line-through; color: var(--muted); }
.check-remove {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 16px; padding: 4px 8px; min-width: 28px; min-height: 28px;
}
.check-remove:hover { color: var(--red); }
.check-add { display: flex; gap: 8px; align-items: center; }
.check-add input { margin: 0; flex: 1; }

/* --- наблюдатели, файлы, время --- */
.watcher-row, .file-row { padding: 5px 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.file-form { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.file-form input { margin: 0; }
.time-entry { border-top: 1px solid var(--border); padding: 7px 0; }
.time-entry:first-of-type { border-top: none; }
.subtasks { list-style: none; padding: 0; margin: 0 0 12px; }
.subtasks li { display: flex; align-items: center; gap: 8px; padding: 5px 0; flex-wrap: wrap; }

/* --- канбан --- */
.kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; align-items: start; }
@media (max-width: 1000px) { .kanban { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .kanban { grid-template-columns: 1fr; } }
.kanban-col {
  background: #e7ecef; border-radius: 6px; padding: 10px; min-height: 200px;
}
.kanban-col.drop-target { outline: 2px dashed var(--primary); }
.kanban-col-head {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  padding: 6px 10px; border-radius: 4px; margin-bottom: 10px; background: #fff;
}
.kanban-cards { display: flex; flex-direction: column; gap: 8px; }
.kanban-card {
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  padding: 10px 12px; cursor: grab; box-shadow: 0 1px 2px rgba(50,58,70,.08);
}
.kanban-card.dragging { opacity: .5; }
.kanban-overdue { border-left: 3px solid var(--red); }
.kanban-soon { border-left: 3px solid var(--yellow-accent); }
.kanban-meta {
  display: flex; gap: 10px; flex-wrap: wrap; margin-top: 6px; font-size: 12.5px;
  color: var(--muted);
}
/* на тач-экранах перетаскивание не работает — статус меняется селектом на карточке */
.kanban-status-select { display: none; }
@media (hover: none), (max-width: 600px) {
  .kanban-status-select { display: block; width: 100%; margin-top: 8px; }
}
