/* web/styles.css */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --surface3: #2a2a2a;
  --border: #333;
  --text: #e8e8e8;
  --text-dim: #888;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --danger: #ef4444;
  --danger-hover: #f87171;
  --success: #22c55e;
  --radius: 8px;
  --sidebar-width: 280px;
}

html, body, #root {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, sans-serif;
  line-height: 1.6;
}

.app-layout {
  display: flex;
  overflow: hidden;
  height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-header {
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
}

.sidebar-header-top {
  display: flex;
  justify-content: space-between;
  align-items:  center;
}

.sidebar-header h1 {
  letter-spacing: -.3px;
  font-size: 16px;
  font-weight: 600;
}

.api-key-settings {
  position: relative;
}

.api-key-btn {
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  position: relative;
  border-radius: 8px;
  justify-content: center;
  align-items:  center;
  width: 36px;
  height: 36px;
  transition: all .2s;
}

.api-key-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.api-key-btn.validated {
  border-color: var(--success);
  color: var(--success);
}

.validated-dot {
  position: absolute;
  background: var(--success);
  border-radius: 50%;
  width: 8px;
  height: 8px;
  top: 4px;
  right: 4px;
}

.api-key-dropdown {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 100;
  width: 260px;
  padding: 16px;
  top: calc(100% + 8px);
  right: 0;
  box-shadow: 0 8px 24px #0006;
}

.dropdown-header {
  color: var(--text);
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 600;
}

.api-key-dropdown input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  width: 100%;
  padding: 10px 12px;
  transition: border-color .2s;
  font-size: 13px;
}

.api-key-dropdown input:focus {
  outline: none;
  border-color: var(--accent);
}

.dropdown-error {
  color: var(--danger);
  margin-top: 8px;
  font-size: 12px;
}

.dropdown-buttons {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.dropdown-btn {
  border-radius: var(--radius);
  cursor: pointer;
  flex: 1;
  padding: 8px 12px;
  transition: all .2s;
  font-size: 13px;
  font-weight: 500;
}

.dropdown-btn.clear {
  border: 1px solid var(--border);
  color: var(--text-dim);
  background: none;
}

.dropdown-btn.clear:hover:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
}

.dropdown-btn.save {
  background: var(--accent);
  color: #fff;
  border: none;
}

.dropdown-btn.save:hover:not(:disabled) {
  background: var(--accent-hover);
}

.dropdown-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.dropdown-status {
  display: flex;
  color: var(--success);
  align-items:  center;
  gap: 6px;
  margin-top: 12px;
  font-size: 12px;
}

.status-dot {
  background: var(--success);
  border-radius: 50%;
  width: 6px;
  height: 6px;
}

.api-key-warning {
  border-radius: var(--radius);
  color: var(--accent);
  text-align: center;
  background: #6366f11a;
  border: 1px solid #6366f14d;
  margin-bottom: 20px;
  padding: 12px 16px;
  font-size: 14px;
}

.new-btn {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  background: none;
  width: 100%;
  padding: 8px 12px;
  transition: all .2s;
  font-size: 13px;
}

.new-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.new-btn:disabled {
  background: var(--accent);
  color: #fff;
  border-style: solid;
  border-color: var(--accent);
  cursor: default;
}

.sidebar-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px;
}

.sidebar-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 32px 16px;
  font-size: 13px;
}

.sidebar-item {
  display: flex;
  border-radius: var(--radius);
  cursor: pointer;
  gap: 10px;
  margin-bottom: 4px;
  padding: 10px;
  transition: background .15s;
}

.sidebar-item:hover {
  background: var(--surface2);
}

.sidebar-item.active {
  background: var(--surface3);
}

.sidebar-thumb {
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 6px;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
}

.sidebar-item-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 2px;
  min-width: 0;
}

.sidebar-item-time {
  color: var(--text-dim);
  font-size: 11px;
}

.sidebar-item-prompt {
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 12px;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 12px;
}

.sidebar-footer .clear-btn {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  background: none;
  width: 100%;
  padding: 8px;
  transition: all .2s;
  font-size: 12px;
}

.sidebar-footer .clear-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.main-panel {
  overflow-y: auto;
  background: var(--bg);
  flex: 1;
  padding: 32px;
}

.generate-panel {
  max-width: 600px;
  margin: 0 auto;
}

.generate-panel h2 {
  margin-bottom: 24px;
  font-size: 20px;
  font-weight: 600;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  cursor: pointer;
  padding: 32px 20px;
  transition: border-color .2s, background .2s;
}

.drop-zone:hover:not(.disabled) {
  border-color: var(--accent);
  background: #6366f10d;
}

.drop-zone.disabled {
  opacity: .5;
  cursor: not-allowed;
}

.drop-zone-content svg {
  color: var(--text-dim);
  margin-bottom: 10px;
}

.drop-zone-content p {
  color: var(--text);
  margin-bottom: 4px;
  font-size: 14px;
}

.drop-zone-content .hint {
  color: var(--text-dim);
  font-size: 12px;
}

.preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.preview-item {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 80px;
  height: 80px;
}

.preview-item img {
  object-fit: cover;
  width: 100%;
  height: 100%;
}

.remove-btn {
  position: absolute;
  color: #fff;
  cursor: pointer;
  display: flex;
  background: #000000b3;
  border: none;
  border-radius: 50%;
  justify-content: center;
  align-items:  center;
  width: 20px;
  height: 20px;
  font-size: 14px;
  line-height: 1;
  top: 2px;
  right: 2px;
}

.remove-btn:hover {
  background: var(--danger);
}

