/* ============================================
   MEANINGFUL MARKETING — Admin bar, login, CRM
   Uses the site tokens from styles.css.
   ============================================ */

/* ---------- Admin bar ---------- */
.admin-bar {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 1200;
    height: var(--admin-bar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 var(--gutter);
    background: var(--espresso);
    color: var(--peach-pale);
    font-size: 0.86rem;
}
.admin-bar[hidden] { display: none; }
.admin-bar-left { display: flex; align-items: center; gap: 0.6rem; }
.admin-bar-left::before {
    content: '';
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--sage);
}
.admin-bar-actions { display: flex; gap: 0.5rem; }
.admin-hint { margin-left: 0.9rem; color: rgba(251, 235, 221, 0.6); font-size: 0.8rem; }
@media (max-width: 900px) { .admin-hint { display: none; } }

/* Section edit buttons (visible only in admin mode) */
[data-admin-tab] { position: relative; }
.admin-edit {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45em 0.9em;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--espresso);
    background: var(--peach);
    border-radius: 999px;
    box-shadow: 0 4px 14px rgba(42, 27, 18, 0.18);
}
.admin-edit:hover { background: var(--espresso); color: var(--peach-pale); }
.hero .admin-edit { top: auto; bottom: 1rem; }

/* In-place editing (admin mode) */
body.is-admin .inline-editable {
    cursor: text;
    outline: 1px dashed transparent;
    outline-offset: 4px;
    border-radius: 3px;
    transition: outline-color var(--fast), background var(--fast);
}
body.is-admin .inline-editable:hover { outline-color: var(--peach); background: rgba(240, 186, 147, 0.2); }
body.is-admin .inline-editing,
body.is-admin .inline-editing:hover {
    outline: 2px solid var(--clay);
    background: rgba(240, 186, 147, 0.22);
    caret-color: var(--clay-deep);
}
.inline-bar {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    z-index: 1250;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    max-width: calc(100vw - 2rem);
    padding: 0.5rem 0.55rem 0.5rem 1rem;
    background: var(--espresso);
    color: var(--peach-pale);
    border-radius: 999px;
    box-shadow: var(--shadow-lift);
    font-size: 0.85rem;
    opacity: 0;
    visibility: hidden;
    transform: translate(-50%, 16px);
    transition: opacity 0.2s, transform 0.25s var(--ease), visibility 0.2s;
}
.inline-bar.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.inline-bar strong { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.inline-bar small { color: rgba(251, 235, 221, 0.6); white-space: nowrap; }
.inline-bar .crm-btn-ghost { color: var(--peach-pale); border-color: rgba(240, 186, 147, 0.35); }
@media (max-width: 600px) { .inline-bar small { display: none; } }

/* ---------- Shared admin controls ---------- */
.crm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 36px;
    padding: 0.45em 1em;
    font-size: 0.86rem;
    font-weight: 500;
    line-height: 1;
    color: var(--peach-pale);
    background: var(--espresso);
    border: 1px solid var(--espresso);
    border-radius: 999px;
    white-space: nowrap;
    transition: background var(--fast), color var(--fast), border-color var(--fast);
}
.crm-btn:hover { background: var(--cocoa); border-color: var(--cocoa); }
.crm-btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.crm-btn-ghost { background: transparent; color: var(--ink); border-color: var(--sand); }
.crm-btn-ghost:hover { background: var(--peach-pale); border-color: var(--peach); color: var(--ink); }
.crm-btn-peach { background: var(--peach); border-color: var(--peach); color: var(--espresso); }
.crm-btn-peach:hover { background: var(--peach-soft); border-color: var(--peach-soft); }
.crm-btn-danger { background: transparent; color: var(--rose); border-color: rgba(201, 107, 107, 0.4); }
.crm-btn-danger:hover { background: rgba(201, 107, 107, 0.1); border-color: var(--rose); }
.crm-btn-sm { min-height: 30px; padding: 0.3em 0.75em; font-size: 0.78rem; }
.crm-btn-icon { width: 30px; min-height: 30px; padding: 0; }
.admin-bar .crm-btn-ghost { color: var(--peach-pale); border-color: rgba(240, 186, 147, 0.35); }
.admin-bar .crm-btn-ghost:hover { background: rgba(240, 186, 147, 0.12); color: var(--peach-pale); }

.crm-field { display: flex; flex-direction: column; gap: 0.35rem; }
.crm-field label,
.crm-field .crm-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--ink-soft);
}
.crm-field input,
.crm-field select,
.crm-field textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    font: inherit;
    font-size: 0.92rem;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--sand);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color var(--fast), box-shadow var(--fast);
}
.crm-field input:focus,
.crm-field select:focus,
.crm-field textarea:focus {
    border-color: var(--clay);
    box-shadow: 0 0 0 3px rgba(240, 186, 147, 0.35);
}
.crm-field textarea { resize: vertical; min-height: 80px; }
.crm-field input[readonly] { color: var(--mist); background: var(--paper-deep); }
.crm-hint { font-size: 0.78rem; color: var(--mist); }
.crm-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.9rem 1rem; }
.crm-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.9rem 1rem; }
.crm-span-2 { grid-column: 1 / -1; }

