/**
 * Components — Кнопки, инпуты, карточки, таблицы, бейджи, модалки, утилиты
 */

/* ===== CARDS ===== */
.card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-card); }
.card-title { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 20px; }

/* ===== BUTTONS ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: var(--radius-sm); font-family: var(--font); font-size: 14px; font-weight: 700; border: none; cursor: pointer; transition: all .2s; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 4px 12px var(--accent-glow); }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary { background: var(--bg3); color: var(--text); }
.btn-secondary:hover { background: #e5e5ea; }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 11px; }
.btn-block { width: 100%; }

/* ===== INPUTS ===== */
.input, .select, textarea.input { width: 100%; padding: 10px 14px; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm); font-family: var(--font); font-size: 14px; color: var(--text); transition: all .2s; }
.input:focus, .select:focus, textarea.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.input-money { font-family: var(--font-mono); font-size: 18px; font-weight: 600; }
.input-sm { padding: 6px 10px; font-size: 13px; font-family: var(--font-mono); width: 100px; }
.input-xs { padding: 4px 8px; font-size: 12px; font-family: var(--font-mono); width: 70px; text-align: center; }
.form-group { margin-bottom: 12px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Группы полей в форме создания заказа */
.of-group {
  margin-bottom: 6px; padding: 12px 14px 4px;
  border: 1px solid var(--border); border-radius: 10px;
  background: color-mix(in srgb, var(--bg2) 40%, transparent);
}
.of-group-label {
  font-size: 11px; font-weight: 800; text-transform: uppercase;
  letter-spacing: .5px; color: var(--text-muted); margin-bottom: 8px;
}

/* Автораширяющийся textarea */
.of-autoexpand { resize: none; overflow: hidden; min-height: 40px; }

/* Чипы сотрудников в форме заказа */
.of-emp-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 6px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg);
}
.of-emp-chip {
  padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 700;
  cursor: pointer; transition: all .15s; opacity: .55;
  border: 2px solid transparent;
}
.of-emp-chip:hover { opacity: .8; }
.of-emp-chip.of-emp-active {
  opacity: 1; border-color: currentColor;
  box-shadow: 0 0 0 2px color-mix(in srgb, currentColor 20%, transparent);
}
.of-work-chip { background: color-mix(in srgb, var(--accent) 12%, var(--bg)); color: var(--accent); }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; margin: -4px; padding: 4px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { padding: 8px 12px; text-align: left; background: var(--bg3); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--text-secondary); white-space: nowrap; position: sticky; z-index: 5; }
.table td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:hover td { background: var(--bg3); }
.table tr.today td { background: var(--accent-light) !important; }
.table .weekend { background: rgba(59,130,246,.04); }

