/* =====================================================
   AdBuilder — Design System & Global Styles
   Modern UI — Inter Font, Dark Shell, Light Canvas
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ── Design Tokens ────────────────────────────────── */
:root {
    --sidebar-w:   272px;
    --header-h:    52px;
    --canvas-w:    1374px;
    --canvas-h:    2090px;

    /* Shell (navbar + sidebar) */
    --shell-bg:        #13131A;
    --shell-border:    rgba(255,255,255,0.07);
    --shell-text:      #8B8BA7;
    --shell-text-hi:   #FFFFFF;

    /* App surfaces */
    --app-bg:          #F2F2F7;
    --surface:         #FFFFFF;
    --surface-2:       #F7F7FA;
    --border:          #E4E4EE;
    --border-strong:   #C8C8D8;

    /* Accent (indigo) */
    --accent:          #5B5BD6;
    --accent-hover:    #4747C2;
    --accent-subtle:   rgba(91,91,214,0.1);
    --accent-text:     #5B5BD6;

    /* Semantic */
    --danger:          #E5484D;
    --danger-hover:    #CC3338;
    --success:         #2DA44E;
    --warning:         #D97706;

    /* Text */
    --text-1:   #111118;
    --text-2:   #60607A;
    --text-3:   #9898B0;

    /* Elevation */
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-sm: 0 1px 4px rgba(0,0,0,0.07), 0 2px 8px rgba(0,0,0,0.05);
    --shadow:    0 4px 16px rgba(0,0,0,0.09), 0 1px 4px rgba(0,0,0,0.05);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.06);

    /* Shape */
    --r-sm:  6px;
    --r:     10px;
    --r-lg:  14px;
    --r-xl:  20px;
}

/* ── Reset / Base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--app-bg);
    color: var(--text-1);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    margin: 0;
}

/* ── Scrollbar ────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 99px; }

/* ── Navbar ───────────────────────────────────────── */
#app-nav {
    height: var(--header-h);
    background: var(--shell-bg);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    border-bottom: 1px solid var(--shell-border);
    flex-shrink: 0;
    position: relative;
    z-index: 200;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    text-decoration: none;
    flex-shrink: 0;
}
.nav-brand-icon {
    width: 28px;
    height: 28px;
    background: var(--accent);
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.5px;
    flex-shrink: 0;
}
.nav-brand-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--shell-text-hi);
    letter-spacing: -0.3px;
}

.nav-sep {
    color: rgba(255,255,255,0.2);
    font-size: 18px;
    font-weight: 300;
    line-height: 1;
    flex-shrink: 0;
}

.nav-crumb {
    font-size: 14px;
    font-weight: 500;
    color: var(--shell-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 280px;
}

.nav-spacer { flex: 1; }

.nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 13px;
    border-radius: var(--r-sm);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid var(--shell-border);
    background: rgba(255,255,255,0.06);
    color: var(--shell-text);
    cursor: pointer;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
.nav-btn:hover { background: rgba(255,255,255,0.1); color: var(--shell-text-hi); }
.nav-btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.nav-btn-primary:hover { background: var(--accent-hover); color: #fff; border-color: var(--accent-hover); }

/* ── Dashboard Page ───────────────────────────────── */
.page-wrap {
    max-width: 1200px;
    margin: 0 auto;
    padding: 36px 32px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-1);
    letter-spacing: -0.4px;
    margin: 0;
}

/* ── Project Cards ────────────────────────────────── */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.project-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 20px;
    cursor: pointer;
    transition: box-shadow .18s, transform .18s, border-color .18s;
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-decoration: none;
    color: inherit;
}
.project-card:hover {
    box-shadow: var(--shadow);
    border-color: var(--border-strong);
    transform: translateY(-2px);
}

.project-card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--r);
    background: var(--accent-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.project-card-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-1);
    letter-spacing: -0.2px;
    line-height: 1.3;
    margin: 0;
}

.project-card-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--text-3);
}

.project-card-meta-dot {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--border-strong);
}

