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

:root {
  --bg: #404040;
  --bg-sidebar: #363636;
  --bg-section: #404040;
  --bg-input: #2d2d2d;
  --bg-table: #2d2d2d;
  --bg-row-hover: #3a3a3a;
  --bg-row-stripe: rgba(255,255,255,0.02);
  --bg-card: #404040;
  --border: #555;
  --text: #e0e0e0;
  --text-dim: #b0b0b0;
  --text-label: #999;
  --btn-add-bg: #555;
  --btn-add-hover: #666;
  --accent: #FF7F2A;
  --accent-hover: #E66E1E;
  --close-hover: #e81123;
  --status-ok: #4caf50;
  --status-err: #e81123;
  --badge-bg: #555;
}

[data-theme="light"] {
  --bg: #f0f0f0;
  --bg-sidebar: #e8e8e8;
  --bg-section: #f5f5f5;
  --bg-input: #fff;
  --bg-table: #fff;
  --bg-row-hover: #f0f0f0;
  --bg-row-stripe: rgba(0,0,0,0.02);
  --bg-card: #fff;
  --border: #ccc;
  --text: #333;
  --text-dim: #666;
  --text-label: #777;
  --btn-add-bg: #ddd;
  --btn-add-hover: #ccc;
  --badge-bg: #ddd;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Toolbar --- */
#toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 36px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.toolbar-drag {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  height: 100%;
  flex: 1;
  -webkit-app-region: drag;
  user-select: none;
}
.toolbar-logo { height: 22px; width: 22px; object-fit: contain; }
.toolbar-title {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 500;
  letter-spacing: 0.3px;
}
.toolbar-controls {
  display: flex;
  height: 100%;
  -webkit-app-region: no-drag;
}
.toolbar-btn {
  width: 46px;
  height: 100%;
  border: none;
  background: none;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.toolbar-btn:hover { background: var(--border); color: var(--text); }
.toolbar-btn-close:hover { background: var(--close-hover); color: #fff; }

/* --- Main layout --- */
#app { display: flex; flex: 1; overflow: hidden; }

/* --- Sidebar --- */
#sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--bg-sidebar);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-right: 1px solid var(--border);
}
/* Connection status */
#connection-status-section {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--bg-section);
  border: 1px solid var(--border);
  border-radius: 5px;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.connected { background: var(--status-ok); }
.status-dot.disconnected { background: var(--status-err); }
#status-label { font-size: 11px; color: var(--text-dim); flex: 1; }
.btn-small {
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--btn-add-bg);
  color: var(--text);
  font-size: 10px;
  cursor: pointer;
}
.btn-small:hover { background: var(--btn-add-hover); }

/* Nav menu */
#nav-menu { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.15s;
  font-size: 12px;
  border-left: 3px solid transparent;
  user-select: none;
}
.nav-item:hover { background: rgba(255, 127, 42, 0.08); }
.nav-item.active {
  background: rgba(255, 127, 42, 0.12);
  border-left-color: var(--accent);
  color: var(--accent);
}
.nav-icon { width: 16px; height: 16px; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--badge-bg);
  color: var(--text-dim);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
}

/* --- Main area --- */
#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  position: relative;
}

/* Header */
#main-header {
  display: flex;
  align-items: center;
  padding: 6px 16px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
  min-height: 44px;
}
#header-left { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
#view-title { font-size: 14px; font-weight: 600; color: var(--accent); }
#total-count { font-size: 11px; color: var(--text-label); }
#header-center {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  max-width: 350px;
}
#search-input {
  flex: 1;
  padding: 5px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 12px;
}
#search-input:focus { outline: none; border-color: var(--accent); }
#search-input::placeholder { color: var(--text-label); }
.btn-icon {
  width: 24px; height: 24px;
  border: none;
  background: none;
  color: var(--text-label);
  cursor: pointer;
  font-size: 12px;
  border-radius: 3px;
}
.btn-icon:hover { color: var(--text); }

