/* Бек Экспресс - Стили */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --sidebar-width: 260px;
  --header-height: 60px;
}

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

html {
  overflow-x: hidden;
  max-width: 100%;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: #1f2937;
  background: #f3f4f6;
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100%;
}

/* Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
  min-width: 0;
  width: 100%;
  overflow-x: hidden;
}

.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, #1e3a5f 0%, #0f172a 100%);
  color: #fff;
  flex-shrink: 0;
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 1000;
}

/* Бургер-меню (көрүнбөйт десктопто) */
.nav-burger {
  display: none;
  position: fixed;
  top: max(8px, env(safe-area-inset-top, 0px));
  left: max(8px, env(safe-area-inset-left, 0px));
  z-index: 1100;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.nav-burger-lines {
  display: block;
  width: 20px;
  height: 2px;
  background: #1f2937;
  border-radius: 1px;
  position: relative;
}

.nav-burger-lines::before,
.nav-burger-lines::after {
  content: '';
  position: absolute;
  left: 0;
  width: 20px;
  height: 2px;
  background: #1f2937;
  border-radius: 1px;
}

.nav-burger-lines::before {
  top: -7px;
}

.nav-burger-lines::after {
  top: 7px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.sidebar-nav {
  padding: 16px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 20px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  transition: background 0.2s;
}

.nav-item:hover {
  background: rgba(255,255,255,0.1);
  color: #fff;
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
}

.nav-item-label {
  flex: 1;
  min-width: 0;
}

.nav-badge {
  flex-shrink: 0;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
  border-radius: 999px;
  background: #f97316;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.nav-item.active .nav-badge {
  background: rgba(255, 255, 255, 0.28);
  color: #fff;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}

.header {
  height: var(--header-height);
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.content {
  flex: 1;
  padding: 24px;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

/* Cards */
.card {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 24px;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e5e7eb;
  font-weight: 600;
}

.card-body {
  padding: 20px;
}

/* Forms */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: #374151;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 15px;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: #6b7280; color: #fff; }

/* Table */
.table {
  width: 100%;
  border-collapse: collapse;
}

.table th, .table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid #e5e7eb;
}

.table th {
  background: #f9fafb;
  font-weight: 600;
  color: #374151;
}

.table tr:hover {
  background: #f9fafb;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
}

.login-box {
  background: #fff;
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  width: 100%;
  max-width: 400px;
}

.login-box h1 {
  text-align: center;
  margin-bottom: 24px;
  color: #1f2937;
}

/* Mobile */
@media (max-width: 768px) {
  .nav-burger {
    display: flex;
    width: 40px;
    height: 40px;
    border-radius: 8px;
  }

  .nav-burger-lines {
    width: 18px;
  }

  .nav-burger-lines::before,
  .nav-burger-lines::after {
    width: 18px;
  }

  .nav-burger-lines::before {
    top: -6px;
  }

  .nav-burger-lines::after {
    top: 6px;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  body.nav-open .sidebar-overlay {
    display: block;
  }

  .main-content {
    margin-left: 0;
  }

  /* Бирдиктүү мобилдик шапка: меню солдо, аталыш + ат жөнү астында */
  .main-content .header {
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    height: auto;
    min-height: auto;
    padding: 10px 16px 12px 58px;
    position: sticky;
    top: 0;
    z-index: 50;
    gap: 4px;
    border-bottom: 1px solid #e2e8f0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  }

  .main-content .header h2 {
    font-size: 1.2rem;
    margin: 0;
    line-height: 1.3;
    font-weight: 600;
    color: #0f172a;
    width: 100%;
  }

  .main-content .header > span {
    font-size: 13px;
    color: #64748b;
    font-weight: 400;
    line-height: 1.35;
    width: 100%;
    display: block;
  }

  /* Контент, формалар, таблицалар (админ/дашборд) */
  .main-content .content {
    padding: 12px max(12px, env(safe-area-inset-right)) 24px max(12px, env(safe-area-inset-left));
  }

  .main-content .card {
    margin-bottom: 16px;
  }

  .main-content .card-header {
    padding: 12px 14px;
    font-size: 0.95rem;
  }

  .main-content .card-body {
    padding: 14px;
  }

  .main-content .card-body:has(> table.table) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  .main-content .table th,
  .main-content .table td {
    padding: 8px 10px;
    font-size: 14px;
  }

  .main-content .btn {
    min-height: 40px;
  }

  .main-content .btn-sm {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 12px;
  }

  .main-content .form-control {
    font-size: 16px;
  }

  .main-content .form-group {
    margin-bottom: 12px;
  }

  /* Башкы бет: тайлдар жана статус столбец */
  .main-content .dash-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
  }

  .main-content .dash-btn .card-body {
    padding: 12px !important;
  }

  .main-content .status-groups {
    gap: 8px;
    padding-bottom: 8px;
    -webkit-overflow-scrolling: touch;
  }

  .main-content .status-box {
    min-width: min(300px, calc(100vw - 72px));
    flex: 0 0 min(300px, calc(100vw - 72px));
  }

  /* Отчёттор: фильтр формасы */
  .main-content .reports-toolbar {
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px !important;
    padding: 12px !important;
  }

  .main-content .reports-toolbar label {
    width: 100%;
  }

  .main-content .reports-toolbar select {
    width: 100%;
    max-width: none;
    min-height: 42px;
  }

  .main-content .reports-toolbar .btn-success {
    margin-left: 0 !important;
    width: 100%;
    justify-content: center;
  }

  /* Настройки: табдар */
  .main-content .settings-tabs {
    gap: 6px !important;
    margin-bottom: 14px !important;
  }

  .main-content .settings-tab {
    flex: 1 1 calc(50% - 6px);
    text-align: center;
    padding: 9px 10px !important;
    font-size: 12px !important;
    min-width: 0;
    box-sizing: border-box;
  }

  /* Айлык: Авансы / Зарплата */
  .main-content .salary-tabs-row {
    display: flex;
    flex-wrap: nowrap;
    width: 100%;
    box-sizing: border-box;
    gap: 6px;
    margin-bottom: 10px;
  }

  .main-content .salary-tab-btn {
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
    min-height: 36px;
    padding: 6px 6px;
    font-size: 12px;
    line-height: 1.25;
    box-sizing: border-box;
  }

  /* Айлык: кнопкалар/инпуттар майдарак болсун, экранга батсын */
  .main-content .expenses-sheet-table .btn.btn-sm {
    min-height: 32px;
    padding: 5px 9px;
    font-size: 12px;
  }

  .main-content .expenses-sheet-table td form .form-control,
  .main-content .expenses-sheet-table input.form-control {
    min-height: 32px;
    padding: 5px 8px;
    font-size: 14px;
  }

  /* Алдын ала төлөм */
  .prepay-row {
    flex-direction: column;
  }

  .prepay-meta {
    min-width: 0 !important;
  }

  .main-content .prepay-card .btn-primary {
    width: 100%;
    justify-content: center;
  }

  /* Админ: формалар бир колонка (flex/grid inline) */
  .main-content .card-body > form[style*="display:grid"],
  .main-content .card-body form[style*="display:grid"] {
    grid-template-columns: 1fr !important;
  }

  .main-content .card-body > form[style*="display:flex"] {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
  }

  .main-content .card-body > form[style*="display:flex"] .form-group {
    min-width: 0 !important;
    width: 100%;
  }

  .main-content .card-body > form[style*="display:flex"] .form-group .btn,
  .main-content .card-body > form[style*="display:flex"] > .btn {
    width: 100%;
    justify-content: center;
  }

  .main-content .card-body [style*="grid-template-columns:repeat(auto-fit"] {
    grid-template-columns: 1fr !important;
  }

  /* Айлык: саптардагы төлөм формалары */
  .main-content .expenses-sheet-table td form[style*="inline-flex"],
  .main-content .expenses-sheet-table td form[style*="display:inline-flex"] {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    white-space: normal !important;
    max-width: 100%;
  }

  .main-content .expenses-sheet-table td form .form-control {
    max-width: none !important;
    width: 100%;
    min-height: 40px;
  }

  .main-content .expenses-sheet-table td form .btn {
    width: 100%;
    justify-content: center;
  }

  /* Таблица: аракеттер колонкасы (форма бар клетка) */
  .main-content .products-sheet-table td:last-child:has(form),
  .main-content .clients-sheet-table td:last-child:has(form),
  .main-content .expenses-sheet-table td:last-child:has(form) {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    white-space: normal !important;
  }

  .main-content .products-sheet-table td:last-child:has(form) form,
  .main-content .clients-sheet-table td:last-child:has(form) form {
    display: flex !important;
    flex-direction: column !important;
    gap: 6px !important;
    margin-left: 0 !important;
  }

  .main-content .products-sheet-table td:last-child:has(form) .btn-sm,
  .main-content .clients-sheet-table td:last-child:has(form) .btn-sm,
  .main-content .expenses-sheet-table td:last-child:has(form) .btn-sm {
    min-height: 40px;
    width: 100%;
    justify-content: center;
  }

  .main-content .settings-sheet-table td:last-child:has(form),
  .main-content .settings-sheet-table td:last-child:has(button) {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .main-content .settings-sheet-table td:last-child:has(form) form {
    display: block !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }

  .main-content .settings-sheet-table td:last-child:has(form) .btn-sm,
  .main-content .settings-sheet-table td:last-child:has(button) .btn-sm {
    width: 100%;
    min-height: 32px;
    padding: 5px 8px;
    font-size: 12px;
    justify-content: center;
  }

  .main-content .table-scroll .table td:last-child {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: stretch;
  }

  .main-content .table-scroll .table td:last-child .btn {
    min-height: 40px;
    width: 100%;
    justify-content: center;
  }

  .main-content .table-scroll .table td:last-child form {
    display: block !important;
    width: 100%;
    margin-left: 0 !important;
  }

  /* Модалдар (оңдоо) — толук тууралык, коопсуз аймак */
  .admin-modal-backdrop {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)) !important;
    align-items: flex-end !important;
  }

  .admin-modal-panel {
    width: 100% !important;
    max-width: 520px !important;
    max-height: min(88vh, 100% - 24px) !important;
    border-radius: 12px 12px 0 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  @media (min-width: 480px) {
    .admin-modal-backdrop {
      align-items: center !important;
    }

    .admin-modal-panel {
      border-radius: 12px !important;
      max-height: 90vh !important;
    }
  }

  .main-content .detail-box {
    max-height: min(88vh, 100% - 32px) !important;
  }

  .admin-modal-panel form > div[style*="display:flex"][style*="margin-top"] {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .admin-modal-panel form > div[style*="display:flex"][style*="margin-top"] .btn {
    width: 100%;
    justify-content: center;
  }
}

/* Компакт Excel-таблицалар (дашборд, чыгымдар, кардарлар, товарлар, отчёттор, настройки, айлык) */
@media (max-width: 768px) {
  .dash-sheet-table,
  .expenses-sheet-table,
  .settings-sheet-table,
  .reports-sheet-table,
  .clients-sheet-table,
  .products-sheet-table {
    font-size: 11px;
    line-height: 1.3;
  }

  .dash-sheet-table thead th,
  .dash-sheet-table tbody td,
  .expenses-sheet-table thead th,
  .expenses-sheet-table tbody td,
  .settings-sheet-table thead th,
  .settings-sheet-table tbody td,
  .reports-sheet-table thead th,
  .reports-sheet-table tbody td,
  .clients-sheet-table thead th,
  .clients-sheet-table tbody td,
  .products-sheet-table thead th,
  .products-sheet-table tbody td {
    padding: 5px 6px;
  }

  .dash-sheet-wrap,
  .expenses-sheet-wrap,
  .settings-sheet-wrap,
  .reports-sheet-wrap,
  .clients-sheet-wrap,
  .products-sheet-wrap {
    -webkit-overflow-scrolling: touch;
  }

  .dash-sheet-toolbar {
    flex-direction: column;
    align-items: stretch !important;
    gap: 10px !important;
  }

  .dash-sheet-toolbar select,
  .dash-sheet-toolbar button {
    width: 100%;
    max-width: none;
  }

  .clients-list-heading,
  .products-list-heading,
  .reports-list-heading,
  .expenses-list-heading,
  .settings-table-heading {
    font-size: 13px !important;
  }

  .detail-modal {
    padding: max(12px, env(safe-area-inset-bottom)) !important;
  }

  .detail-box {
    padding: 16px 14px !important;
    border-radius: 10px !important;
  }

  .detail-items {
    font-size: 13px !important;
  }
}

@media (max-width: 576px) {
  .main-content .dash-grid {
    grid-template-columns: 1fr;
  }

  .main-content .settings-tab {
    flex: 1 1 100%;
  }
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.badge-new { background: #dbeafe; color: #1d4ed8; }
.badge-sent { background: #d1fae5; color: #059669; }
.badge-cancelled { background: #fee2e2; color: #dc2626; }

/* Горизонталдуу скролл: болгону бул аймак кыймылдайт, баракча эмес */
.admin-hscroll {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  overscroll-behavior-y: auto;
}

.dash-sheet-wrap,
.products-sheet-wrap,
.clients-sheet-wrap,
.expenses-sheet-wrap,
.settings-sheet-wrap,
.reports-sheet-wrap,
.table-scroll {
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.dash-sheet-wrap .dash-sheet-table {
  min-width: 560px;
}

.products-sheet-wrap .products-sheet-table {
  min-width: 640px;
}

.clients-sheet-wrap .clients-sheet-table {
  min-width: 640px;
}

.expenses-sheet-wrap .expenses-sheet-table {
  min-width: 760px;
}

.settings-sheet-wrap .settings-sheet-table {
  min-width: 720px;
}

.reports-sheet-wrap .reports-sheet-table {
  min-width: 560px;
}

.table-scroll {
  width: 100%;
}

.table-scroll .table {
  min-width: 560px;
}

/* Модалдар (оңдоо): сайдбардан жогору */
.admin-modal-backdrop {
  z-index: 1200;
  box-sizing: border-box;
}

.admin-modal-panel {
  box-sizing: border-box;
}
