/* ========== ADH Brand Tokens ========== */
:root {
  --apex: #0038A8;
  --apex-dark: #001F5E;
  --molten: #FF5000;
  --carbide: #1B1F24;
  --carbide-dark: #2A3038;
  --titanium: #8D99AE;
  --silver: #F0F2F5;
  --silver-text: #E1E4E8;

  --bg: var(--silver);
  --bg-card: #ffffff;
  --bg-hover: #E6E9ED;
  --text: var(--carbide);
  --text-secondary: var(--titanium);
  --border: var(--silver-text);
  --primary: var(--apex);
  --primary-hover: var(--apex-dark);
  --primary-light: #EBF0F9;
  --danger: var(--molten);
  --danger-hover: #D94400;
  --success: #10b981;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,56,168,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 30px rgba(0,56,168,.08), 0 4px 12px rgba(0,0,0,.05);
  --shadow-apex: 0 4px 14px rgba(0,56,168,.20);
  --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 800px;
  margin: 0 auto;
  padding: 32px 16px;
}

/* ========== Header ========== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

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

.logo-icon {
  width: 30px;
  height: 30px;
  color: var(--primary);
}

.header h1 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--carbide);
}

.header-right {
  display: flex;
  gap: 6px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--primary);
  border-color: var(--primary);
}

.icon-btn svg { width: 18px; height: 18px; }

/* ========== Settings Panel ========== */
.settings-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.settings-inner {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-inner label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.settings-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.api-key-field {
  position: relative;
  flex: 1;
  min-width: 0;
}

.settings-input-row input {
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: 'JetBrains Mono', 'Cascadia Code', monospace;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.api-key-field input {
  padding-right: 42px;
}

.settings-input-row input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 56, 168, 0.1);
}

.api-key-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transform: translateY(-50%);
  transition: background var(--transition), color var(--transition);
}

.api-key-toggle:hover,
.api-key-toggle:focus-visible {
  background: var(--bg-hover);
  color: var(--primary);
}

.api-key-toggle:focus-visible {
  outline: 2px solid rgba(0, 56, 168, 0.35);
  outline-offset: 2px;
}

.api-key-toggle svg {
  width: 17px;
  height: 17px;
  pointer-events: none;
}

.settings-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  user-select: none;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--primary);
}

.settings-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
  opacity: 0.8;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  cursor: default;
  opacity: 0.78;
  transform: none;
  box-shadow: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-apex);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 6px 20px rgba(0,56,168,.28);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0) scale(0.97); }

.btn-ghost {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--titanium);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 5px 12px;
  font-size: 0.78rem;
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-copy {
  background: var(--primary-light);
  color: var(--primary);
  padding: 5px 12px;
  font-size: 0.78rem;
  border: 1px solid transparent;
}

.btn-copy:hover {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-apex);
}

.btn-secondary {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid rgba(0, 56, 168, 0.12);
  padding: 5px 12px;
  font-size: 0.78rem;
}

.btn-secondary:hover {
  background: rgba(0, 56, 168, 0.12);
}

.btn-small {
  padding: 5px 12px;
  font-size: 0.78rem;
}

/* ========== Drop Zone ========== */
.drop-zone {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 52px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-card);
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 4px rgba(0, 56, 168, 0.08);
}

.drop-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.drop-icon {
  width: 48px;
  height: 48px;
  color: var(--titanium);
  margin-bottom: 14px;
  transition: color var(--transition);
}

.drop-zone:hover .drop-icon,
.drop-zone.drag-over .drop-icon {
  color: var(--primary);
}

.drop-text {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--carbide);
}

.drop-hint {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

/* ========== History ========== */
.history-section {
  margin-top: 28px;
}

.history-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.history-header h2 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.history-heading {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-subtitle {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.history-actions {
  display: flex;
  gap: 8px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  text-align: center;
  padding: 56px 16px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  transition: all var(--transition);
}

.history-item:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

.history-item-uploading {
  border-color: rgba(0, 56, 168, 0.14);
}

.history-item-error {
  border-color: rgba(255, 80, 0, 0.2);
}

.history-thumb-button {
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 6px;
  flex-shrink: 0;
}

.history-thumb-button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}

.history-thumb {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-hover);
  cursor: pointer;
  transition: transform var(--transition);
}

.history-thumb:hover {
  transform: scale(1.05);
}

.history-info {
  flex: 1;
  min-width: 0;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.history-name,
.history-url {
  font-size: 0.82rem;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  font-weight: 600;
  min-width: 0;
  flex: 1;
}

.history-name {
  color: var(--text);
}

.history-url:hover {
  color: var(--primary-hover);
  text-decoration: underline;
}

.history-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  flex-shrink: 0;
}

.history-status-uploading {
  color: var(--primary);
  background: rgba(0, 56, 168, 0.08);
}

.history-status-error {
  color: var(--danger);
  background: rgba(255, 80, 0, 0.12);
}

.history-meta {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.history-error {
  font-size: 0.78rem;
  color: var(--danger);
  margin-top: 6px;
}

.history-progress {
  width: 100%;
  height: 6px;
  background: var(--bg-hover);
  border-radius: 999px;
  margin-top: 8px;
  overflow: hidden;
}

.history-progress-bar {
  height: 100%;
  width: 0;
  background: var(--primary);
  border-radius: inherit;
  transition: width 0.2s ease;
}

.history-btns {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--carbide);
  color: var(--silver);
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(27,31,36,.25);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 999;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ========== Lightbox ========== */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(27,31,36,.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}

/* ========== Utilities ========== */
.hidden { display: none !important; }

/* ========== Responsive ========== */
@media (max-width: 600px) {
  #app { padding: 20px 12px; }
  .drop-zone { padding: 36px 16px; }
  .settings-input-row { flex-wrap: wrap; }
  .history-header { flex-direction: column; align-items: stretch; }
  .history-row { flex-wrap: wrap; }
  .history-btns { flex-direction: column; gap: 4px; }
  .history-item { flex-wrap: wrap; }
}
