:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2f6fde;
  --accent-soft: #e8f0fd;
  --danger: #c63b3b;
  --danger-soft: #fdeceb;
  --ok-soft: #e7f6ec;
  --ok: #1e7b3c;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0; }
code { font-size: .85em; background: var(--bg); padding: 1px 6px; border-radius: 4px; color: var(--muted); }
[hidden] { display: none !important; }

/* Layout */
body.with-nav { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: #1d2330; color: #cfd5df; padding: 20px 14px;
  display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; color: #fff; font-size: 1.05rem; padding: 0 8px; word-break: break-word; }
.brand .area { display: block; font-weight: 400; font-size: .8rem; color: #8b94a6; }
.sidebar nav, .sidebar-foot { display: flex; flex-direction: column; gap: 2px; }
.sidebar-foot { margin-top: auto; border-top: 1px solid #333b4b; padding-top: 12px; }
.sidebar a, .sidebar .linklike {
  color: #cfd5df; text-decoration: none; padding: 7px 8px; border-radius: 6px; text-align: left; font: inherit;
}
.sidebar a:hover, .sidebar .linklike:hover { background: #2a3242; color: #fff; }
.sidebar a.active { background: var(--accent); color: #fff; }
.main { padding: 28px 36px 60px; max-width: 1100px; width: 100%; }
body.bare .main { max-width: 400px; margin: 10vh auto; padding: 0 16px; }

@media (max-width: 760px) {
  body.with-nav { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .main { padding: 20px 16px 40px; }
}

/* Headings and cards */
.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.hint { color: var(--muted); margin: 0 0 16px; font-size: .9rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card.danger { border-color: #f1c4c4; }
.card.danger h2 { color: var(--danger); }

/* Flash */
.flash { padding: 10px 14px; border-radius: var(--radius); background: var(--ok-soft); color: var(--ok); margin-bottom: 18px; }
.flash-err { background: var(--danger-soft); color: var(--danger); }

/* Buttons */
.btn, button.btn {
  display: inline-block; border: 1px solid var(--accent); background: var(--accent); color: #fff;
  padding: 7px 14px; border-radius: 6px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.07); }
.btn.btn-secondary { background: var(--panel); color: var(--text); border-color: var(--line); }
.btn.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-small { padding: 3px 10px; font-size: .85rem; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
.linklike.danger { color: var(--danger); }
.inline { display: inline; }

/* Forms */
.form { display: grid; gap: 14px; max-width: 640px; }
.field { display: grid; gap: 5px; }
.field label, .label { font-weight: 600; font-size: .9rem; }
.field small { color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=url], select, textarea {
  font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.actions-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-form { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.row-form .field { flex: 1; min-width: 140px; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
td .actions-row { justify-content: flex-end; }

/* Badges and tabs */
.badge { display: inline-block; font-size: .72rem; padding: 1px 7px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge.muted { background: #eceef1; color: var(--muted); }
.badge.warn { background: var(--danger-soft); color: var(--danger); }
.tabs { display: flex; gap: 4px; background: #eceef1; padding: 3px; border-radius: 8px; }
.tabs a { padding: 5px 12px; border-radius: 6px; text-decoration: none; color: var(--muted); }
.tabs a.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* Page tree */
ul.tree { list-style: none; margin: 0; padding: 0; }
ul.tree ul.tree { padding-left: 26px; }
.tree .row {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; margin: 2px 0;
  border-radius: 6px; border: 1px solid transparent; background: var(--panel);
}
.tree .row:hover { border-color: var(--line); background: #fafbfc; }
.tree .grip { cursor: grab; color: #b3b9c4; user-select: none; letter-spacing: -2px; }
.tree .title { font-weight: 500; text-decoration: none; color: var(--text); }
.tree .title:hover { color: var(--accent); }
.tree .url { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree .row-actions { margin-left: auto; display: flex; gap: 12px; font-size: .85rem; white-space: nowrap; }
.tree .row-actions a { text-decoration: none; }
.tree li.dragging > .row { opacity: .4; }
.tree .row.drop-before { box-shadow: inset 0 3px 0 var(--accent); }
.tree .row.drop-after { box-shadow: inset 0 -3px 0 var(--accent); }
.tree .row.drop-inside, .tree .tree-empty.drop-inside { background: var(--accent-soft); border-color: var(--accent); }
.tree-empty { padding: 12px; color: var(--muted); border: 1px dashed var(--line); border-radius: 6px; text-align: center; }

/* Login */
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; }
.login-card h1 { margin-bottom: 4px; }
.login-card p { color: var(--muted); margin-top: 0; }
.login-card .btn { width: 100%; margin-top: 4px; }

.muted { color: var(--muted); }
.stack { display: grid; gap: 6px; }

/* Media library */
.meter { width: 100%; height: 8px; margin: -8px 0 18px; accent-color: var(--accent); }
.dropzone { display: flex; align-items: center; gap: 16px; padding: 22px; border: 2px dashed var(--line); border-radius: var(--radius); flex-wrap: wrap; }
.dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone label { flex: 1; cursor: pointer; display: grid; gap: 2px; }
.dropzone label strong { color: var(--accent); }
.dropzone small { color: var(--muted); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.media-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.media-thumb { display: flex; align-items: center; justify-content: center; aspect-ratio: 4 / 3; background: #eef0f3; text-decoration: none; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-ext { color: var(--muted); font-size: .8rem; padding: 8px; text-align: center; word-break: break-all; }
.media-info { padding: 10px 12px; display: grid; gap: 6px; font-size: .88rem; }
.media-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-info input { font-size: .8rem; padding: 5px 7px; }
.copy-url { cursor: copy; color: var(--muted); }
.alt-form { display: flex; gap: 6px; align-items: center; }

/* Grid */
.readonly { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.field small.error { color: var(--danger); }
.grid-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pager { justify-content: center; margin-top: 14px; }

/* Grid image field + its media picker */
.grid-thumb { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; background: var(--bg); display: block; }
.field-image { display: flex; align-items: center; gap: 12px; }
.field-image .grid-thumb { width: 90px; height: 68px; }

#ipAdminPicker { position: fixed; inset: 0; background: rgba(15, 18, 26, .5); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
#ipAdminPicker[hidden] { display: none; }
#ipAdminPicker .ip-picker { background: var(--panel); border-radius: 12px; padding: 20px; width: min(720px, 100%); max-height: 80vh; display: grid; gap: 14px; grid-template-rows: auto auto 1fr; }
#ipAdminPicker .ip-picker-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#ipAdminPicker .ip-picker-head h2 { margin-right: auto; }
#ipAdminPicker input[type=search] { max-width: 220px; }
#ipAdminPicker .ip-note { margin: 0; color: var(--muted); }
#ipAdminPicker .ip-note:empty { display: none; }
#ipAdminPicker .ip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; overflow-y: auto; }
#ipAdminPicker .ip-file { display: grid; gap: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--panel); cursor: pointer; font: inherit; text-align: left; }
#ipAdminPicker .ip-file:hover, #ipAdminPicker .ip-file:focus { border-color: var(--accent); outline: none; }
#ipAdminPicker .ip-file img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 5px; background: var(--bg); }
#ipAdminPicker .ip-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .82rem; }