/* ===== BADGES ===== */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-pending { background: var(--orange-bg); color: var(--orange); }
.badge-approved { background: var(--green-bg); color: var(--green); }
.badge-rejected { background: var(--red-bg); color: var(--red); }
.badge-warning { background: rgba(251,191,36,.15); color: #b45309; }
.badge-success { background: rgba(34,197,94,.12); color: #15803d; }
.status-badge { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.mono-val { font-family: var(--font-mono); font-weight: 700; }

/* ===== PAYMENT METHOD BUTTONS ===== */
.pay-method-btn {
  flex: 1; padding: 8px 12px; border: 2px solid var(--border); border-radius: 8px;
  background: var(--bg2); cursor: pointer; font-size: 13px; font-weight: 600;
  transition: all .15s; text-align: center;
}
.pay-method-btn:hover { border-color: var(--accent); }
.pay-method-btn.active { border-color: #22C55E; background: #22C55E12; color: #16A34A; }

/* ===== EMPLOYEE COLORS (dynamic — injected via JS) ===== */
.emp-tag { display: inline-flex; padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; white-space: nowrap; }

/* ===== CONTACTS ===== */
.contact-btns { display: flex; gap: 6px; margin-top: 6px; }
.contact-btn { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 6px; font-size: 11px; font-weight: 700; text-decoration: none; transition: all .15s; }
.contact-btn.tg { background: #E3F2FD; color: #1976D2; }
.contact-btn.tg:hover { background: #BBDEFB; }
.contact-btn.sms { background: #E8F5E9; color: #388E3C; }
.contact-btn.sms:hover { background: #C8E6C9; }
.contact-btn.call { background: var(--bg3); color: var(--text-secondary); }
.contact-btn.call:hover { background: #e5e5ea; }

/* ===== MODALS ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 10000; padding: 20px; }
.modal-overlay.hidden { display: none; }
.modal-content { background: var(--bg2); border-radius: 20px; padding: 24px; max-width: 600px; width: 100%; max-height: 90vh; overflow-y: auto; }
.modal-wide { max-width: 800px; }
.modal-order-detail { max-width: 1100px; }
.od-layout { display: flex; gap: 20px; min-height: 0; }
.od-layout-main { flex: 1; min-width: 0; }
.od-layout-history { width: 280px; flex-shrink: 0; border-left: 1px solid var(--border); padding-left: 16px; max-height: 60vh; overflow-y: auto; }
.od-layout-history::-webkit-scrollbar { width: 4px; }
.od-layout-history::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.od-hist-item { font-size: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); line-height: 1.6; }
.od-hist-date { color: var(--text-muted); margin-right: 4px; }
.od-hist-action { font-weight: 600; }
.od-hist-status { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.od-hist-emp { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 600; margin-left: 4px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; position: sticky; top: -24px; background: var(--bg2); z-index: 10; padding: 24px 0 12px 0; margin-top: -24px; }
.modal-title { font-size: 18px; font-weight: 800; }
.modal-close { width: 32px; height: 32px; border-radius: 50%; border: none; background: var(--bg3); cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ===== CRM DIALOGS (confirm / prompt) ===== */
.crm-dialog-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 20000; padding: 20px; opacity: 0; transition: opacity .2s; }
.crm-dialog-overlay.show { opacity: 1; }
.crm-dialog { background: var(--bg2); border-radius: 20px; padding: 24px; max-width: 420px; width: 100%; box-shadow: 0 8px 32px rgba(0,0,0,.18); }
.crm-dialog-body { font-size: 15px; font-weight: 600; line-height: 1.5; margin-bottom: 16px; color: var(--text); }
.crm-dialog-input { width: 100%; margin-bottom: 16px; }
.crm-dialog-footer { display: flex; gap: 8px; justify-content: flex-end; }
.btn-danger { background: var(--danger, #e53935); color: #fff; border: none; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger, #e53935) 85%, #000); }

/* ===== FILTER ===== */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 12px; }
.page-header h2 { font-size: 22px; font-weight: 900; }
.filter-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-btn { padding: 6px 14px; border-radius: 20px; font-size: 12px; font-weight: 700; border: 2px solid var(--border); background: var(--bg2); color: var(--text-secondary); cursor: pointer; transition: all .15s; }
.filter-btn:hover { border-color: var(--accent); color: var(--accent); }
.filter-btn.active { background: var(--accent-light); color: var(--accent); border-color: var(--accent); font-weight: 800; }

/* ===== DICTIONARY SEARCH WIDGET ===== */
.dict-search-wrap {
  position: relative;
}
.dict-search-input {
  width: 100%;
}
.dict-search-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 220px;
  overflow-y: auto;
  background: var(--card-bg, #fff);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  z-index: 100;
  margin-top: 4px;
}
.dict-dd-item {
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.dict-dd-item:last-child { border-bottom: none; }
.dict-dd-item:hover { background: var(--bg-secondary, #f5f5f5); }
.dict-dd-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}
.dict-dd-name b { color: var(--accent, #2563EB); }
.dict-dd-path {
  font-size: 11px;
  color: var(--text-muted);
}
.dict-dd-empty {
  padding: 14px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ===== SEARCH HIGHLIGHT ===== */
mark, .wh-table mark { background: #fef08a; color: inherit; padding: 0 1px; border-radius: 2px; font-weight: inherit; }

/* ===== COLUMN SETTINGS GEAR ===== */
.cs-gear-btn { font-size: 18px !important; padding: 6px 10px !important; min-width: 36px; line-height: 1; }
.cs-popup {
  position: fixed; z-index: 20000;
  background: var(--bg2, #fff); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 8px 32px rgba(0,0,0,.18);
  padding: 12px 16px; min-width: 200px; max-width: 280px;
}
.cs-popup-title { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 8px; }
.cs-popup-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 4px; cursor: pointer; font-size: 13px; font-weight: 600;
  border-radius: 6px; transition: background .1s;
}
.cs-popup-item:hover { background: var(--bg3); }
.cs-popup-item input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.cs-popup-item input:disabled + span { opacity: .5; }
.cs-popup-footer { display: flex; gap: 6px; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); }

/* ===== UTILS ===== */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px); padding: 14px 28px; border-radius: 14px; font-size: 15px; font-weight: 800; z-index: 10300; transition: transform .4s cubic-bezier(.16,1,.3,1); max-width: 90%; text-align: center; box-shadow: 0 6px 24px rgba(0,0,0,.15); }
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: #16a34a; color: #fff; }
.toast.error { background: var(--red); color: #fff; }
.toast.info { background: var(--blue); color: #fff; }
.loading { position: fixed; inset: 0; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 9999; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { margin-top: 16px; font-size: 14px; color: var(--text-secondary); }
.hidden { display: none !important; }
.empty-state { text-align: center; padding: 60px 20px; }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state .title { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.empty-state .desc { color: var(--text-muted); font-size: 14px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }

/* ===== MODE TOGGLE (Заказы / Продажи) ===== */
.mode-toggle-btn {
  padding: 8px 20px;
  font-size: 13px;
  font-weight: 700;
  border: 2px solid var(--border);
  background: var(--bg2);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all .15s;
}
.mode-toggle-btn:first-child { border-radius: 10px 0 0 10px; }
.mode-toggle-btn:last-child { border-radius: 0 10px 10px 0; border-left: none; }
.mode-toggle-btn:hover { color: var(--accent); border-color: var(--accent); }
.mode-toggle-btn.mode-toggle-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.mode-toggle-btn:last-child.mode-toggle-active {
  background: #16A34A;
  border-color: #16A34A;
  color: #fff;
}