/* Filter area */
#header-right { display: flex; align-items: center; gap: 8px; }
.filter-select {
  padding: 4px 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
}
.filter-select:focus { outline: none; border-color: var(--accent); }
.filter-date {
  padding: 4px 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
  width: 120px;
}
.filter-date:focus { outline: none; border-color: var(--accent); }
.btn-export {
  padding: 4px 12px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: none;
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-export:hover { background: var(--accent); color: #fff; }

/* Pagination */
#pagination { display: flex; align-items: center; gap: 6px; flex-shrink: 0; margin-left: auto; }
.page-btn {
  width: 26px; height: 26px;
  border: 1px solid var(--border);
  background: var(--bg-section);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.page-btn:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#page-info { font-size: 11px; color: var(--text-dim); min-width: 60px; text-align: center; }

/* Content area */
#content-area { flex: 1; overflow: hidden; position: relative; }
#table-wrapper { position: absolute; inset: 0; overflow: hidden; }
#table-scroll { position: absolute; inset: 0; overflow: auto; }

/* --- Order Panel --- */
.order-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 720px;
  min-width: 380px;
  max-width: 95vw;
  background: var(--bg-sidebar);
  border-left: 2px solid var(--accent);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow: hidden;
}
.panel-resize-handle {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  cursor: col-resize;
  z-index: 55;
  background: transparent;
  transition: background 0.15s;
}
.panel-resize-handle:hover,
.panel-resize-handle.active { background: var(--accent); }
.order-panel.open { transform: translateX(0); }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-title { font-size: 16px; font-weight: 700; color: var(--accent); }
.panel-subtitle { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.panel-pdf-btn {
  padding: 4px 10px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: none;
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.panel-pdf-btn:hover { background: var(--accent); color: #fff; }
.panel-close {
  width: 28px; height: 28px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.panel-close:hover { background: var(--border); color: var(--text); }
.panel-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}
.panel-tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}
.panel-tab:hover { color: var(--text); }
.panel-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}
.panel-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.panel-table thead { position: sticky; top: 0; z-index: 5; }
.panel-table thead th {
  background: var(--bg-section);
  color: var(--text-dim);
  font-weight: 600;
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-size: 10px;
  text-transform: uppercase;
}
.panel-table tbody td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.panel-table tbody tr:nth-child(even) { background: var(--bg-row-stripe); }
.panel-table tbody tr:hover { background: var(--bg-row-hover); }
.panel-empty { text-align: center; color: var(--text-label); padding: 32px 16px; font-size: 13px; }
.panel-timeline { padding: 12px 20px; }
.panel-tl-item {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  align-items: flex-start;
}
.panel-tl-item:last-child { border-bottom: none; }
.panel-tl-dot {
  width: 8px; height: 8px;
  min-width: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 5px;
}
.panel-tl-info { flex: 1; min-width: 0; }
.panel-tl-product { font-size: 11px; color: var(--text-label); }
.panel-tl-body { color: var(--text); margin-top: 2px; }
.panel-tl-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

/* --- Data-grid Table --- */
#data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  border: 1px solid var(--border);
}
#data-table thead { position: sticky; top: 0; z-index: 10; }
#data-table thead th {
  background: var(--bg-sidebar);
  color: var(--text-dim);
  font-weight: 600;
  padding: 8px 12px;
  text-align: left;
  border-bottom: 2px solid var(--accent);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  user-select: none;
  position: relative;
}
#data-table thead th:last-child { border-right: none; }
#data-table thead th .sort-arrow {
  font-size: 9px;
  margin-left: 4px;
  opacity: 0.3;
  display: inline-block;
  vertical-align: middle;
}
#data-table thead th.sortable { cursor: pointer; }
#data-table thead th.sortable:hover { color: var(--accent); }
#data-table thead th.sortable:hover .sort-arrow { opacity: 0.7; }
#data-table thead th.sorted-asc,
#data-table thead th.sorted-desc { color: var(--accent); }
#data-table thead th.sorted-asc .sort-arrow,
#data-table thead th.sorted-desc .sort-arrow { opacity: 1; color: var(--accent); }
.col-resize-handle {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 4px;
  cursor: col-resize;
  background: transparent;
  z-index: 2;
}
.col-resize-handle:hover,
.col-resize-handle.active { background: var(--accent); }
#data-table thead th { position: relative; }
#data-table tbody td {
  padding: 6px 12px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}
#data-table tbody td:last-child { border-right: none; }
#data-table tbody tr.order-row:nth-child(4n+1) { background: transparent; }
#data-table tbody tr.order-row:nth-child(4n+3) { background: var(--bg-row-stripe); }
#data-table tbody tr.order-row:hover,
#data-table tbody tr.order-row:nth-child(4n+1):hover,
#data-table tbody tr.order-row:nth-child(4n+3):hover { background: var(--bg-row-hover); }
#data-table tbody tr.clickable { cursor: pointer; }
#data-table tbody td.num { font-family: 'Consolas', 'Courier New', monospace; font-weight: 600; color: var(--accent); }
#data-table tbody td.amount { text-align: right; font-weight: 500; }
.empty-msg { text-align: center; color: var(--text-label); padding: 40px !important; font-size: 13px; }

