/* ----- Переменные ----- */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #1e293b;
  --border: #e2e8f0;
  --card-shadow: 0 1px 3px rgba(0,0,0,0.06);
  --radius: 8px;
  --transition: 0.3s ease;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --text: #f1f5f9;
  --border: #334155;
  --card-shadow: 0 1px 3px rgba(255,255,255,0.05);
}

/* ----- Сброс и база ----- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  transition: background var(--transition), color var(--transition);
}

.container {
  max-width: 1300px;
  margin: 0 auto;
  padding: 20px;
  width: 100%;
}

/* ----- Навигация (ГЛАВНОЕ) ----- */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-container {
  max-width: 1300px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
  min-height: 56px;
  position: relative;
}

.nav-brand {
  flex-shrink: 0;
}

.nav-brand a {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 1.2rem;
  white-space: nowrap;
}

.nav-search {
  flex: 1;
  min-width: 100px;
  position: relative;
}

.nav-search input {
  width: 100%;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: auto;
}

.nav-actions .theme-btn {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 30px;
  color: var(--text);
  min-width: 44px;
  min-height: 44px;
}

.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  min-width: 44px;
  min-height: 44px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  order: 2;
}

.nav-toggle span {
  display: block;
  width: 28px;
  height: 3px;
  background: var(--text);
  border-radius: 2px;
  transition: var(--transition);
}

.nav-links {
  list-style: none;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
}

.nav-links li a {
  color: var(--text);
  text-decoration: none;
  padding: 8px 4px;
  display: block;
  font-size: 0.95rem;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
}

.nav-links li a:hover {
  border-bottom-color: var(--text);
}

.nav-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.3);
  z-index: 99;
}

.nav-overlay.active {
  display: block;
}

/* ----- Кнопки ----- */
.btn {
  display: inline-block;
  padding: 6px 14px;
  border: none;
  border-radius: var(--radius);
  font-weight: 500;
  cursor: pointer;
  font-size: 0.9rem;
  transition: var(--transition);
  background: var(--border);
  color: var(--text);
  line-height: 1.4;
  min-height: 36px;
}

