/* ============================================================
   PixCut Studio — light "studio" theme (sidebar + workspace)
   ============================================================ */
:root {
  --bg: #f4f5f9;
  --bg-2: #ffffff;
  --bg-3: #eef0f6;
  --line: #e2e5ee;
  --text: #14172b;
  --muted: #6b7189;
  --accent: #4f46e5;
  --accent-2: #06b6d4;
  --accent-soft: #eef0ff;
  --ok: #16a34a;
  --err: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 23, 43, .05), 0 8px 24px -12px rgba(20, 23, 43, .15);
  --font: 'Inter', system-ui, sans-serif;
  color-scheme: light dark; /* native scrollbars and form controls follow the theme */
}
:root:not([data-theme="light"]) { }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --bg-2: #171a23; --bg-3: #1f2330; --line: #2a2f3d;
    --text: #eef0f6; --muted: #9096ad; --accent: #818cf8; --accent-2: #22d3ee; --accent-soft: #23264a;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1117; --bg-2: #171a23; --bg-3: #1f2330; --line: #2a2f3d;
  --text: #eef0f6; --muted: #9096ad; --accent: #818cf8; --accent-2: #22d3ee; --accent-soft: #23264a;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
html[dir="rtl"] body { font-family: 'Tajawal', var(--font); }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }
input[type="text"], input[type="number"], input[type="password"], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg-2); color: var(--text); font: inherit; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg-2) 85%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; }
.logo {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.top-actions { display: flex; gap: 10px; align-items: center; }
.lang-toggle, .admin-link {
  padding: 7px 12px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg-2);
  color: var(--text); font: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer; text-decoration: none;
}
.lang-toggle:hover, .admin-link:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 24px;
  max-width: 1400px; margin: 0 auto; padding: 24px 16px 64px;
}
@media (max-width: 960px) { .layout { grid-template-columns: 1fr; } .sidebar { position: static !important; } }