/* Status badges */
.status-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.5;
  white-space: nowrap;
}
.status-badge.status-done     { background: rgba(76,175,80,0.18); color: #4caf50; }
.status-badge.status-ready    { background: rgba(33,150,243,0.18); color: #2196f3; }
.status-badge.status-progress { background: rgba(255,127,42,0.18); color: var(--accent); }
.status-badge.status-start    { background: rgba(158,158,158,0.18); color: #9e9e9e; }
[data-theme="light"] .status-badge.status-done     { background: rgba(76,175,80,0.15); color: #2e7d32; }
[data-theme="light"] .status-badge.status-ready    { background: rgba(33,150,243,0.15); color: #1565c0; }
[data-theme="light"] .status-badge.status-progress { background: rgba(255,127,42,0.15); color: #e66e1e; }
[data-theme="light"] .status-badge.status-start    { background: rgba(158,158,158,0.15); color: #757575; }

/* Stats bar */
#stats-bar {
  display: flex;
  gap: 24px;
  padding: 8px 16px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 11px;
}
.stats-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.stats-label {
  color: var(--text-label);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.3px;
}
.stats-value {
  color: var(--text);
  font-weight: 600;
}
.stats-value.accent { color: var(--accent); }

/* Status Board */
#status-board {
  position: absolute;
  inset: 0;
  overflow: auto;
  display: flex;
  gap: 12px;
  padding: 12px;
}
.status-column {
  flex: 1;
  min-width: 200px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
}
.status-column-header {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 12px;
  color: var(--accent);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.status-column-count {
  font-size: 10px;
  background: var(--badge-bg);
  color: var(--text-dim);
  padding: 1px 6px;
  border-radius: 8px;
}
.status-column-body { flex: 1; overflow-y: auto; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.status-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.status-card:hover { border-color: var(--accent); }
.status-card-id { font-size: 10px; color: var(--text-label); }
.status-card-name { font-size: 12px; color: var(--text); margin: 2px 0; }
.status-card-meta { font-size: 10px; color: var(--text-dim); display: flex; justify-content: space-between; }

/* Summary view */
#summary-view {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 12px;
}
.summary-section {
  margin-bottom: 16px;
}
.summary-section h3 {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 8px;
}
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.summary-row:hover { background: var(--bg-row-hover); }
.summary-total {
  font-weight: 600;
  color: var(--accent);
}

/* Detail modal */
#detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.detail-box {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
  max-width: 700px;
  max-height: 80vh;
  width: 90%;
  overflow-y: auto;
  position: relative;
}
.detail-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
}
.detail-close:hover { color: var(--close-hover); }
.detail-title {
  font-size: 16px;
  color: var(--accent);
  margin-bottom: 12px;
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
}
.detail-field { margin-bottom: 4px; }
.detail-label { font-size: 10px; color: var(--text-label); text-transform: uppercase; }
.detail-value { font-size: 13px; color: var(--text); }

/* Status bar */
#status-bar {
  display: flex;
  justify-content: space-between;
  padding: 3px 16px;
  background: var(--bg-sidebar);
  border-top: 1px solid var(--border);
  font-size: 10px;
  color: var(--text-label);
  flex-shrink: 0;
}

/* Loading overlay */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.loading-box {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 30px 40px;
  text-align: center;
  min-width: 250px;
}
.loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 13px; color: var(--text); }

/* Expandable order rows */
.order-row { cursor: pointer; }
.order-row.expanded { background: var(--bg-row-hover) !important; }
.order-row.expanded .expand-icon { transform: rotate(90deg); }
.expand-icon {
  font-size: 8px;
  margin-right: 6px;
  color: var(--text-label);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: var(--bg-section);
  transition: transform 0.2s ease, background 0.15s;
  vertical-align: middle;
  flex-shrink: 0;
}
.order-row:hover .expand-icon { background: var(--border); }
.sub-rows { overflow: hidden; }
.sub-rows td { padding: 0 !important; border-right: none !important; }
.sub-rows:not([style*="display: none"]) td { border-bottom: 2px solid var(--accent) !important; }
.sub-loading { padding: 10px 24px; color: var(--text-label); font-size: 11px; }
.sub-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.sub-table thead th {
  background: var(--bg-section);
  color: var(--text-dim);
  font-weight: 600;
  padding: 6px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
  font-size: 10px;
  text-transform: uppercase;
}
.sub-table thead th:last-child { border-right: none; }
.sub-table tbody td {
  padding: 5px 16px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.sub-table tbody td:last-child { border-right: none; }
.sub-table tbody tr:last-child td { border-bottom: none; }
.sub-table tbody tr:nth-child(even) { background: var(--bg-row-stripe, rgba(128,128,128,0.04)); }
.sub-table tbody tr:hover { background: var(--bg-row-hover); }
.sub-table .status-badge { font-size: 10px; padding: 1px 8px; }

/* History button & table */
.btn-history {
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--btn-add-bg);
  color: var(--text);
  font-size: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.btn-history:hover { background: var(--accent); border-color: var(--accent); }
.history-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 10px; }
.history-table thead th {
  background: var(--bg-section);
  color: var(--text-dim);
  font-weight: 600;
  padding: 6px 10px;
  text-align: left;
  border-bottom: 2px solid var(--accent);
  white-space: nowrap;
  font-size: 11px;
  text-transform: uppercase;
}
.history-table tbody td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.history-table tbody tr:hover { background: var(--bg-row-hover); }

/* --- Analytics --- */
#analytics-view {
  position: absolute;
  inset: 0;
  overflow: auto;
  padding: 16px;
}
.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto;
  gap: 16px;
}
.analytics-widget {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  min-height: 280px;
  display: flex;
  flex-direction: column;
}
.analytics-widget.full-width {
  grid-column: 1 / -1;
  min-height: auto;
}
.analytics-widget h3 {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 12px;
  font-weight: 600;
}
.analytics-widget svg { overflow: visible; }
.analytics-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.analytics-legend-item { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-dim); }
.analytics-legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #808080; }

