:root {
    --blue: #1677d2;
    --blue-dark: #0b4f91;
    --ink: #172b42;
    --muted: #65758b;
    --line: #dbe6f0;
    --surface: #ffffff;
    --soft-blue: #eef6ff;
}

* { box-sizing: border-box; }

body {
    min-height: 100vh;
    margin: 0;
    padding: 28px;
    color: var(--ink);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: #f3f7fb;
    background-image: radial-gradient(circle at 10% 0%, rgba(22, 119, 210, .11), transparent 32rem);
}

.container {
    width: min(1180px, 100%);
    margin: 0 auto;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid rgba(219, 230, 240, .9);
    border-radius: 18px;
    box-shadow: 0 18px 50px rgba(27, 59, 91, .12);
}

.site-header {
    position: relative;
    display: flex;
    min-height: 108px;
    align-items: center;
    justify-content: center;
    padding: 22px 92px;
    background: linear-gradient(135deg, #fafdff 0%, #edf6ff 100%);
    border-bottom: 1px solid var(--line);
}

.site-header h1 {
    margin: 0;
    color: var(--blue-dark);
    font-size: clamp(1.45rem, 3vw, 2.15rem);
    font-weight: 750;
    letter-spacing: -.035em;
    text-align: center;
}

.site-logo {
    position: absolute;
    left: 24px;
    top: 50%;
    width: 120px;
    height: 90px;
    object-fit: contain;
    transform: translateY(-50%);
    border-radius: 14px;
    filter: drop-shadow(0 5px 8px rgba(22, 77, 130, .18));
}

#tab-bar {
    display: flex;
    gap: 8px;
    padding: 16px 24px 0;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
}

.tab {
    flex: 0 0 auto;
    padding: 11px 16px 13px;
    color: var(--muted);
    background: transparent;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    user-select: none;
    transition: color .2s, border-color .2s, background .2s;
}

.tab:hover { color: var(--blue); background: var(--soft-blue); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }

.workspace {
    display: grid;
    grid-template-columns: minmax(290px, 360px) minmax(0, 1fr);
    gap: 28px;
    padding: 26px;
}

.control-panel { display: flex; flex-direction: column; gap: 18px; }
.control-panel > div { min-width: 0; }

label {
    display: block;
    margin-bottom: 7px;
    color: var(--ink);
    font-size: 12px;
    font-weight: 750;
}

select, input[type="text"], input[type="password"], textarea {
    width: 100%;
    padding: 10px 11px;
    color: var(--ink);
    background: #fbfdff;
    border: 1px solid #cbd9e7;
    border-radius: 8px;
    outline: none;
    font: inherit;
    font-size: 13px;
    transition: border-color .2s, box-shadow .2s;
}

select:focus, input:focus, textarea:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(22, 119, 210, .12);
}

textarea { min-height: 140px; resize: vertical; }

.api-key-container {
    padding: 14px;
    background: var(--soft-blue);
    border: 1px solid #cfe3f8;
    border-radius: 12px;
}

.api-row { display: flex; gap: 8px; }
.api-row input { min-width: 0; }
.model-field { margin-top: 12px; }
.prompt-heading { display: flex; align-items: center; gap: 8px; }
.prompt-heading label { margin: 0; }

button {
    border: 0;
    font: inherit;
    font-weight: 700;
}

button.action-btn {
    padding: 9px 12px;
    color: #fff;
    background: var(--blue);
    border-radius: 8px;
    cursor: pointer;
    transition: background .2s, transform .2s, box-shadow .2s;
}

button.action-btn:hover { background: var(--blue-dark); box-shadow: 0 5px 12px rgba(11, 79, 145, .2); }
button.action-btn:active { transform: translateY(1px); }

#getApiKeyBtn { white-space: nowrap; }

#template_list {
    display: flex;
    width: 100%;
    height: 240px;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    padding: 4px 6px 4px 0;
}

#controls_row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
#system_notice { display: none; margin-top: 0; }
#controls_row .action-btn { flex: 1 1 auto; }

.preview-panel {
    display: flex;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 620px;
    padding: 24px;
    background: #f8fbfe;
    border: 1px solid var(--line);
    border-radius: 16px;
}

.preview-heading { width: 100%; margin-bottom: 16px; text-align: center; }
.eyebrow { color: var(--blue); font-size: 11px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.preview-heading h2 { margin: 4px 0 0; color: var(--ink); font-size: 1.2rem; }

#img-container {
    display: flex;
    width: min(420px, 100%);
    height: min(620px, 68vh);
    min-height: 380px;
    position: relative;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #fff;
    border: 2px dashed #a9c8e6;
    border-radius: 12px;
    box-shadow: 0 10px 28px rgba(35, 76, 112, .08);
}

#img-preview { display: none; max-width: 100%; max-height: 100%; object-fit: contain; }
.loading-text { display: none; position: absolute; z-index: 20; padding: 10px 14px; color: var(--ink); background: rgba(255, 255, 255, .94); border-radius: 8px; box-shadow: 0 5px 16px rgba(24, 57, 88, .12); font-size: 14px; }

footer { padding: 16px 24px 20px; color: var(--muted); border-top: 1px solid var(--line); font-size: 12px; text-align: center; }
select:disabled { opacity: .55; cursor: not-allowed; }

@media (max-width: 800px) {
    body { padding: 12px; }
    .workspace { grid-template-columns: 1fr; padding: 18px; }
    .preview-panel { min-height: auto; }
    #img-container { height: 68vh; }
}

@media (max-width: 480px) {
    .site-header { min-height: 92px; padding: 18px 64px; }
    .site-logo { left: 14px; width: 46px; height: 46px; border-radius: 10px; }
    .site-header h1 { font-size: 1.25rem; }
    #tab-bar { padding-left: 14px; padding-right: 14px; }
    .workspace { padding: 14px; }
    .api-row { flex-direction: column; }
    .preview-panel { padding: 14px; }
    #img-container { min-height: 300px; }
}
