/* ============================================
   Image Studio CSS — KinSoft AI
   RTL Arabic Design System
   ============================================ */

/* App Layout */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.app-header-inner {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
}

.app-header-start {
  display: flex;
  align-items: center;
  gap: 14px;
}

.app-header-end {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-toggle {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: transparent;
  border: 0;
  padding: 6px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s;
}

.sidebar-toggle:hover { background: var(--surface-muted); }

.sidebar-toggle span {
  width: 18px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  display: block;
}

.page-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  padding-inline-start: 10px;
  border-inline-start: 2px solid var(--accent);
}

.credits-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--accent);
  transition: transform 0.2s;
}

.credits-badge.pulse {
  animation: creditPulse 0.4s ease;
}

@keyframes creditPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

.credits-icon { font-size: 0.9rem; }

.back-btn { font-size: 0.8rem; }

/* App Layout */
.app-layout {
  display: flex;
  min-height: calc(100vh - 58px);
}

/* Sidebar */
.app-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg);
  border-inline-end: 1px solid var(--border);
  padding: 16px 0;
  transition: width 0.25s ease, opacity 0.25s ease;
  overflow: hidden;
}

.app-sidebar.collapsed {
  width: 0;
  opacity: 0;
  pointer-events: none;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 10px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.sidebar-link:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.sidebar-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.sidebar-icon { font-size: 1rem; }

/* Main Content */
.app-main {
  flex: 1;
  padding: 24px;
  background: var(--bg-alt);
  overflow-x: hidden;
}

/* Studio Grid */
.studio-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  max-width: 1200px;
}

/* Studio Card */
.studio-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

/* Tabs */
.studio-tabs {
  display: flex;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  padding: 4px;
  gap: 2px;
}

.studio-tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.studio-tab:hover { background: var(--surface); color: var(--text); }

.studio-tab.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* Tab Panes */
.tab-pane {
  display: none;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.tab-pane.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Form Elements */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  min-height: 120px;
  transition: border-color 0.15s;
  line-height: 1.6;
}

.form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-select {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 12px center;
  padding-left: 32px;
}

html[dir="rtl"] .form-select {
  background-position: right 12px center;
  padding-right: 32px;
  padding-left: 12px;
}

.form-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Cost Badge */
.cost-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  margin-bottom: 14px;
}

.cost-icon { font-size: 0.85rem; }

/* Generate Button */
.btn-generate {
  width: 100%;
  height: 46px;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s, transform 0.1s;
  position: relative;
}

.btn-generate:hover { background: var(--accent-hover); }
.btn-generate:active { transform: scale(0.98); }
.btn-generate:disabled { opacity: 0.7; cursor: not-allowed; }

/* Spinner */
.btn-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

.hidden { display: none !important; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: 10px;
  background: var(--bg-alt);
  min-height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
  overflow: hidden;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone-inner {
  text-align: center;
  padding: 20px;
}

.dropzone-icon { font-size: 2rem; display: block; margin-bottom: 8px; }

.dropzone-inner p {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.dropzone-hint { font-size: 0.8rem !important; }

.dropzone-browse {
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  text-decoration: underline;
}

.dropzone-preview {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-alt);
}

.dropzone-preview img {
  max-height: 140px;
  max-width: 100%;
  border-radius: 8px;
  object-fit: contain;
}

.dropzone-clear {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,0.5);
  color: #fff;
  border: 0;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Output Column */
.output-card {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
}

.output-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.output-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.output-display {
  flex: 1;
  min-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-alt);
  position: relative;
  margin: 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
}

/* Placeholder */
.output-placeholder {
  text-align: center;
  padding: 40px 20px;
}

.placeholder-icon {
  font-size: 3.5rem;
  margin-bottom: 14px;
  opacity: 0.4;
}

.output-placeholder p {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 6px;
}

.placeholder-hint {
  font-size: 0.8rem !important;
  color: var(--text-light) !important;
}

/* Loading */
.output-loading {
  text-align: center;
  padding: 40px 20px;
}

.loading-spinner-large {
  width: 50px;
  height: 50px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

.output-loading p {
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}

/* Result */
.output-result {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  box-sizing: border-box;
}

.result-real-img {
  width: 100%;
  max-width: 520px;
  height: auto;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 12px;
  display: block;
  margin: 0 auto;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
  border: 1px solid var(--border);
  transition: transform 0.2s;
}

.result-real-img:hover {
  transform: scale(1.01);
}

.result-quick-actions button {
  min-height: 42px;
  padding: 8px 18px;
  font-weight: 600;
  border-radius: 8px;
}

/* History */
.history-section {
  padding: 16px 18px;
  border-top: 1px solid var(--border);
}

.history-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  min-height: 70px;
}

.history-empty {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.history-empty p {
  font-size: 0.8rem;
  color: var(--text-light);
}

.history-thumb {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  background: var(--bg-alt);
  display: flex;
  align-items: center;
  justify-content: center;
}

.history-thumb:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}

/* Mobile & Tablet Responsiveness */
@media (max-width: 900px) {
  .app-header-inner {
    padding: 0 14px;
    height: 54px;
  }
  .page-title {
    display: none;
  }
  .studio-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .app-main {
    padding: 14px;
  }
  .app-sidebar {
    position: fixed;
    top: 54px;
    inset-inline-start: 0;
    height: calc(100vh - 54px);
    z-index: 50;
    background: var(--bg);
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
    transform: translateX(100%);
    transition: transform 0.25s ease;
  }
  .app-sidebar.open {
    transform: translateX(0);
  }
  .output-display {
    margin: 10px;
    min-height: 240px;
  }
  .btn-generate {
    min-height: 48px;
    font-size: 1.05rem;
  }
  .form-textarea {
    font-size: 16px; /* Prevents auto-zoom in mobile Safari/Chrome */
  }
}

@media (max-width: 600px) {
  .app-main {
    padding: 10px;
  }
  .form-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .ratio-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .history-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .result-quick-actions {
    flex-direction: column;
  }
  .result-quick-actions button {
    width: 100%;
  }
}
