/* ===== CSS Variables ===== */
:root {
  --sidebar-width: 220px;
  --sidebar-bg: #2c3e50;
  --sidebar-active: #e67e22;
  --sidebar-text: #bdc3c7;
  --sidebar-hover: #34495e;
  --header-height: 60px;
  --primary: #27ae60;
  --primary-hover: #219a52;
  --danger: #e74c3c;
  --warning: #f39c12;
  --info: #3498db;
  --success: #27ae60;
  --dark: #2c3e50;
  --light: #ecf0f1;
  --white: #ffffff;
  --gray: #95a5a6;
  --gray-light: #bdc3c7;
  --gray-lighter: #ecf0f1;
  --text: #2c3e50;
  --text-muted: #7f8c8d;
  --border: #ddd;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.15);
  --radius: 6px;
  --radius-lg: 10px;
}

/* ===== Reset ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif; font-size: 14px; color: var(--text); background: #f5f6fa; }

/* ===== Layout ===== */
.app-layout { display: flex; height: 100vh; }
.sidebar { width: var(--sidebar-width); background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; position: fixed; height: 100vh; max-height: 100vh; z-index: 100; transition: transform 0.3s; overflow: hidden; }
.main-content { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar-logo { padding: 20px; text-align: center; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-logo .avatar { width: 60px; height: 60px; border-radius: 50%; background: var(--sidebar-active); display: flex; align-items: center; justify-content: center; margin: 0 auto 10px; font-size: 24px; color: white; }
.sidebar-logo .org-name { font-size: 12px; color: var(--gray-light); }

.sidebar-nav { flex: 1; padding: 10px 0; overflow-y: auto; }
.sidebar-nav a { display: flex; align-items: center; padding: 12px 20px; color: var(--sidebar-text); text-decoration: none; transition: all 0.2s; font-size: 14px; gap: 12px; }
.sidebar-nav a:hover { background: var(--sidebar-hover); color: white; }
.sidebar-nav a.active { background: var(--sidebar-active); color: white; }
.sidebar-nav a .icon { font-size: 18px; width: 24px; text-align: center; }
.sidebar-nav a .badge { background: var(--danger); color: white; border-radius: 10px; padding: 2px 8px; font-size: 11px; margin-left: auto; }

/* ===== Header ===== */
.top-header { height: var(--header-height); background: white; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.top-header h1 { font-size: 20px; font-weight: 600; }
.header-actions { display: flex; align-items: center; gap: 16px; }
.header-search { position: relative; }
.header-search input { padding: 8px 16px 8px 36px; border: 1px solid var(--border); border-radius: 20px; font-size: 13px; width: 250px; outline: none; }
.header-search input:focus { border-color: var(--primary); }
.header-search .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--gray); }

/* ===== Content Area ===== */
.content-area { padding: 24px; flex: 1; overflow-y: auto; }

/* ===== Cards ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: white; border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow); display: flex; align-items: flex-start; gap: 16px; transition: transform 0.2s; }
.stat-card:hover { transform: translateY(-2px); }
.stat-card .stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; color: white; flex-shrink: 0; }
.stat-card .stat-info h3 { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.stat-card .stat-info .value { font-size: 24px; font-weight: 700; }
.stat-card .stat-info .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.bg-primary { background: var(--primary) !important; }
.bg-danger { background: var(--danger) !important; }
.bg-warning { background: var(--warning) !important; }
.bg-info { background: var(--info) !important; }
.bg-success { background: var(--success) !important; }
.bg-dark { background: var(--dark) !important; }
.bg-gray { background: var(--gray) !important; }

/* ===== Tables ===== */
.table-card { background: white; border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; }
.table-card .table-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 12px; }
.table-card .table-header h2 { font-size: 16px; font-weight: 600; }

