/* ============================================
   CREATIVEFORGE — Criativos em Massa
   Palette: Navy-Dark + Orange
   ============================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-root: #080b14;
    --bg-sidebar: #0a0e1a;
    --bg-card: #0f1322;
    --bg-card-hover: #131830;
    --bg-surface: #141929;
    --bg-input: #0b0f1c;
    --bg-section: #0d1120;
    --border: #1a2038;
    --border-hover: #252d4a;

    --text-primary: #e8eaf0;
    --text-secondary: #7c829a;
    --text-muted: #464d68;

    --accent: #F97316;
    --accent-hover: #fb923c;
    --accent-dim: rgba(249, 115, 22, 0.12);
    --accent-glow: rgba(249, 115, 22, 0.20);

    --danger: #ef4444;
    --danger-dim: rgba(239, 68, 68, 0.12);
    --success: #22c55e;

    --radius: 6px;
    --radius-lg: 10px;
    --radius-pill: 100px;
    --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    --sidebar-w: 220px;
    --sidebar-collapsed: 56px;
}

html { font-size: 14px; }
body {
    font-family: var(--font);
    background: var(--bg-root);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ===========================
   LAYOUT
   =========================== */
.app-layout { display: flex; min-height: 100vh; }

/* --- SIDEBAR --- */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; bottom: 0;
    z-index: 50;
    transition: width 250ms ease;
    overflow: hidden;
}

/* COLLAPSED STATE */
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .brand-info,
.sidebar.collapsed .sidebar-label,
.sidebar.collapsed .status-label,
.sidebar.collapsed .brand-desc { display: none; }
.sidebar.collapsed .sidebar-link { justify-content: center; padding: 10px 0; }
.sidebar.collapsed .sidebar-link.active::before { left: 0; }
.sidebar.collapsed .sidebar-brand { padding: 14px 12px; justify-content: center; }
.sidebar.collapsed .brand-logo { justify-content: center; }
.sidebar.collapsed .sidebar-toggle svg { transform: rotate(180deg); }
.sidebar.collapsed .webhook-badge { justify-content: center; }

.sidebar-brand { padding: 18px 16px; border-bottom: 1px solid var(--border); }
.brand-logo { display: flex; align-items: flex-start; gap: 10px; }
.brand-icon {
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; flex-shrink: 0;
    background: var(--accent-dim);
    border-radius: var(--radius);
}
.brand-info { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-weight: 700; font-size: 14px; white-space: nowrap; }
.brand-desc { font-size: 10px; color: var(--text-muted); line-height: 1.3; margin-top: 2px; }

/* --- SIDEBAR NAV --- */
.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px;
    background: none; border: none;
    color: var(--text-secondary);
    font-family: var(--font); font-size: 13px; font-weight: 500;
    cursor: pointer; border-radius: var(--radius);
    transition: var(--transition); text-align: left; position: relative;
    white-space: nowrap;
}
.sidebar-link:hover { color: var(--text-primary); background: rgba(255,255,255,0.03); }
.sidebar-link.active { color: var(--accent); background: var(--accent-dim); }
.sidebar-link.active::before {
    content: ''; position: absolute; left: -8px; top: 6px; bottom: 6px;
    width: 3px; background: var(--accent); border-radius: 0 3px 3px 0;
}
.sidebar-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }

.sidebar-footer { padding: 14px 16px; border-top: 1px solid var(--border); }
.webhook-badge { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-muted); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.status-dot.offline { background: var(--danger); box-shadow: 0 0 6px rgba(239,68,68,0.5); }
.status-dot.online { background: var(--success); box-shadow: 0 0 6px rgba(34,197,94,0.5); animation: pulse-dot 2s infinite; }
@keyframes pulse-dot { 0%,100%{opacity:1}50%{opacity:0.4} }

/* --- SIDEBAR TOGGLE --- */
.sidebar-toggle {
    position: absolute; top: 50%; right: -12px;
    transform: translateY(-50%);
    width: 24px; height: 24px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-surface); border: 1px solid var(--border);
    color: var(--text-muted); cursor: pointer;
    border-radius: 50%; z-index: 51;
    transition: var(--transition);
}
.sidebar-toggle:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }
.sidebar-toggle svg { transition: transform 250ms ease; }

/* --- MAIN --- */
.main-area {
    flex: 1; margin-left: var(--sidebar-w);
    display: flex; flex-direction: column;
    min-height: 100vh;
    transition: margin-left 250ms ease;
}
.main-area.sidebar-collapsed { margin-left: var(--sidebar-collapsed); }

/* --- TOPBAR --- */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 28px;
    border-bottom: 1px solid var(--border);
    background: rgba(8, 11, 20, 0.75);
    backdrop-filter: blur(10px);
    position: sticky; top: 0; z-index: 40;
    gap: 16px; flex-wrap: wrap;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-icon { font-size: 22px; }
