:root {
  --bg: #f4f5f7;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #eef0f3;
  --border: #dfe3ea;
  --border-strong: #c8ced8;
  --text: #1a1d24;
  --text-dim: #6b7280;
  --accent: #b8291f;
  --accent-hover: #8f1e17;
  --danger: #b8291f;
  --ok: #2e7d32;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(20, 24, 32, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* Login page */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(180deg, #f4f5f7 0%, #e6eaef 100%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 4px;
}
.login-brand .mark {
  width: 34px; height: 34px; border-radius: 8px; background: var(--accent);
  color: #fff; display:flex; align-items:center; justify-content:center; font-weight: 800;
}
.login-title { font-size: 22px; margin: 20px 0 6px; }
.login-sub { color: var(--text-dim); font-size: 13px; margin: 0 0 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 13px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(184, 41, 31, 0.12);
}
.field textarea { min-height: 90px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border-radius: 8px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 14px;
  transition: all .15s;
  font-family: inherit;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: #fff; border-color: var(--border-strong); color: var(--text); }
.btn-outline:hover { background: var(--bg-hover); }
.btn-danger { background: transparent; border-color: rgba(184, 41, 31, 0.4); color: var(--danger); }
.btn-danger:hover { background: rgba(184, 41, 31, 0.08); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.alert { padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.alert-err { background: rgba(184,41,31,0.08); color: var(--accent); border: 1px solid rgba(184,41,31,0.25); }
.alert-ok { background: rgba(46,125,50,0.08); color: var(--ok); border: 1px solid rgba(46,125,50,0.25); }

/* Admin layout */
.admin {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
  min-width: 0;
}
.sidebar {
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px; font-weight: 700;
  padding: 6px 8px 18px; border-bottom: 1px solid var(--border);
  color: var(--text);
}
.sidebar .brand .mark {
  width: 30px; height: 30px; border-radius: 7px; background: var(--accent);
  color: #fff; display:flex; align-items:center; justify-content:center; font-weight: 800;
}
.side-nav { margin-top: 14px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-nav button {
  text-align: left;
  background: transparent;
  color: var(--text-dim);
  border: none;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: inherit;
}
.side-nav button:hover { background: var(--bg-hover); color: var(--text); }
.side-nav button.active { background: var(--accent); color: #fff; font-weight: 600; }
.side-nav .icon { font-size: 16px; }

.side-user {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--text-dim);
  font-size: 13px;
}

.content {
  padding: 24px 30px 40px;
  min-width: 0;
  overflow-x: hidden;
}
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-title { margin: 0; font-size: 24px; font-weight: 800; color: var(--text); letter-spacing: -0.01em; }
.page-sub { color: var(--text-dim); font-size: 13px; margin: 4px 0 0; }

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 14px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); font-weight: 700; }

/* Table */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  border-radius: var(--radius);
}
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  min-width: 640px;
}
.table th, .table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th {
  background: #f7f9fb;
  color: var(--text-dim);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg-hover); }
.table img.thumb { width: 42px; height: 42px; object-fit: cover; border-radius: 6px; }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }

.badge {
  display: inline-flex;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-new { background: rgba(184,41,31,0.12); color: var(--accent); }
.badge-ok { background: rgba(46,125,50,0.12); color: var(--ok); }
.badge-out { background: rgba(184,41,31,0.1); color: var(--accent); }
.badge-cat { background: rgba(107,114,128,0.12); color: var(--text-dim); }

/* Modal */
.modal-back {
  position: fixed; inset: 0;
  background: rgba(20, 24, 32, 0.5);
  display: none;
  align-items: center; justify-content: center;
  z-index: 50;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-back.show { display: flex; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow: auto;
  padding: 24px;
  box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 4px; font-size: 20px; color: var(--text); }
.modal p.sub { color: var(--text-dim); margin: 0 0 20px; font-size: 13px; }
.modal-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.thumb-preview {
  width: 88px; height: 88px;
  border-radius: 8px;
  background: var(--bg-hover);
  border: 1px dashed var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  color: var(--text-dim);
  font-size: 24px;
}
.thumb-preview img { width: 100%; height: 100%; object-fit: cover; }

/* Multi-image editor */
.imgs-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 10px;
}
.imgs-grid .imgs-cell {
  position: relative;
  width: 88px;
  height: 88px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-hover);
  border: 1px solid var(--border);
}
.imgs-grid .imgs-cell img { width: 100%; height: 100%; object-fit: cover; }
.imgs-grid .imgs-cell.primary { outline: 2px solid var(--accent); }
.imgs-grid .imgs-cell .imgs-actions {
  position: absolute;
  inset: 0;
  background: rgba(20, 24, 32, 0.55);
  opacity: 0;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.imgs-grid .imgs-cell:hover .imgs-actions { opacity: 1; }
.imgs-grid .imgs-cell .imgs-actions button {
  background: rgba(255,255,255,0.9);
  border: 1px solid var(--border);
  color: var(--text);
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
}
.imgs-grid .imgs-cell .imgs-actions button:hover { background: #fff; color: var(--accent); }
.imgs-grid .imgs-cell .imgs-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}
.imgs-add {
  width: 88px;
  height: 88px;
  border-radius: 8px;
  border: 2px dashed var(--border-strong);
  background: #fff;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  font-family: inherit;
}
.imgs-add:hover { border-color: var(--accent); color: var(--accent); }
.imgs-hint { color: var(--text-dim); font-size: 12px; }

/* Specs editor */
.specs-editor {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.specs-row {
  display: grid;
  grid-template-columns: 1fr 1.5fr 32px;
  gap: 6px;
  align-items: center;
}
.specs-row input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
}
.specs-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(184,41,31,0.12);
}
.specs-row button {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--danger);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  font-family: inherit;
}
.specs-row button:hover { background: rgba(184,41,31,0.08); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow);
  transform: translateY(20px);
  opacity: 0;
  transition: all .2s;
  z-index: 100;
  max-width: 320px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.err { border-color: var(--danger); color: var(--danger); }