/* Panel backdrop */
#panel-backdrop {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4); z-index: 8;
  cursor: pointer;
}

/* Tables view */
#tables-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#tables-data { overflow: auto; flex: 1; }
#tables-data-table { width: 100%; border-collapse: collapse; font-size: 11px; }
#tables-data-table thead { position: sticky; top: 0; z-index: 2; }
#tables-data-table th { background: var(--bg); color: var(--accent); font-weight: 600; padding: 5px 8px; text-align: left; border-bottom: 2px solid var(--accent); white-space: nowrap; font-size: 10px; text-transform: uppercase; }
#tables-data-table td { padding: 3px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
#tables-data-table tbody tr:hover { background: var(--hover); }
#tables-data-table .num { color: var(--text-dim); font-size: 10px; width: 40px; }

/* Panel history grouped by item */
.panel-history-item { margin-bottom: 14px; }
.panel-history-header { font-size: 12px; font-weight: 600; color: var(--accent); padding: 6px 0; border-bottom: 1px solid var(--border); margin-bottom: 6px; }

.mobile-nav { display: none; }

/* --- Login overlay --- */
#login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  text-align: center;
  max-width: 380px;
  width: 90%;
  padding: 40px 32px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.login-logo { margin-bottom: 24px; }
.login-logo-img { width: 64px; height: 64px; object-fit: contain; margin-bottom: 8px; }
.login-app-name { font-size: 20px; font-weight: 700; color: var(--accent); letter-spacing: -0.5px; }
.login-message { font-size: 13px; color: var(--text-dim); margin-bottom: 24px; line-height: 1.5; }

