* { box-sizing: border-box; }
body { margin: 0; font-family: 'Segoe UI', Roboto, system-ui, sans-serif; background: #f4f3ee; color: #26291f; }
a { color: #4f6b2f; }

/* Layout */
.admin-layout { display: flex; min-height: 100vh; }
.admin-sidebar { width: 220px; flex-shrink: 0; background: #1f2a1a; color: #fff; display: flex; flex-direction: column; padding: 22px 0; position: sticky; top: 0; height: 100vh; }
.admin-brand { font-weight: 800; font-size: 1.15rem; padding: 0 22px 22px; color: #fff; border-bottom: 1px solid rgba(255,255,255,0.1); margin-bottom: 14px; }
.admin-brand span { color: #9fb46a; }
.admin-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.admin-nav a { color: #cdd2c0; text-decoration: none; font-size: 0.92rem; padding: 11px 22px; display: flex; align-items: center; gap: 10px; transition: background 0.12s ease, color 0.12s ease; }
.admin-nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.admin-nav .ic { font-size: 1rem; width: 18px; text-align: center; }
.admin-user { padding: 16px 22px 0; border-top: 1px solid rgba(255,255,255,0.1); margin-top: 12px; padding-top: 16px; display: flex; align-items: center; justify-content: space-between; font-size: 0.85rem; color: #cdd2c0; }
.admin-user form { display: inline; }
.admin-user button.link { background: none; border: none; color: #9fb46a; cursor: pointer; font-size: 0.85rem; padding: 0; font-family: inherit; font-weight: 600; }

.deploy-widget { padding: 12px 22px; border-top: 1px solid rgba(255,255,255,0.1); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.deploy-status { font-size: 0.75rem; color: #9ba189; line-height: 1.3; }
.deploy-status.ok { color: #9fd66a; }
.deploy-status.building { color: #ffcf6a; }
.deploy-status.err { color: #ff8a8a; }
.deploy-status.off { color: #7a806c; }
.deploy-widget button.link { background: none; border: none; color: #9fb46a; cursor: pointer; font-size: 0.75rem; padding: 0; font-family: inherit; font-weight: 600; white-space: nowrap; }

.admin-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.admin-banner { background: linear-gradient(135deg, #ff8a3d 0%, #ff611d 100%); padding: 30px 32px; color: #fff; }
.admin-banner h1 { margin: 0; font-size: 1.6rem; color: #fff; }
.admin-wrap { max-width: 1100px; padding: 28px 32px 60px; width: 100%; }
.admin-wrap-wide { max-width: 1600px; }
.admin-wrap-wide .stack, .admin-wrap-wide form.stack { max-width: none; }

/* Login page (no sidebar) */
.login-wrap { max-width: 380px; margin: 90px auto; }

h1 { font-size: 1.6rem; margin-top: 0; }
h2 { font-size: 1.15rem; }
.card { background: #fff; border: 1px solid #e5e2da; border-radius: 10px; padding: 20px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.stat-grid .card { position: relative; overflow: hidden; padding: 20px 20px 18px; }
.stat-grid .card strong { display: block; font-size: 1.9rem; color: #1f2a1a; margin-top: 6px; }
.stat-grid .card span:last-child { font-size: 0.85rem; color: #6b7062; }
.stat-icon { font-size: 1.3rem; }
.stat-grid .stat-a { border-top: 3px solid #4f6b2f; }
.stat-grid .stat-b { border-top: 3px solid #ff8a3d; }
.stat-grid .stat-c { border-top: 3px solid #3d7ba6; }
.stat-grid .stat-d { border-top: 3px solid #c2493d; }

table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #e5e2da; border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid #eeece5; font-size: 0.9rem; }
th { background: #f6f5f0; font-weight: 700; color: #4c5142; text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #fbfaf6; }
.actions-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.btn { display: inline-block; background: #4f6b2f; color: #fff; padding: 9px 16px; border-radius: 6px; text-decoration: none; font-weight: 600; border: none; cursor: pointer; font-size: 0.9rem; }
.btn:hover { background: #435c28; }
.btn-outline { background: transparent; color: #4f6b2f; border: 1px solid #4f6b2f; }
.btn-danger { background: #c2493d; }
.btn-danger:hover { background: #a13a2e; }
.btn-sm { padding: 5px 10px; font-size: 0.82rem; }
form.stack, .stack { display: flex; flex-direction: column; gap: 16px; max-width: 760px; }
form.stack label, .stack label { display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; font-weight: 600; color: #33362e; }
form.stack .row2, .stack .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
fieldset { border: 1px solid #e5e2da; border-radius: 8px; padding: 16px; display: flex; flex-direction: column; gap: 16px; margin: 0; }
fieldset legend { font-weight: 700; font-size: 0.9rem; color: #33362e; padding: 0 6px; }
fieldset label { display: flex; flex-direction: column; gap: 6px; font-size: 0.88rem; font-weight: 600; color: #33362e; }
input, textarea, select { font: inherit; padding: 9px 11px; border: 1px solid #d7d4c9; border-radius: 6px; width: 100%; background: #fff; }
input:focus, textarea:focus, select:focus { outline: 2px solid #9fb46a; outline-offset: 0; border-color: #9fb46a; }
textarea { resize: vertical; }
.hint { font-weight: 400; color: #7a7e6d; font-size: 0.8rem; }
.error { color: #a13a2e; font-weight: 600; font-size: 0.9rem; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 0.74rem; font-weight: 700; }
.badge-new { background: #fdeccb; color: #935b0b; }
.badge-contacted { background: #d9ecd0; color: #35692a; }
.badge-closed { background: #e5e2da; color: #5b5f52; }

select[multiple] { min-height: 130px; }
.btn[disabled] { opacity: 0.4; cursor: default; }
.btn[disabled]:hover { background: transparent; }

.leads-topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 16px; flex-wrap: wrap; }
.leads-heading strong { font-size: 1.15rem; color: #1f2a1a; }
.leads-search { display: flex; gap: 8px; }
.leads-search input { width: 240px; }
.leads-search select { width: auto; }
.leads-bulk-actions, .leads-io-actions { display: flex; gap: 8px; align-items: center; }
.leads-import-form { display: flex; gap: 8px; align-items: center; }
.leads-import-form input[type="file"] { width: auto; padding: 6px; font-size: 0.82rem; }
.table-scroll { overflow-x: auto; border-radius: 10px; }
.table-scroll table { min-width: 1200px; }
.leads-pagination { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }
.pagination-buttons { display: flex; gap: 8px; align-items: center; }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 18px; }
.media-item { background: #fff; border: 1px solid #e5e2da; border-radius: 10px; overflow: hidden; }
.media-item img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #f0efe9; display: block; }
.media-item-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.media-url { font-size: 0.76rem; color: #6b7062; background: #f6f5f0; }
.media-alt-form { display: flex; gap: 6px; }
.media-alt-form input[type="text"] { flex: 1; }

.lib-picker-overlay { position: fixed; inset: 0; background: rgba(20, 24, 14, 0.6); z-index: 300; display: flex; align-items: center; justify-content: center; padding: 30px; }
.lib-picker { background: #fff; border-radius: 10px; width: 100%; max-width: 800px; max-height: 80vh; display: flex; flex-direction: column; overflow: hidden; }
.lib-picker-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid #e5e2da; }
.lib-picker-header h3 { margin: 0; font-size: 1.1rem; }
.lib-picker-close { background: none; border: none; font-size: 1.6rem; line-height: 1; cursor: pointer; color: #6b7062; }
.lib-picker-grid { padding: 18px 20px; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.lib-picker-item { border: 1px solid #e5e2da; border-radius: 8px; overflow: hidden; background: #fff; cursor: pointer; padding: 0; text-align: left; }
.lib-picker-item:hover { border-color: #4f6b2f; }
.lib-picker-item img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: #f0efe9; }
.lib-picker-item span { display: block; padding: 6px 8px; font-size: 0.72rem; color: #6b7062; word-break: break-all; }
.lib-picker-upload { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid #e5e2da; background: #f6f5f0; flex-wrap: wrap; }
.lib-picker-upload input[type="file"] { flex: 1; min-width: 180px; width: auto; }
.lp-upload-status { font-size: 0.8rem; color: #6b7062; }

/* Analytics */
.an-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.an-live { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; color: #33362e; background: #fff; border: 1px solid #e5e2da; border-radius: 20px; padding: 7px 16px; }
.an-live strong { font-size: 1.05rem; color: #1f2a1a; }
.an-live-dot { width: 9px; height: 9px; border-radius: 50%; background: #3ec46d; box-shadow: 0 0 0 0 rgba(62,196,109,0.6); animation: an-pulse 1.8s infinite; }
@keyframes an-pulse { 0% { box-shadow: 0 0 0 0 rgba(62,196,109,0.55); } 70% { box-shadow: 0 0 0 8px rgba(62,196,109,0); } 100% { box-shadow: 0 0 0 0 rgba(62,196,109,0); } }
.an-range { display: flex; gap: 4px; background: #fff; border: 1px solid #e5e2da; border-radius: 8px; padding: 4px; }
.an-range-btn { background: none; border: none; padding: 6px 14px; border-radius: 6px; font: inherit; font-size: 0.85rem; font-weight: 600; color: #6b7062; cursor: pointer; }
.an-range-btn:hover { background: #f4f3ee; }
.an-range-btn.active { background: #4f6b2f; color: #fff; }
.an-stat-grid { grid-template-columns: repeat(4, 1fr); }
.an-stat-grid .card strong { font-size: 1.5rem; }
.an-grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 16px; }
.an-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 16px; }
.card h2 { margin: 0 0 14px; font-size: 1rem; }

.an-bars { display: flex; flex-direction: column; gap: 10px; }
.an-bar-row { display: grid; grid-template-columns: 130px 1fr 40px; align-items: center; gap: 10px; font-size: 0.84rem; }
.an-bar-label { color: #33362e; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-bar-track { background: #f0efe9; border-radius: 4px; height: 8px; overflow: hidden; }
.an-bar-fill { background: #4f6b2f; height: 100%; border-radius: 4px; }
.an-bar-value { text-align: right; font-weight: 700; color: #1f2a1a; }
.an-conversions .an-bar-fill { background: #ff8a3d; }
.an-empty { color: #8a8f7c; font-size: 0.88rem; margin: 10px 0; }

.an-chart-card { min-width: 0; }
.an-chart { width: 100%; }
.an-chart-svg { width: 100%; height: 220px; display: block; }
.an-grid-line { stroke: #eeece5; stroke-width: 1; }
.an-line-pageviews { stroke: #ff8a3d; stroke-width: 2; }
.an-line-visitors { stroke: #4f6b2f; stroke-width: 2; }
.an-dot-pv { fill: #ff8a3d; }
.an-chart-label { fill: #8a8f7c; font-size: 9px; }
.an-chart-legend { display: flex; gap: 16px; font-size: 0.78rem; color: #6b7062; margin-top: 6px; }
.an-legend-pv { color: #ff8a3d; font-weight: 600; }
.an-legend-uv { color: #4f6b2f; font-weight: 600; }

.an-feed-card { display: flex; flex-direction: column; min-width: 0; }
.an-feed { max-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.an-feed-item { font-size: 0.82rem; color: #4c5142; padding: 7px 0; border-bottom: 1px solid #f0efe9; }
.an-feed-item code { background: #f6f5f0; padding: 1px 5px; border-radius: 4px; font-size: 0.78rem; }
.an-feed-meta { color: #8a8f7c; }
.an-feed-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #3ec46d; margin-right: 4px; }
.an-feed-dot-event { background: #ff8a3d; }

@media (max-width: 900px) {
  .an-stat-grid { grid-template-columns: repeat(2, 1fr); }
  .an-grid-2, .an-grid-3 { grid-template-columns: 1fr; }
}

/* Rich text editor */
.richtext-wrap { position: relative; border: 1px solid #d7d4c9; border-radius: 6px; overflow: hidden; background: #fff; font-weight: 400; }
.richtext-toolbar { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; background: #f6f5f0; border-bottom: 1px solid #e5e2da; }
.richtext-btn { font-size: 0.78rem; padding: 5px 9px; border-radius: 5px; border: 1px solid #d7d4c9; background: #fff; color: #33362e; cursor: pointer; font-family: inherit; line-height: 1.2; }
.richtext-btn:hover { background: #f0efe9; border-color: #4f6b2f; }
.richtext-btn.active { background: #4f6b2f; color: #fff; border-color: #4f6b2f; }
.richtext-editor { min-height: 260px; max-height: 640px; overflow-y: auto; padding: 14px 16px; font-size: 0.95rem; line-height: 1.6; color: #26291f; }
.richtext-editor:focus { outline: none; }
.richtext-editor h2, .richtext-editor h3, .richtext-editor h4 { margin: 0.8em 0 0.4em; }
.richtext-editor p { margin: 0 0 0.8em; }
.richtext-editor blockquote { border-left: 3px solid #4f6b2f; padding-left: 0.85em; margin: 0.8em 0; color: #555; }
.richtext-editor ul, .richtext-editor ol { padding-left: 1.4em; margin: 0 0 0.8em; }
.richtext-editor img { max-width: 100%; height: auto; border-radius: 4px; cursor: pointer; display: block; margin: 0.6em 0; }
.richtext-editor img.richtext-img-selected { outline: 2px solid #4f6b2f; outline-offset: 2px; }
.richtext-editor .video-embed { position: relative; margin: 0.8em 0; }
.richtext-raw-view { display: none; width: 100%; min-height: 260px; max-height: 640px; border: none; border-radius: 0; font-family: Consolas, Menlo, monospace; font-size: 0.82rem; padding: 14px 16px; background: #1e1e2e; color: #e2e4f0; resize: vertical; }
.richtext-wrap.richtext-raw-mode .richtext-editor { display: none; }
.richtext-wrap.richtext-raw-mode .richtext-raw-view { display: block; }
.richtext-img-delete { position: absolute; width: 22px; height: 22px; border-radius: 50%; background: #c2493d; color: #fff; border: none; cursor: pointer; display: none; align-items: center; justify-content: center; font-size: 15px; line-height: 1; z-index: 5; transform: translate(-50%, -50%); }
.richtext-img-delete:hover { background: #a13a2e; }

.toc-check-list { display: flex; flex-direction: column; gap: 6px; background: #f6f5f0; border: 1px solid #e5e2da; border-radius: 6px; padding: 12px 14px; font-weight: 400; }
.toc-check-row { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 0.88rem; color: #33362e; cursor: pointer; }
.toc-check-row input { width: auto; }
.toc-check-row.toc-check-sub { margin-left: 20px; color: #6b7062; }
