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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f5f5;
  color: #333;
  font-size: 15px;
  line-height: 1.45;
}

/* Auth screen */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1a1a2e, #16213e);
}

.auth-box {
  background: white;
  padding: 40px;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,0.2);
  width: 360px;
}

.auth-box h1 {
  font-size: 24px;
  margin-bottom: 8px;
  color: #1a1a2e;
}

.auth-box p {
  color: #666;
  margin-bottom: 24px;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid #e0e0e0;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-size: 14px;
  color: #666;
}

.auth-tab.active {
  color: #4a6cf7;
  border-bottom-color: #4a6cf7;
  font-weight: 600;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form input {
  padding: 12px 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.auth-form input:focus {
  border-color: #4a6cf7;
}

.auth-form button {
  padding: 12px;
  background: #4a6cf7;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.auth-form button:hover {
  background: #3b5de7;
}

.auth-error {
  color: #e74c3c;
  margin-top: 12px;
  font-size: 14px;
}

/* Header */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: white;
  border-bottom: 1px solid #e0e0e0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.header-left h1 {
  font-size: 22px;
  color: #1a1a2e;
}

.subtitle {
  font-size: 14px;
  color: #888;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.update-time {
  font-size: 13px;
  color: #888;
}

.refresh-btn {
  padding: 8px 20px;
  background: #4a6cf7;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}

.refresh-btn:hover {
  background: #3b5de7;
}

.refresh-btn:disabled {
  background: #aaa;
  cursor: not-allowed;
}

/* Tabs */
.tabs {
  display: flex;
  padding: 0 24px;
  background: white;
  border-bottom: 1px solid #e0e0e0;
}

.tab {
  padding: 12px 24px;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  font-size: 15px;
  color: #555;
  transition: all 0.2s;
}

.tab:hover {
  color: #333;
  background: #f8f8f8;
}

.tab.active {
  color: #4a6cf7;
  border-bottom-color: #4a6cf7;
  font-weight: 600;
}

/* Loading & Error */
.loading {
  text-align: center;
  padding: 60px;
  color: #888;
  font-size: 16px;
}

.error {
  text-align: center;
  padding: 40px;
  color: #e74c3c;
  font-size: 14px;
}

/* Table */
.table-container {
  overflow-x: auto;
  margin: 16px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

thead th {
  position: sticky;
  top: 0;
  background: #f8f9fa;
  padding: 10px 12px;
  text-align: center;
  border-bottom: 2px solid #dee2e6;
  font-weight: 600;
  color: #495057;
  white-space: nowrap;
  z-index: 10;
}

thead th:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 20;
  background: #f8f9fa;
  min-width: 160px;
}

tbody td {
  padding: 8px 12px;
  text-align: center;
  border-bottom: 1px solid #eee;
}

tbody td:first-child {
  text-align: left;
  font-weight: 500;
  position: sticky;
  left: 0;
  background: white;
  z-index: 5;
  white-space: nowrap;
}

tbody tr:nth-child(even) td {
  background: #fafafa;
}

tbody tr:nth-child(even) td:first-child {
  background: #fafafa;
}

tbody tr:hover td {
  background: #f0f4ff;
}

tbody tr:hover td:first-child {
  background: #f0f4ff;
}

/* Значения */
.cell-zero {
  color: #ccc;
}

.cell-value {
  color: #333;
  font-weight: 500;
}

.cell-total {
  font-weight: 700;
  color: #1a1a2e;
}

/* Итого строка */
th.col-total,
td.col-total {
  border-left: 2px solid #dee2e6;
  background: #f0f4ff !important;
}

/* Stale data indicator */
.stale-indicator {
  color: #e67e22;
  font-size: 12px;
  margin-left: 8px;
}

/* --- Multi-page layout (Phase 0+) --- */
.logout-btn, .settings-btn {
  padding: 8px 16px;
  background: #fff;
  color: #555;
  border: 1px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.logout-btn:hover, .settings-btn:hover { background: #f0f0f0; }
.settings-btn { font-weight: 500; }

.settings-subtabs {
  padding: 0 24px;
}

.main-tabs .tab {
  font-size: 15px;
  font-weight: 500;
}

.sub-tabs {
  background: #fafbfc;
  border-bottom: 1px solid #eee;
}

.page {
  padding-bottom: 40px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: white;
  border-bottom: 1px solid #e0e0e0;
}

.page-header h2 {
  font-size: 18px;
  color: #1a1a2e;
}

.primary-btn {
  padding: 10px 20px;
  background: #4a6cf7;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.primary-btn:hover { background: #3b5de7; }

.notice {
  margin: 16px 24px;
  padding: 16px;
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 8px;
  color: #7a5c00;
  font-size: 14px;
}

/* --- Credentials selector --- */
.credentials-selector-row {
  padding: 12px 24px;
  background: #fafbfc;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}
.credentials-selector-row select {
  padding: 6px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
}

/* --- Credentials list --- */
.credentials-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 24px;
}

.cred-card {
  background: white;
  border: 1px solid #e3e6ea;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.cred-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.cred-card-header strong {
  font-size: 15px;
  color: #1a1a2e;
  margin-right: 8px;
}

.cred-actions { display: flex; gap: 8px; }
.cred-actions button {
  padding: 6px 12px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.cred-actions button:hover { background: #f5f5f5; }
.cred-actions button.danger { color: #c0392b; border-color: #e4a8a0; }
.cred-actions button.danger:hover { background: #fdedec; }
.cred-actions button:disabled { opacity: 0.6; cursor: wait; }

.cred-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 13px;
  color: #555;
}
.cred-meta code {
  background: #f4f5f7;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  margin-left: 4px;
  vertical-align: middle;
}
.badge-ok   { background: #e7f7ee; color: #0f8a3e; }
.badge-err  { background: #fdedec; color: #c0392b; }
.badge-warn { background: #fff3cd; color: #7a5c00; }

/* --- Modal --- */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-box {
  background: white;
  border-radius: 10px;
  padding: 24px;
  width: 440px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.modal-box h3 {
  margin-bottom: 16px;
  color: #1a1a2e;
  font-size: 17px;
}
.modal-box label {
  display: block;
  font-size: 13px;
  color: #555;
  margin-top: 10px;
  margin-bottom: 4px;
}
.modal-box input[type=text] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}
.modal-box input[type=text]:focus { border-color: #4a6cf7; }
.hint { color: #888; font-weight: normal; font-size: 12px; }
.field-hint {
  font-size: 12px;
  color: #6b7280;
  margin-top: 4px;
  line-height: 1.4;
  background: #f6f8fb;
  padding: 8px 10px;
  border-radius: 5px;
  border-left: 3px solid #4a6cf7;
}

.scheme-fieldset {
  margin-top: 14px;
  border: 1px solid #e3e6ea;
  border-radius: 6px;
  padding: 10px 14px;
}
.scheme-fieldset legend { padding: 0 6px; font-size: 13px; color: #555; }
.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin: 6px 0 !important;
  font-size: 14px;
  color: #333 !important;
}

.modal-actions {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.modal-actions button {
  padding: 10px 22px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 15px;
  border: 1px solid #ccc;
  background: white;
  color: #333;
  font-weight: 500;
}
.modal-actions button.primary-btn {
  border-color: #4a6cf7;
  background: #4a6cf7;
  color: #fff;
}
.modal-actions button.primary-btn:hover { background: #3b5de7; }

/* --- Row total --- */
.row-total td {
  font-weight: 700 !important;
  background: #f0f4ff !important;
}

/* --- Sortable columns --- */
th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
}
th.sortable::after {
  content: '⇅';
  margin-left: 6px;
  color: #bbb;
  font-size: 10px;
  vertical-align: middle;
}
th.sortable:hover { background: #eef1f5 !important; color: #333; }
th.sort-asc::after  { content: '▲'; color: #4a6cf7; font-size: 9px; }
th.sort-desc::after { content: '▼'; color: #4a6cf7; font-size: 9px; }

/* --- Alert highlights --- */
.cell-critical { background: #fdecea !important; color: #c0392b; font-weight: 600; }
.cell-warning  { background: #fff3cd !important; color: #7a5c00; font-weight: 600; }
tbody tr:hover .cell-critical { background: #fbd5d1 !important; }
tbody tr:hover .cell-warning  { background: #ffe9a3 !important; }

.critical-badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 7px;
  margin-left: 6px;
  border-radius: 10px;
  background: #c0392b;
  color: white;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

/* --- Thresholds page --- */
.thresholds-actions { display: flex; gap: 10px; }
.secondary-btn {
  padding: 10px 16px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.secondary-btn:hover { background: #f5f5f5; }

input.th-input {
  width: 70px;
  padding: 4px 6px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  text-align: center;
}
input.th-input:focus {
  border-color: #4a6cf7;
  outline: none;
}
input.th-input.th-dirty {
  border-color: #4a6cf7;
  background: #f0f4ff;
}
#thresholds-table thead th:first-child,
#thresholds-table tbody td:first-child {
  min-width: 180px;
}
#thresholds-table tbody td {
  padding: 4px 6px;
}
#thresholds-hint {
  margin: 16px 24px;
}

/* --- Shipment items --- */
.shipment-item-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  align-items: center;
}
.shipment-item-row select.si-product { flex: 1; padding: 6px 8px; border: 1px solid #ccc; border-radius: 4px; }
.shipment-item-row input.si-qty { width: 70px; padding: 6px 8px; border: 1px solid #ccc; border-radius: 4px; text-align: center; }
.shipment-item-row .si-remove {
  width: 28px; height: 28px;
  background: #fff; border: 1px solid #e4a8a0; color: #c0392b;
  border-radius: 4px; cursor: pointer; font-size: 16px; font-weight: 700;
}
.shipment-item-row .si-remove:hover { background: #fdedec; }

.modal-box select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  font-size: 14px;
}

/* --- Recommendations --- */
.rec-form {
  background: white;
  margin: 16px 24px;
  padding: 20px;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  max-width: 500px;
}
.rec-form label { display: block; margin: 10px 0 4px; font-size: 13px; color: #555; }
.rec-form input[type=number],
.rec-form select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  font-size: 14px;
}

.rec-summary {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding: 0 24px;
  margin-top: 16px;
}
.rec-summary-card {
  background: #f0f4ff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  min-width: 160px;
}
.rec-summary-warn { background: #fff3cd; color: #7a5c00; }
.rec-summary-err  { background: #fdecea; color: #c0392b; }

.rec-row-shortfall td { background: #fff6f6 !important; }

.rec-remaining-card {
  display: flex;
  justify-content: space-between;
  padding: 8px 14px;
  background: white;
  border: 1px solid #e3e6ea;
  border-radius: 6px;
  font-size: 14px;
}
.rec-remaining-card strong { color: #4a6cf7; }

@media (max-width: 768px) {
  header {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }

  .tabs {
    overflow-x: auto;
    padding: 0 12px;
  }

  .table-container {
    margin: 8px;
  }
}
