/* =========================================================
   MOBILE-REDESIGN.CSS — визуальный реворк для телефонов.
   Сохраняет текущую дизайн-систему, но делает интерфейс
   более удобным и плотным на узких экранах.
   Загружается после responsive.css и добавляет слой
   переопределений только для мобильной версии.
   ========================================================= */

@media (min-width: 901px) {
  .mobile-global-topbar,
  .mobile-nav-header,
  .mobile-nav-title,
  .mobile-nav-back,
  .mobile-nav-toggle {
    display: none !important;
  }
}

@media (max-width: 900px) {
  :root {
    --mobile-page-pad: 14px;
    --mobile-surface: #ffffff;
    --mobile-soft-surface: #f7f8fc;
    --mobile-card-shadow: 0 8px 18px rgba(15, 23, 42, 0.05);
    --mobile-card-radius: 16px;
    --mobile-control-radius: 12px;
  }

  body {
    background: linear-gradient(180deg, #f4f6fb 0%, #eef2f7 100%);
  }

  .main-content {
    padding: 56px var(--mobile-page-pad) calc(env(safe-area-inset-bottom, 0px) + 150px);
    max-width: 100%;
  }

  .app-container {
    display: flex;
    flex-direction: column;
    background: transparent;
  }

  .sidebar {
    width: 100%;
    position: relative;
    top: auto;
    z-index: 5;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(12px);
    border-right: none;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    padding: 10px 12px 12px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
    gap: 8px;
    overflow: visible;
  }

  .mobile-global-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    z-index: 200;
    pointer-events: none;
  }

  .mobile-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 44px;
    gap: 8px;
    padding: 8px 4px 6px;
    position: sticky;
    top: 28px;
    z-index: 55;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(8px);
  }

  .mobile-nav-title {
    flex: 1;
    text-align: center;
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
  }

  .mobile-nav-toggle,
  .mobile-nav-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(227, 227, 232, 0.9);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 10px 22px rgba(15, 23, 42, 0.1);
    pointer-events: auto;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, transform 0.12s ease;
  }

  .mobile-nav-toggle:hover,
  .mobile-nav-back:hover {
    background: var(--surface-hover);
    border-color: var(--border-strong);
    color: var(--text);
    transform: translateY(-1px);
  }

  .mobile-nav-back {
    position: absolute;
    left: 12px;
    top: 12px;
  }

  .mobile-nav-toggle {
    position: absolute;
    right: 12px;
    top: 12px;
  }

  .sidebar.mobile-nav-open .mobile-nav-back {
    display: inline-flex;
  }

  .sidebar.mobile-nav-open .mobile-nav-toggle {
    display: none;
  }

  .logo {
    display: none;
  }

  #appVersionBadge {
    top: 12px;
    right: 12px;
    z-index: 30;
    opacity: 0.75;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(8px);
    border-color: rgba(227, 227, 232, 0.9);
  }

  .menu-row {
    width: 100%;
    gap: 6px;
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .menu-row::-webkit-scrollbar { display: none; }

  .menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 700;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.02);
    text-align: center;
  }

  .sidebar.mobile-nav-open {
    max-height: calc(100vh - 44px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sidebar.mobile-nav-open .menu-btn {
    display: flex;
  }

  .sidebar:not(.mobile-nav-open) .sidebar-footer {
    display: none;
  }

  .sidebar.mobile-nav-open .sidebar-footer {
    display: grid;
  }

  .menu-btn.active {
    background: var(--accent-soft);
    border-color: rgba(79, 70, 229, 0.18);
    color: var(--accent);
  }

  .lock-btn {
    display: none !important;
    height: 38px;
    min-width: 52px;
    border-radius: 12px;
    background: var(--mobile-soft-surface);
    border-color: var(--border);
    color: var(--text-muted);
    font-size: 11px;
  }

  .sidebar.mobile-nav-open .menu-btn.active[data-tab="products"] + .lock-btn {
    display: inline-flex !important;
  }

  .sidebar-footer {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    padding-top: 8px;
    margin-top: 2px;
  }

  .action-cluster {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .action-cluster-secondary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .btn-primary,
  .btn-secondary,
  .btn-add,
  .btn-save,
  .btn-export,
  .btn-small,
  .btn-copy,
  .btn-import,
  .btn-cancel,
  .mobile-actions-toggle,
  .btn-text-link {
    min-height: 38px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: -0.01em;
  }

  .btn-primary,
  .btn-add,
  .btn-save,
  .btn-export {
    box-shadow: 0 8px 16px rgba(37, 99, 235, 0.18);
  }

  .btn-secondary,
  .btn-copy,
  .btn-import,
  .btn-cancel,
  .btn-small {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  }

  .toolbar {
    margin-bottom: 12px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid var(--border);
    border-radius: var(--mobile-card-radius);
    box-shadow: var(--mobile-card-shadow);
    gap: 10px;
  }

  .toolbar-left,
  .toolbar-right {
    width: 100%;
    gap: 8px;
  }

  .toolbar-left {
    display: grid;
    grid-template-columns: 1fr;
  }

  .toolbar-right {
    justify-content: space-between;
    align-items: stretch;
  }

  #searchProduct,
  #categoryFilter,
  #supplierFilter,
  select,
  input,
  textarea {
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    min-height: 40px;
    padding: 9px 12px;
    font-size: 13px;
  }

  #searchProduct {
    min-width: 0;
    width: 100%;
  }

  .toolbar-actions-list {
    right: 0;
    left: 0;
    top: calc(100% + 6px);
    border-radius: 14px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--border);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
    z-index: 21;
  }

  .mobile-actions-toggle {
    width: 42px;
    min-width: 42px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--mobile-soft-surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 20px;
    line-height: 1;
    position: relative;
    z-index: 12;
  }

  .orders-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding-bottom: 0;
  }

  .orders-sidebar,
  .orders-main,
  .customers-section,
  .items-section,
  .summary-settings,
  .summary-filters,
  .summary-card,
  .profile-container,
  .table-container,
  .summary-detail-table,
  .product-table,
  .order-table {
    border-radius: var(--mobile-card-radius);
  }

  .orders-sidebar {
    width: 100%;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border);
    box-shadow: var(--mobile-card-shadow);
    overflow: hidden;
  }

  .orders-sidebar-header {
    padding: 12px 12px 10px;
    border-bottom: 1px solid var(--border);
  }

  .btn-new-order {
    width: 100%;
    min-height: 42px;
    border-radius: 12px;
    font-size: 13px;
  }

  .orders-list {
    display: grid;
    gap: 6px;
    max-height: none;
    padding: 8px;
  }

  .order-item,
  .customer-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    min-height: 44px;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.02);
  }

  .order-item.active,
  .customer-item.active {
    background: var(--accent-soft);
    border-color: rgba(79, 70, 229, 0.18);
  }

  .order-item span:first-child,
  .customer-item span:first-child {
    color: var(--text);
    font-weight: 600;
  }

  .orders-main {
    min-width: 0;
  }

  .order-header {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border);
    border-radius: var(--mobile-card-radius);
    padding: 12px;
    box-shadow: var(--mobile-card-shadow);
    margin-bottom: 12px;
  }

  .order-name-input {
    min-height: 44px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 15px;
    padding: 9px 12px;
  }

  .order-meta-row {
    margin-top: 10px;
    gap: 6px;
  }

  .order-meta-field {
    background: var(--mobile-soft-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 7px 10px;
    min-height: 40px;
    font-size: 12px;
    color: var(--text-muted);
  }

  .order-meta-field input[type="text"] {
    min-height: 32px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 12px;
  }

  .order-dates-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    background: rgba(79, 70, 229, 0.04);
    border: 1px solid rgba(79, 70, 229, 0.12);
    border-radius: 14px;
    padding: 10px;
    margin: 0 0 12px;
  }

  .order-dates-row label {
    background: var(--surface);
    border-radius: 10px;
    border: 1px solid rgba(79, 70, 229, 0.06);
    padding: 8px 9px;
    min-height: 68px;
    justify-content: center;
  }

  .order-dates-row input[type="date"] {
    min-height: 36px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 12px;
  }

  .section-title-row {
    margin: 8px 0 10px;
    padding: 0;
  }

  .customers-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .customers-list .customer-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    border-radius: 12px;
    padding: 9px 10px;
    min-height: 46px;
    line-height: 1.2;
    flex-wrap: nowrap;
  }

  .customers-list .customer-item > span:first-child,
  .customers-list .customer-item > .editable-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .customers-list .customer-item .paid-badge,
  .customers-list .customer-item .btn-delete-small {
    flex-shrink: 0;
  }

  .customer-add-btn,
  .btn-add-centered {
    min-height: 42px;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 12.5px;
  }

  .table-container {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border);
    border-radius: var(--mobile-card-radius);
    box-shadow: var(--mobile-card-shadow);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .product-table,
  .summary-detail-table,
  .order-table {
    min-width: 620px;
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: transparent;
  }

  .product-table thead th,
  .summary-detail-table thead th,
  .order-table thead th {
    background: #f7f8fc;
    color: var(--text-muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
  }

  .product-table tbody td,
  .summary-detail-table tbody td,
  .order-table tbody td {
    background: var(--surface);
    padding: 9px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    line-height: 1.35;
    vertical-align: middle;
  }

  .product-table tbody tr:last-child td,
  .summary-detail-table tbody tr:last-child td,
  .order-table tbody tr:last-child td {
    border-bottom: none;
  }

  .btn-small,
  .summary-detail-table .btn-small,
  .product-table .btn-small,
  .order-table .btn-small {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 88px;
    max-width: none;
    min-height: 32px;
    height: auto;
    padding: 7px 10px !important;
    font-size: 11px !important;
    line-height: 1.1 !important;
    border-radius: 10px;
    white-space: nowrap !important;
    overflow-wrap: normal !important;
    word-break: normal !important;
  }

  .summary-settings,
  .summary-filters {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border);
    border-radius: var(--mobile-card-radius);
    box-shadow: var(--mobile-card-shadow);
    padding: 12px;
    gap: 8px;
    margin-bottom: 12px;
  }

  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .summary-card {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--mobile-card-shadow);
    padding: 12px 14px;
  }

  .summary-label {
    font-size: 10px;
    letter-spacing: 0.08em;
  }

  .summary-value {
    font-size: 20px;
    line-height: 1.1;
  }

  .summary-order-group {
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--surface);
  }

  .summary-order-group-head {
    padding: 9px 10px;
    font-size: 12px;
  }

  .summary-order-group-body {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 8px 10px;
  }

  .profile-container {
    max-width: none;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border);
    border-radius: var(--mobile-card-radius);
    box-shadow: var(--mobile-card-shadow);
    padding: 18px 16px;
  }

  .profile-form {
    gap: 12px;
  }

  .form-group input {
    min-height: 42px;
    border-radius: 12px;
  }

  .role-badge {
    font-size: 9px;
  }

  .force-save-fab,
  .undo-fab,
  .refresh-fab {
    display: block;
    position: fixed;
    right: 14px;
    z-index: 30;
    border-radius: 12px;
    box-shadow: 0 14px 28px rgba(15, 23, 42, 0.12);
  }

  .undo-fab {
    bottom: 62px;
  }

  .refresh-fab {
    bottom: 104px;
  }

  .force-save-fab {
    bottom: 14px;
    min-height: 42px;
    padding: 10px 14px;
    font-size: 12px;
  }

  .undo-fab,
  .refresh-fab {
    min-height: 34px;
    padding: 8px 12px;
    font-size: 11.5px;
  }
}

@media (max-width: 560px) {
  :root {
    --mobile-page-pad: 12px;
  }

  .main-content {
    padding-left: 12px;
    padding-right: 12px;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .order-dates-row {
    grid-template-columns: 1fr;
  }

  .menu-btn {
    font-size: 11.5px;
    padding: 8px 8px;
  }

  .order-meta-row {
    flex-direction: column;
    align-items: stretch;
  }

  .order-meta-field {
    width: 100%;
    justify-content: space-between;
  }

  .lock-btn {
    font-size: 10px;
  }
}