.project-card-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.btn-card-primary {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 7px 12px;
    border-radius: var(--r-sm);
    font-size: 12.5px;
    font-weight: 500;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s;
}
.btn-card-primary:hover { background: var(--accent-hover); color: #fff; }

.btn-card-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 31px;
    height: 31px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-2);
    cursor: pointer;
    font-size: 13px;
    transition: background .15s, color .15s, border-color .15s;
}
.btn-card-icon:hover { background: var(--border); color: var(--text-1); }
.btn-card-icon.danger:hover { background: #FEE2E2; border-color: #FCA5A5; color: var(--danger); }

/* Empty state */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 72px 32px;
    color: var(--text-3);
}
.empty-state-icon {
    font-size: 40px;
    margin-bottom: 16px;
    opacity: .5;
}
.empty-state-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-2);
    margin-bottom: 6px;
}
.empty-state p { font-size: 13.5px; margin: 0; }

/* ── Editor Layout ────────────────────────────────── */
#editor-layout {
    display: flex;
    height: calc(100vh - var(--header-h));
    overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────── */
#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--shell-bg);
    border-right: 1px solid var(--shell-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid var(--shell-border);
}

.sidebar-label {
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--shell-text);
    margin-bottom: 10px;
}

.sidebar-project-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--shell-text-hi);
    letter-spacing: -0.2px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-project-meta {
    font-size: 12px;
    color: var(--shell-text);
}

/* Add-product column buttons */
.sidebar-col-btns {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.btn-add-product {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border-radius: var(--r-sm);
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--shell-border);
    color: var(--shell-text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, color .15s;
    text-align: left;
    width: 100%;
}
.btn-add-product:hover {
    background: rgba(91,91,214,0.18);
    border-color: rgba(91,91,214,0.35);
    color: #A5A5F5;
}
.btn-add-product .col-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 5px;
    background: rgba(255,255,255,0.08);
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
    color: var(--shell-text-hi);
}

.sidebar-hint {
    font-size: 12px;
    color: var(--shell-text);
    line-height: 1.6;
}
.sidebar-hint strong { color: rgba(255,255,255,0.5); font-weight: 500; }

/* ── Canvas Wrapper ───────────────────────────────── */
#canvas-wrapper {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 24px;
    background: #252531;
    background-image: radial-gradient(rgba(255,255,255,0.03) 1px, transparent 1px);
    background-size: 24px 24px;
    position: relative;
}

#canvas-scaler { transform-origin: top left; }

#canvas {
    width: var(--canvas-w);
    height: var(--canvas-h);
    display: flex;
    flex-direction: row;
    background: #fff;
    box-shadow: 0 8px 48px rgba(0,0,0,0.45), 0 2px 12px rgba(0,0,0,0.3);
    position: relative;
    overflow: hidden;
}

.canvas-column {
    flex: 1;
    height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #E0E0E0;
}
.canvas-column:last-child { border-right: none; }

.column-drop-zone {
    flex: 1;
    min-height: 100%;
    padding: 4px;
}

.column-label {
    font-size: 9px;
    color: #BBBBC8;
    text-align: center;
    padding: 5px 0;
    background: #FAFAFA;
    border-bottom: 1px solid #EBEBEB;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    user-select: none;
    font-family: 'Inter', sans-serif;
}

/* ── Buttons (global) ─────────────────────────────── */
.btn-primary-modern {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: var(--r-sm);
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background .15s, box-shadow .15s;
    font-family: inherit;
}
.btn-primary-modern:hover { background: var(--accent-hover); }

/* ── Modals ───────────────────────────────────────── */
.modal-content {
    border: none;
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-1);
    letter-spacing: -0.3px;
}

.modal-body {
    padding: 20px 24px;
    background: var(--surface);
}

.modal-footer {
    padding: 14px 24px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    gap: 8px;
}

/* Form fields */
.form-label {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-2);
    margin-bottom: 5px;
}

.form-control, .form-select {
    border-radius: var(--r-sm);
    border: 1px solid var(--border-strong);
    font-size: 13.5px;
    font-family: inherit;
    color: var(--text-1);
    padding: 8px 11px;
    transition: border-color .15s, box-shadow .15s;
    background: var(--surface);
}
.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
    outline: none;
}

.form-control-color {
    padding: 5px;
    height: 38px;
}

/* File input styling */
.file-upload-area {
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--r);
    padding: 14px;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
    position: relative;
}
.file-upload-area:hover {
    border-color: var(--accent);
    background: var(--accent-subtle);
}
.file-upload-area input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}
.file-upload-icon { font-size: 20px; margin-bottom: 4px; color: var(--text-3); }
.file-upload-text { font-size: 12px; color: var(--text-2); }
.file-upload-hint { font-size: 11px; color: var(--text-3); margin-top: 2px; }

