:root, [data-theme="light"] {
  --bg: #f8f9fa;
  --text: #1a1a2e;
  --hint: #8e8ea0;
  --link: #5b6abf;
  --btn: #5b6abf;
  --btn-text: #ffffff;
  --secondary-bg: #ffffff;
  --section-bg: #ffffff;
  --accent: #c9a84c;
  --accent-light: #f5efd6;
  --danger: #e74c3c;
  --success: #2ecc71;
  --warning: #f1c40f;
  --radius: 14px;
  --nav-height: 64px;
  --shadow: 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --border: #e8e8ef;
  --card-hover: #f0f0f8;
}

[data-theme="dark"] {
  --bg: #0f0f1a;
  --text: #e4e4ef;
  --hint: #6b6b80;
  --link: #7b8adf;
  --btn: #5b6abf;
  --btn-text: #ffffff;
  --secondary-bg: #1a1a2e;
  --section-bg: #1a1a2e;
  --accent: #c9a84c;
  --accent-light: #2a2618;
  --danger: #e74c3c;
  --success: #2ecc71;
  --warning: #f1c40f;
  --radius: 14px;
  --nav-height: 64px;
  --shadow: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,.4);
  --border: #2a2a3e;
  --card-hover: #222236;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, 'SF Pro', 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--nav-height) + 16px);
  -webkit-font-smoothing: antialiased;
}

/* Bottom Nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--section-bg);
  display: flex;
  justify-content: space-around;
  align-items: center;
  border-top: 1px solid var(--border);
  z-index: 100;
  box-shadow: 0 -2px 10px rgba(0,0,0,.05);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  background: none;
  border: none;
  color: var(--hint);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: all .2s;
  border-radius: 12px;
}
.nav-btn.active { color: var(--btn); background: var(--accent-light); }
.nav-icon { font-size: 20px; }
.nav-label { font-weight: 600; letter-spacing: 0.3px; }

/* Views */
.view { display: none; padding: 16px; }
.view.active { display: block; }

.view-header {
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.view-header h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

/* Theme toggle */
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
  box-shadow: var(--shadow);
}
.theme-toggle:active { transform: scale(0.9); }

/* Stats */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 14px 8px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform .15s;
}
.stat-card:active { transform: scale(0.96); }
.stat-num {
  display: block;
  font-size: 24px;
  font-weight: 700;
}
.stat-label {
  font-size: 11px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.stat-done .stat-num { color: var(--success); }
.stat-progress .stat-num { color: var(--warning); }
.stat-backlog .stat-num { color: var(--hint); }

/* Section title */
.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 16px 0 8px;
}

/* Project bars */
.project-bars { display: flex; flex-direction: column; gap: 6px; }
.project-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: var(--secondary-bg);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all .15s;
  box-shadow: var(--shadow);
  border: 1px solid transparent;
}
.project-bar:hover { border-color: var(--border); }
.project-bar:active { transform: scale(0.98); }
.project-bar .bar-id {
  font-weight: 600;
  font-size: 12px;
  min-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-bar .bar-fill {
  flex: 1;
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}
.project-bar .bar-fill-inner {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width .3s;
}
.project-bar .bar-count {
  font-size: 13px;
  font-weight: 600;
  min-width: 28px;
  text-align: right;
}

/* Task list */
.task-list { display: flex; flex-direction: column; gap: 4px; }
.task-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--secondary-bg);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all .15s;
  box-shadow: var(--shadow);
  border: 1px solid transparent;
}
.task-item:hover { border-color: var(--border); background: var(--card-hover); }
.task-item:active { transform: scale(0.98); }
.task-priority {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}
.task-priority.urgent { background: var(--danger); }
.task-priority.high { background: var(--warning); }
.task-priority.normal { background: var(--hint); }
.task-priority.none { background: transparent; border: 1px solid var(--hint); }
.task-content { flex: 1; min-width: 0; }
.task-title {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
}
.task-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--hint);
}
.task-label {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
}

/* Search */
.search-bar { margin-top: 8px; }
.search-bar input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--secondary-bg);
  color: var(--text);
  outline: none;
  box-shadow: var(--shadow);
  transition: all .2s;
}
.search-bar input:focus { border-color: var(--btn); box-shadow: 0 0 0 3px rgba(91,106,191,.15); }

/* Label filters */
.label-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.label-chip {
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  background: var(--secondary-bg);
  color: var(--text);
  border: none;
  cursor: pointer;
  transition: all .15s;
}
.label-chip.active {
  background: var(--accent);
  color: #fff;
}

/* Project tabs */
.project-tabs {
  display: flex;
  overflow-x: auto;
  gap: 4px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.project-tab {
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--secondary-bg);
  border: none;
  color: var(--text);
  cursor: pointer;
}
.project-tab.active {
  background: var(--btn);
  color: var(--btn-text);
}

