/* ─── Avenir ────────────────────────────────────────────────────────── */
@font-face {
    font-family: 'Avenir';
    src: url('/assets/fonts/Avenir-Book.ttf') format('truetype');
    font-weight: 300;
    font-style: normal;
}
@font-face {
    font-family: 'Avenir';
    src: url('/assets/fonts/Avenir-Roman.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
}
@font-face {
    font-family: 'Avenir';
    src: url('/assets/fonts/Avenir-Medium.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
}
@font-face {
    font-family: 'Avenir';
    src: url('/assets/fonts/Avenir-Heavy.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
}

/* ─── Reset & base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:        #1a1a1e;
    --surface:   #25252b;
    --surface2:  #2e2e36;
    --border:    #3a3a44;
    --accent:    #5b7fff;
    --accent-h:  #4a6cf0;
    --danger:    #e05050;
    --text:      #e8e8f0;
    --text-muted:#8888a0;
    --radius:    6px;
    --panel-w:   220px;
    --topbar-h:  48px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
    line-height: 1.4;
    height: 100vh;
    overflow: hidden;
}

/* ─── Utilities ────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ─── Buttons ──────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 5px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
    white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--border); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.active   { background: var(--accent); border-color: var(--accent); color: #fff; }

.btn-primary  { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-h); border-color: var(--accent-h); }

.btn-outline  { background: transparent; }
.btn-outline:hover:not(:disabled) { background: var(--surface2); }

.btn-danger   { background: transparent; border-color: transparent; color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(224,80,80,0.15); }

.btn-sm       { padding: 3px 8px; font-size: 11px; }
.btn-block    { width: 100%; }

.btn-group { display: flex; gap: 4px; }

/* ─── Top bar ──────────────────────────────────────────────────────── */
.topbar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    z-index: 100;
}
.ratio-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
}

.custom-size-inputs {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: 4px;
}
.custom-size-inputs input[type="number"] {
    width: 58px;
    text-align: center;
    padding: 3px 5px;
    font-size: 12px;
}
.custom-size-inputs span {
    color: var(--text-muted);
    font-size: 12px;
}
.custom-unit {
    font-size: 11px;
}

.topbar-brand {
    font-weight: 600;
    font-size: 15px;
    letter-spacing: 0.01em;
    color: var(--text);
    flex: 0 0 var(--panel-w);
}
.topbar-center { flex: 1; display: flex; justify-content: center; }
.topbar-right  { flex: 0 0 var(--panel-w); display: flex; justify-content: flex-end; }

/* ─── Editor layout ────────────────────────────────────────────────── */
.editor-page { background: var(--bg); }

.editor-layout {
    display: flex;
    height: calc(100vh - var(--topbar-h));
    margin-top: var(--topbar-h);
}

/* ─── Panels ───────────────────────────────────────────────────────── */
.panel {
    width: var(--panel-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}
.panel-right {
    border-right: none;
    border-left: 1px solid var(--border);
}

.panel-section {
    border-bottom: 1px solid var(--border);
    padding: 10px;
}

.panel-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.empty-state {
    color: var(--text-muted);
    font-size: 11px;
    text-align: center;
    padding: 12px 0;
}

/* ─── Shared grid item structure ────────────────────────────────────── */
.media-grid,
.logo-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

.media-item,
.logo-item {
    border-radius: 4px;
    border: 2px solid transparent;
    background: var(--surface2);
    overflow: hidden;
    transition: border-color 0.15s;
    display: flex;
    flex-direction: column;
}
.media-item:hover  { border-color: var(--border); }
.media-item.active { border-color: var(--accent); }
.logo-item:hover   { border-color: var(--border); }
.logo-item.active  { border-color: var(--accent); }

/* Thumbnail area — square, image fills it */
.item-thumb {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    cursor: pointer;
}
.media-item .item-thumb img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
}
.logo-item .item-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
}
.logo-item .item-thumb img {
    max-width: 100%; max-height: 100%;
    object-fit: contain;
    pointer-events: none;
}
.logo-item .item-thumb svg {
    max-width: 100%; max-height: 100%;
    display: block;
}

/* Name label below thumbnail */
.item-name {
    font-size: 10px;
    padding: 3px 5px 4px;
    color: var(--text-muted);
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    cursor: text;
    border-top: 1px solid var(--border);
    transition: color 0.1s;
}
.item-name:hover { color: var(--text); }

.item-name-input {
    width: 100%;
    font-size: 10px;
    padding: 3px 5px;
    background: var(--surface);
    border: none;
    border-top: 1px solid var(--accent);
    color: var(--text);
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
}

/* Delete button (media only) */
.media-delete {
    position: absolute;
    top: 2px; right: 2px;
    width: 18px; height: 18px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.65);
    color: #fff;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.item-thumb:hover .media-delete { display: flex; }

/* ─── Template list ─────────────────────────────────────────────────── */
.template-list { display: flex; flex-direction: column; gap: 3px; }

.template-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 4px;
    border-radius: 4px;
    background: var(--surface2);
}
.template-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    margin-right: 4px;
}
.template-actions { display: flex; gap: 3px; flex-shrink: 0; }

/* ─── Canvas area ───────────────────────────────────────────────────── */
.canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    background: var(--bg);
    overflow: auto;
    padding: 24px 16px 16px;
    gap: 12px;
}

.canvas-wrapper {
    box-shadow: 0 4px 32px rgba(0,0,0,0.5);
    border-radius: 2px;
    overflow: hidden;
    flex-shrink: 0;
}

.canvas-toolbar {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}
.toolbar-sep {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 2px;
}

/* ─── Property panel ────────────────────────────────────────────────── */
.props-empty {
    color: var(--text-muted);
    font-size: 11px;
    text-align: center;
    padding: 16px 0 8px;
    line-height: 1.6;
}

.props-group { display: flex; flex-direction: column; gap: 8px; }

.prop-row {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.prop-row label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
}
.prop-row-split {
    flex-direction: row;
    gap: 8px;
}
.prop-row-split > div {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    padding: 4px 7px;
    outline: none;
    transition: border-color 0.15s;
}
input:focus, select:focus { border-color: var(--accent); }

input[type="color"] {
    width: 100%;
    height: 28px;
    padding: 2px 3px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface2);
    cursor: pointer;
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    cursor: pointer;
}

/* Label + compact number input on one line, above a full-width slider */
.slider-row-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2px;
}
.slider-row-label label { margin-bottom: 0; }
.slider-row-label input[type="number"] {
    width: 64px;
    text-align: right;
}

input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }
.checkbox-label { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-muted); cursor: pointer; }

/* ─── Color field (swatch + hex input) ──────────────────────────────── */
.color-field {
    display: flex;
    align-items: center;
    gap: 4px;
}
.color-field input[type="color"] {
    width: 28px;
    flex-shrink: 0;
}
.color-field .color-hex {
    flex: 1;
    width: 0;
    font-family: 'Courier New', monospace;
    text-transform: uppercase;
    min-width: 0;
}

/* ─── Modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.modal h3 { font-size: 14px; font-weight: 600; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }

/* ─── Login page ────────────────────────────────────────────────────── */
.login-page {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}
.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 36px 32px;
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.login-logo {
    text-align: center;
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}
.login-error {
    color: var(--danger);
    font-size: 12px;
    text-align: center;
    margin-top: -8px;
}

/* ─── Scrollbar ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
