:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-soft: #f7f8fc;
  --text: #111827;
  --muted: #667085;
  --line: #e6e8ef;
  --brand: #1f3ae0;
  --brand-soft: #e9edff;
  --success: #0f9d58;
  --error: #dc3545;
  --warning: #b86d00;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow: 0 8px 20px rgba(17, 24, 39, .07);
  --sidebar-w: 260px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); }

#toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: grid; gap: 8px; }
.toast { border-radius: var(--radius-sm); padding: 10px 14px; color: #fff; font-size: 13px; box-shadow: var(--shadow); }
.toast.success { background: var(--success); }
.toast.error { background: var(--error); }
.toast.info { background: #344054; }
.toast.fade-out { opacity: .1; transform: translateY(-8px); transition: all .3s; }

.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top left, #2f4eff, #141c33 55%, #0f1324 100%);
}
.auth-wrapper { width: 100%; max-width: 420px; }
.auth-brand { text-align: center; color: #fff; margin-bottom: 20px; }
.auth-brand .brand-icon { font-size: 44px; margin-bottom: 8px; }
.auth-brand h1 { font-size: 30px; margin-bottom: 8px; }
.auth-brand p { color: #d5dbff; font-size: 14px; }
.auth-card { background: var(--surface); border-radius: var(--radius-lg); padding: 28px; box-shadow: var(--shadow); }
.auth-card h2 { margin-bottom: 16px; font-size: 24px; }
.auth-note { margin-bottom: 14px; color: var(--muted); font-size: 13px; }
.auth-footer { margin-top: 14px; font-size: 13px; color: var(--muted); text-align: center; }
.auth-footer a { color: var(--brand); text-decoration: none; font-weight: 600; }
.verify-icon { font-size: 36px; margin-bottom: 8px; text-align: center; }

.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
input[type="text"], input[type="email"], input[type="password"], input[type="date"], select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.checkbox-label { display: inline-flex !important; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.checkbox-label input { width: auto; accent-color: var(--brand); }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  background: #fff;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-outline { border-color: var(--line); background: #fff; }
.btn-danger { background: var(--error); color: #fff; }
.btn-small, .btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-full { width: 100%; }
.btn-spinner { width: 13px; height: 13px; border-radius: 50%; border: 2px solid rgba(255,255,255,.4); border-top-color: currentColor; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#app-view { display: flex; min-height: 100vh; }
#sidebar {
  width: var(--sidebar-w);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  background: #121826;
  color: #d0d5dd;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,.07);
}
.sidebar-brand { padding: 20px 18px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-icon-sm { font-size: 20px; }
.brand-copy { display: grid; }
.brand-name { font-size: 14px; color: #fff; font-weight: 700; }
.brand-sub { font-size: 12px; color: #98a2b3; }
.sidebar-nav { padding: 12px 10px; display: grid; gap: 4px; }
.nav-item { text-decoration: none; color: #98a2b3; border-radius: 8px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; font-size: 14px; font-weight: 500; }
.nav-item.active, .nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-footer { margin-top: auto; padding: 14px; border-top: 1px solid rgba(255,255,255,.08); display: grid; gap: 10px; }
.user-info { display: flex; align-items: center; gap: 8px; }
.user-avatar { width: 28px; height: 28px; border-radius: 50%; background: #2f4eff; color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.user-email { font-size: 12px; color: #cfd3df; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#main-content { margin-left: var(--sidebar-w); width: calc(100% - var(--sidebar-w)); padding: 24px; }
.page { display: none; }
.page.active { display: block; }
.page-header { margin-bottom: 18px; }
.page-header h1 { font-size: 28px; margin-bottom: 4px; }
.page-header p { color: var(--muted); font-size: 14px; }

.tool-switcher { display: inline-flex; gap: 6px; background: #e9edf8; padding: 5px; border-radius: var(--radius-sm); margin-bottom: 14px; }
.tool-switch { border: none; background: transparent; border-radius: 7px; padding: 8px 12px; color: #344054; font-weight: 600; cursor: pointer; }
.tool-switch.active { background: #fff; color: var(--brand); box-shadow: 0 3px 10px rgba(17,24,39,.08); }
.create-panel { display: none; }
.create-panel.active { display: block; }

.workspace-grid { display: grid; grid-template-columns: 320px 1fr 340px; gap: 14px; align-items: start; }
.surface-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.surface-card h3 { font-size: 15px; margin-bottom: 10px; }
.workspace-main .surface-card { min-height: 300px; }

.upload-area {
  border: 1px dashed #bfc7dd;
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  min-height: 200px;
  display: grid;
  place-items: center;
  overflow: hidden;
  cursor: pointer;
}
.upload-area.drag-over { border-color: var(--brand); background: #eef2ff; }
.upload-placeholder { text-align: center; padding: 14px; }
.upload-icon { font-size: 28px; margin-bottom: 6px; color: #344054; }
.upload-placeholder p { font-size: 13px; margin-bottom: 4px; }
.upload-hint { font-size: 12px; color: var(--muted); }
.upload-preview { width: 100%; max-height: 360px; object-fit: contain; background: #fff; }
.file-meta { margin-top: 10px; font-size: 12px; color: var(--muted); }
.inline-error { color: var(--error); font-size: 12px; margin-top: 8px; min-height: 16px; }

.tool-controls { display: grid; gap: 12px; }
.color-input-row, .language-select-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.color-input-row input[type="color"] { width: 38px; height: 34px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; }
.color-preview-link { font-size: 12px; color: var(--brand); cursor: pointer; font-weight: 600; }
.btn-remove-color, .btn-remove-language { border: none; background: #fee4e2; color: #b42318; width: 24px; height: 24px; border-radius: 50%; cursor: pointer; font-size: 14px; }

.job-status-panel { display: none; margin-bottom: 10px; border: 1px solid #d9e2ff; background: #f5f8ff; color: #1e3a8a; border-radius: var(--radius-sm); padding: 10px; font-size: 12px; }
.result-images { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.result-image-box { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px; background: #fafbff; position: relative; }
.result-image-box h4 { font-size: 12px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.result-image-box img { width: 100%; max-height: 360px; object-fit: contain; border-radius: 8px; background: #fff; border: 1px solid #e8ebf4; }
.batch-results-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.batch-summary { border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; padding: 10px; }

.image-loading-overlay {
  position: absolute;
  inset: 34px 10px 10px 10px;
  border-radius: 8px;
  background: rgba(255,255,255,.86);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.image-loading-spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid #d0d5dd; border-top-color: var(--brand); animation: spin .7s linear infinite; }
.image-loading-text { font-size: 12px; color: #475467; }

.revision-timeline {
  min-height: 120px;
  max-height: 240px;
  overflow: auto;
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
}
.revision-item { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 6px; }
.prompt-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.prompt-chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 10px; font-size: 12px; color: #344054; cursor: pointer; }
.prompt-chip:hover { border-color: #b7c4ff; background: #f8f9ff; }

.chat-messages {
  min-height: 160px;
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #f8faff;
  padding: 8px;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chat-msg { padding: 8px 10px; border-radius: 8px; font-size: 13px; line-height: 1.45; max-width: 90%; }
.chat-msg.user { background: #2f4eff; color: #fff; align-self: flex-end; }
.chat-msg.assistant { background: #fff; border: 1px solid var(--line); align-self: flex-start; }
.chat-msg.system { color: #667085; font-size: 12px; margin: 0 auto; }
.chat-input-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.chat-input-row input {
  flex: 1 1 240px;
  min-width: 180px;
}
#color-selection-container {
  flex: 1 1 220px;
  min-width: 180px;
}
#color-selection-container label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}
#chat-input {
  width: 100%;
}
.chat-input-row .btn {
  flex: 0 0 auto;
}

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat-card { border-radius: var(--radius-sm); border: 1px solid var(--line); background: #fff; padding: 12px; }
.stat-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.stat-value { font-size: 22px; font-weight: 700; color: #1d2939; }

.jobs-toolbar { margin-bottom: 10px; }
.jobs-toolbar { display: flex; justify-content: space-between; gap: 10px; align-items: center; flex-wrap: wrap; }
.jobs-toolbar input { max-width: 320px; }
.log-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.log-tab { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 10px; font-size: 12px; color: #344054; cursor: pointer; }
.log-tab.active { border-color: #b7c4ff; color: var(--brand); background: #eff3ff; }

.log-table-wrapper { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-md); overflow: auto; margin-bottom: 10px; }
.log-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.log-table th, .log-table td { text-align: left; padding: 10px; border-bottom: 1px solid #edf0f6; white-space: nowrap; }
.log-table th { color: #475467; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; background: #f8f9fd; }
.log-table tbody tr:hover { background: #f9fbff; }
.log-empty { padding: 26px; text-align: center; font-size: 13px; color: var(--muted); }
.log-pagination { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 12px; color: var(--muted); }
.badge { border-radius: 999px; padding: 3px 8px; font-size: 11px; font-weight: 600; }
.badge-success { color: #067647; background: #dcfae6; }
.badge-error { color: #b42318; background: #fee4e2; }

.admin-create-user, .admin-table-wrapper { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-md); padding: 12px; margin-bottom: 10px; }
.admin-create-grid { display: grid; grid-template-columns: 1.2fr 1.2fr auto auto auto; gap: 8px; align-items: center; }
.admin-activity-filter { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.admin-users-empty, .admin-users-error { padding: 14px; text-align: center; font-size: 12px; color: var(--muted); }
.admin-users-error { color: var(--error); }

.color-preview-popup, .admin-delete-modal { position: fixed; inset: 0; z-index: 9998; display: flex; align-items: center; justify-content: center; }
.color-preview-overlay, .admin-delete-overlay { position: absolute; inset: 0; background: rgba(16,24,40,.6); }
.color-preview-content, .admin-delete-content { position: relative; z-index: 9999; background: #fff; border-radius: var(--radius-md); box-shadow: var(--shadow); }
.color-preview-content { width: min(800px, 90vw); padding: 18px; }
.color-preview-close { position: absolute; top: 8px; right: 10px; border: none; background: transparent; cursor: pointer; font-size: 24px; }
.color-preview-picker-container { margin: 8px 0; display: flex; gap: 10px; align-items: center; }
.color-preview-display { height: 300px; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 10px; }
.color-preview-hex { font-size: 24px; font-weight: 700; }
.color-preview-rgb { font-size: 14px; color: var(--muted); }
.admin-delete-content { width: min(420px, 90vw); padding: 18px; }
.admin-delete-actions { margin-top: 12px; display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 1320px) {
  .workspace-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  #sidebar { position: static; width: 100%; height: auto; }
  #app-view { display: block !important; }
  #main-content { margin-left: 0; width: 100%; }
}