.crm-card {
    background: var(--paper);
    border: 1px solid var(--sand);
    border-radius: var(--radius-md);
    padding: 1.25rem;
}
.crm-card + .crm-card { margin-top: 1rem; }
.crm-card h3 {
    font-family: var(--font-text);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 1rem;
}
.crm-card p { font-size: 0.9rem; color: var(--ink-muted); }

.crm-status {
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    padding: 0.25em 0.7em;
    font-size: 0.76rem;
    font-weight: 500;
    border-radius: 999px;
    background: var(--paper-deep);
    color: var(--ink-soft);
    border: 1px solid transparent;
    white-space: nowrap;
}
.crm-status::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.crm-status-nou       { background: var(--peach); color: var(--espresso); }
.crm-status-contactat { background: var(--peach-pale); color: var(--clay-deep); }
.crm-status-discutie  { background: #FFF6D9; color: #8A6B1F; }
.crm-status-oferta    { background: #E9EEF8; color: #3F5A8A; }
.crm-status-castigat  { background: #E4EDE0; color: #3F5E35; }
.crm-status-pierdut   { background: #F6E1E1; color: #8E3A3A; }

.crm-status-select {
    font: inherit;
    font-size: 0.8rem;
    padding: 0.3em 1.6em 0.3em 0.7em;
    border: 1px solid var(--sand);
    border-radius: 999px;
    background: var(--paper);
    color: var(--ink);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%237A5E4B' stroke-width='1.5' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.6em center;
}

/* ---------- Login modal ---------- */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 1500;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgba(42, 27, 18, 0.55);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    animation: crmFade 0.25s var(--ease);
}
.login-card {
    width: min(100%, 400px);
    padding: 2.25rem 2rem 1.75rem;
    background: var(--paper);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lift);
    animation: crmPop 0.35s var(--ease);
}
.login-card .nav-logo { margin-bottom: 1.25rem; }
.login-card h2 { font-size: 1.9rem; margin-bottom: 0.25rem; }
.login-card > p { font-size: 0.92rem; color: var(--ink-muted); margin-bottom: 1.5rem; }
.login-card form { display: grid; gap: 1rem; }
.login-error { font-size: 0.86rem; color: var(--rose); }
.login-error[hidden] { display: none; }
.login-actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: 0.25rem; }
.login-card .crm-hint { margin-top: 1.25rem; }

/* ---------- CRM panel ---------- */
.crm-overlay {
    position: fixed;
    inset: 0;
    z-index: 1400;
    background: rgba(42, 27, 18, 0.5);
    animation: crmFade 0.25s var(--ease);
}
.crm {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    background: var(--paper);
    animation: crmPop 0.3s var(--ease);
}
.crm-side {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1.25rem 1rem;
    background: var(--espresso);
    color: var(--peach-pale);
    overflow-y: auto;
}
.crm-side .nav-logo { color: var(--peach-pale); padding: 0.25rem 0.5rem 1.25rem; }
.crm-side .nav-wordmark { font-size: 1.15rem; }
.crm-side .nav-wordmark em { color: var(--peach); }
.crm-side-group {
    margin: 0.9rem 0.6rem 0.35rem;
    font-size: 0.72rem;
    font-weight: 500;
    color: rgba(251, 235, 221, 0.45);
}
.crm-tab {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    padding: 0.6rem 0.75rem;
    font-size: 0.9rem;
    color: rgba(251, 235, 221, 0.78);
    border-radius: var(--radius-sm);
    text-align: left;
    transition: background var(--fast), color var(--fast);
}
.crm-tab:hover { background: rgba(240, 186, 147, 0.1); color: var(--peach-pale); }
.crm-tab.active { background: var(--peach); color: var(--espresso); font-weight: 500; }
.crm-tab .crm-count {
    min-width: 22px;
    padding: 0.1em 0.5em;
    font-size: 0.72rem;
    text-align: center;
    border-radius: 999px;
    background: rgba(251, 235, 221, 0.15);
}
.crm-tab.active .crm-count { background: rgba(42, 27, 18, 0.15); }
.crm-side-foot { margin-top: auto; padding-top: 1rem; display: grid; gap: 0.4rem; }
.crm-side-foot .crm-btn-ghost { color: var(--peach-pale); border-color: rgba(240, 186, 147, 0.3); }
.crm-side-foot .crm-btn-ghost:hover { background: rgba(240, 186, 147, 0.12); color: var(--peach-pale); }

.crm-main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.crm-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem var(--gutter);
    border-bottom: 1px solid var(--sand);
    background: var(--paper);
}
.crm-head h2 { font-size: 1.7rem; margin: 0; }
.crm-head p { font-size: 0.85rem; color: var(--mist); }
.crm-head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-end; }
.crm-body { flex: 1; overflow-y: auto; padding: 1.5rem var(--gutter) 3rem; background: var(--paper-deep); }
.crm-section + .crm-section { margin-top: 1.5rem; }

