/* ═══════════════════════════════════════════════════
   REST GLOBAL — Стили
   ═══════════════════════════════════════════════════ */

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

:root {
  --c-primary:   #1a56db;
  --c-primary-h: #1648c0;
  --c-accent:    #0e9f6e;
  --c-danger:    #e02424;
  --c-warn:      #d97706;
  --c-bg:        #f3f4f6;
  --c-surface:   #ffffff;
  --c-border:    #e5e7eb;
  --c-text:      #111827;
  --c-muted:     #6b7280;
  --c-sidebar:   #1e2939;
  --c-sidebar-h: #263347;
  --c-sidebar-t: #d1d5db;
  --sidebar-w:   240px;
  --radius:      8px;
  --shadow:      0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:   0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg:   0 10px 15px rgba(0,0,0,.08), 0 4px 6px rgba(0,0,0,.05);
}

html, body { height: 100%; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; color: var(--c-text); }

/* ────────────── LOGIN ────────────── */
.login-body { background: var(--c-bg); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-wrap { width: 100%; max-width: 380px; padding: 1rem; }
.login-card { background: var(--c-surface); border-radius: 12px; padding: 2.5rem 2rem; box-shadow: var(--shadow-lg); }
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-card h2 { text-align: center; font-size: 1.25rem; color: var(--c-muted); margin-bottom: 1.5rem; font-weight: 500; }
.login-card label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .375rem; }
.login-card input[type=password] { width: 100%; padding: .6rem .875rem; border: 1.5px solid var(--c-border); border-radius: var(--radius); font-size: 1rem; transition: border-color .15s; }
.login-card input[type=password]:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(26,86,219,.15); }