.btn.primary { background: #2563eb; color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.secondary { background: #94a3b8; color: #fff; }
.btn.secondary:hover { background: #64748b; }
.btn.success { background: #16a34a; color: #fff; }
.btn.success:hover { background: #15803d; }
.btn.danger { background: #dc2626; color: #fff; }
.btn.danger:hover { background: #b91c1c; }
.btn.warning { background: #f59e0b; color: #fff; }
.btn.small { padding: 4px 10px; font-size: 0.8rem; min-height: 30px; }

/* ----- Формы ----- */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 4px;
  font-size: 0.9rem;
}

input, textarea, select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* ----- Таблицы ----- */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -12px;
  padding: 0 12px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--card-shadow);
  min-width: 600px;
}

.data-table th {
  background: var(--bg);
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 0.9rem;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.data-table tr:hover {
  background: var(--bg);
}

/* ----- Канбан ----- */
.kanban-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.kanban-column {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--card-shadow);
}

.kanban-column h3 {
  margin-bottom: 12px;
  font-size: 1rem;
  text-align: center;
}

.kanban-list {
  min-height: 100px;
}

.kanban-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  cursor: grab;
}

.kanban-card:active {
  cursor: grabbing;
}

.card-title {
  font-weight: 500;
}

.card-meta {
  font-size: 0.8rem;
  color: #64748b;
}

.card-actions {
  margin-top: 8px;
  display: flex;
  gap: 4px;
}

/* ----- Сметы ----- */
.estimate-block {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--card-shadow);
}

.estimate-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.estimate-header h3 {
  margin: 0;
}

/* ----- Карточки статистики ----- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--card-shadow);
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.stat-label {
  font-size: 0.85rem;
  color: #64748b;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 600;
  display: block;
  margin-top: 6px;
}

/* ----- Модалки ----- */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  max-width: 500px;
  width: 90%;
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-content .close {
  position: absolute;
  right: 16px;
  top: 12px;
  font-size: 24px;
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ----- Табы ----- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tablink {
  background: none;
  border: none;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 500;
  color: var(--text);
  border-bottom: 2px solid transparent;
}

.tablink.active {
  border-bottom-color: #2563eb;
}

.tabcontent {
  display: none;
}

.tabcontent.active {
  display: block;
}

/* ----- Утилиты и прочее ----- */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.page-header h1 {
  font-size: 1.8rem;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.actions input,
.actions select {
  width: auto;
  min-width: 120px;
}

.flash {
  background: #fef3c7;
  border-left: 4px solid #f59e0b;
  padding: 10px 16px;
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.login-page {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-container {
  background: var(--surface);
  padding: 36px;
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  width: 100%;
  max-width: 380px;
}

.login-container h1 {
  text-align: center;
  margin-bottom: 24px;
}

.comment-item {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ----- Поиск (выпадающий список) ----- */
.search-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 300px;
  overflow-y: auto;
  z-index: 200;
}

.search-item {
  display: block;
  padding: 8px 12px;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}

.search-item:hover {
  background: var(--bg);
}

/* ----- Адаптивность (мобильные) ----- */
@media (max-width: 720px) {
  .container {
    padding: 12px;
  }

  .nav-container {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    align-items: center;
    gap: 8px;
  }

  .nav-brand {
    display: block;
  }

  .nav-brand a {
    font-size: 1rem;
  }

  .nav-search {
    flex: none;
    min-width: 60px;
  }

  .nav-search input {
    font-size: 14px;
    padding: 6px 10px;
  }

  .nav-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 0;
    justify-self: end;
  }

  .nav-actions .theme-btn {
    font-size: 1.2rem;
    min-width: 40px;
    min-height: 40px;
    padding: 4px;
  }

  .nav-toggle {
    display: flex;
    justify-self: start;
  }

  .nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: center;
    background: var(--surface);
    padding: 8px 0;
    border-top: 1px solid var(--border);
    order: 5;
    grid-column: 1 / -1;
  }

  .nav-links.active {
    display: flex;
  }

  .nav-links li {
    width: 100%;
  }

  .nav-links li a {
    padding: 14px 16px;
    font-size: 1.1rem;
    text-align: center;
    border-bottom: none;
    width: 100%;
  }

  .nav-links li a:hover {
    border-bottom: none;
    background: var(--bg);
  }

  .nav-overlay.active {
    display: block;
  }

  .navbar.menu-open .nav-brand,
  .navbar.menu-open .nav-search {
    display: none !important;
  }

  .navbar.menu-open .nav-container {
    grid-template-columns: auto 1fr auto;
  }

  .navbar.menu-open .nav-toggle {
    justify-self: start;
    margin-left: 0 !important;
  }

  .navbar.menu-open .nav-actions {
    justify-self: end;
    margin-left: 0 !important;
  }

  .navbar.menu-open .nav-links {
    display: flex !important;
  }

  .nav-links li a::before {
    content: none;
  }

  .navbar.menu-open .nav-links li a::before {
    content: none !important;
  }

  .search-dropdown {
    width: 100% !important;
    min-width: 0 !important;
    left: 0 !important;
    right: 0 !important;
  }

  .btn {
    padding: 10px 16px;
    font-size: 1rem;
    min-height: 44px;
    min-width: 44px;
  }

  .btn.small {
    padding: 6px 12px;
    font-size: 0.9rem;
    min-height: 36px;
    min-width: 36px;
  }

  .data-table {
    font-size: 0.85rem;
    min-width: 500px;
  }

  .data-table th,
  .data-table td {
    padding: 8px 8px;
    white-space: nowrap;
  }

  .kanban-board {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .kanban-column {
    padding: 8px;
  }

  .kanban-card {
    padding: 12px;
  }

  .card-actions .btn {
    min-height: 36px;
    min-width: 36px;
    padding: 4px 8px;
  }

  .modal-content {
    max-width: 100%;
    width: 100%;
    height: 100%;
    border-radius: 0;
    padding: 16px;
    overflow-y: auto;
  }

  .modal {
    align-items: stretch;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .stat-card {
    padding: 12px;
  }

  .stat-value {
    font-size: 1.3rem;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .actions input,
  .actions select {
    width: 100%;
    min-width: unset;
  }

  .estimate-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .estimate-header h3 {
    font-size: 1.1rem;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .quick-form input,
  .quick-form select {
    flex: 1 1 100%;
    width: 100%;
  }

  .quick-form .btn {
    flex: 1 1 45%;
  }
}