/* ── Reset & Variables ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f1f5f9; --surface: #ffffff; --border: #dee2e6;
  --accent: #16a34a; --blue: #0369a1; --text: #0f172a; --muted: #6b7280;
  --error: #dc2626; --radius: 14px; --shadow: 0 1px 4px rgba(0,0,0,.08);
}
body { background: var(--bg); color: var(--text); font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; min-height: 100vh; display: flex; flex-direction: column; }

/* Header */
.header { background: #fff; border-bottom: 1px solid var(--border); padding: 10px 20px; display: flex; align-items: center; justify-content: space-between; box-shadow: var(--shadow); position: sticky; top: 0; z-index: 100; }
.header-left { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 1.6rem; }
.app-name { font-size: 1.1rem; font-weight: 700; }
.user-info { font-size: 0.8rem; color: var(--muted); margin-right: 8px; }

/* Layout */
.main-layout { display: grid; grid-template-columns: 420px 1fr; flex: 1; height: calc(100vh - 53px); overflow: hidden; }
.left-panel { overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; border-right: 1px solid var(--border); }
.right-panel { overflow-y: auto; padding: 16px; background: #f8fafc; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.card-title { font-size: 0.88rem; font-weight: 700; margin-bottom: 10px; }
.card-desc { font-size: 0.77rem; color: var(--muted); margin-bottom: 10px; line-height: 1.5; }

/* Form */
.form-grid { display: grid; grid-template-columns: 150px 1fr; gap: 8px 10px; align-items: center; }
.form-grid label { font-size: 0.82rem; font-weight: 600; }
.field-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.field-row > label { font-size: 0.8rem; font-weight: 600; }
.input-btn-row { display: flex; gap: 6px; align-items: center; }
.input-btn-row input[type="text"] { flex: 1; min-width: 0; }
.input-note { font-size: 0.77rem; color: var(--muted); }

input[type="text"], input[type="number"], textarea, select {
  background: #fff; border: 1px solid #d0d7e2; border-radius: 10px;
  color: var(--text); padding: 8px 11px; font-size: 0.84rem; outline: none;
  transition: border-color .2s; width: 100%; font-family: inherit;
}
input:focus, textarea:focus, select:focus { border-color: var(--blue); }
textarea { resize: vertical; }

/* Radio */
.radio-group { display: flex; flex-direction: column; gap: 6px; }
.radio-label { display: flex; align-items: center; gap: 8px; font-size: 0.84rem; cursor: pointer; padding: 6px 8px; border-radius: 8px; }
.radio-label:hover { background: #f1f5f9; }
.radio-label input[type="radio"] { accent-color: var(--accent); width: 15px; height: 15px; }

/* Buttons */
.btn { cursor: pointer; border: none; border-radius: 10px; font-weight: 600; font-size: 0.82rem; padding: 8px 13px; transition: opacity .2s, transform .1s; white-space: nowrap; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-blue { background: #e0f2fe; color: var(--blue); border: 1px solid #7dd3fc; }
.btn-blue:hover:not(:disabled) { background: #bae6fd; }
.btn-green { background: #dcfce7; color: var(--accent); border: 1px solid #86efac; }
.btn-green:hover:not(:disabled) { background: #bbf7d0; }
.btn-red { background: #fee2e2; color: var(--error); border: 1px solid #fca5a5; }
.btn-outline { background: transparent; border: 1px solid var(--border); }
.btn-outline:hover { background: #f1f5f9; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); font-size: 0.77rem; padding: 5px 10px; }
.btn-ghost:hover { background: #f1f5f9; }

/* Action buttons */
.action-buttons { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.btn-run  { background: #16a34a; color: #fff; font-size: 0.88rem; padding: 12px; border-radius: 12px; }
.btn-run:hover:not(:disabled)  { background: #15803d; }
.btn-pause{ background: #eab308; color: #fff; font-size: 0.88rem; padding: 12px; border-radius: 12px; }
.btn-pause:hover:not(:disabled){ background: #ca8a04; }
.btn-stop { background: #dc2626; color: #fff; font-size: 0.88rem; padding: 12px; border-radius: 12px; }
.btn-stop:hover:not(:disabled) { background: #b91c1c; }

/* Progress */
.progress-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 0.84rem; font-weight: 600; }
.progress-bar-bg { background: #e2e8f0; border-radius: 99px; height: 8px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: linear-gradient(90deg,#16a34a,#22c55e); border-radius: 99px; transition: width .4s; width: 0%; }
.progress-text { font-size: 0.77rem; color: var(--muted); margin-top: 4px; }

/* Badge */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 0.71rem; font-weight: 700; }
.badge-pending { background: #fef9c3; color: #854d0e; }
.badge-running { background: #dbeafe; color: #1d4ed8; }
.badge-done    { background: #dcfce7; color: #15803d; }
.badge-error   { background: #fee2e2; color: #dc2626; }

/* Tables */
.batch-table, .cookie-table { width: 100%; border-collapse: collapse; font-size: 0.79rem; margin-top: 8px; }
.batch-table th, .cookie-table th { background: #f8fafc; padding: 6px 8px; text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); }
.batch-table td, .cookie-table td { padding: 6px 8px; border-bottom: 1px solid #f1f5f9; }
.batch-table tr:hover td { background: #f8fafc; cursor: pointer; }
.batch-table tr.active-row td { background: #eff6ff; }

/* Ref preview */
.ref-preview { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ref-preview img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }

/* Results */
.results-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.results-header h2 { font-size: 0.95rem; font-weight: 700; }
.results-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px,1fr)); gap: 12px; }
.empty-state { grid-column: 1/-1; text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-icon { font-size: 2.8rem; margin-bottom: 10px; }

/* Image card */
.img-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow); transition: transform .15s; }
.img-card:hover { transform: translateY(-2px); }
.img-card img { width: 100%; aspect-ratio: 16/9; object-fit: cover; display: block; background: #f1f5f9; }
.img-card-body { padding: 7px 10px; }
.img-card-prompt { font-size: 0.74rem; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.img-card-error { font-size: 0.74rem; color: var(--error); padding: 7px 10px; }
.img-card-actions { padding: 6px 10px; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.img-card-actions a { font-size: 0.74rem; color: var(--blue); text-decoration: none; font-weight: 600; }
.img-card-actions a:hover { text-decoration: underline; }

/* Error */
.error-msg { background: #fee2e2; border: 1px solid #fca5a5; border-radius: 10px; padding: 10px 14px; color: var(--error); font-size: 0.82rem; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal { background: #fff; border-radius: var(--radius); width: 680px; max-width: 95vw; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal-header { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-size: 0.95rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: #f1f5f9; }
.modal-body { padding: 14px 18px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 10px; }
.modal-footer { padding: 10px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }
.cookie-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.cookie-help { background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px; padding: 10px 12px; font-size: 0.77rem; color: #1e40af; line-height: 1.6; }
.cookie-help a { color: #1d4ed8; }
.status-ok  { color: #16a34a; font-weight: 600; }
.status-err { color: #dc2626; font-weight: 600; }
.status-pending { color: #6b7280; }

@media (max-width: 768px) {
  .main-layout { grid-template-columns: 1fr; height: auto; }
  .left-panel, .right-panel { height: auto; }
}

/* ── Login Screen ──────────────────────────────────────────────────────────── */
.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #f0fdf4 0%, #ecfeff 50%, #eff6ff 100%); }
.login-card { background: #fff; border-radius: 20px; padding: 40px 36px; width: 380px; max-width: 95vw; box-shadow: 0 8px 40px rgba(0,0,0,.1); text-align: center; }
.login-logo { font-size: 3rem; margin-bottom: 8px; }
.login-card h2 { font-size: 1.4rem; font-weight: 800; margin-bottom: 4px; }
.login-subtitle { color: var(--muted); font-size: 0.84rem; margin-bottom: 20px; }
.login-tabs { display: flex; gap: 0; margin-bottom: 20px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.login-tab { flex: 1; padding: 9px; border: none; background: #f8fafc; cursor: pointer; font-weight: 600; font-size: 0.84rem; transition: background .2s, color .2s; }
.login-tab.active { background: var(--accent); color: #fff; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card input { padding: 11px 14px; border-radius: 10px; border: 1px solid #d0d7e2; font-size: 0.88rem; }
.login-btn { padding: 12px; font-size: 0.92rem; border-radius: 12px; background: var(--accent); color: #fff; border: none; cursor: pointer; font-weight: 700; }
.login-btn:hover { background: #15803d; }
.auth-error { background: #fee2e2; color: var(--error); padding: 8px 12px; border-radius: 8px; font-size: 0.82rem; text-align: left; }

/* ── Header Nav ────────────────────────────────────────────────────────────── */
.header-nav { display: flex; gap: 4px; }
.nav-btn { background: none; border: none; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 0.82rem; font-weight: 600; color: var(--muted); transition: background .2s, color .2s; }
.nav-btn:hover { background: #f1f5f9; }
.nav-btn.active { background: #dcfce7; color: var(--accent); }

/* ── Tab Content ───────────────────────────────────────────────────────────── */
.tab-content { flex: 1; }

/* ── History / Admin Container ─────────────────────────────────────────────── */
.history-container, .admin-container { max-width: 1200px; margin: 0 auto; padding: 20px; }
.history-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.history-header h2 { font-size: 1rem; font-weight: 700; }
.admin-container h2 { font-size: 1rem; font-weight: 700; }
.admin-container select { padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border); font-size: 0.78rem; }
