 :root {
    --bg: #0f0f14; --bg-card: #1a1a24; --bg-input: #12121a; --bg-hover: #22222e;
    --border: #2a2a3a; --border-focus: #6366f1;
    --text: #e4e4ef; --text-dim: #8888a0; --text-bright: #fff;
    --accent: #6366f1; --accent-hover: #818cf8;
    --green: #22c55e; --green-hover: #16a34a;
    --red: #ef4444; --red-hover: #dc2626;
    --yellow: #FCC917; --blue: #2ABDFB;
    --radius: 8px; --radius-sm: 5px;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
  }
  * { box-sizing: border-box; margin: 0; padding: 0; }
  body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

  /* ── Top Bar ── */
  #topbar {
    height: 52px; background: var(--bg-card); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; padding: 0 20px; gap: 12px; flex-shrink: 0; z-index: 50;
  }
  #topbar .logo { font-weight: 700; font-size: 14px; color: var(--accent); letter-spacing: -0.3px; white-space: nowrap; }
  #topbar .sep { width: 1px; height: 24px; background: var(--border); }
  .tb-btn {
    display: flex; align-items: center; gap: 6px; padding: 6px 14px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: transparent; color: var(--text); font-size: 12px;
    font-weight: 500; cursor: pointer; transition: all 0.15s; white-space: nowrap; font-family: inherit;
  }
  .tb-btn:hover { background: var(--bg-hover); border-color: var(--text-dim); }
  .tb-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
  .tb-btn.primary:hover { background: var(--accent-hover); }
  .tb-btn.success { background: var(--green); border-color: var(--green); color: #fff; }
  .tb-btn.success:hover { background: var(--green-hover); }
  .tb-btn svg { width: 14px; height: 14px; }
  #topbar .spacer { flex: 1; }
  #status { font-size: 11px; color: var(--text-dim); max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* ── Main Layout ── */
  #main { display: flex; flex: 1; overflow: hidden; }

  /* ── Panel lateral ── */
  #panel {
    width: 300px; min-width: 300px; background: var(--bg-card); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; overflow: hidden; transition: width 0.2s;
  }
  #panel.collapsed { width: 0; min-width: 0; overflow: hidden; }
  .panel-header {
    padding: 14px 16px 10px; font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 1.2px; color: var(--text-dim); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
  }
  .panel-header button { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 16px; line-height: 1; }
  .panel-header button:hover { color: var(--text); }
  .panel-scroll { flex: 1; overflow-y: auto; padding: 0; }
  .panel-scroll::-webkit-scrollbar { width: 4px; }
  .panel-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

  /* Header image section */
  .header-section {
    padding: 12px 16px; border-bottom: 1px solid var(--border);
  }
  .header-section label { font-size: 11px; color: var(--text-dim); font-weight: 500; display: block; margin-bottom: 6px; }
  .header-thumb {
    width: 100%; height: 60px; object-fit: cover; border-radius: var(--radius-sm);
    border: 1px solid var(--border); cursor: pointer; display: block; margin-bottom: 8px;
  }
  .header-thumb:hover { border-color: var(--accent); }
  .input-row { display: flex; gap: 6px; }
  .input-row input { flex: 1; }

  /* Category in panel */
  .cat-group { border-bottom: 1px solid var(--border); }
  .cat-header {
    display: flex; align-items: center; padding: 10px 16px; gap: 8px; cursor: pointer;
    transition: background 0.1s;
  }
  .cat-header:hover { background: var(--bg-hover); }
  .cat-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
  .cat-name { font-size: 13px; font-weight: 600; flex: 1; color: var(--text-bright); }
  .cat-count { font-size: 11px; color: var(--text-dim); background: var(--bg); padding: 1px 7px; border-radius: 10px; }
  .cat-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.15s; }
  .cat-header:hover .cat-actions { opacity: 1; }
  .cat-action-btn {
    width: 22px; height: 22px; border: none; border-radius: 4px; background: transparent;
    color: var(--text-dim); cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: 12px;
  }
  .cat-action-btn:hover { background: var(--bg-hover); color: var(--text); }
  .cat-action-btn.del:hover { color: var(--red); }

  /* Event item in panel */
  .evt-item {
    display: flex; align-items: center; gap: 10px; padding: 8px 16px 8px 28px;
    cursor: pointer; transition: background 0.1s; border-left: 2px solid transparent;
  }
  .evt-item:hover { background: var(--bg-hover); }
  .evt-item.active { border-left-color: var(--accent); background: var(--bg-hover); }
  .evt-thumb {
    width: 36px; height: 36px; border-radius: var(--radius-sm); object-fit: cover;
    background: var(--bg); flex-shrink: 0;
  }
  .evt-info { flex: 1; min-width: 0; }
  .evt-info .name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .evt-info .meta { font-size: 10px; color: var(--text-dim); margin-top: 2px; }

  /* ── Preview Area ── */
  #preview-area {
    flex: 1; background: #1e1e26; overflow-y: auto; display: flex; justify-content: center;
    padding: 24px 20px 60px;
  }
  #preview-area::-webkit-scrollbar { width: 6px; }
  #preview-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
  #newsletter-frame {
    background: #fff; width: 620px; flex-shrink: 0; border-radius: var(--radius);
    box-shadow: var(--shadow); overflow: hidden; align-self: flex-start;
  }
  #newsletter-frame iframe { width: 100%; border: none; display: block; min-height: 400px; }

  /* ── Inputs globales ── */
  input[type="text"], input[type="url"], select, textarea {
    width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg-input); color: var(--text); font-size: 12px; font-family: inherit;
    transition: border-color 0.15s;
  }
  input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
  input::placeholder { color: var(--text-dim); }

  /* ── Modal ── */
  .modal-bg {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center; z-index: 200;
  }
  .modal-bg.hidden { display: none; }
  .modal-box {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
    width: 540px; max-height: 85vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  }
  .modal-box::-webkit-scrollbar { width: 4px; }
  .modal-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
  .modal-head {
    padding: 18px 24px 14px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
  }
  .modal-head h3 { font-size: 15px; font-weight: 600; }
  .modal-head button { background: none; border: none; color: var(--text-dim); cursor: pointer; font-size: 20px; line-height: 1; }
  .modal-head button:hover { color: var(--text); }
  .modal-body { padding: 18px 24px; }
  .modal-foot {
    padding: 14px 24px; border-top: 1px solid var(--border);
    display: flex; gap: 8px; justify-content: flex-end;
  }

  .field { margin-bottom: 14px; }
  .field label { display: block; font-size: 11px; font-weight: 500; color: var(--text-dim); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.5px; }
  .field-row { display: flex; gap: 8px; }
  .field-row > div { flex: 1; }
  .fetch-row { display: flex; gap: 6px; }
  .fetch-row input { flex: 1; }

  .fetched-card {
    background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 10px 14px; margin-bottom: 14px; font-size: 12px;
  }
  .fetched-card p { margin: 3px 0; }
  .fetched-card strong { color: var(--accent); }

  .img-preview {
    max-width: 100%; max-height: 120px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); margin-top: 6px; display: block;
  }

  .border-picker { display: flex; gap: 8px; }
  .border-opt {
    flex: 1; padding: 8px; border: 2px solid var(--border); border-radius: var(--radius-sm);
    text-align: center; cursor: pointer; font-size: 11px; font-weight: 600; transition: all 0.15s;
    background: var(--bg-input); font-family: inherit; color: var(--text);
  }
  .border-opt:hover { border-color: var(--text-dim); }
  .border-opt.active-yellow { border-color: var(--yellow); background: rgba(252,201,23,0.1); }
  .border-opt.active-blue { border-color: var(--blue); background: rgba(42,189,251,0.1); }

  .modal-btn {
    padding: 8px 18px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.15s; font-family: inherit;
  }
  .modal-btn.cancel { background: transparent; color: var(--text-dim); }
  .modal-btn.cancel:hover { background: var(--bg-hover); color: var(--text); }
  .modal-btn.save { background: var(--accent); border-color: var(--accent); color: #fff; }
  .modal-btn.save:hover { background: var(--accent-hover); }
  .modal-btn.delete { background: transparent; border-color: var(--red); color: var(--red); }
  .modal-btn.delete:hover { background: var(--red); color: #fff; }

  /* Spinner */
  .spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--accent); border-top-color: transparent; border-radius: 50%; animation: spin 0.5s linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* Toast */
  .toast {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
    background: var(--bg-card); border: 1px solid var(--border); padding: 10px 20px;
    border-radius: var(--radius); font-size: 12px; z-index: 300; box-shadow: var(--shadow);
    transition: opacity 0.3s, transform 0.3s; pointer-events: none;
  }
  .toast.hidden { opacity: 0; transform: translateX(-50%) translateY(10px); }