/* Overview */
.crm-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.crm-stat { padding: 1.1rem 1.25rem; }
.crm-stat-num { font-family: var(--font-display); font-size: 2.4rem; font-weight: 500; line-height: 1; color: var(--ink); }
.crm-stat-label { font-size: 0.82rem; color: var(--mist); margin-top: 0.4rem; }
.crm-pipeline { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--paper-deep); margin: 0.5rem 0 0.9rem; }
.crm-pipeline span { display: block; min-width: 0; }
.crm-legend { display: flex; flex-wrap: wrap; gap: 0.5rem 1.2rem; font-size: 0.82rem; color: var(--ink-muted); }
.crm-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 0.35em; vertical-align: -1px; }
.crm-overview-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 1rem; }
.crm-recent { list-style: none; display: grid; gap: 0.4rem; }
.crm-recent li { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.55rem 0.65rem; border-radius: var(--radius-sm); font-size: 0.9rem; }
.crm-recent li:hover { background: var(--peach-pale); cursor: pointer; }
.crm-recent strong { font-weight: 500; color: var(--ink); }
.crm-recent small { color: var(--mist); font-size: 0.78rem; }
.crm-empty { padding: 2rem 1rem; text-align: center; color: var(--mist); font-size: 0.92rem; }
.crm-empty strong { display: block; font-family: var(--font-display); font-size: 1.4rem; font-weight: 500; color: var(--ink); margin-bottom: 0.3rem; }

/* Leads */
.crm-toolbar { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-bottom: 1rem; }
.crm-toolbar input[type="search"],
.crm-toolbar select {
    min-height: 36px;
    padding: 0.4rem 0.8rem;
    font: inherit;
    font-size: 0.88rem;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--sand);
    border-radius: 999px;
    outline: none;
}
.crm-toolbar input[type="search"] { flex: 1 1 200px; }
.crm-toolbar input:focus, .crm-toolbar select:focus { border-color: var(--clay); }
.crm-toolbar .crm-spacer { flex: 1; }

.crm-table-wrap { background: var(--paper); border: 1px solid var(--sand); border-radius: var(--radius-md); overflow: auto; }
.crm-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.crm-table th {
    padding: 0.75rem 0.9rem;
    font-size: 0.76rem;
    font-weight: 500;
    color: var(--mist);
    text-align: left;
    border-bottom: 1px solid var(--sand);
    white-space: nowrap;
}
.crm-table td { padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--paper-deep); vertical-align: middle; }
.crm-table tbody tr { cursor: pointer; transition: background var(--fast); }
.crm-table tbody tr:hover { background: var(--peach-pale); }
.crm-table tbody tr:last-child td { border-bottom: 0; }
.crm-table .crm-cell-main strong { display: block; font-weight: 500; color: var(--ink); }
.crm-table .crm-cell-main span { font-size: 0.78rem; color: var(--mist); }
.crm-table .crm-cell-date { color: var(--mist); white-space: nowrap; }

/* Drawer */
.crm-drawer-overlay { position: fixed; inset: 0; z-index: 1450; background: rgba(42, 27, 18, 0.35); animation: crmFade 0.2s; }
.crm-drawer {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: min(560px, 100%);
    display: flex;
    flex-direction: column;
    background: var(--paper);
    box-shadow: var(--shadow-lift);
    animation: crmSlide 0.3s var(--ease);
}
.crm-drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: 1.25rem 1.5rem 1rem; border-bottom: 1px solid var(--sand); }
.crm-drawer-head h3 { font-family: var(--font-display); font-size: 1.6rem; font-weight: 500; margin: 0 0 0.2rem; }
.crm-drawer-head p { font-size: 0.82rem; color: var(--mist); }
.crm-drawer-body { flex: 1; overflow-y: auto; padding: 1.25rem 1.5rem; display: grid; gap: 1rem; align-content: start; }
.crm-drawer-foot { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; flex-wrap: wrap; padding: 1rem 1.5rem; border-top: 1px solid var(--sand); background: var(--paper); }
.crm-drawer-foot > div { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.crm-lead-meta { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; font-size: 0.8rem; color: var(--mist); }

/* Content list editor */
.crm-items { display: grid; gap: 0.9rem; }
.crm-item { background: var(--paper); border: 1px solid var(--sand); border-radius: var(--radius-md); overflow: hidden; }
.crm-item-head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.75rem 0.6rem 1rem;
    background: var(--peach-pale);
    border-bottom: 1px solid var(--sand);
}
.crm-item-head strong { flex: 1; font-size: 0.9rem; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-item-head .crm-order { font-family: var(--font-display); font-size: 1.1rem; color: var(--clay-deep); min-width: 1.4em; }
.crm-item-body { padding: 1rem; display: grid; gap: 0.9rem; }
.crm-item.collapsed .crm-item-body { display: none; }
.crm-sticky-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    margin-top: 1.25rem;
    padding: 0.9rem 0;
    background: linear-gradient(to top, var(--paper-deep) 70%, transparent);
}
.crm-unsaved { display: none; align-self: center; margin-right: auto; font-size: 0.82rem; color: var(--clay-deep); }
.crm-dirty .crm-unsaved { display: inline; }