.topbar-title { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.topbar-subtitle { font-size: 12px; color: var(--text-secondary); margin-top: 1px; }
.mobile-menu-btn { display: none; background: none; border: none; color: var(--text-secondary); cursor: pointer; padding: 4px; }

.creative-counter {
    font-size: 11px; font-weight: 600; color: var(--text-muted);
    background: var(--bg-surface); padding: 4px 12px;
    border-radius: var(--radius-pill); border: 1px solid var(--border);
}

/* --- CONTENT --- */
.content-area { flex: 1; padding: 24px 28px; overflow-y: auto; }
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeUp 250ms ease-out; }
@keyframes fadeUp { from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)} }

/* --- SECTION --- */
.section-block {
    background: var(--bg-section); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 20px 24px; margin-bottom: 20px;
}
.section-header { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.section-number { font-size: 16px; }
.section-title { font-size: 15px; font-weight: 700; }

/* --- BUTTONS --- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px; border: none; border-radius: var(--radius);
    font-family: var(--font); font-size: 13px; font-weight: 600;
    cursor: pointer; transition: var(--transition); white-space: nowrap;
}
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-primary {
    background: var(--accent); color: #000;
    box-shadow: 0 1px 8px rgba(249,115,22,0.25);
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(249,115,22,0.3); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text-primary); border-color: var(--border-hover); background: rgba(255,255,255,0.03); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(239,68,68,0.25); }
.btn-danger:hover { background: var(--danger-dim); border-color: var(--danger); }

/* --- CREATIVE CANVAS --- */
.creative-canvas {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}

/* --- CREATIVE CARD --- */
.creative-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-lg); overflow: hidden;
    transition: var(--transition);
    animation: cardIn 350ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes cardIn { from{opacity:0;transform:scale(0.96) translateY(10px)} }
.creative-card:hover { border-color: var(--border-hover); }

.card-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,0.01);
}
.card-header-left { display: flex; align-items: center; gap: 10px; }
.card-number { font-size: 11px; font-weight: 700; color: var(--accent); letter-spacing: 0.8px; }
.sent-badge {
    display: inline-flex; align-items: center; gap: 3px;
    font-size: 10px; font-weight: 700; color: var(--success);
    background: rgba(34, 197, 94, 0.12);
    padding: 2px 8px; border-radius: var(--radius-pill);
    border: 1px solid rgba(34, 197, 94, 0.25);
    animation: badgeIn 300ms ease-out;
}
@keyframes badgeIn { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }
.card-actions { display: flex; gap: 2px; }
.card-action-btn {
    width: 26px; height: 26px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: 1px solid transparent;
    color: var(--text-muted); cursor: pointer;
    border-radius: var(--radius); transition: var(--transition);
}
.card-action-btn:hover { color: var(--text-primary); border-color: var(--border); background: rgba(255,255,255,0.03); }
.card-action-btn.delete:hover { color: var(--danger); border-color: rgba(239,68,68,0.3); }
.card-action-btn.send-one:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }

/* --- FORMAT SELECTOR (inside card) --- */
.card-format-bar {
    display: flex; gap: 0; padding: 6px 14px;
    border-bottom: 1px solid var(--border);
    background: rgba(255,255,255,0.015);
    overflow-x: auto;
}
.card-format-btn {
    padding: 5px 12px;
    background: none; border: none;
    color: var(--text-muted); font-family: var(--font);
    font-size: 11px; font-weight: 500;
    cursor: pointer; border-radius: var(--radius-pill);
    transition: var(--transition); white-space: nowrap;
}
.card-format-btn:hover { color: var(--text-secondary); }
.card-format-btn.active {
    background: var(--accent); color: #000; font-weight: 700;
    box-shadow: 0 1px 6px rgba(249,115,22,0.3);
}

/* --- CARD FIELDS (Client, AI, Style, Effect) --- */
.card-fields {
    padding: 10px 14px 6px;
    border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 6px;
}
.field-row { display: flex; gap: 8px; }
.field-group { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.field-group.field-grow { flex: 1.5; }
.field-micro-label { font-size: 9px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.card-input, .card-select {
    width: 100%;
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text-primary);
    font-family: var(--font); font-size: 12px;
    padding: 6px 10px; transition: var(--transition);
}
.card-input::placeholder { color: var(--text-muted); }
.card-input:focus, .card-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.card-select { cursor: pointer; appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%237c829a' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 8px center; padding-right: 24px;
}
.card-select option { background: var(--bg-card); color: var(--text-primary); }

/* --- DRAG & DROP FEEDBACK --- */
.photo-slot.drag-over, .reference-slot.drag-over {
    border: 2px dashed var(--accent) !important;
    background: var(--accent-dim) !important;
    box-shadow: inset 0 0 20px rgba(249,115,22,0.1);
}

/* --- PHOTO GRID --- */
.photo-grid {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 2px; padding: 2px; margin: 10px 14px;
    background: var(--border); border-radius: var(--radius);
}
.photo-slot {
    aspect-ratio: 1; position: relative;
    background: var(--bg-input); cursor: pointer;
    overflow: hidden; transition: var(--transition);
}
.photo-slot:hover { background: var(--bg-surface); }
.photo-slot.has-image .photo-placeholder { display: none; }
.photo-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-placeholder {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    width: 100%; height: 100%; gap: 4px;
    color: var(--text-muted); font-size: 10px; font-weight: 500;
}
.photo-placeholder svg { opacity: 0.35; }
.photo-slot .remove-photo {
    position: absolute; top: 4px; right: 4px;
    width: 20px; height: 20px;
    display: none; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.7); border: none;
    color: #fff; cursor: pointer; border-radius: 50%; font-size: 12px;
}
.photo-slot.has-image:hover .remove-photo { display: flex; }
.photo-slot input[type="file"] { display: none; }