/* Status filter */
.status-filter {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}
.filter-btn {
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  background: var(--secondary-bg);
  border: none;
  color: var(--text);
  cursor: pointer;
}
.filter-btn.active {
  background: var(--btn);
  color: var(--btn-text);
}

/* Task detail */
.task-detail { padding: 0 0 20px; }
.task-detail h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
  line-height: 1.3;
}
.task-detail .td-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.td-label {
  font-size: 12px;
  color: var(--hint);
  min-width: 70px;
}
.td-value {
  font-size: 14px;
  font-weight: 500;
}
.td-status {
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}
.td-status.todo { background: var(--secondary-bg); }
.td-status.in-progress { background: #fff3cd; color: #856404; }
.td-status.done { background: #d4edda; color: #155724; }
.td-description {
  margin-top: 16px;
  padding: 12px;
  background: var(--secondary-bg);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 60vh;
  overflow-y: auto;
}
.td-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.back-btn {
  background: none;
  border: none;
  color: var(--btn);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 0;
}

/* Calendar */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 16px;
  font-weight: 600;
}
.cal-nav-btn {
  background: var(--secondary-bg);
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 18px;
  cursor: pointer;
  color: var(--text);
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  margin-bottom: 16px;
}
.cal-header {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--hint);
  padding: 4px;
}
.cal-day {
  text-align: center;
  padding: 8px 4px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  position: relative;
}
.cal-day.other { color: var(--hint); opacity: 0.4; }
.cal-day.today { background: var(--btn); color: var(--btn-text); font-weight: 700; }
.cal-day.selected { outline: 2px solid var(--accent); }
.cal-day.has-tasks::after {
  content: '';
  display: block;
  width: 4px;
  height: 4px;
  background: var(--danger);
  border-radius: 50%;
  margin: 2px auto 0;
}

/* Create form */
.create-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.create-form label {
  font-size: 13px;
  font-weight: 600;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.create-form input,
.create-form select,
.create-form textarea {
  padding: 10px 12px;
  border: 1px solid var(--secondary-bg);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--secondary-bg);
  color: var(--text);
  outline: none;
  font-family: inherit;
}
.create-form input:focus,
.create-form select:focus,
.create-form textarea:focus {
  border-color: var(--btn);
}
.label-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.btn-primary {
  padding: 14px;
  background: var(--btn);
  color: var(--btn-text);
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}
.btn-primary:active { opacity: 0.8; }

/* Sync badge */
.sync-badge {
  font-size: 11px;
  color: var(--hint);
  display: block;
  margin-top: 2px;
}

/* amoCRM block */
.crm-block {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 8px;
}
.crm-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--hint);
  font-size: 13px;
  text-align: center;
}
.crm-icon { font-size: 28px; }
.btn-small {
  padding: 6px 16px;
  border-radius: 8px;
  background: var(--btn);
  color: var(--btn-text);
  border: none;
  font-size: 12px;
  cursor: pointer;
}
.crm-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.crm-stat {
  text-align: center;
}
.crm-stat-num {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}
.crm-stat-label {
  font-size: 10px;
  color: var(--hint);
  text-transform: uppercase;
}