/* Login form inputs */
.login-input {
  display: block;
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.login-input:focus { border-color: var(--accent); }
.login-input::placeholder { color: var(--text-label); }

.btn-login-submit {
  display: block;
  width: 100%;
  padding: 11px 0;
  margin-bottom: 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn-login-submit:hover { background: var(--accent-hover); }
.btn-login-submit:active { transform: scale(0.98); }
.btn-login-submit:disabled { opacity: 0.6; cursor: not-allowed; }

.login-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.login-separator-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}
.login-separator-text {
  font-size: 12px;
  color: var(--text-label);
  flex-shrink: 0;
}

.btn-yandex-login {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 32px;
  border: none;
  border-radius: 8px;
  background: #FC3F1D;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  width: 100%;
}
.btn-yandex-login:hover { background: #E0330A; }
.btn-yandex-login:active { transform: scale(0.98); }
.login-error {
  margin-top: 16px;
  color: var(--close-hover);
  font-size: 13px;
  padding: 10px;
  border-radius: 6px;
  background: rgba(232,17,35,0.1);
  border: 1px solid rgba(232,17,35,0.2);
}

/* --- User info in sidebar --- */
#user-info-section {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-section);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.user-info-avatar { flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%; overflow: hidden; background: var(--border); }
.user-info-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-info-name {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-logout {
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: none;
  color: var(--text-dim);
  font-size: 10px;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-logout:hover { background: var(--close-hover); border-color: var(--close-hover); color: #fff; }

/* =================== MOBILE (max-width: 768px) =================== */
@media (max-width: 768px) {
  /* ---- toolbar ---- */
  #toolbar { height: 40px; padding: 0 8px; }
  .toolbar-logo { height: 22px; }
  .toolbar-title { font-size: 12px; }
  .toolbar-btn { width: 28px; height: 28px; }

  /* ---- app layout ---- */
  #app { flex-direction: column; }
  #sidebar { display: none; }
  #main-area { margin-left: 0; margin-bottom: 60px; }
  #panel-backdrop { z-index: 19; }

  /* ---- bottom nav ---- */
  .mobile-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--bg-sidebar); border-top: 1px solid var(--border);
    height: 56px; padding-bottom: env(safe-area-inset-bottom);
  }
  .mnav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: none; border: none; color: var(--text-dim); cursor: pointer; gap: 2px;
    font-size: 9px; padding: 4px 0; transition: color 0.15s;
  }
  .mnav-item svg { width: 18px; height: 18px; }
  .mnav-item.active { color: var(--accent); }

  /* ---- main header ---- */
  #main-header {
    flex-wrap: wrap; padding: 6px 8px; gap: 4px; height: auto; min-height: 36px;
  }
  #header-left { flex: 1 1 auto; }
  #view-title { font-size: 14px; }
  #total-count { font-size: 10px; }
  #header-center { order: 3; width: 100%; }
  #search-input { height: 30px; font-size: 12px; }
  #header-right { order: 2; flex: 0 0 auto; gap: 4px; }
  #pagination { order: 2; }
  #pagination .page-btn { width: 26px; height: 26px; font-size: 10px; }
  #page-info { font-size: 10px; }
  .filter-select, .filter-date { height: 28px; font-size: 11px; max-width: 100px; }
  .btn-export, .btn-small { height: 28px; font-size: 11px; padding: 0 8px; }

  /* ---- stats bar ---- */
  #stats-bar { padding: 6px 8px; gap: 8px; flex-wrap: wrap; }
  .stats-label { font-size: 9px; }
  .stats-value { font-size: 12px; }

  /* ---- data table ---- */
  #data-table { font-size: 11px; }
  #data-table th { padding: 4px 6px; font-size: 9px; }
  #data-table td { padding: 5px 6px; }
  #table-scroll { overflow-x: auto; }
  .col-resize-handle { display: none; }

  /* ---- order panel ---- */
  .order-panel {
    position: fixed; top: 40px; right: 0; bottom: 56px; left: 0;
    width: 100% !important; max-width: 100% !important; min-width: unset !important;
    z-index: 21; border-left: none; border-top: 2px solid var(--accent);
    transform: translateX(100%); transition: transform 0.3s ease;
  }
  .order-panel.open { transform: translateX(0); }
  #panel-resize-handle { display: none; }
  .panel-header { padding: 10px; }
  .panel-title { font-size: 14px; }
  .panel-tab { font-size: 11px; padding: 6px 10px; }

  /* ---- status board ---- */
  #status-board { flex-direction: column; overflow-y: auto; gap: 10px; padding: 8px; }
  .status-column { min-width: unset; max-width: unset; width: 100%; flex: none; }
  .status-column-body { max-height: none; }

  /* ---- summary ---- */
  #summary-view { padding: 8px; }

  /* ---- analytics ---- */
  .analytics-grid { grid-template-columns: 1fr !important; gap: 8px; padding: 8px; }
  .analytics-widget.full-width { grid-column: 1; }

  /* ---- tables view ---- */
  #tables-toolbar { padding: 8px; flex-wrap: wrap; }
  #tables-data-table { font-size: 10px; }
  #tables-data-table th { font-size: 9px; padding: 4px 5px; }
  #tables-data-table td { font-size: 10px; padding: 3px 5px; }
  #tables-data { max-height: calc(100vh - 200px) !important; }

  /* ---- detail overlay ---- */
  .detail-box { width: 92vw; max-width: 400px; max-height: 80vh; }

  /* ---- loading ---- */
  .loading-box { padding: 24px; }
  .loading-text { font-size: 13px; }

  /* ---- panel table ---- */
  .panel-table { font-size: 10px; }
  .panel-table th { font-size: 9px; padding: 4px 5px; }
  .panel-table td { font-size: 10px; padding: 4px 5px; }
}

/* =================== MOBILE SMALL (max-width: 400px) =================== */
@media (max-width: 400px) {
  #main-header { padding: 4px 6px; }
  #view-title { font-size: 13px; }
  .filter-select, .filter-date { max-width: 80px; font-size: 10px; height: 26px; }
  #search-input { height: 28px; font-size: 11px; }
  #data-table { font-size: 10px; }
  #data-table td { padding: 4px 4px; }
  .mnav-item svg { width: 16px; height: 16px; }
  .mnav-item { font-size: 8px; }
}