.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
table th { background: #f8f9fa; padding: 12px 16px; text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 2px solid var(--border); white-space: nowrap; cursor: pointer; }
table th:hover { background: #eef0f2; }
table td { padding: 12px 16px; border-bottom: 1px solid var(--gray-lighter); vertical-align: middle; }
table tr:hover { background: #f8f9fa; }
table tr:last-child td { border-bottom: none; }
table .checkbox { width: 18px; height: 18px; cursor: pointer; }

/* ===== Buttons ===== */
.btn { padding: 8px 20px; border: none; border-radius: var(--radius); font-size: 13px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; transition: all 0.2s; text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c0392b; }
.btn-warning { background: var(--warning); color: white; }
.btn-info { background: var(--info); color: white; }
.btn-info:hover { background: #2980b9; }
.btn-dark { background: var(--dark); color: white; }
.btn-outline { background: white; color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--gray-lighter); }
.btn-sm { padding: 4px 12px; font-size: 12px; }
.btn-lg { padding: 12px 28px; font-size: 15px; }

/* ===== Status Badges ===== */
.status-badge { padding: 4px 12px; border-radius: 4px; font-size: 12px; font-weight: 500; display: inline-block; white-space: nowrap; }
.status-new { background: #3498db; color: white; }
.status-in_progress { background: #27ae60; color: white; }
.status-on_approval { background: #e67e22; color: white; }
.status-waiting_parts { background: #f39c12; color: white; }
.status-delivery { background: #2ecc71; color: white; }
.status-ready { background: #95a5a6; color: white; }
.status-completed { background: #2c3e50; color: white; }
.status-cancelled { background: #e74c3c; color: white; }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.form-group label .required { color: var(--danger); }
.form-control { width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; outline: none; transition: border-color 0.2s; }
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(39,174,96,0.1); }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237f8c8d' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-actions { display: flex; gap: 12px; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ===== Modals ===== */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 1000; display: flex; align-items: flex-start; justify-content: center; padding: 40px 20px; overflow-y: auto; }
.modal { background: white; border-radius: var(--radius-lg); width: 100%; max-width: 700px; box-shadow: var(--shadow-lg); animation: modalIn 0.2s ease; }
.modal-lg { max-width: 900px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 18px; font-weight: 600; }
.modal-close { width: 32px; height: 32px; border: none; background: none; font-size: 20px; cursor: pointer; color: var(--gray); border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: var(--gray-lighter); }
.modal-body { padding: 24px; max-height: 60vh; overflow-y: auto; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 12px; flex-wrap: wrap; }
.modal-footer .btn { min-width: 100px; justify-content: center; }

@keyframes modalIn { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Tabs ===== */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tabs .tab { padding: 10px 20px; font-size: 14px; color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all 0.2s; }
.tabs .tab:hover { color: var(--text); }
.tabs .tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }

/* ===== Filter Bar ===== */
.filter-bar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; background: white; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.filter-bar .filter-group { display: flex; align-items: center; gap: 8px; }
.filter-bar select, .filter-bar input { padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; }

/* ===== Pagination ===== */
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-top: 1px solid var(--border); }
.pagination .page-btns { display: flex; gap: 4px; }
.pagination .page-btn { width: 32px; height: 32px; border: 1px solid var(--border); background: white; border-radius: var(--radius); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.pagination .page-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.pagination .page-btn:hover:not(.active) { background: var(--gray-lighter); }

/* ===== Charts ===== */
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: 24px; margin-top: 24px; }
.chart-card { background: white; border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 20px; }
.chart-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 16px; color: var(--text); }
.chart-container { position: relative; height: 300px; }

/* ===== Donut Chart ===== */
.donut-chart { width: 200px; height: 200px; margin: 0 auto; }
.donut-legend { margin-top: 16px; }
.donut-legend-item { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; }
.donut-legend-color { width: 12px; height: 12px; border-radius: 3px; }

/* ===== Mobile Orders List ===== */
.mobile-orders-list { display: none; }
.order-card-mobile { display: none; }

/* ===== Timeline ===== */
.timeline { padding: 0 0 0 20px; border-left: 2px solid var(--border); }
.timeline-item { position: relative; padding: 0 0 20px 20px; }
.timeline-item::before { content: ''; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); border: 2px solid white; }
.timeline-item .time { font-size: 12px; color: var(--text-muted); }
.timeline-item .event { font-size: 13px; margin-top: 4px; }

/* ===== Empty State ===== */
.empty-state { text-align: center; padding: 60px 20px; }
.empty-state .icon { font-size: 48px; color: var(--gray-light); margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--text-muted); margin-bottom: 8px; }
.empty-state p { font-size: 14px; color: var(--gray); }

/* ===== Login Page ===== */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #2c3e50 0%, #3498db 100%); padding: 20px; }
.login-card { background: white; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); width: 100%; max-width: 420px; padding: 40px; }
.login-card h1 { text-align: center; font-size: 24px; margin-bottom: 8px; }
.login-card .subtitle { text-align: center; color: var(--text-muted); margin-bottom: 30px; }
.login-card .logo-icon { text-align: center; font-size: 48px; margin-bottom: 20px; }

/* ===== Device Info ===== */
.device-info { display: flex; gap: 16px; padding: 12px 16px; background: #f8f9fa; border-radius: var(--radius); margin-bottom: 16px; }
.device-info .device-icon { font-size: 32px; }
.device-info .device-details h4 { font-size: 14px; font-weight: 600; }
.device-info .device-details p { font-size: 12px; color: var(--text-muted); }

/* ===== Tags ===== */
.tag { display: inline-block; padding: 2px 8px; border-radius: 3px; font-size: 11px; font-weight: 500; margin-right: 4px; }
.tag-vip { background: #f39c12; color: white; }
.tag-blacklist { background: #e74c3c; color: white; }

/* ===== Toast ===== */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 2000; }
.toast { padding: 12px 20px; border-radius: var(--radius); color: white; font-size: 14px; margin-bottom: 8px; animation: toastIn 0.3s ease; box-shadow: var(--shadow-lg); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }

@keyframes toastIn { from { opacity: 0; transform: translateX(100px); } to { opacity: 1; transform: translateX(0); } }

/* ===== Mobile Menu Toggle ===== */
.menu-toggle { display: none; background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text); padding: 4px; }
.sidebar-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 99; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); height: 100vh; max-height: 100vh; overflow: hidden; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-nav { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; min-height: 0; }
  .sidebar-overlay.active { display: block; }
  .main-content { margin-left: 0; }
  .menu-toggle { display: block; }
  .header-search { display: none; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .charts-grid { grid-template-columns: 1fr; }
  .modal { margin: 10px; max-width: 100%; }
  .modal-body { max-height: 70vh; }
  .desktop-only { display: none !important; }
  .mobile-orders-list { display: block !important; }
  .table-card .table-header { flex-direction: column; align-items: stretch; }
  .top-header { padding: 0 12px; }
  .content-area { padding: 12px; }
  
  /* Таблицы без горизонтальной прокрутки */
  .table-responsive { overflow-x: visible; }
  table { font-size: 12px; }
  table td, table th { padding: 8px 6px; }
  
  /* Скрываем次要ные колонки на мобильных */
  .hide-mobile { display: none !important; }
  
  /* Карточки заказов на мобильных */
  .order-card-mobile {
    display: block;
    background: white;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    cursor: pointer;
  }
  .desktop-only { display: none !important; }
  .mobile-orders-list { display: block !important; }
  
  /* Кнопка + Заказ на всю ширину */
  .btn-full-mobile { width: 100% !important; text-align: center !important; }
  .filter-row-mobile { flex-direction: column !important; gap: 8px !important; }
  .filter-row-mobile .btn { width: 100% !important; text-align: center !important; }
  
  /* Модальное окно заказа */
  .modal { max-height: 95vh; overflow-y: auto; margin: 0; border-radius: 16px 16px 0 0; position: fixed; bottom: 0; left: 0; right: 0; }
  .modal-footer { position: sticky; bottom: 0; background: white; padding: 12px 16px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 8px; z-index: 10; }
  .modal-footer .btn { flex: 1; min-width: 80px; text-align: center; padding: 12px 8px; }
  .modal-footer .btn-danger { order: -1; }
  .modal-footer .btn-primary { order: 3; }
  
  .order-card-mobile .order-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
  }
  .order-card-mobile .order-info {
    font-size: 12px;
    color: var(--text-muted);
  }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card .stat-info .value { font-size: 20px; }
  .top-header h1 { font-size: 16px; }
  .sidebar-nav a { padding: 10px 16px; font-size: 13px; }
}

/* ===== Demo Banner ===== */
.demo-banner {
  padding: 10px 20px;
  margin: 0 16px 0 16px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
  color: white;
}
.demo-banner.demo-warning {
  background: linear-gradient(135deg, #f39c12 0%, #e67e22 100%);
}
.demo-banner.demo-urgent {
  background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
  animation: demo-pulse 2s infinite;
}
.demo-banner.demo-expired {
  background: linear-gradient(135deg, #95a5a6 0%, #7f8c8d 100%);
}
.demo-banner-content {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 1200px;
  margin: 0 auto;
}
.demo-banner .demo-icon { font-size: 24px; flex-shrink: 0; }
.demo-banner .demo-text { display: flex; flex-direction: column; gap: 2px; }
.demo-banner .demo-text strong { font-size: 14px; }
.demo-banner .demo-text span { font-size: 12px; opacity: 0.9; }
.demo-banner .demo-text a { color: white; font-weight: 600; text-decoration: underline; }

@keyframes demo-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.85; }
}

/* ===== Tariff Cards (Landing + In-App) ===== */
.land-tariff-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary);
}
.tariff-period {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.tariff-features .disabled {
  color: #ccc;
  text-decoration: line-through;
}

@media(max-width: 768px) {
  .demo-banner { margin: 0 8px 8px 8px; }
  .demo-banner-content { flex-direction: column; text-align: center; gap: 4px; }
}

/* ===== Print ===== */
@media print {
  .sidebar, .top-header, .btn, .filter-bar, .pagination { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .content-area { padding: 0 !important; }
  .demo-banner { display: none !important; }
}