/* Blog editor + images */
.crm-status-published { background: #E4EDE0; color: #3F5E35; }
.crm-status-draft { background: var(--paper-deep); color: var(--mocha); }
.crm-editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.crm-editor-side .crm-card + .crm-card { margin-top: 1rem; }
.crm-toolbar-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
.crm-toolbar-btns { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.crm-body-textarea { min-height: 420px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9rem; line-height: 1.6; tab-size: 2; }
.crm-preview { min-height: 420px; padding: 1.25rem 1.5rem; background: var(--paper); border: 1px solid var(--sand); border-radius: var(--radius-sm); font-size: 1rem; }
.crm-preview:empty::before { content: 'Nimic de previzualizat inca.'; color: var(--mist); }
.crm-cover-preview { margin-bottom: 0.8rem; border-radius: var(--radius-sm); overflow: hidden; background: var(--paper-deep); aspect-ratio: 3 / 2; }
.crm-cover-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.crm-upload-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.crm-upload-card { background: var(--paper); border: 1px solid var(--sand); border-radius: var(--radius-md); overflow: hidden; display: flex; flex-direction: column; }
.crm-upload-card > a { display: block; aspect-ratio: 4 / 3; background: var(--paper-deep); }
.crm-upload-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.crm-upload-meta { display: flex; justify-content: space-between; gap: 0.5rem; padding: 0.6rem 0.75rem 0.2rem; font-size: 0.78rem; color: var(--mist); }
.crm-upload-meta strong { font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crm-upload-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0.4rem 0.75rem 0.75rem; }
.crm-btn input[type="file"] { display: none; }
@media (max-width: 1100px) { .crm-editor { grid-template-columns: 1fr; } }

/* Settings */
.crm-settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.crm-settings-grid .crm-card + .crm-card { margin-top: 0; }
.crm-danger-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.crm-inline-confirm { display: inline-flex; gap: 0.4rem; align-items: center; font-size: 0.84rem; color: var(--rose); }

/* Toast */
.crm-toast {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    z-index: 1600;
    transform: translate(-50%, 20px);
    padding: 0.7rem 1.2rem;
    font-size: 0.88rem;
    color: var(--peach-pale);
    background: var(--espresso);
    border-radius: 999px;
    box-shadow: var(--shadow-lift);
    opacity: 0;
    transition: opacity 0.25s, transform 0.3s var(--ease);
    pointer-events: none;
}
.crm-toast.show { opacity: 1; transform: translate(-50%, 0); }
.crm-toast.error { background: var(--rose); color: #fff; }

@keyframes crmFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes crmPop { from { opacity: 0; transform: translateY(10px) scale(0.99); } to { opacity: 1; transform: none; } }
@keyframes crmSlide { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }

body.crm-open { overflow: hidden; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .crm { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
    .crm-side { flex-direction: row; align-items: center; gap: 0.3rem; padding: 0.6rem 0.75rem; overflow-x: auto; overflow-y: hidden; }
    .crm-side .nav-logo, .crm-side-group { display: none; }
    .crm-tab { width: auto; white-space: nowrap; padding: 0.45rem 0.7rem; font-size: 0.84rem; }
    .crm-side-foot { margin: 0 0 0 auto; padding: 0; display: flex; }
    .crm-side-foot .crm-btn { white-space: nowrap; }
    .crm-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .crm-overview-grid, .crm-settings-grid { grid-template-columns: 1fr; }
    .crm-grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
    .admin-bar { font-size: 0.8rem; }
    .admin-bar-left span.admin-user { display: none; }
    .crm-grid-2, .crm-grid-3 { grid-template-columns: 1fr; }
    .crm-head { flex-direction: column; align-items: flex-start; }
    .crm-head-actions { justify-content: flex-start; }
    .crm-table .crm-col-optional { display: none; }
    .crm-field input, .crm-field select, .crm-field textarea { font-size: 16px; }
}
