/* P1METER.EU — admin panel styles */

:root {
  --green: #2a9d5c;
  --green-dark: #1f7a46;
  --green-soft: #e8f5ed;
  --green-ring: rgba(42, 157, 92, 0.35);
  --red: #dc2626;
  --red-soft: #fef2f2;
  --amber: #f59e0b;

  --ink: #0f1318;
  --ink-soft: #334049;
  --muted: #6b7480;
  --muted-2: #9aa3ae;
  --line: #e3e6ea;
  --line-soft: #eef1f4;
  --bg: #f4f5f7;
  --bg-panel: #ffffff;
  --bg-code: #f5f7f9;

  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 20px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 10px 40px rgba(15, 23, 42, 0.16);

  --header-h: 56px;
  --tree-w: 320px;

  --font-sans: 'Figtree', -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Menlo', monospace;

  --t: 180ms cubic-bezier(.4,0,.2,1);
  --t-fast: 120ms ease;
}

* { box-sizing: border-box; }

/* Critical: make sure `hidden` attribute always wins over explicit `display`
   (e.g. .modal has display:flex which would otherwise override it) */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; }
body.admin-body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--green-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ────────── Login screen ────────── */
.login-body {
  background: radial-gradient(1200px 800px at 20% -10%, rgba(42,157,92,0.12), transparent),
              radial-gradient(800px 600px at 100% 100%, rgba(42,157,92,0.08), transparent),
              var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  min-height: 100vh;
}
.login-wrap { width: 100%; max-width: 400px; }
.login-card {
  background: var(--bg-panel);
  border-radius: 16px;
  padding: 36px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.login-logo { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; }
.login-brand-name { font-weight: 800; font-size: 18px; letter-spacing: 0.02em; }
.login-brand-sub { font-size: 13px; color: var(--muted); }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-back { display: inline-block; margin-top: 22px; color: var(--muted); font-size: 13px; }
.alert {
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  margin-bottom: 16px;
}
.alert-error { background: var(--red-soft); color: var(--red); border: 1px solid #fecaca; }
.alert-success { background: var(--green-soft); color: var(--green-dark); border: 1px solid #bbf7d0; }

/* Form fields */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); letter-spacing: 0.02em; }
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  background: var(--bg-panel);
  color: var(--ink);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  outline: none;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-ring);
}

/* ────────── Buttons ────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.2;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg); }
.btn-ghost.active { background: var(--green-soft); color: var(--green-dark); border-color: var(--green); }
.btn-danger { background: #fff; color: var(--red); border-color: #fecaca; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; padding: 11px 14px; }
.btn .icon { font-size: 14px; line-height: 1; }

/* ────────── Admin header ────────── */
.admin-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 24px;
  align-items: center;
  padding: 0 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
}
.admin-brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; }
.admin-brand img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; }
.admin-brand:hover { text-decoration: none; }
.admin-pill {
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green-dark);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-left: 4px;
}
.admin-nav { display: flex; gap: 2px; }
.admin-nav-item {
  color: var(--ink-soft);
  font-weight: 500;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 13.5px;
  transition: background var(--t-fast), color var(--t-fast);
}
.admin-nav-item:hover { background: var(--line-soft); color: var(--ink); text-decoration: none; }
.admin-nav-item.active { background: var(--green-soft); color: var(--green-dark); }
.admin-user { display: flex; align-items: center; gap: 14px; }
.admin-user-name { font-size: 13px; color: var(--muted); }
.admin-link-muted { color: var(--muted); font-size: 13px; }
.admin-link-muted:hover { color: var(--ink); text-decoration: none; }

/* ────────── Workbench (tree + editor) ────────── */
.admin-workbench {
  display: grid;
  grid-template-columns: var(--tree-w) 1fr;
  height: calc(100vh - var(--header-h));
  overflow: hidden;
}

.admin-tree-pane {
  border-right: 1px solid var(--line);
  background: var(--bg-panel);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.admin-tree-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.admin-tree-header h2 { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.admin-tree-hint { font-size: 11.5px; color: var(--muted-2); }

/* Tree */
.admin-tree { font-size: 13.5px; }
.admin-tree-list { list-style: none; padding: 0; margin: 0; }
.admin-tree-list .admin-tree-list { padding-left: 20px; margin-left: 8px; border-left: 1px dashed var(--line); }
.tree-node {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px 0;
}
.tree-node-handle {
  display: flex;
  flex: 1;
  min-width: 0;
  align-items: center;
  gap: 4px;
  padding: 5px 6px;
  border-radius: 5px;
  background: transparent;
  border: 0;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  font: inherit;
  font-size: 13px;
  transition: background var(--t-fast);
  min-height: 28px;
}
.tree-node-handle:hover { background: var(--line-soft); }
.tree-node-handle.active { background: var(--green-soft); color: var(--green-dark); font-weight: 600; }
.tree-node-icon { flex: none; width: 14px; height: 14px; opacity: 0.6; display: inline-flex; align-items: center; justify-content: center; }
.tree-node-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-node-actions { display: none; gap: 2px; flex: none; }
.tree-node:hover .tree-node-actions { display: inline-flex; }
.tree-node-actions button {
  width: 22px; height: 22px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px;
  line-height: 1;
}
.tree-node-actions button:hover { background: var(--bg); color: var(--ink); }
.tree-node-actions .btn-delete:hover { color: var(--red); background: var(--red-soft); }

.tree-product > .tree-node > .tree-node-handle { font-weight: 700; }
.tree-dir-children { display: none; }
.tree-dir.open > .tree-dir-children { display: block; }
.tree-dir > .tree-node .tree-node-icon::before { content: '▸'; transition: transform var(--t); display: inline-block; color: var(--muted); }
.tree-dir.open > .tree-node .tree-node-icon::before { transform: rotate(90deg); }
.tree-file > .tree-node .tree-node-icon::before { content: '·'; color: var(--muted-2); }
.sortable-ghost { opacity: 0.35; background: var(--green-soft) !important; }
.sortable-drag { opacity: 0.9; box-shadow: var(--shadow-lg); }

/* ────────── Editor pane ────────── */
.admin-editor-pane {
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}
.editor-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted-2);
  gap: 12px;
}
.editor-empty svg { color: var(--muted-2); }
.editor-empty p { font-size: 14px; }

