/* ============================================================
   Admin — sidebar layout, portfolio editor. Loaded after style.css.
   ============================================================ */

.adm, .adm-auth { --adm-bg: #f3f4f6; --adm-line: #e4e6eb; --adm-side: #0f1830; --adm-side-2: #16223f; background: var(--adm-bg); }
.adm .ai, .adm-auth .ai { width: 18px; height: 18px; flex-shrink: 0; }
.adm a:not(.btn):not(.quick):not(.section-tile):not(.stat-card) { color: var(--navy); }

/* ---------- Sign-in card ---------- */
.adm-auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(900px 500px at 80% -10%, rgba(220, 171, 124, .18), transparent 60%), linear-gradient(160deg, #172f5a, #0f1830 70%); }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 16px; padding: 32px; box-shadow: 0 30px 80px rgba(0, 0, 0, .35); }
.auth-card h1 { font-size: 1.5rem; margin: 22px 0 8px; }
.auth-card .form { margin-top: 18px; }
.auth-brand { display: flex; align-items: center; gap: 12px; font: 700 1rem var(--head); color: var(--ink); text-transform: uppercase; letter-spacing: .02em; }
.auth-brand small { display: block; font: 500 0.75rem var(--body); color: var(--muted); text-transform: none; letter-spacing: 0; }
.auth-back { display: inline-block; margin-top: 20px; font-size: 0.85rem; color: var(--muted); }
.auth-back:hover { color: var(--ink); }

/* ---------- Layout ---------- */
.adm { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
.adm-side {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
  background: var(--adm-side); color: #aeb8cc; padding: 20px 14px; scrollbar-width: thin; scrollbar-color: #2a3858 transparent;
}
.adm-brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 20px; margin-bottom: 8px; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.adm-brand .logo-mark { background: var(--ivory); color: var(--ink); }
.adm-brand strong { display: block; color: #fff; font: 700 0.92rem var(--head); text-transform: uppercase; letter-spacing: .03em; }
.adm-brand small { display: block; font-size: 0.74rem; color: #8290ab; }
.adm-nav { display: flex; flex-direction: column; gap: 1px; flex: 1; }
.adm-nav-group { margin: 18px 10px 6px; font: 600 0.66rem var(--body); letter-spacing: .16em; text-transform: uppercase; color: #66748f; }
.adm-nav a, .adm-side-foot a, .adm-side-foot button {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 8px; font-size: 0.88rem; color: #c3cad8 !important;
  transition: background .15s, color .15s; background: none; border: 0; font-family: inherit; cursor: pointer; width: 100%; text-align: left;
}
.adm-nav a .ai, .adm-side-foot .ai { width: 17px; height: 17px; color: #7d8aa6; transition: color .15s; }
.adm-nav a:hover, .adm-side-foot a:hover, .adm-side-foot button:hover { background: var(--adm-side-2); color: #fff !important; }
.adm-nav a[aria-current="page"] { background: rgba(220, 171, 124, .14); color: #fff !important; box-shadow: inset 3px 0 0 var(--cognac-light); }
.adm-nav a[aria-current="page"] .ai { color: var(--cognac-light); }
.adm-count { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--cognac); color: #fff; font-size: 0.72rem; text-align: center; }
.adm-side-foot { margin-top: 18px; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .08); display: flex; flex-direction: column; gap: 1px; }
.adm-side-foot form { margin: 0; }

.adm-body { min-width: 0; display: flex; flex-direction: column; }
.adm-top { display: none; }
.adm-scrim { display: none; }
.adm-main { width: 100%; max-width: 1080px; margin: 0 auto; padding: 36px 40px 120px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- Page head ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; padding-bottom: 6px; }
.page-crumb { margin: 0 0 6px; font: 600 0.7rem var(--body); letter-spacing: .16em; text-transform: uppercase; color: var(--cognac); }
.page-head h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); font-weight: 800; }
.page-lead { margin: 8px 0 0; color: var(--muted); max-width: 46em; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.adm .btn .ai { width: 15px; height: 15px; }

/* ---------- Cards ---------- */
.adm .panel { border-color: var(--adm-line); border-radius: 12px; box-shadow: 0 1px 2px rgba(16, 26, 51, .04); padding: 24px; }
.adm .panel h2 { font-size: 1.05rem; margin-bottom: 4px; }
.panel-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 18px; }
.adm .stat-card { border-color: var(--adm-line); border-radius: 12px; box-shadow: 0 1px 2px rgba(16, 26, 51, .04); }
.adm .stat-card:hover { border-color: var(--navy); }
.adm .stat-card strong { font-size: 1.8rem; }
.adm .list { border-color: var(--adm-line); border-radius: 12px; }
.notice-flash { position: sticky; top: 12px; z-index: 20; box-shadow: 0 6px 20px rgba(16, 26, 51, .1); transition: opacity .6s, transform .6s; }
.notice-flash.fade { opacity: 0; transform: translateY(-6px); pointer-events: none; }
.adm code { background: var(--adm-bg); padding: 1px 6px; border-radius: 4px; font-size: .85em; }

/* Dashboard */
.quick-add { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 22px; }
.quick { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 10px; background: var(--ink); color: #fff; font-size: 0.86rem; font-weight: 500; transition: background .15s, transform .15s; }
.quick:hover { background: var(--navy); transform: translateY(-1px); }
.quick .ai { color: var(--cognac-light); }
.section-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.section-tile { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--adm-line); border-radius: 10px; color: var(--ink); transition: border-color .15s, background .15s; }
.section-tile:hover { border-color: var(--navy); background: #fafbfc; }
.section-tile .ai { color: var(--cognac); }
.section-tile strong { display: block; font-size: 0.9rem; font-weight: 600; }
.section-tile small { color: var(--muted); font-size: 0.78rem; }

/* ---------- Editor fields ---------- */
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.field { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-half { grid-column: auto; }
.field-label { font-size: 0.84rem; font-weight: 600; color: var(--ink); }
.field-label .req { color: var(--cognac); }
.field-help { font-size: 0.78rem; color: var(--muted); line-height: 1.45; }
.adm input:not([type=checkbox]):not([type=radio]):not([type=file]), .adm select, .adm textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid #d5d9e0; border-radius: 8px; background: #fff;
  font: 0.93rem/1.5 var(--body); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
.adm textarea { resize: vertical; }
.adm input:focus, .adm select:focus, .adm textarea:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(23, 47, 90, .12); }
.adm input:user-invalid, .adm textarea:user-invalid { border-color: var(--bad); }

/* On/off switch */
.switch { display: inline-flex; align-items: center; gap: 10px; font-size: 0.88rem; color: var(--text); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch span { position: relative; width: 38px; height: 22px; border-radius: 999px; background: #cfd4dc; transition: background .2s; flex-shrink: 0; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); transition: transform .2s; }
.switch input:checked + span { background: var(--ink); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--cognac); outline-offset: 2px; }

/* Image field */
.img-field { display: flex; gap: 14px; align-items: center; }
.img-preview { position: relative; width: 96px; height: 96px; flex-shrink: 0; border-radius: 10px; overflow: hidden; display: grid; place-items: center;
  background: repeating-conic-gradient(#eef0f3 0 25%, #f8f9fa 0 50%) 0 0 / 14px 14px; border: 1px solid var(--adm-line); }
.img-preview img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.img-preview span { font-size: 0.72rem; color: var(--muted); }
.img-preview img + span { position: absolute; left: 4px; bottom: 4px; padding: 1px 6px; border-radius: 4px; background: var(--cognac); color: #fff; font-size: 0.66rem; }
.img-field:not(.is-new) .img-preview img + span { display: none; }
.img-controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.img-controls .field-help { flex-basis: 100%; }
.img-pick { cursor: pointer; }
.img-field[data-empty="1"] .img-remove { display: none; }

/* ---------- List editor ---------- */
.cms { display: flex; flex-direction: column; gap: 16px; }
.list-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.list-bar-actions { display: flex; gap: 4px; }
.items { display: flex; flex-direction: column; gap: 10px; }
.item { background: #fff; border: 1px solid var(--adm-line); border-radius: 12px; box-shadow: 0 1px 2px rgba(16, 26, 51, .04); transition: border-color .2s, box-shadow .2s; }
.item.is-open { border-color: #c9ced8; box-shadow: 0 8px 28px rgba(16, 26, 51, .08); }
.item.moved { animation: flashItem 1s ease; }
@keyframes flashItem { from { box-shadow: 0 0 0 3px rgba(220, 171, 124, .7); } to { box-shadow: 0 1px 2px rgba(16, 26, 51, .04); } }
.item-head { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 10px; }
.item-grip { color: #b3b9c4; display: flex; }
.item-grip .ai { width: 16px; height: 16px; }
.item-thumb { width: 46px; height: 46px; border-radius: 8px; overflow: hidden; flex-shrink: 0; background: var(--adm-bg); border: 1px solid var(--adm-line); }
.item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-toggle { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 1px; background: none; border: 0; padding: 4px 0; text-align: left; cursor: pointer; font: inherit; }
.item-title { font-size: 0.95rem; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.item-sub { font-size: 0.8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.item-sub:empty { display: none; }
.item-badge { display: none; padding: 2px 8px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); font-size: 0.72rem; font-weight: 600; white-space: nowrap; }
.item.is-hidden .item-badge { display: inline-block; }
.item.is-hidden .item-title, .item.is-hidden .item-thumb { opacity: .55; }
.item-actions { display: flex; gap: 2px; }
.icon-btn { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 0; background: none; color: var(--muted); cursor: pointer; transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--adm-bg); color: var(--ink); }
.icon-btn .ai { width: 17px; height: 17px; }
.icon-btn-danger:hover { background: var(--bad-soft); color: var(--bad); }
.item-chevron .ai { transition: transform .2s; }
.item.is-open .item-chevron .ai { transform: rotate(90deg); }
.item:first-child [data-move="-1"], .item:last-of-type [data-move="1"] { opacity: .35; pointer-events: none; }
.item-fixed .item-toggle { cursor: default; }
.item-fixed .field { width: auto; grid-column: auto; flex-direction: row; }
.item-fixed .switch { font-size: 0.82rem; color: var(--muted); }
.item-body { padding: 6px 18px 20px; border-top: 1px solid var(--adm-line); }
.item-body .field-grid { padding-top: 16px; }
.add-item { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 16px; border: 1.5px dashed #c6ccd6; border-radius: 12px; background: transparent;
  color: var(--navy); font: 600 0.9rem var(--body); cursor: pointer; transition: border-color .15s, background .15s; }
.add-item:hover { border-color: var(--navy); background: #fff; }
.add-item .ai { width: 18px; height: 18px; }

/* Save bar */
.savebar { position: sticky; bottom: 16px; z-index: 15; display: flex; justify-content: space-between; align-items: center; gap: 16px;
  margin-top: 8px; padding: 12px 14px 12px 20px; border-radius: 12px; background: var(--ink); color: #c7cfdd; box-shadow: 0 16px 40px rgba(16, 26, 51, .25); }
.savebar-status { font-size: 0.88rem; display: flex; align-items: center; gap: 8px; }
.savebar-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #58b27f; }
.cms.is-dirty .savebar-status { color: #fff; }
.cms.is-dirty .savebar-status::before { background: var(--cognac-light); }
.savebar .btn-primary { background: var(--ivory); border-color: var(--ivory); color: var(--ink); }
.savebar .btn-primary:hover { background: #fff; }

/* Backup */
.rev-list { display: flex; flex-direction: column; margin-top: 12px; }
.rev { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--adm-line); margin: 0; }
.rev span { display: flex; flex-direction: column; }
.rev strong { font-weight: 600; color: var(--ink); font-size: 0.92rem; }

/* ---------- Narrow screens ---------- */
@media (max-width: 900px) {
  .adm { grid-template-columns: 1fr; }
  .adm-side { position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 60; transform: translateX(-100%); transition: transform .25s ease; }
  .menu-open .adm-side { transform: none; box-shadow: 20px 0 60px rgba(0, 0, 0, .3); }
  .adm-scrim { position: fixed; inset: 0; z-index: 55; background: rgba(10, 16, 32, .45); }
  .menu-open .adm-scrim { display: block; }
  .adm-top { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 40; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--adm-line); }
  .adm-top-title { flex: 1; font: 700 0.9rem var(--head); color: var(--ink); text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .adm-main { padding: 24px 16px 110px; }
}
@media (max-width: 640px) {
  .field-grid { grid-template-columns: 1fr; }
  .field-half { grid-column: 1 / -1; }
  .item-grip, .item-actions [data-duplicate] { display: none; }
  .item-head { gap: 8px; padding: 8px; }
  .item-thumb { width: 38px; height: 38px; }
  .icon-btn { width: 30px; height: 30px; }
  .item-body { padding: 4px 14px 16px; }
  .adm .panel { padding: 18px; }
  .savebar { bottom: 10px; padding: 10px 10px 10px 14px; }
  .page-head { align-items: flex-start; }
}