.toast.ok { border-color: var(--ok); color: var(--ok); }

.empty { padding: 40px; text-align: center; color: var(--text-dim); }

/* Mobile topbar (hidden by default, shown on small screens) */
.mobile-topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 40;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
}
.mobile-topbar .brand {
  padding: 0;
  border: none;
  font-size: 15px;
  gap: 8px;
  flex: 1;
}
.mobile-topbar .brand .mark { width: 28px; height: 28px; font-size: 13px; }
.mt-burger {
  width: 40px; height: 40px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.drawer-back {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 32, 0.5);
  z-index: 45;
  backdrop-filter: blur(3px);
}
.drawer-back.show { display: block; }
body.no-scroll { overflow: hidden; }

@media (max-width: 820px) {
  .admin { grid-template-columns: 1fr; }
  .mobile-topbar { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    height: 100vh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow);
    flex-direction: column;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar .brand { padding: 16px 12px; }
  .side-nav { flex-direction: column; }
  .side-nav button { white-space: normal; padding: 12px 14px; font-size: 15px; min-height: 48px; }
  .side-user { display: flex; }

  .content { padding: 16px; }

  /* tables → scrollable */
  .table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { min-width: 640px; font-size: 13px; }
  .table th, .table td { padding: 9px 10px; }

  /* forms/panels */
  .panel { padding: 16px; }

  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
  .page-header .btn { align-self: stretch; text-align: center; justify-content: center; }
  .page-title { font-size: 20px; }

  /* image editor cells stay tappable */
  .imgs-grid .imgs-cell { width: 84px; height: 84px; }
  .imgs-grid .imgs-cell .imgs-actions { opacity: 1; background: transparent; }
  .imgs-grid .imgs-cell .imgs-actions button {
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    position: absolute;
    width: 24px; height: 24px;
    border-radius: 5px;
  }
  .imgs-grid .imgs-cell .imgs-actions button[data-cover],
  .imgs-grid .imgs-cell .imgs-actions button[data-hp-cover] { top: 4px; right: 4px; }
  .imgs-grid .imgs-cell .imgs-actions button[data-del],
  .imgs-grid .imgs-cell .imgs-actions button[data-hp-del] { bottom: 4px; right: 4px; }
  .imgs-add { width: 84px; height: 84px; }

  /* buttons min tap */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }

  /* toast float from bottom */
  .toast { left: 16px; right: 16px; bottom: 16px; max-width: none; }
}

/* Mobile — real phone modal fullscreen, single column form */
@media (max-width: 640px) {
  .modal-back { padding: 0; align-items: stretch; justify-content: stretch; }
  .modal {
    max-width: none;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    border: none;
    padding: 18px 16px 96px;
    display: flex;
    flex-direction: column;
  }
  .modal h2 { font-size: 19px; padding-right: 40px; margin-bottom: 4px; }
  .modal p.sub { font-size: 13px; margin-bottom: 16px; }

  /* every field row stacks vertically */
  .modal-row { grid-template-columns: 1fr !important; gap: 4px !important; }
  .field { margin-bottom: 12px; }
  .field label { font-size: 11px; }
  .field input, .field select, .field textarea { padding: 12px 12px; font-size: 15px; min-height: 46px; border-radius: 8px; }
  .field textarea { min-height: 100px; }

  /* image preview inline for service form: stack */
  .field > div[style*="display:flex"][style*="gap:12px"] { flex-direction: column; align-items: stretch !important; }
  .thumb-preview { width: 100%; height: 160px; }

  /* specs editor: label + value stacked */
  .specs-row { grid-template-columns: 1fr 32px; gap: 6px; }
  .specs-row input:first-child { grid-column: 1 / -1; margin-bottom: -3px; font-weight: 600; }

  /* sticky actions at bottom */
  .modal-actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-card);
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    margin: 0;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    z-index: 5;
  }
  .modal-actions .btn { flex: 1; min-height: 48px; }
}

@media (max-width: 380px) {
  .content { padding: 12px; }
  .panel { padding: 14px; }
  .field input, .field select, .field textarea { font-size: 14px; }
  .imgs-grid .imgs-cell { width: 72px; height: 72px; }
  .imgs-add { width: 72px; height: 72px; font-size: 24px; }
  .modal { padding: 16px 14px 92px; }
}

/* Hide old horizontal sidebar (was for old mobile layout) */
.side-nav { }