/* Responsible grid */
.responsible-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}
.resp-card {
  background: var(--secondary-bg);
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
  transition: background .15s;
}
.resp-card:active { background: var(--btn); color: var(--btn-text); }
.resp-name {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.resp-stats {
  font-size: 11px;
  color: var(--hint);
  margin-bottom: 4px;
}
.resp-bar {
  height: 3px;
  background: var(--bg);
  border-radius: 2px;
  overflow: hidden;
}
.resp-bar-fill {
  height: 100%;
  background: var(--success);
  border-radius: 2px;
}

/* Responsible filters */
.responsible-filters {
  display: flex;
  overflow-x: auto;
  gap: 4px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
}
.resp-chip {
  padding: 5px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  background: var(--secondary-bg);
  border: none;
  color: var(--text);
  cursor: pointer;
}
.resp-chip.active {
  background: var(--accent);
  color: #fff;
}

/* Task responsible tag */
.task-resp {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 500;
  background: rgba(212,168,67,0.15);
  color: var(--accent);
}

/* Task due date */
.task-due { font-size: 10px; }

/* Task project tag */
.task-proj {
  font-weight: 600;
  font-size: 10px;
}

/* Tasks count */
.tasks-count {
  font-size: 12px;
  color: var(--hint);
  margin-bottom: 8px;
}

/* Empty state */
.empty {
  color: var(--hint);
  padding: 16px;
  text-align: center;
  font-size: 13px;
}

/* Checkbox */
.checkbox {
  width: 20px;
  height: 20px;
  min-width: 20px;
  border: 2px solid var(--hint);
  border-radius: 4px;
  margin-top: 2px;
  flex-shrink: 0;
  cursor: pointer;
  transition: all .2s;
  position: relative;
}
.checkbox:hover { border-color: var(--accent); }
.checkbox.done {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox.done::after {
  content: '✓';
  color: #fff;
  position: absolute;
  top: -1px;
  left: 3px;
  font-size: 14px;
  font-weight: bold;
}
.task-title.task-done {
  text-decoration: line-through;
  opacity: 0.5;
}
.task-item.item-done {
  opacity: 0.7;
}
.status-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  font-weight: 600;
}
.status-badge.in-progress { background: #e3f2fd; color: #1565c0; }
.status-badge.todo { background: #fff3e0; color: #e65100; }
.status-badge.backlog { background: var(--secondary-bg); color: var(--hint); }

/* Priority badges */
.prio-badge {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  font-weight: 600;
}
.prio-badge.urgent { background: #fde8e8; color: #c62828; }
.prio-badge.high { background: #fff3e0; color: #e65100; }
.prio-badge.medium { background: #fff8e1; color: #f9a825; }
.prio-badge.low { background: #e3f2fd; color: #1565c0; }

[data-theme="dark"] .prio-badge.urgent { background: #3e1a1a; color: #ef5350; }
[data-theme="dark"] .prio-badge.high { background: #3e2a1a; color: #ff8a65; }
[data-theme="dark"] .prio-badge.medium { background: #3e3a1a; color: #ffd54f; }
[data-theme="dark"] .prio-badge.low { background: #1a2a3e; color: #64b5f6; }

/* Priority left stripe on task card */
.prio-stripe-urgent { border-left: 3px solid #e53935; }
.prio-stripe-high { border-left: 3px solid #ff6d00; }
.prio-stripe-medium { border-left: 3px solid #fdd835; }
.prio-stripe-low { border-left: 3px solid #42a5f5; }

/* Edit controls */
.td-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.btn-edit, .btn-save {
  padding: 6px 14px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.btn-edit { background: var(--secondary-bg); color: var(--text); }
.btn-save { background: var(--success); color: #fff; }
.hidden { display: none !important; }

.td-select, .td-date {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--secondary-bg);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.td-select:not(:disabled), .td-date:not(:disabled) {
  border-color: var(--btn);
  background: var(--bg);
}
.editable {
  border: 1px dashed var(--btn);
  border-radius: 8px;
  padding: 4px 8px;
}

/* Label checkboxes */
.td-labels-edit {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.label-check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 12px;
  background: var(--secondary-bg);
  cursor: pointer;
  transition: all .15s;
}
.label-check.active {
  background: var(--lcolor, var(--accent));
  color: #fff;
}
.label-check input { display: none; }

/* Calendar count badge */
.cal-count {
  display: block;
  font-size: 8px;
  color: var(--danger);
  font-weight: 700;
  line-height: 1;
}

/* Calendar assign */
.cal-assign {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}
.cal-select {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--secondary-bg);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}

/* Users */
.users-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--secondary-bg);
  border-radius: var(--radius);
}
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}
.user-info { flex: 1; }
.user-name { font-size: 14px; font-weight: 600; }
.user-role {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  display: inline-block;
  margin-top: 2px;
}
.role-admin { background: #e74c3c; color: #fff; }
.role-editor { background: var(--secondary-bg); color: var(--hint); }
.user-tgid { font-size: 11px; color: var(--hint); }

/* Task detail fields */
.td-field {
  margin-bottom: 10px;
}
.td-title-wrap h2 {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.3;
  margin: 0;
}
.td-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--btn);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}
.td-desc-edit {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--btn);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  resize: vertical;
}
.btn-cancel {
  padding: 6px 14px;
  border-radius: 8px;
  border: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: var(--secondary-bg);
  color: var(--hint);
}
.btn-add-label {
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 12px;
  background: none;
  border: 1px dashed var(--hint);
  color: var(--hint);
  cursor: pointer;
}
.btn-add-label:active { border-color: var(--btn); color: var(--btn); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}
.modal {
  background: var(--section-bg);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 320px;
}
.modal h3 {
  font-size: 16px;
  margin-bottom: 12px;
}
.modal .td-input {
  margin-bottom: 12px;
}
.color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.color-opt {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .15s;
}
.color-opt.selected {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--bg);
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.btn-primary-sm {
  padding: 8px 16px;
  background: var(--btn);
  color: var(--btn-text);
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: #333;
  color: #fff;
  border-radius: 8px;
  font-size: 13px;
  z-index: 200;
  transition: opacity .3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

/* Loader */
.loader {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
}
.loader.hidden { display: none; }
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--secondary-bg);
  border-top-color: var(--btn);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