/* Image preview */
.img-preview {
    max-height: 120px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    object-fit: contain;
    display: block;
    margin-top: 8px;
}

/* Section group inside modal */
.form-section {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 14px;
    margin-bottom: 4px;
}
.form-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-3);
    margin-bottom: 12px;
}

/* Modal buttons */
.btn-modal-cancel {
    padding: 8px 16px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text-2);
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s;
}
.btn-modal-cancel:hover { background: var(--app-bg); }

.btn-modal-submit {
    padding: 8px 20px;
    border-radius: var(--r-sm);
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background .15s;
}
.btn-modal-submit:hover { background: var(--accent-hover); }
.btn-modal-submit:disabled { opacity: .55; cursor: not-allowed; }

/* ── Toasts ───────────────────────────────────────── */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

/* ── Zoom bar ─────────────────────────────────────── */
#zoom-bar {
    backdrop-filter: blur(8px);
    background: rgba(20,20,30,0.72) !important;
    border: 1px solid rgba(255,255,255,0.1) !important;
    border-radius: var(--r) !important;
    color: #fff;
}
#zoom-bar button {
    color: rgba(255,255,255,0.85) !important;
    text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}
#zoom-bar button:hover {
    color: #fff !important;
    background: rgba(255,255,255,0.12) !important;
    border-radius: 4px;
}
#zoom-level {
    color: #fff !important;
    text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

/* ── Templates page ───────────────────────────────── */
.templates-table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
}
.templates-table thead th {
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-3);
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    white-space: nowrap;
}
.templates-table thead th:first-child { border-radius: var(--r-sm) 0 0 0; }
.templates-table thead th:last-child  { border-radius: 0 var(--r-sm) 0 0; }

.templates-table tbody tr {
    transition: background .1s;
}
.templates-table tbody tr:hover td { background: var(--surface-2); }
.templates-table tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    vertical-align: middle;
    font-size: 13.5px;
    color: var(--text-1);
}
.templates-table tbody td:first-child { border-left: 1px solid var(--border); }
.templates-table tbody td:last-child  { border-right: 1px solid var(--border); }
.templates-table tbody tr:last-child td { border-bottom: 1px solid var(--border); }
.templates-table tbody tr:last-child td:first-child { border-radius: 0 0 0 var(--r-sm); }
.templates-table tbody tr:last-child td:last-child  { border-radius: 0 0 var(--r-sm) 0; }

.table-wrap {
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    overflow: hidden;
    box-shadow: var(--shadow-xs);
}
.table-wrap .templates-table thead th:first-child,
.table-wrap .templates-table thead th:last-child { border-radius: 0; }

.template-thumb {
    width: 52px;
    height: 52px;
    object-fit: cover;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
}
.template-thumb-empty {
    width: 52px;
    height: 52px;
    border-radius: var(--r-sm);
    border: 1px dashed var(--border-strong);
    background: var(--surface-2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--text-3);
}

.tpl-title { font-weight: 600; color: var(--text-1); }
.tpl-subtitle { font-size: 12px; color: var(--text-3); margin-top: 1px; }

.color-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-2);
}
.color-chip-dot {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 1px solid rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.btn-tbl {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    font-size: 13px;
    color: var(--text-2);
    transition: background .13s, color .13s, border-color .13s;
}
.btn-tbl:hover { background: var(--surface-2); color: var(--text-1); }
.btn-tbl.danger:hover { background: #FEF2F2; border-color: #FECACA; color: var(--danger); }

/* ── Autocomplete list ────────────────────────────── */
#autocompleteList {
    border: 1px solid var(--border-strong);
    border-radius: var(--r);
    box-shadow: var(--shadow);
    overflow: hidden;
}
#autocompleteList .list-group-item {
    font-size: 13px;
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 9px 12px;
    color: var(--text-1);
}
#autocompleteList .list-group-item:last-child { border-bottom: none; }
#autocompleteList .list-group-item:hover { background: var(--accent-subtle); }

/* ── SortableJS ───────────────────────────────────── */
.sortable-ghost {
    opacity: .3;
    background: #D0CFFF !important;
    outline: 2px dashed var(--accent);
}
.sortable-chosen { box-shadow: 0 8px 24px rgba(0,0,0,.22); }