.prompt-section {
  margin-top: 20px;
}

.prompt-section label {
  display: block;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 500;
}

.prompt-section textarea {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  resize: vertical;
  width: 100%;
  min-height: 100px;
  padding: 12px;
  transition: border-color .2s;
  font-family: inherit;
  font-size: 14px;
}

.prompt-section textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.prompt-section textarea:disabled {
  opacity: .5;
}

.error-message {
  border-radius: var(--radius);
  color: var(--danger);
  background: #ef44441a;
  border: 1px solid #ef44444d;
  margin-top: 12px;
  padding: 10px 14px;
  font-size: 13px;
}

.generate-btn {
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  border: none;
  width: 100%;
  margin-top: 20px;
  padding: 14px 24px;
  transition: background .2s, opacity .2s;
  font-size: 15px;
  font-weight: 600;
}

.generate-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.generate-btn:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.loading-text {
  display: inline-flex;
  align-items:  center;
  gap: 8px;
}

.spinner {
  display: inline-block;
  animation: spin .8s linear infinite;
  border: 2px solid #ffffff4d;
  border-top-color: #fff;
  border-radius: 50%;
  width: 16px;
  height: 16px;
}

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

.record-detail {
  max-width: 700px;
  margin: 0 auto;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items:  center;
  margin-bottom: 20px;
}

.back-btn {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  background: none;
  padding: 8px 16px;
  transition: all .2s;
  font-size: 13px;
}

.back-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.delete-btn {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer;
  background: none;
  padding: 8px 16px;
  transition: all .2s;
  font-size: 13px;
}

.delete-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.detail-time {
  color: var(--text-dim);
  display: flex;
  align-items:  center;
  gap: 16px;
  margin-bottom: 24px;
  font-size: 13px;
}

.detail-api-key {
  background: var(--surface2);
  color: var(--text-dim);
  border-radius: 4px;
  padding: 4px 10px;
  font-family: monospace;
  font-size: 12px;
}

.detail-section {
  margin-bottom: 28px;
}

.detail-section h3 {
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
}

.detail-prompt {
  color: var(--text);
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  padding: 14px;
  font-size: 14px;
  line-height: 1.6;
}

.detail-images {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-thumb {
  object-fit: cover;
  border: 2px solid var(--border);
  cursor: pointer;
  border-radius: 8px;
  flex-shrink: 0;
  width: 120px;
  height: 120px;
  transition: transform .2s, border-color .2s;
}

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

.detail-thumb.output {
  border-color: var(--success);
}

.detail-thumb.output:hover {
  border-color: var(--accent);
}

.output-image-wrapper {
  display: flex;
  align-items:  center;
  gap: 12px;
}

.output-action-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.action-btn {
  display: flex;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  align-items:  center;
  gap: 8px;
  padding: 8px 14px;
  transition: all .2s;
  font-size: 13px;
}

.action-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.action-btn.download:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.action-btn.reuse:hover {
  border-color: var(--success);
  background: var(--success);
  color: #fff;
}

.action-btn svg {
  flex-shrink: 0;
}

.preview-item.preset {
  border-color: var(--accent);
}

.preset-badge {
  position: absolute;
  background: var(--accent);
  color: #fff;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 600;
  bottom: 4px;
  left: 4px;
}

.lightbox-overlay {
  position: fixed;
  display: flex;
  z-index: 1000;
  background: #000000eb;
  justify-content: center;
  align-items:  center;
  padding: 20px;
  inset: 0;
}

.lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
}

.lightbox-content img {
  object-fit: contain;
  border-radius: var(--radius);
  max-width: 100%;
  max-height: 90vh;
}

.lightbox-close {
  position: absolute;
  background: var(--surface2);
  color: #fff;
  cursor: pointer;
  display: flex;
  border: none;
  border-radius: 50%;
  justify-content: center;
  align-items:  center;
  width: 32px;
  height: 32px;
  font-size: 18px;
  top: -12px;
  right: -12px;
}

.lightbox-close:hover {
  background: var(--danger);
}

.modal-overlay {
  position: fixed;
  display: flex;
  z-index: 1001;
  background: #000c;
  justify-content: center;
  align-items:  center;
  padding: 20px;
  inset: 0;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 360px;
  padding: 24px;
}

.modal-content h2 {
  text-align: center;
  margin-bottom: 20px;
  font-size: 18px;
  font-weight: 600;
}

.modal-content form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-content input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  width: 100%;
  padding: 12px;
  transition: border-color .2s;
  font-size: 14px;
}

.modal-content input:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-content input:disabled {
  opacity: .5;
}

.modal-error {
  color: var(--danger);
  text-align: center;
  font-size: 13px;
}

.modal-buttons {
  display: flex;
  gap: 12px;
}

.modal-btn {
  border-radius: var(--radius);
  cursor: pointer;
  flex: 1;
  padding: 10px 16px;
  transition: all .2s;
  font-size: 14px;
  font-weight: 500;
}

.modal-btn.cancel {
  border: 1px solid var(--border);
  color: var(--text-dim);
  background: none;
}

.modal-btn.cancel:hover:not(:disabled) {
  border-color: var(--text-dim);
  color: var(--text);
}

.modal-btn.confirm {
  background: var(--accent);
  color: #fff;
  border: none;
}

.modal-btn.confirm:hover:not(:disabled) {
  background: var(--accent-hover);
}

.modal-btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

@media (width <= 768px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    width: 100%;
    min-width: 100%;
    height: auto;
    max-height: 40vh;
  }

  .main-panel {
    padding: 20px;
  }
}
