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

:root {
  --purple:     #7c3aed;
  --purple-bg:  #ede9fe;
  --green:      #16a34a;
  --green-bg:   #dcfce7;
  --blue:       #2563eb;
  --blue-bg:    #dbeafe;
  --amber:      #d97706;
  --amber-bg:   #fef3c7;
  --red:        #dc2626;
  --red-bg:     #fee2e2;
  --grey-50:    #f8fafc;
  --grey-100:   #f1f5f9;
  --grey-200:   #e2e8f0;
  --grey-300:   #cbd5e1;
  --grey-400:   #94a3b8;
  --grey-500:   #64748b;
  --grey-600:   #475569;
  --grey-700:   #334155;
  --grey-800:   #1e293b;
  --grey-900:   #0f172a;
  --radius:     8px;
  --radius-lg:  12px;
  --shadow:     0 1px 3px rgba(0,0,0,.1);
  --shadow-md:  0 4px 12px rgba(0,0,0,.12);
  --sidebar-w:  220px;
  --sidebar-bg: #0f172a;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--grey-800); background: var(--grey-50); min-height: 100vh; }

/* ── Layout ── */
#app-shell { display: flex; min-height: 100vh; }
#sidebar { width: var(--sidebar-w); background: var(--sidebar-bg); position: fixed; top: 0; left: 0; bottom: 0; display: flex; flex-direction: column; z-index: 100; }
#main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ── Sidebar ── */
.sidebar-header { padding: 1.25rem 1rem 1rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-logo { display: flex; align-items: center; gap: .65rem; text-decoration: none; }
.logo-icon { font-size: 1.5rem; }
.logo-text { font-size: .95rem; font-weight: 700; color: white; }
.logo-sub  { font-size: .7rem; color: rgba(255,255,255,.4); }
.sidebar-nav { flex: 1; padding: .75rem 0; overflow-y: auto; }
.nav-link { display: flex; align-items: center; gap: .6rem; padding: .55rem 1rem; color: rgba(255,255,255,.6); text-decoration: none; font-size: .85rem; font-weight: 500; transition: all .15s; }
.nav-link:hover { background: rgba(255,255,255,.06); color: white; }
.nav-link.active { background: rgba(255,255,255,.1); color: white; font-weight: 600; }
.nav-icon { font-size: 1rem; width: 18px; text-align: center; }
.sidebar-footer { padding: .75rem 0; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-credits { margin: 0 .75rem .5rem; padding: .5rem .75rem; border-radius: var(--radius); background: rgba(255,255,255,.06); }
.sidebar-credits .cr-label { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: rgba(255,255,255,.35); margin-bottom: .15rem; }
.sidebar-credits .cr-value { font-size: .9rem; font-weight: 700; color: white; }
.sidebar-credits .cr-value.low { color: #f87171; }
.sidebar-credits .cr-value.medium { color: #fbbf24; }

/* ── Page ── */
.page-header { background: white; border-bottom: 1px solid var(--grey-200); padding: 1.2rem 1.5rem; display: flex; align-items: center; justify-content: space-between; gap: .75rem; position: sticky; top: 0; z-index: 10; }
.page-header h1 { font-size: 1.15rem; font-weight: 700; }
.page-header p  { font-size: .82rem; color: var(--grey-500); margin-top: .1rem; }
.page-body { padding: 1.5rem; }

/* ── Cards ── */
.card { background: white; border-radius: var(--radius-lg); border: 1.5px solid var(--grey-200); padding: 1.25rem; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1rem; border-radius: var(--radius); font-size: .85rem; font-weight: 600; border: 1.5px solid transparent; cursor: pointer; text-decoration: none; transition: all .15s; white-space: nowrap; font-family: inherit; }
.btn-primary   { background: var(--purple); color: white; border-color: var(--purple); }
.btn-primary:hover { background: #6d28d9; }
.btn-secondary { background: white; color: var(--grey-700); border-color: var(--grey-200); }
.btn-secondary:hover { background: var(--grey-50); border-color: var(--grey-400); }
.btn-danger    { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: var(--red); color: white; }
.btn-ghost     { background: transparent; color: var(--grey-500); border-color: transparent; }
.btn-ghost:hover { background: var(--grey-100); color: var(--grey-700); }
.btn-sm { padding: .28rem .6rem; font-size: .78rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.spinner { width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.35); border-top-color: white; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Forms ── */
.field { display: flex; flex-direction: column; gap: .3rem; }
.field label { font-size: .78rem; font-weight: 700; color: var(--grey-600); }
input, select, textarea {
  padding: .5rem .75rem;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius);
  font-size: .9rem;
  font-family: inherit;
  outline: none;
  background: white;
  transition: border-color .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--purple); }
textarea { resize: vertical; min-height: 90px; }

/* ── Toggle ── */
.toggle-wrap { display: flex; align-items: center; gap: .6rem; cursor: pointer; user-select: none; }
.toggle-wrap label { cursor: pointer; font-size: .85rem; font-weight: 600; color: var(--grey-700); }
.toggle { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track { position: absolute; inset: 0; background: #e53e3e; border-radius: 999px; transition: background .2s; }
.toggle input:checked + .toggle-track { background: #38a169; }
.toggle-thumb { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: white; border-radius: 50%; transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle input:checked ~ .toggle-thumb { left: 21px; }

/* ── Aspect ratio pills ── */
.aspect-pills { display: flex; flex-wrap: wrap; gap: .4rem; }
.aspect-pill { padding: .3rem .65rem; border-radius: var(--radius); border: 1.5px solid var(--grey-200); background: white; font-size: .78rem; font-weight: 600; color: var(--grey-600); cursor: pointer; transition: all .15s; white-space: nowrap; }
.aspect-pill:hover { border-color: var(--purple); color: var(--purple); }
.aspect-pill.selected { border-color: var(--purple); background: var(--purple-bg); color: var(--purple); }

/* ── Model select card ── */
.model-select { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .5rem; }
.model-card { padding: .6rem .9rem; border-radius: var(--radius); border: 1.5px solid var(--grey-200); background: white; cursor: pointer; transition: all .15s; }
.model-card:hover { border-color: var(--purple); }
.model-card.selected { border-color: var(--purple); background: var(--purple-bg); }
.model-card .mc-group { font-size: .65rem; font-weight: 700; color: var(--grey-400); text-transform: uppercase; letter-spacing: .06em; }
.model-card .mc-name  { font-size: .82rem; font-weight: 700; color: var(--grey-800); margin-top: .1rem; }
.model-card.selected .mc-name { color: var(--purple); }
.mc-credits { font-size: .65rem; font-weight: 700; color: var(--amber); margin-top: .15rem; }
.mc-tags { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .35rem; align-items: center; }
.mc-tag { font-size: .6rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: .1rem .4rem; border-radius: 999px; background: var(--purple-bg); color: var(--purple); }
.mc-tag-btn { font-size: .7rem; width: 18px; height: 18px; border-radius: 50%; border: 1.5px dashed var(--grey-300); background: none; color: var(--grey-400); cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; flex-shrink: 0; transition: all .15s; }
.mc-tag-btn:hover { border-color: var(--purple); color: var(--purple); }

/* ── Tag filter bar ── */
.tag-filter-bar { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .75rem; align-items: center; }
.tag-filter-btn { font-size: .72rem; font-weight: 600; padding: .25rem .7rem; border-radius: 999px; border: 1.5px solid var(--grey-200); background: white; color: var(--grey-600); cursor: pointer; transition: all .15s; }
.tag-filter-btn:hover { border-color: var(--purple); color: var(--purple); }
.tag-filter-btn.active { border-color: var(--purple); background: var(--purple-bg); color: var(--purple); }

/* ── Tag chips (modal) ── */
.tag-chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .72rem; font-weight: 600; padding: .2rem .55rem; border-radius: 999px; background: var(--purple-bg); color: var(--purple); }
.tag-chip.removable { cursor: pointer; }
.tag-chip.removable:hover { background: #fed7d7; color: var(--red); }
.tag-chip.removable::after { content: '×'; font-size: .85rem; line-height: 1; }
.tag-chip.suggest { background: var(--grey-100); color: var(--grey-600); cursor: pointer; }
.tag-chip.suggest:hover { background: var(--purple-bg); color: var(--purple); }

/* ── Image grid ── */
.image-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
.img-card { background: white; border-radius: var(--radius-lg); border: 1.5px solid var(--grey-200); overflow: hidden; position: relative; }
.img-card .img-thumb { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; cursor: pointer; background: var(--grey-100); }
.img-card .img-thumb.pending { display: flex; align-items: center; justify-content: center; }
.img-card .img-meta { padding: .6rem .75rem; }
.img-card .img-model { font-size: .7rem; font-weight: 700; color: var(--purple); text-transform: uppercase; letter-spacing: .05em; }
.img-card .img-prompt { font-size: .78rem; color: var(--grey-600); margin-top: .15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.img-card .img-date { font-size: .7rem; color: var(--grey-400); margin-top: .1rem; }
.img-card .img-actions { display: flex; gap: .3rem; padding: 0 .6rem .6rem; }
.img-card .img-status { padding: .5rem .75rem; font-size: .75rem; font-weight: 600; }
.img-card .img-status.generating { color: var(--amber); }
.img-card .img-status.failed { color: var(--red); }

/* ── Pending card ── */
.img-pending-box { display: flex; flex-direction: column; align-items: center; justify-content: center; aspect-ratio: 1; background: var(--grey-50); gap: .5rem; }
.img-pending-box .spinner { border: 2px solid var(--grey-200); border-top-color: var(--purple); width: 24px; height: 24px; }

/* ── Generation form ── */
.gen-form { display: flex; flex-direction: column; gap: 1.25rem; max-width: 720px; }
.gen-section-label { font-size: .72rem; font-weight: 700; color: var(--grey-500); text-transform: uppercase; letter-spacing: .08em; margin-bottom: .4rem; }

/* ── Folder tabs ── */
.folder-tabs { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1.25rem; align-items: center; }
.folder-tab { padding: .35rem .85rem; border-radius: 999px; border: 1.5px solid var(--grey-200); background: white; font-size: .82rem; font-weight: 600; color: var(--grey-600); cursor: pointer; transition: all .15s; white-space: nowrap; }
.folder-tab:hover { border-color: var(--purple); color: var(--purple); }
.folder-tab.active { background: var(--purple); border-color: var(--purple); color: white; }
.folder-tab.del-tab { color: var(--red); border-color: transparent; background: transparent; font-size: .72rem; padding: .2rem .4rem; }
.folder-tab.del-tab:hover { background: var(--red-bg); }

/* ── Lightbox ── */
#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 500; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#lightbox.hidden { display: none; }
#lightbox-toolbar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: center; gap: .5rem; padding: .75rem 1rem; background: rgba(0,0,0,.5); z-index: 1; }
#lightbox-toolbar button, #lightbox-toolbar a { background: rgba(255,255,255,.15); border: none; color: white; font-size: 1.1rem; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; text-decoration: none; transition: background .15s; flex-shrink: 0; }
#lightbox-toolbar button:hover, #lightbox-toolbar a:hover { background: rgba(255,255,255,.3); }
#lb-zoom-reset { width: auto !important; padding: 0 .75rem; font-size: .8rem; font-weight: 600; border-radius: 999px !important; min-width: 56px; }
#lightbox-img-wrap { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; padding-top: 56px; box-sizing: border-box; cursor: grab; }
#lightbox-img-wrap.dragging { cursor: grabbing; }
#lightbox-img { display: block; transform-origin: center center; transition: transform .15s; max-width: 100%; max-height: 100%; object-fit: contain; border-radius: var(--radius); user-select: none; -webkit-user-drag: none; }

/* ── Modal ── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-backdrop.hidden { display: none; }
.modal { background: white; border-radius: var(--radius-lg); padding: 1.5rem; width: 100%; max-width: 440px; box-shadow: var(--shadow-md); }
.modal h2 { font-size: 1rem; font-weight: 700; margin-bottom: 1.25rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }

/* ── Toast ── */
#toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 999; display: flex; flex-direction: column; gap: .5rem; }
.toast { background: var(--grey-900); color: white; padding: .65rem 1rem; border-radius: var(--radius); font-size: .85rem; font-weight: 500; animation: slideIn .2s ease; max-width: 300px; }
.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Login ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--grey-50); padding: 1rem; }
.login-card { background: white; border-radius: var(--radius-lg); border: 1.5px solid var(--grey-200); padding: 2rem; width: 100%; max-width: 360px; }
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo .icon { font-size: 2.5rem; }
.login-logo h1 { font-size: 1.3rem; font-weight: 800; margin-top: .4rem; }
.login-logo p  { font-size: .8rem; color: var(--grey-400); }
.login-error { color: var(--red); font-size: .82rem; margin-top: .75rem; text-align: center; }

/* ── Mobile hamburger ── */
#mobile-menu-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border: 1.5px solid var(--grey-200);
  border-radius: var(--radius);
  background: white;
  cursor: pointer;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 99; }
.sidebar-overlay.open { display: block; }

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  #sidebar { display: flex; width: 75vw; max-width: 260px; transform: translateX(-100%); transition: transform .25s ease; z-index: 100; }
  #sidebar.open { transform: translateX(0); }
  #main { margin-left: 0; }
  .page-body { padding: 1rem; }
  #mobile-menu-btn { display: flex; }
  .page-header { gap: .75rem; }
  .image-grid { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
  .model-select { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 420px) {
  .image-grid { grid-template-columns: 1fr 1fr; gap: .5rem; }
}