/* --- REFERENCE --- */
.reference-section { padding: 0 14px; margin-bottom: 10px; }
.reference-label { font-size: 10px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; letter-spacing: 0.5px; text-transform: uppercase; }
.reference-slot {
    width: 100%; height: 72px;
    background: var(--bg-input); border: 1px dashed var(--border);
    border-radius: var(--radius); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    gap: 8px; color: var(--text-muted); font-size: 11px;
    transition: var(--transition); position: relative; overflow: hidden;
}
.reference-slot:hover { border-color: var(--accent); color: var(--text-secondary); }
.reference-slot.has-image { border-style: solid; }
.reference-slot.has-image .ref-placeholder { display: none; }
.reference-slot img { width: 100%; height: 100%; object-fit: cover; }
.reference-slot .remove-photo {
    position: absolute; top: 4px; right: 4px;
    width: 20px; height: 20px;
    display: none; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.7); border: none;
    color: #fff; cursor: pointer; border-radius: 50%; font-size: 12px;
}
.reference-slot.has-image:hover .remove-photo { display: flex; }
.reference-slot input[type="file"] { display: none; }

/* --- DESCRIPTION --- */
.description-section { padding: 0 14px 14px; }
.desc-label { font-size: 10px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; letter-spacing: 0.5px; text-transform: uppercase; }
.desc-textarea {
    width: 100%; min-height: 56px; max-height: 140px;
    background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text-primary);
    font-family: var(--font); font-size: 13px;
    padding: 10px 12px; resize: vertical; transition: var(--transition);
}
.desc-textarea::placeholder { color: var(--text-muted); }
.desc-textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }

/* --- ADD CARD --- */
.add-card-btn {
    display: flex; align-items: center; justify-content: center;
    width: 100%; padding: 24px; margin-top: 16px;
    background: none; border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-muted); cursor: pointer;
    font-family: var(--font); font-size: 13px; font-weight: 600;
    gap: 8px; transition: var(--transition);
}
.add-card-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.add-card-btn:active { transform: scale(0.98); }

/* --- CONFIG --- */
.config-panel { max-width: 640px; }
.config-desc { font-size: 13px; color: var(--text-secondary); margin-bottom: 16px; }
.config-field { margin-bottom: 12px; }
.field-label { font-size: 11px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; display: block; text-transform: uppercase; letter-spacing: 0.5px; }
.input-row { display: flex; gap: 8px; }
.merit-input {
    flex: 1; background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text-primary);
    font-family: var(--font); font-size: 13px; padding: 10px 14px; transition: var(--transition);
}
.merit-input::placeholder { color: var(--text-muted); }
.merit-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.webhook-test-row { display: flex; align-items: center; gap: 12px; }
.test-result { font-size: 12px; font-weight: 500; }
.test-result.success { color: var(--success); }
.test-result.error { color: var(--danger); }
.config-actions-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- TOAST --- */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 18px; min-width: 260px;
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: var(--radius); font-size: 13px;
    animation: toastIn 250ms ease-out;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes toastIn { from{opacity:0;transform:translateX(16px)} }
.toast-exit { animation: toastOut 180ms ease-in forwards; }
@keyframes toastOut { to{opacity:0;transform:translateX(16px)} }

/* --- OVERLAY --- */
.overlay {
    display: none; position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,0.85); backdrop-filter: blur(6px);
    align-items: center; justify-content: center;
}
.overlay.active { display: flex; }
.overlay-content { text-align: center; }
.send-progress-ring { width: 110px; height: 110px; margin: 0 auto 20px; position: relative; }
.send-progress-ring svg { transform: rotate(-90deg); }
.progress-bg { fill: none; stroke: var(--border); stroke-width: 6; }
.progress-fill { fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round; stroke-dasharray: 264; stroke-dashoffset: 264; transition: stroke-dashoffset 400ms ease; }
.progress-text { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 800; color: var(--accent); }
.overlay-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.overlay-desc { color: var(--text-secondary); font-size: 13px; margin-bottom: 16px; }

/* --- RESPONSIVE --- */
@media (max-width: 860px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: 8px 0 40px rgba(0,0,0,0.6); }
    .sidebar-toggle { display: none; }
    .main-area { margin-left: 0 !important; }
    .mobile-menu-btn { display: block; }
    .content-area { padding: 16px; }
    .creative-canvas { grid-template-columns: 1fr; }
    .topbar { padding: 12px 16px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