/* ---------- sidebar ---------- */
.sidebar {
  position: sticky; top: 76px; align-self: start;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: calc(100vh - 100px); overflow-y: auto;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
.side-head { padding: 18px 20px 12px; border-bottom: 1px solid var(--line); }
.side-head h2 { font-size: 16px; }
.side-head p { margin: 2px 0 0; font-size: 13px; }
.block { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.block:last-child { border-bottom: 0; }
.block h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 10px; }

.tpl-list { display: grid; gap: 8px; }
.tpl {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg-3); cursor: pointer; text-align: start; font: inherit; color: var(--text);
  transition: .15s;
}
.tpl:hover { border-color: var(--accent); }
.tpl.active { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.tpl .ic { font-size: 20px; }
.tpl .nm { font-weight: 600; font-size: 14px; }
.tpl .sz { font-size: 12px; color: var(--muted); }
.custom-size { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 8px; align-items: end; margin-top: 10px; }
.custom-size label { font-size: 11.5px; color: var(--muted); display: grid; gap: 4px; }
.custom-size input { padding: 8px 10px; }
.custom-size .x { padding-bottom: 8px; color: var(--muted); }
.size-readout { margin-top: 10px; font-size: 13px; color: var(--muted); }
.size-readout strong { color: var(--text); }

.anchor-row { display: flex; gap: 14px; align-items: center; }
.anchor-grid { display: grid; grid-template-columns: repeat(3, 26px); gap: 5px; padding: 6px; background: var(--bg-3); border-radius: 10px; flex-shrink: 0; }
.anchor-grid button { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg-2); cursor: pointer; transition: .12s; }
.anchor-grid button:hover { border-color: var(--accent); }
.anchor-grid button.active { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

.pills { display: flex; background: var(--bg-3); padding: 4px; border-radius: 10px; gap: 4px; }
.pills button { flex: 1; padding: 8px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.pills button.active { background: var(--bg-2); color: var(--accent); box-shadow: var(--shadow); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; cursor: pointer; }
.switch-row + .switch-row { border-top: 1px dashed var(--line); }
.switch-row b { display: block; font-size: 14px; font-weight: 600; }
.switch-row span { display: block; font-size: 12px; color: var(--muted); }
.switch-row input { display: none; }
.switch-row i { position: relative; flex-shrink: 0; width: 40px; height: 22px; border-radius: 99px; background: var(--line); transition: .2s; }
.switch-row i::after { content: ''; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch-row input:checked + i { background: var(--accent); }
.switch-row input:checked + i::after { transform: translateX(18px); }
html[dir="rtl"] .switch-row input:checked + i::after { transform: translateX(-18px); }

.field { display: grid; gap: 5px; margin-bottom: 10px; }
.field > span { font-size: 12.5px; font-weight: 500; color: var(--muted); }

/* ---------- workspace ---------- */
/* align-content: start — the column is as tall as the sticky sidebar; without it the grid
   stretches the hero and dropzone rows to fill that height, leaving a big gap between them. */
.workspace { display: grid; gap: 20px; min-width: 0; align-content: start; }
.hero { padding: 8px 4px 0; }
.badge {
  display: inline-block; padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent); margin-bottom: 10px;
}
.hero h1 { font-size: clamp(26px, 4vw, 38px); font-weight: 800; }
.hero p { margin: 6px 0 0; max-width: 640px; }

.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 44px 20px; text-align: center;
  background: var(--bg-2); cursor: pointer; transition: .18s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dz-art { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 18px; display: grid; place-items: center; font-size: 28px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 10px 24px -8px color-mix(in srgb, var(--accent) 60%, transparent); }
.dropzone h3 { font-size: 18px; }
.dropzone p { margin: 4px 0 12px; }
.fmt-chips { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; }
.fmt-chips span { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--bg-3); color: var(--muted); }

.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h3 { font-size: 15px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card-foot { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; padding: 14px 18px; border-top: 1px solid var(--line); }
.count { display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 8px; border-radius: 99px; background: var(--accent); color: #fff; font-size: 12px; margin-inline-start: 6px; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 11px 18px; border-radius: 10px; border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; transition: .15s; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--accent) 70%, transparent); }
.btn-primary:not(:disabled):hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn-soft { background: var(--bg-3); color: var(--text); border-color: var(--line); }
.btn-soft:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: color-mix(in srgb, var(--err) 12%, transparent); color: var(--err); }

/* thumbs */
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; padding: 18px; }
.thumb { position: relative; border: 2px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg-3); transition: .15s; }
.thumb.selected { border-color: var(--accent); }
.thumb .img { position: relative; aspect-ratio: 1; display: grid; place-items: center; overflow: hidden; background: repeating-conic-gradient(var(--bg-3) 0 25%, var(--bg-2) 0 50%) 0 0/16px 16px; cursor: pointer; }
.thumb .img img { max-width: 100%; max-height: 100%; object-fit: contain; transition: transform .25s; }
.thumb .check { position: absolute; top: 8px; inset-inline-start: 8px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.35); display: grid; place-items: center; color: #fff; font-size: 13px; }
.thumb.selected .check { background: var(--accent); border-color: var(--accent); }
.thumb .rot { position: absolute; top: 8px; inset-inline-end: 8px; display: flex; gap: 4px; opacity: 0; transition: .15s; }
.thumb:hover .rot { opacity: 1; }
.thumb .rot button { width: 26px; height: 26px; border-radius: 7px; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 14px; }
.thumb .meta { padding: 8px; display: grid; gap: 6px; }
.thumb .nm { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb .meta input { padding: 7px 9px; font-size: 12.5px; }
.thumb .ai-busy { position: absolute; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 600; }

/* results */
.res-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; padding: 18px; }
.res { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg-3); }
.res .img { position: relative; aspect-ratio: 4/5; display: grid; place-items: center; overflow: hidden; background: var(--bg-3); }
.res .img img { width: 100%; height: 100%; object-fit: cover; }
.res .chips { position: absolute; top: 8px; inset-inline-start: 8px; display: flex; gap: 4px; }
.res .chips span { font-size: 10.5px; font-weight: 700; padding: 3px 7px; border-radius: 6px; background: rgba(0,0,0,.6); color: #fff; }
.res .chips span.grad { background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.res .chips span.ai { background: #16a34a; }
.res .info { padding: 10px; display: grid; gap: 6px; }
.res .fn { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.res .sz { font-size: 11.5px; color: var(--muted); }
.res .btn { justify-content: center; }

/* overlay / modal */
.overlay, .modal { position: fixed; inset: 0; z-index: 50; display: none; place-items: center; background: rgba(10, 12, 24, .55); backdrop-filter: blur(6px); }
.overlay.show, .modal.show { display: grid; }
.progress-box { background: var(--bg-2); border-radius: 16px; padding: 28px 32px; min-width: 300px; text-align: center; box-shadow: var(--shadow); }
.spinner { width: 42px; height: 42px; margin: 0 auto 14px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 6px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 12px; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }
.modal-card { width: min(1100px, 94vw); max-height: 90vh; overflow: auto; background: var(--bg-2); border-radius: 16px; box-shadow: var(--shadow); }
.prev-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; padding: 18px; }
.prev-grid .p { text-align: center; }
.prev-grid img { width: 100%; border-radius: 10px; border: 1px solid var(--line); }
.prev-grid .t { font-size: 12.5px; font-weight: 600; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prev-grid .i { font-size: 11.5px; color: var(--muted); }

/* toasts */
.toasts { position: fixed; bottom: 20px; inset-inline-end: 20px; z-index: 60; display: grid; gap: 8px; }
.toast { padding: 12px 16px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 13.5px; border-inline-start: 4px solid var(--err); animation: pop .2s; max-width: 360px; }
.toast.ok { border-inline-start-color: var(--ok); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