/* ────────────── LOGO ────────────── */
.logo-rg { font-size: 1.4rem; font-weight: 800; letter-spacing: .04em; color: #fff; }
.logo-rg span { color: #60a5fa; }
.login-logo .logo-rg { color: var(--c-primary); }
.login-logo .logo-rg span { color: var(--c-accent); }

/* ────────────── LAYOUT ────────────── */
.app-body { display: flex; height: 100vh; overflow: hidden; background: var(--c-bg); }

.sidebar {
  width: var(--sidebar-w); background: var(--c-sidebar); display: flex; flex-direction: column;
  flex-shrink: 0; overflow-y: auto; transition: width .2s;
}
.sidebar-header { padding: 1.25rem 1rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-nav { flex: 1; padding: .5rem 0; }
.nav-item {
  display: flex; align-items: center; gap: .625rem; padding: .65rem 1rem;
  color: var(--c-sidebar-t); text-decoration: none; font-size: .9rem; font-weight: 500;
  border-radius: 0; transition: background .15s, color .15s;
}
.nav-item svg { width: 1.1rem; height: 1.1rem; fill: currentColor; flex-shrink: 0; }
.nav-item:hover { background: var(--c-sidebar-h); color: #fff; }
.nav-item.active { background: var(--c-primary); color: #fff; }
.sidebar-footer { padding: .75rem; border-top: 1px solid rgba(255,255,255,.08); }

.main-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }

.page-header {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 1.25rem 1.5rem; background: var(--c-surface); border-bottom: 1px solid var(--c-border);
  position: sticky; top: 0; z-index: 10;
}
.page-header h1 { font-size: 1.2rem; font-weight: 700; flex: 1; }

.page-body { padding: 1.5rem; }

/* ────────────── BUTTONS ────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1rem;
  border-radius: var(--radius); font-size: .875rem; font-weight: 500; border: none;
  cursor: pointer; text-decoration: none; transition: background .15s, box-shadow .15s, opacity .15s;
  white-space: nowrap;
}
.btn svg { width: 1rem; height: 1rem; fill: currentColor; flex-shrink: 0; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--c-primary-h); }
.btn-success { background: var(--c-accent); color: #fff; }
.btn-success:hover:not(:disabled) { background: #0b8a5e; }
.btn-danger { background: var(--c-danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #c01a1a; }
.btn-outline { background: transparent; color: var(--c-primary); border: 1.5px solid var(--c-primary); }
.btn-outline:hover:not(:disabled) { background: rgba(26,86,219,.06); }
.btn-ghost { background: transparent; color: var(--c-sidebar-t); }
.btn-ghost:hover:not(:disabled) { background: var(--c-sidebar-h); color: #fff; }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; padding: .7rem 1rem; }
.btn-icon { padding: .4rem; border-radius: 6px; }

/* ────────────── CARDS / TABLE ────────────── */
.card { background: var(--c-surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1rem; }
.card-header { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--c-border); }
.card-header h3 { font-size: 1rem; font-weight: 600; flex: 1; }
.card-body { padding: 1.25rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { text-align: left; padding: .625rem .875rem; background: var(--c-bg); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--c-muted); border-bottom: 1px solid var(--c-border); }
td { padding: .625rem .875rem; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f9fafb; }
.table-actions { display: flex; gap: .3rem; }

/* ────────────── FORMS ────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .3rem; color: var(--c-text); }
.form-control {
  width: 100%; padding: .55rem .875rem; border: 1.5px solid var(--c-border);
  border-radius: var(--radius); font-size: .9rem; color: var(--c-text);
  transition: border-color .15s, box-shadow .15s; background: #fff;
}
.form-control:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(26,86,219,.12); }
select.form-control { cursor: pointer; }
.form-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.form-hint { font-size: .78rem; color: var(--c-muted); margin-top: .25rem; }

/* ────────────── REQUISITES GRID ────────────── */
.req-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }

/* ────────────── DEAL ITEMS TABLE ────────────── */
.items-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.items-table th, .items-table td { padding: .5rem .625rem; border: 1px solid var(--c-border); }
.items-table th { background: var(--c-bg); font-weight: 600; font-size: .78rem; text-transform: uppercase; }
.items-table input, .items-table select { width: 100%; padding: .3rem .5rem; border: 1px solid var(--c-border); border-radius: 5px; font-size: .875rem; }
.items-table .col-num   { width: 2.5rem; text-align: center; }
.items-table .col-qty   { width: 5rem; }
.items-table .col-days  { width: 6rem; }
.items-table .col-price { width: 8rem; }
.items-table .col-cur   { width: 7rem; }
.items-table .col-sum   { width: 7rem; font-weight: 600; }
.items-table .col-act   { width: 3rem; text-align: center; }
.items-total { text-align: right; padding: .75rem .875rem; font-weight: 700; font-size: 1rem; background: var(--c-bg); border-radius: 0 0 var(--radius) var(--radius); }

/* ────────────── SERVICES CATALOG ────────────── */
.catalog-layout { display: flex; gap: 1.25rem; }
.catalog-sidebar { width: 240px; flex-shrink: 0; }
.catalog-main { flex: 1; min-width: 0; }
.folder-tree { list-style: none; }
.folder-item {
  display: flex; align-items: center; padding: .5rem .75rem; border-radius: var(--radius);
  cursor: pointer; font-size: .9rem; gap: .5rem; transition: background .12s;
}
.folder-item:hover { background: #f3f4f6; }
.folder-item.active { background: rgba(26,86,219,.1); color: var(--c-primary); font-weight: 600; }
.folder-item svg { width: 1rem; height: 1rem; fill: var(--c-warn); flex-shrink: 0; }
.folder-item.active svg { fill: var(--c-primary); }
.folder-item-actions { margin-left: auto; display: none; gap: .2rem; }
.folder-item:hover .folder-item-actions { display: flex; }

/* ────────────── BREADCRUMB ────────────── */
.breadcrumb { display: flex; align-items: center; gap: .375rem; font-size: .85rem; color: var(--c-muted); margin-bottom: .75rem; flex-wrap: wrap; }
.breadcrumb a { color: var(--c-primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep::after { content: '/'; }

/* ────────────── STATUS BADGE ────────────── */
.badge { display: inline-flex; align-items: center; padding: .2rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-active  { background: #d1fae5; color: #065f46; }
.badge-done    { background: #dbeafe; color: #1e40af; }
.badge-cancel  { background: #fee2e2; color: #991b1b; }

/* ────────────── MODAL ────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal {
  background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column;
}
.modal-lg { max-width: 780px; }
.modal-header { display: flex; align-items: center; padding: 1rem 1.25rem; border-bottom: 1px solid var(--c-border); }
.modal-header h3 { flex: 1; font-size: 1.05rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--c-muted); line-height: 1; padding: 0 .25rem; }
.modal-close:hover { color: var(--c-text); }
.modal-body { flex: 1; overflow-y: auto; padding: 1.25rem; }
.modal-footer { padding: 1rem 1.25rem; border-top: 1px solid var(--c-border); display: flex; gap: .625rem; justify-content: flex-end; }

/* ────────────── SEARCH ────────────── */
.search-wrap { position: relative; }
.search-wrap svg { position: absolute; left: .625rem; top: 50%; transform: translateY(-50%); width: .9rem; height: .9rem; fill: var(--c-muted); pointer-events: none; }
.search-input { padding-left: 2rem !important; }

/* ────────────── EMPTY STATE ────────────── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--c-muted); }
.empty-state svg { width: 3rem; height: 3rem; fill: var(--c-border); margin-bottom: .75rem; }
.empty-state p { font-size: 1rem; margin-bottom: .25rem; color: var(--c-text); }
.empty-state small { font-size: .85rem; }

/* ────────────── TOAST ────────────── */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 200; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  padding: .75rem 1.1rem; border-radius: var(--radius); color: #fff; font-size: .875rem;
  box-shadow: var(--shadow-md); animation: slide-in .25s ease; max-width: 320px;
  display: flex; align-items: center; gap: .5rem;
}
.toast svg { width: 1rem; height: 1rem; fill: currentColor; flex-shrink: 0; }
.toast-success { background: var(--c-accent); }
.toast-error   { background: var(--c-danger); }
.toast-info    { background: var(--c-primary); }
@keyframes slide-in { from { transform: translateX(110%); opacity: 0; } to { transform: none; opacity: 1; } }

/* ────────────── ERROR BOX ────────────── */
.error-box { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; padding: .75rem 1rem; border-radius: var(--radius); font-size: .875rem; margin-bottom: 1rem; }

/* ────────────── MISC ────────────── */
.text-muted { color: var(--c-muted); }
.text-right { text-align: right; }
.gap-2 { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.divider { border: none; border-top: 1px solid var(--c-border); margin: 1rem 0; }
.loading { color: var(--c-muted); padding: 2rem; text-align: center; }
.page-loading { padding: 3rem; text-align: center; color: var(--c-muted); font-size: 1.1rem; }

.client-info-box { background: var(--c-bg); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.client-info-box p { font-size: .85rem; color: var(--c-muted); margin-top: .2rem; }

.doc-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.doc-status { font-size: .82rem; color: var(--c-muted); }

/* service picker in modal */
.service-picker-list { max-height: 340px; overflow-y: auto; border: 1px solid var(--c-border); border-radius: var(--radius); }
.service-picker-item { display: flex; align-items: center; padding: .625rem .875rem; gap: .625rem; cursor: pointer; transition: background .1s; font-size: .875rem; }
.service-picker-item:not(:last-child) { border-bottom: 1px solid var(--c-border); }
.service-picker-item:hover { background: var(--c-bg); }
.service-picker-item .sp-name { flex: 1; font-weight: 500; }
.service-picker-item .sp-price { color: var(--c-muted); font-size: .82rem; white-space: nowrap; }
.service-picker-folder { padding: .4rem .875rem; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--c-muted); background: var(--c-bg); border-bottom: 1px solid var(--c-border); }

/* ────────────── КОНВЕРТЕР ВАЛЮТ ────────────── */
.conv-widget {
  margin: .75rem .5rem;
  background: rgba(255,255,255,.06);
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,.1);
  overflow: hidden;
}
.conv-header {
  display: flex; align-items: center; gap: .4rem;
  padding: .5rem .75rem;
  font-size: .75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: rgba(255,255,255,.5);
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.conv-header svg { width: .85rem; height: .85rem; fill: rgba(255,255,255,.4); flex-shrink:0; }
.conv-updated { margin-left: auto; font-size: .65rem; font-weight: 400; color: rgba(255,255,255,.3); }
.conv-body { padding: .625rem .625rem .5rem; }
.conv-row {
  display: flex; gap: .375rem; align-items: center;
}
.conv-row input {
  flex: 1; min-width: 0;
  padding: .4rem .5rem;
  background: #0f172a; border: 1px solid rgba(255,255,255,.2);
  border-radius: 6px; color: #f1f5f9; font-size: .875rem;
  transition: border-color .15s;
}
.conv-row input:focus { outline: none; border-color: rgba(96,165,250,.7); }
.conv-row input[readonly] { color: #60a5fa; font-weight: 600; cursor: default; }
.conv-row select {
  width: 80px; flex-shrink: 0;
  padding: .4rem .3rem;
  background: #0f172a; border: 1px solid rgba(255,255,255,.2);
  border-radius: 6px; color: #f1f5f9; font-size: .8rem;
  cursor: pointer;
}
.conv-row select:focus { outline: none; border-color: rgba(96,165,250,.7); }
.conv-row select option {
  background: #0f172a;
  color: #f1f5f9;
}
.conv-swap-btn {
  display: block; width: 100%; margin: .35rem 0;
  background: rgba(255,255,255,.07); border: none;
  border-radius: 6px; color: rgba(255,255,255,.6);
  font-size: 1rem; padding: .2rem; cursor: pointer;
  transition: background .15s, color .15s;
  text-align: center;
}
.conv-swap-btn:hover { background: rgba(255,255,255,.14); color: #fff; }
.conv-rate-line {
  margin-top: .4rem;
  font-size: .7rem; color: rgba(255,255,255,.35);
  text-align: center; min-height: .9rem;
}
.conv-error { color: #f87171; }

/* ────────────── МОБИЛЬНЫЙ ТОПБАР + ГАМБУРГЕР ────────────── */
.mobile-topbar {
  display: none;
  align-items: center; gap: .75rem;
  padding: .6rem .875rem;
  background: var(--c-sidebar);
  position: sticky; top: 0; z-index: 50;
}
.mobile-logo { font-size: 1.2rem; }

.sidebar-toggle {
  display: flex;
  width: 2rem; height: 2rem; flex-shrink: 0;
  background: transparent; border: none;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 5px; cursor: pointer; padding: 0;
}
.sidebar-toggle span {
  display: block; width: 1.1rem; height: 2px;
  background: #fff; border-radius: 2px;
  transition: transform .25s, opacity .25s;
}
.sidebar-open .sidebar-toggle span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.sidebar-open .sidebar-toggle span:nth-child(2) { opacity: 0; }
.sidebar-open .sidebar-toggle span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0; z-index: 149;
  background: rgba(0,0,0,.45);
}
.sidebar-open .sidebar-backdrop { display: block; }

@media (max-width: 768px) {
  .app-body { flex-direction: column; height: 100dvh; }
  .mobile-topbar { display: flex; width: 100%; flex-shrink: 0; }

  /* Сайдбар полностью выводим из потока — фиксированный поверх */
  .sidebar {
    position: fixed; inset: 0; right: auto; z-index: 150;
    width: var(--sidebar-w); height: 100%;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .sidebar-open .sidebar { transform: translateX(0); }

  .main-content { flex: 1; overflow-y: auto; min-height: 0; margin-left: 0; }

  .catalog-layout { flex-direction: column; }
  .catalog-sidebar { width: 100%; }
  .form-row { grid-template-columns: 1fr; }
  .req-grid { grid-template-columns: 1fr; }
  .page-body { padding: 1rem; }
}

/* ────────────── PRINT ────────────── */
@media print {
  .sidebar, .page-header, .doc-actions, .btn, .toast-container { display: none !important; }
  .main-content { overflow: visible; }
  body { background: white; }
}
