* { box-sizing: border-box; }

:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #172033;
  --muted: #687386;
  --border: #dfe4ec;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --shadow: 0 8px 30px rgba(23, 32, 51, .08);
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button, input { font: inherit; }
button { cursor: pointer; }

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 18px max(20px, calc((100% - 1180px) / 2));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.topbar h1 { margin: 0; font-size: 25px; }

.container {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 60px;
}

.card, .search-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.search-card { padding: 20px; margin-bottom: 22px; }

label { display: block; font-weight: 700; margin-bottom: 8px; }
input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 13px;
  outline: none;
  background: white;
}
input:focus { border-color: var(--primary); }

.search-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; }
button { border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 700; }
.primary { background: var(--primary); color: white; }
.primary:hover { background: var(--primary-dark); }
.secondary { background: #eef2f7; color: var(--text); }
.secondary:hover { background: #e5eaf1; }

.icon-btn { background: transparent; padding: 8px 10px; font-size: 18px; }
.card { padding: 20px; margin-bottom: 28px; }
.section-title, .list-header { display: flex; justify-content: space-between; align-items: center; gap: 15px; }
.section-title h2, .list-header h2 { margin: 0 0 12px; }

.form-grid.single { display: block; margin-bottom: 18px; }

.field-label { margin-top: 4px; }
.mark-options { display: flex; gap: 14px; margin-bottom: 25px; }
.mark-option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 125px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 18px;
  margin: 0;
  font-weight: 400;
  color: #687386;
}
.mark-option input { width: 20px; height: 20px; margin: 0; accent-color: var(--primary); }

.photo-label { color: #8792a8; font-weight: 400; letter-spacing: .5px; }
.upload-box { padding: 0; margin-bottom: 15px; }
.photo-button {
  background: white;
  color: var(--primary);
  border: 1px solid #9dbbff;
}
.upload-box span { display: block; color: var(--muted); margin-top: 9px; }

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.preview-item { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: #eef2f7; border: 1px solid var(--border); }
.preview-item img { width: 100%; height: 100%; object-fit: cover; }
.preview-number { position: absolute; top: 7px; left: 7px; background: rgba(0,0,0,.7); color: white; border-radius: 7px; padding: 4px 7px; font-size: 12px; font-weight: bold; }

.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.form-actions .primary { min-width: 190px; }
.count { background: #eaf1ff; color: var(--primary); padding: 5px 10px; border-radius: 20px; font-weight: 700; }

.packages-list { display: grid; gap: 14px; margin-top: 15px; }
.package { background: white; border: 1px solid var(--border); border-radius: 14px; padding: 16px; display: grid; grid-template-columns: 150px 1fr auto; gap: 18px; align-items: center; }
.package-cover { width: 150px; height: 110px; object-fit: cover; border-radius: 10px; background: #eef2f7; }
.package h3 { margin: 0 0 7px; }
.package-meta { color: var(--muted); font-size: 14px; margin-top: 8px; }
.package-mark { display: inline-block; border: 1px solid var(--border); border-radius: 8px; padding: 5px 9px; font-size: 13px; color: #687386; }
.package-mark.discount { background: #f5f9ff; }
.package-mark.defect { background: #fff7f7; color: var(--danger); }
.package-actions { display: flex; gap: 8px; flex-direction: column; }
.danger { color: var(--danger); background: #fff0f0; }

.empty { text-align: center; padding: 55px 20px; color: var(--muted); }
.empty-icon { font-size: 45px; }
.empty h3 { color: var(--text); margin-bottom: 5px; }

.viewer { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; }
.viewer-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.65); }
.viewer-window { position: relative; z-index: 1; width: min(1100px, 100%); max-height: 92vh; overflow: auto; background: white; border-radius: 18px; padding: 20px; }
.viewer-header { display: flex; justify-content: space-between; align-items: center; }
.viewer-header h2 { margin: 0; }
.viewer-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-top: 15px; }
.viewer-photo img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; cursor: zoom-in; }
.viewer-text { margin-top: 18px; padding: 15px; background: #f6f8fb; border-radius: 12px; }

.toast { position: fixed; right: 20px; bottom: 20px; background: #172033; color: white; padding: 13px 17px; border-radius: 10px; transform: translateY(100px); opacity: 0; transition: .25s; z-index: 2000; }
.toast.show { transform: translateY(0); opacity: 1; }
.hidden { display: none !important; }

@media (max-width: 700px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar .primary { width: 100%; }
  .search-row { grid-template-columns: 1fr; }
  .package { grid-template-columns: 100px 1fr; }
  .package-cover { width: 100px; height: 100px; }
  .package-actions { grid-column: 1 / -1; flex-direction: row; }
  .package-actions button { flex: 1; }
  .preview-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 420px) {
  .container { width: min(100% - 20px, 1180px); margin-top: 15px; }
  .card { padding: 20px; }
  .mark-options { gap: 8px; }
  .mark-option { min-width: 0; flex: 1; padding: 12px 10px; }
  .form-actions { flex-direction: row; }
  .form-actions button { flex: 1; }
}

.viewer-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.viewer-actions button { flex: 1; min-width: 220px; }

.viewer-photos { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.viewer-photo {
  position: relative;
  border: 0;
  padding: 0;
  background: #eef2f7;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1;
}
.viewer-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.viewer-photo span {
  position: absolute; left: 8px; top: 8px; padding: 4px 7px; border-radius: 7px;
  background: rgba(0,0,0,.7); color: white; font-size: 12px; font-weight: 700;
}
.viewer-photo:hover img { transform: scale(1.03); transition: .15s; }

.lightbox {
  position: fixed; inset: 0; z-index: 3000; display: flex; align-items: center; justify-content: center;
}
.lightbox-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.92); }
.lightbox-content { position: relative; z-index: 2; width: min(92vw, 1200px); height: min(92vh, 900px); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.lightbox-top { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: center; align-items: center; color: white; font-weight: 700; z-index: 3; }
.lightbox-counter { color: white; }
#lightboxCounter { background: rgba(0,0,0,.55); padding: 7px 12px; border-radius: 20px; }
.lightbox-close { position: absolute; right: 0; top: -4px; border: 0; background: rgba(255,255,255,.13); color: white; border-radius: 50%; width: 42px; height: 42px; font-size: 22px; cursor: pointer; }
.lightbox-image { max-width: 100%; max-height: calc(100% - 10px); object-fit: contain; user-select: none; border-radius: 4px; }
.lightbox-nav { position: relative; z-index: 3; border: 0; background: rgba(255,255,255,.14); color: white; width: 52px; height: 70px; border-radius: 14px; font-size: 55px; line-height: 50px; display: flex; align-items: center; justify-content: center; cursor: pointer; margin: 0 14px; }
.lightbox-nav:hover { background: rgba(255,255,255,.25); }
.lightbox-nav:disabled { opacity: .2; cursor: default; }
.lightbox-prev { order: 1; }
.lightbox-content { order: 2; }
.lightbox-next { order: 3; }

.share-modal { position: fixed; inset: 0; z-index: 3500; display: flex; align-items: center; justify-content: center; padding: 20px; }
.share-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); }
.share-window { position: relative; z-index: 1; width: min(480px, 100%); background: white; border-radius: 18px; padding: 26px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.share-window h3 { margin: 0 0 10px; font-size: 23px; }
.share-window p { color: var(--muted); line-height: 1.5; margin: 0 0 20px; }
.share-window select { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: white; margin-bottom: 15px; }
.share-submit { width: 100%; }
.share-close { position: absolute; right: 10px; top: 10px; }
.no-scroll { overflow: hidden; }

@media (max-width: 700px) {
  .viewer-window { max-height: 96vh; padding: 15px; }
  .viewer-photos { grid-template-columns: repeat(3, 1fr); gap: 7px; }
  .viewer-actions { flex-direction: column; }
  .viewer-actions button { width: 100%; }
  .lightbox { padding: 0 4px; }
  .lightbox-content { width: calc(100vw - 80px); height: 90vh; }
  .lightbox-nav { position: absolute; top: 50%; transform: translateY(-50%); margin: 0; width: 42px; height: 58px; font-size: 45px; }
  .lightbox-prev { left: 5px; }
  .lightbox-next { right: 5px; }
  .lightbox-close { right: -4px; top: 5px; }
  .lightbox-top { top: 5px; }
}


/* Exact-photo selection for download / Telegram */
.photo-action-window { width: min(760px, 100%); max-height: 90vh; overflow: auto; }
.selection-toolbar { display: flex; align-items: center; gap: 8px; margin: 12px 0 14px; flex-wrap: wrap; }
.selection-toolbar button { padding: 8px 12px; }
#selectedPhotosCount { margin-left: auto; color: var(--muted); font-weight: 700; }
.photo-selection-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  max-height: 430px;
  overflow: auto;
  padding: 2px;
}
.selection-photo {
  position: relative; aspect-ratio: 1; padding: 0; overflow: hidden; border: 3px solid transparent;
  border-radius: 12px; background: #eef2f7; cursor: pointer;
}
.selection-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.selection-photo b {
  position: absolute; left: 7px; top: 7px; min-width: 25px; height: 25px; padding: 3px 6px;
  border-radius: 8px; background: rgba(0,0,0,.72); color: white; font-size: 13px;
}
.selection-check {
  position: absolute; right: 7px; top: 7px; width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.55); color: transparent;
  font-weight: 900; border: 2px solid white;
}
.selection-photo.selected { border-color: var(--primary); }
.selection-photo.selected .selection-check { background: var(--primary); color: white; }
.selection-photo:not(.selected) { opacity: .58; }
.selection-photo:hover { opacity: 1; }
.telegram-main-btn { display: flex; align-items: center; justify-content: center; gap: 8px; }
.telegram-icon {
  display: inline-flex; width: 25px; height: 25px; border-radius: 50%; align-items: center; justify-content: center;
  background: #fff; color: var(--primary); font-size: 14px; transform: rotate(-8deg);
}
.telegram-direct-btn {
  width: 58px; height: 58px; margin: 14px auto 0; border-radius: 50%; background: #229ED9; color: white;
  display: flex; align-items: center; justify-content: center; font-size: 22px; box-shadow: 0 8px 20px rgba(34,158,217,.25);
}
.telegram-direct-btn .telegram-icon { width: 42px; height: 42px; background: white; color: #229ED9; }
.telegram-hint { text-align: center; font-size: 13px !important; margin-top: 10px !important; }

@media (max-width: 700px) {
  .photo-selection-grid { grid-template-columns: repeat(3, 1fr); max-height: 52vh; }
  #selectedPhotosCount { width: 100%; margin-left: 0; }
  .photo-action-window { padding: 20px; }
}
.cloud-status{margin-bottom:12px;font-size:13px;font-weight:600}.cloud-status.online{color:#177245}.cloud-status.offline{color:#9a5b00}
