:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --line: #d9dfec;
  --text: #1f2a44;
  --blue: #1e88e5;
  --green: #2e7d32;
  --orange: #f57c00;
  --danger: #b91c1c;
  --gray: #9ca3af;
  font-family: Inter, Arial, sans-serif;
}

/* ── Login Overlay ── */
#loginOverlay {
  display: flex;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  align-items: center;
  justify-content: center;
}
#loginOverlay.hidden { display: none; }
.login-box {
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}

/* ── Base ── */
body { margin: 0; background: var(--bg); color: var(--text); }
header { padding: 14px 20px 16px; background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); color: #fff; border-bottom: 3px solid #e55a1c; }
header h1 { margin: 0 0 2px; font-size: 20px; letter-spacing: -.3px; }
header p { margin: 0; opacity: .65; font-size: 13px; }
main { padding: 16px; display: grid; gap: 16px; }

/* ── Cards ── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.card h2 { margin: 0 0 12px; font-size: 16px; }

/* ── Forms ── */
.grid-form { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; }
input, select, textarea, button { padding: 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); border-color: var(--blue); }
button { background: var(--blue); color: white; border: none; cursor: pointer; font-weight: 600; }
button:hover { opacity: .88; }
.btn-primary { background: var(--blue); color: #fff; border: none; border-radius: 8px; padding: 10px 18px; cursor: pointer; font-weight: 600; }

/* ── Toolbar ── */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; flex-wrap: wrap; }
.toolbar-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ── View toggle ── */
.view-toggle { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.toggle-btn { border: none; border-radius: 0; background: #fff; color: var(--text); padding: 8px 16px; font-weight: 500; cursor: pointer; }
.toggle-btn.active { background: var(--blue); color: #fff; }
.nav-group { display: flex; align-items: center; gap: 4px; }
.nav-btn { background: #fff; border: 1px solid var(--line); color: var(--text); padding: 8px 12px; border-radius: 8px; font-size: 16px; cursor: pointer; line-height: 1; }
.nav-btn:hover { background: var(--bg); }

/* ── Calendar ── */
.calendar { display: grid; border: 1px solid var(--line); border-radius: 8px; overflow-x: auto; overflow-y: visible; }
.calendar.day-view { grid-template-columns: 64px 1fr; }
.calendar.week-view { grid-template-columns: 64px repeat(7, 1fr); }

.cal-cell, .cal-hour, .cal-header { border: 1px solid var(--line); padding: 4px; background: #fff; box-sizing: border-box; }
.cal-hour { background: #eef2ff; font-weight: 600; font-size: 12px; display: flex; align-items: center; justify-content: center; height: 52px; }
.cal-header { background: #e5edff; font-weight: 700; font-size: 12px; text-align: center; min-height: 36px; display: flex; align-items: center; justify-content: center; padding: 6px 4px; }
.cal-header.today { background: #dbeafe; }

.cal-cell { height: 52px; position: relative; overflow: visible; }
.cal-cell.droppable-hover { background: #eff6ff; }

/* ── Events ── */
.event { border-radius: 6px; color: white; font-size: 11px; padding: 4px 22px 4px 6px; cursor: grab; line-height: 1.3; position: absolute; top: 2px; left: 2px; right: 2px; margin: 0; overflow: hidden; z-index: 5; box-sizing: border-box; }
.event:active { cursor: grabbing; }
.event.obhliadka { background: var(--blue); }
.event.montaz { background: var(--green); }
.event.volno { background: var(--orange); }
.event-del { position: absolute; top: 2px; right: 3px; background: none; border: none; color: rgba(255,255,255,0.75); font-size: 12px; cursor: pointer; padding: 0 2px; line-height: 1; border-radius: 3px; }
.event-del:hover { color: #fff; background: rgba(0,0,0,0.2); }

/* ── Jobs table ── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { border: 1px solid var(--line); padding: 8px; text-align: left; }
th { background: #f1f5fb; font-weight: 600; }
tr.job-done td { color: var(--gray); text-decoration: line-through; }
tr.job-done td:last-child, tr.job-done td:nth-last-child(2), tr.job-done td:nth-last-child(3) { text-decoration: none; }
.status-badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; background: #e5edff; color: var(--blue); }
.status-badge.done { background: #dcfce7; color: var(--green); }
.status-badge.lost { background: #fee2e2; color: var(--danger); }
.btn-detail { background: none; border: 1px solid var(--blue); color: var(--blue); padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.btn-end { background: none; border: 1px solid var(--danger); color: var(--danger); padding: 4px 10px; border-radius: 6px; cursor: pointer; font-size: 12px; }

/* ── Alert ── */
.alert { margin-top: 10px; padding: 10px 14px; border-radius: 8px; background: #fee2e2; color: var(--danger); border: 1px solid #fecaca; font-size: 13px; }
.hidden { display: none !important; }

/* ── History ── */
#historyList { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
#historyList li { font-size: 13px; padding: 4px 0; border-bottom: 1px solid var(--line); }

/* ── 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: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 680px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; }
.modal-header h2 { margin: 0; font-size: 17px; }
.btn-icon { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--gray); padding: 4px 8px; border-radius: 6px; }
.btn-icon:hover { background: var(--bg); }
.modal-info { padding: 8px 20px 12px; font-size: 13px; color: #555; border-bottom: 1px solid var(--line); line-height: 1.6; }

/* ── Tabs ── */
.tabs { display: flex; gap: 0; padding: 12px 20px 0; border-bottom: 1px solid var(--line); }
.tab-btn { background: none; border: none; border-bottom: 2px solid transparent; color: var(--gray); padding: 8px 14px; cursor: pointer; font-weight: 500; font-size: 13px; margin-bottom: -1px; border-radius: 0; }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-content { display: none; padding: 16px 20px 20px; }
.tab-content.active { display: block; }

/* ── Photos ── */
.upload-btn { display: inline-block; background: var(--blue); color: #fff; padding: 10px 18px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; margin-bottom: 12px; }
.upload-btn input { display: none; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.photo-thumb { position: relative; border-radius: 8px; overflow: hidden; aspect-ratio: 1; background: var(--bg); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; cursor: pointer; display: block; }
.photo-thumb .btn-del { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff; border: none; border-radius: 50%; width: 22px; height: 22px; font-size: 12px; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }

/* ── Offer set tabs ── */
.offer-tab { background: #fff; border: 1px solid var(--line); border-bottom: none; color: var(--gray); padding: 7px 14px; font-size: 12px; font-weight: 600; cursor: pointer; border-radius: 8px 8px 0 0; margin-right: 2px; }
.offer-tab.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ── Catalog search results ── */
.catalog-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.catalog-row:last-child { border-bottom: none; }
.catalog-row:hover { background: #f8faff; }

/* ── Offer set product rows ── */
.offer-prod-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.offer-prod-row:last-of-type { border-bottom: none; }

/* ── PDF / Print ── */
#pdf-content { display: none; }

@media print {
  @page { size: A4 portrait; margin: 14mm 18mm 14mm 18mm; }
  body > *:not(#pdf-content) { display: none !important; }
  #pdf-content { display: block !important; font-family: Arial, sans-serif; font-size: 11px; color: #111; }

  /* Header */
  .ph { display: flex; align-items: center; gap: 18px; border-bottom: 3px solid #e55a1c; padding-bottom: 10px; margin-bottom: 12px; }
  .ph-logo { height: 56px; width: auto; }
  .ph-right { flex: 1; text-align: right; }
  .ph-title { font-size: 20px; font-weight: 900; color: #0f172a; letter-spacing: -.5px; }
  .ph-meta { font-size: 10px; color: #555; margin-top: 2px; }

  /* Customer block */
  .pc { background: #f1f5f9; border-left: 4px solid #1e88e5; padding: 8px 12px; margin-bottom: 14px; line-height: 1.7; font-size: 11px; }
  .pc-lbl { font-size: 9px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: #888; margin-bottom: 3px; }

  /* Comparison table */
  .ptbl { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: 10.5px; }
  .ptbl thead tr th { background: #0f172a; color: #fff; padding: 7px 9px; text-align: center; border: 1px solid #0f172a; }
  .ptbl .col-lbl { background: #334155; width: 80px; font-size: 10px; text-align: left; }
  .ptbl .col-set { width: calc((100% - 80px) / 3); }
  .ptbl .col-empty { background: #1e293b; }
  .set-lbl { font-size: 12px; font-weight: 800; }
  .set-nm  { font-size: 10px; opacity: .8; font-style: italic; margin-top: 2px; }

  .ptbl tbody td { padding: 7px 9px; vertical-align: top; border: 1px solid #d1d9e0; }
  .col-lbl  { background: #f8faff; font-size: 10px; font-weight: 600; color: #444; text-align: left; }
  .prod-cell { background: #fff; }
  .prod-empty { background: #f8faff; color: #aaa; text-align: center; }

  .pp-name  { font-weight: 700; font-size: 11.5px; color: #0f172a; }
  .pp-code  { font-size: 9.5px; color: #888; margin-top: 1px; }
  .pp-price { font-size: 10px; color: #555; margin: 3px 0; }
  .pp-pros-lbl { font-size: 9px; font-weight: 700; color: #15803d; text-transform: uppercase; letter-spacing: .6px; margin-top: 5px; }
  .pp-cons-lbl { font-size: 9px; font-weight: 700; color: #b91c1c; text-transform: uppercase; letter-spacing: .6px; margin-top: 4px; }
  .pp-pros { margin: 2px 0 2px 12px; padding: 0; font-size: 10px; color: #166534; line-height: 1.55; list-style: none; }
  .pp-cons { margin: 2px 0 2px 12px; padding: 0; font-size: 10px; color: #991b1b; line-height: 1.55; list-style: none; }
  .pp-pros li::before { content: "✓ "; }
  .pp-cons li::before { content: "✗ "; }
  .pp-note  { font-size: 10px; color: #666; font-style: italic; margin-top: 4px; border-top: 1px dashed #d1d9e0; padding-top: 3px; }

  .row-total td { background: #f0fdf4 !important; font-weight: 700; border-top: 2px solid #15803d; }
  .row-novat td { background: #f8faff !important; font-size: 10px; color: #666; }
  .price-cell { text-align: center !important; font-weight: 700; }
  .row-total .price-cell { font-size: 13px; color: #15803d; }

  /* Footer */
  .pf { border-top: 1px solid #ccc; padding-top: 8px; margin-top: 6px; font-size: 9.5px; color: #777; display: flex; justify-content: space-between; gap: 20px; }
  .p-empty { color: #888; font-style: italic; }
}

/* ── Job number badge ── */
.job-num { font-size: 11px; color: var(--gray); font-weight: 400; letter-spacing: .3px; }
.modal-job-num { display: inline-block; font-size: 12px; font-weight: 600; color: var(--orange); background: #fff5e6; border: 1px solid #fdd7a2; border-radius: 6px; padding: 2px 8px; margin-top: 2px; }

/* ── Inspection tab sections ── */
.insp-section { padding: 0 0 4px; }
.insp-section-title { margin: 0 0 10px; font-size: 13px; font-weight: 700; color: var(--text); text-transform: uppercase; letter-spacing: .6px; opacity: .75; }
.insp-divider { border: none; border-top: 1px solid var(--line); margin: 18px 0; }

/* ── Photo editor placeholder ── */
.photo-editor-wrap { margin-top: 14px; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; background: #f8faff; }
.photo-editor-header { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; background: #eef2ff; border-bottom: 1px solid var(--line); }
.photo-editor-fname { font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: calc(100% - 40px); }
.photo-editor-canvas-wrap { position: relative; background: #111; display: flex; align-items: center; justify-content: center; min-height: 220px; }
.photo-editor-img { display: block; max-width: 100%; max-height: 55vh; object-fit: contain; }
.photo-editor-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.photo-editor-overlay-msg { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.55); color: #fff; font-size: 12px; padding: 5px 12px; border-radius: 20px; white-space: nowrap; pointer-events: none; }
.photo-editor-toolbar { display: flex; gap: 8px; padding: 10px 12px; background: #f1f5fb; border-top: 1px solid var(--line); flex-wrap: wrap; }
.btn-tool { background: #fff; border: 1px solid var(--line); color: var(--text); padding: 7px 14px; border-radius: 8px; font-size: 13px; cursor: pointer; font-weight: 500; }
.btn-tool:disabled { opacity: .4; cursor: not-allowed; }
.btn-tool:not(:disabled):hover { background: var(--bg); }