.editor-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  margin: 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel);
}
.editor-breadcrumb { font-size: 13px; color: var(--muted); font-family: var(--font-mono); }
.editor-breadcrumb strong { color: var(--ink); font-weight: 600; font-family: var(--font-sans); }
.editor-actions { display: flex; gap: 8px; }

.editor-toolbar {
  display: flex;
  gap: 2px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
  flex-wrap: wrap;
}
.editor-toolbar button {
  min-width: 30px;
  height: 28px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  border-radius: 5px;
  cursor: pointer;
  color: var(--ink-soft);
  font: inherit;
  font-size: 13px;
  transition: background var(--t-fast), color var(--t-fast);
}
.editor-toolbar button:hover { background: var(--line-soft); color: var(--ink); }
.toolbar-sep { width: 1px; background: var(--line); margin: 4px 6px; }

.editor-split {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
  min-height: 0;
}
.editor-split.split { grid-template-columns: 1fr 1fr; }

#editor-textarea {
  width: 100%; height: 100%;
  border: 0;
  padding: 22px 26px;
  font-family: var(--font-mono);
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--bg-panel);
  resize: none;
  outline: none;
  overflow-y: auto;
  tab-size: 2;
}

.editor-preview {
  padding: 22px 26px;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: #fff;
  font-size: 14px;
}
.editor-preview h1 { margin-top: 0; font-size: 30px; }
.editor-preview h2 { font-size: 22px; margin-top: 1.6em; }
.editor-preview h3 { font-size: 18px; }
.editor-preview code:not(pre code) {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: var(--bg-code);
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid var(--line);
}
.editor-preview pre {
  background: var(--bg-code);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  overflow-x: auto;
  font-size: 12.5px;
}
.editor-preview blockquote {
  margin: 1em 0;
  padding: 2px 16px;
  border-left: 3px solid var(--green);
  background: var(--green-soft);
  color: var(--ink-soft);
  border-radius: 0 6px 6px 0;
}
.editor-preview img { max-width: 100%; border: 1px solid var(--line); border-radius: 6px; }
.editor-preview table { width: 100%; border-collapse: collapse; border: 1px solid var(--line); border-radius: 6px; }
.editor-preview th, .editor-preview td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.editor-preview a { color: var(--green-dark); font-weight: 500; }

/* ────────── Settings ────────── */
.admin-settings {
  max-width: 760px;
  margin: 32px auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.settings-card {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 26px;
  box-shadow: var(--shadow-sm);
}
.settings-card h2 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 700;
}
.password-form { display: flex; flex-direction: column; gap: 14px; max-width: 380px; }
.lang-switch { display: flex; gap: 8px; }
.form-msg { margin-top: 14px; font-size: 13px; }
.form-msg.ok { color: var(--green-dark); }
.form-msg.err { color: var(--red); }
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; font-size: 13px; }
.info-list dt { color: var(--muted); font-weight: 600; }
.info-list dd { margin: 0; }
.info-list code { font-family: var(--font-mono); font-size: 12.5px; background: var(--bg-code); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--line); }

/* ────────── Toast ────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: toast-in 180ms ease forwards;
  max-width: 380px;
}
.toast.ok { background: var(--green-dark); }
.toast.err { background: var(--red); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ────────── Modal ────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fade-in 150ms ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal-dialog {
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 460px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
  animation: scale-in 180ms cubic-bezier(.4,0,.2,1);
}
@keyframes scale-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
.modal-title { margin: 0 0 16px; font-size: 17px; font-weight: 700; }
.modal-body { display: flex; flex-direction: column; gap: 14px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.modal-desc { color: var(--muted); font-size: 13.5px; margin: 0; }
.modal-warning { color: var(--red); background: var(--red-soft); padding: 10px 14px; border-radius: 6px; font-size: 13px; }

/* ────────── Responsive ────────── */
@media (max-width: 900px) {
  .admin-workbench { grid-template-columns: 1fr; }
  .admin-tree-pane { max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .editor-container { margin: 10px; }
}
@media (max-width: 640px) {
  .admin-header { grid-template-columns: auto 1fr; padding: 0 12px; gap: 10px; }
  .admin-nav { display: none; }
  .admin-user-name { display: none; }
  .admin-brand span:not(.admin-pill) { display: none; }
}
