/* ============================================================
   Matrixloader — Ultimate Low White Neumorphism UI
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
  /* Colors */
  --bg-color: #ebf0f6;
  --text-main: #2d3748;
  --text-muted: #718096;
  --accent: #4a90e2;
  --accent-hover: #357abd;
  --error: #e53e3e;
  --success: #38a169;
  
  /* Neumorphic Shadows */
  --shadow-out: 8px 8px 16px #d1d9e6, -8px -8px 16px #ffffff;
  --shadow-in: inset 6px 6px 12px #d1d9e6, inset -6px -6px 12px #ffffff;
  --shadow-out-hover: 4px 4px 8px #d1d9e6, -4px -4px 8px #ffffff;
  
  --font-main: 'Plus Jakarta Sans', system-ui, sans-serif;
  --radius-s: 12px;
  --radius-m: 20px;
  --radius-l: 30px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-color);
  background-image: 
    radial-gradient(at 0% 0%, rgba(74, 144, 226, 0.08) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(0, 245, 212, 0.08) 0px, transparent 50%),
    radial-gradient(at 100% 0%, rgba(245, 166, 35, 0.05) 0px, transparent 50%);
  background-attachment: fixed;
  background-size: 200% 200%;
  animation: bgPan 15s ease infinite alternate;
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

@keyframes bgPan {
  0% { background-position: 0% 0%; }
  100% { background-position: 100% 100%; }
}

::selection { background: rgba(74, 144, 226, 0.2); color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

h1, h2, h3 { font-weight: 700; margin: 0; color: #1a202c; letter-spacing: -0.02em; }
h1 {
  background: linear-gradient(135deg, #1a202c 0%, #4a90e2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: inline-block;
}

.lede { color: var(--text-muted); max-width: 56ch; margin: 10px 0 22px; font-size: 16px; }
.lede-small { color: var(--text-muted); font-size: 14px; margin: 4px 0 12px; }

/* ============================================================
   Layout & Topbar
   ============================================================ */
.frame { min-height: 100vh; display: flex; flex-direction: column; position: relative; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  margin: 20px 30px;
  border-radius: var(--radius-m);
  background: var(--bg-color);
  box-shadow: var(--shadow-out);
}

.wordmark {
  font-weight: 800;
  font-size: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-main);
}
.wordmark-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 15px rgba(74, 144, 226, 0.6);
}

/* Tabs */
.tabs { display: flex; gap: 16px; flex-wrap: wrap; }
.tab {
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-color);
  box-shadow: var(--shadow-out);
  border: none;
  border-radius: var(--radius-s);
  padding: 10px 20px;
  cursor: pointer;
  transition: all 0.25s ease;
}
.tab:hover {
  color: var(--accent);
  box-shadow: var(--shadow-out-hover);
  transform: translateY(2px);
}
.tab.is-active {
  color: var(--accent);
  box-shadow: var(--shadow-in);
}

.body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  padding: 0 30px 40px;
}

.stage { max-width: 800px; margin: 0 auto; width: 100%; padding: 20px 0; }

.panel { display: none; }
.panel.is-active { display: block; animation: fadeUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

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

/* ============================================================
   Forms & Inputs
   ============================================================ */
textarea, input[type="text"] {
  width: 100%;
  background: var(--bg-color);
  box-shadow: var(--shadow-in);
  border: 2px solid transparent;
  border-radius: var(--radius-m);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 16px;
  padding: 20px;
  resize: vertical;
  transition: all 0.3s ease;
}
textarea:focus, input[type="text"]:focus {
  border-color: rgba(74, 144, 226, 0.2);
  outline: none;
}
textarea::placeholder, input::placeholder { color: #a0aec0; }

.intake-actions { margin-top: 24px; display: flex; gap: 16px; align-items: center; }

.search-row { display: flex; gap: 16px; margin-top: 12px; }
.search-row input { flex: 1; }

/* Buttons */
.btn {
  background: var(--bg-color);
  box-shadow: var(--shadow-out);
  color: var(--text-main);
  font-family: var(--font-main);
  font-weight: 700;
  font-size: 15px;
  border: none;
  border-radius: var(--radius-m);
  padding: 14px 28px;
  cursor: pointer;
  transition: all 0.25s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn:hover {
  box-shadow: var(--shadow-out-hover);
  transform: translateY(2px);
}
.btn:active {
  box-shadow: var(--shadow-in);
  transform: translateY(4px);
}
.btn-primary { 
  color: var(--accent); 
}
.btn-primary:disabled { opacity: 0.5; pointer-events: none; }
.btn-primary.is-busy { opacity: 0.7; pointer-events: none; }

.btn-ghost {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 16px;
  cursor: pointer;
  transition: color 0.2s;
}
.btn-ghost:hover { color: var(--accent); }

.tab-divider {
  width: 2px;
  background: var(--shadow-in);
  border-radius: 2px;
  margin: 0 4px;
}

.btn-telegram {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #2AABEE 0%, #229ED9 100%);
  color: #ffffff;
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 20px;
  border-radius: var(--radius-s);
  box-shadow: 4px 4px 10px rgba(42, 171, 238, 0.25), -4px -4px 10px rgba(255, 255, 255, 0.8), inset 1px 1px 2px rgba(255, 255, 255, 0.4);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.btn-telegram:hover {
  transform: translateY(-2px);
  box-shadow: 6px 6px 15px rgba(42, 171, 238, 0.35), -6px -6px 15px rgba(255, 255, 255, 0.9), inset 1px 1px 2px rgba(255, 255, 255, 0.4);
}
.btn-telegram svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ============================================================
   Flow Steps
   ============================================================ */
.flow-steps {
  display: flex; gap: 24px; list-style: none; padding: 0; margin: 40px 0 0; flex-wrap: wrap;
}
.flow-step { display: flex; align-items: center; gap: 12px; font-weight: 600; color: #a0aec0; }
.flow-num {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--bg-color);
  box-shadow: var(--shadow-out);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: inherit;
}
.flow-step.is-done { color: var(--text-muted); }
.flow-step.is-done .flow-num { color: var(--success); box-shadow: var(--shadow-in); }
.flow-step.is-current { color: var(--accent); }
.flow-step.is-current .flow-num { box-shadow: var(--shadow-in); }

/* ============================================================
   Result Cards
   ============================================================ */
.preview, .result-card {
  display: flex; gap: 24px; margin-top: 40px; padding: 24px;
  background: var(--bg-color);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-out);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.preview:hover, .result-card:hover {
  transform: translateY(-5px);
  box-shadow: 12px 12px 24px #d1d9e6, -12px -12px 24px #ffffff;
}
.preview.is-hidden { display: none; }
.preview-thumb, .result-card img {
  width: 200px; height: 112px; object-fit: cover;
  border-radius: var(--radius-m);
  box-shadow: 4px 4px 10px rgba(0,0,0,0.1);
  flex-shrink: 0;
  transition: transform 0.4s ease;
}
.preview:hover .preview-thumb, .result-card:hover img {
  transform: scale(1.02);
}
.result-card img { width: 140px; height: 78px; }

.preview-body, .result-info { min-width: 0; flex: 1; }
.preview-title { font-size: 20px; margin-bottom: 12px; line-height: 1.4; color: var(--text-main); }

.tag-row { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.tag {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  background: var(--bg-color); padding: 6px 12px;
  border-radius: var(--radius-s);
  box-shadow: var(--shadow-in);
}
.tag.tag-platform { color: var(--accent); box-shadow: var(--shadow-out); }

.quality-grid { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 16px; }
.chip {
  font-family: var(--font-main); font-size: 14px; font-weight: 600;
  color: var(--text-main); background: var(--bg-color);
  box-shadow: var(--shadow-out);
  border: none; border-radius: var(--radius-m);
  padding: 12px 20px; cursor: pointer; transition: all 0.25s ease;
}
.chip:hover {
  color: var(--accent); box-shadow: var(--shadow-out-hover); transform: translateY(2px);
}
.chip:active { box-shadow: var(--shadow-in); transform: translateY(4px); }

.result-list { display: flex; flex-direction: column; gap: 20px; margin-top: 40px; }
.result-title { font-size: 16px; margin-bottom: 8px; color: var(--text-muted); font-weight: 600; }

/* ============================================================
   Download Overlay
   ============================================================ */
.download-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(235, 240, 246, 0.85); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9999; display: flex; align-items: center; justify-content: center;
}
.overlay-card {
  background: var(--bg-color);
  border-radius: var(--radius-l);
  padding: 50px 40px;
  width: 90%; max-width: 480px;
  text-align: center;
  box-shadow: var(--shadow-out);
}
.loader-spinner {
  width: 60px; height: 60px;
  border: 4px solid #d1d9e6; border-top-color: var(--accent);
  border-radius: 50%; margin: 0 auto 24px;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.overlay-card h3 { margin: 0 0 12px; font-size: 22px; color: var(--text-main); }
.overlay-meta, .overlay-status { font-size: 15px; color: var(--text-muted); font-weight: 500; }

.progress-track {
  height: 8px; background: var(--bg-color);
  box-shadow: var(--shadow-in);
  border-radius: 4px; overflow: hidden; margin: 24px 0;
}
.progress-fill {
  height: 100%; background: var(--accent);
  border-radius: 4px; transition: width 0.4s ease;
}
.overlay-actions { margin-top: 24px; display: none; gap: 16px; justify-content: center; }

/* ============================================================
   Tables & Dashboard
   ============================================================ */
.table-wrap {
  margin-top: 40px; overflow-x: auto;
  background: var(--bg-color); padding: 24px;
  border-radius: var(--radius-l); box-shadow: var(--shadow-out);
}
.history-table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.history-table th { text-align: left; font-weight: 700; color: var(--text-muted); padding: 0 16px 16px 0; border-bottom: 2px solid #d1d9e6; }
.history-table td { padding: 16px 16px 16px 0; border-bottom: 1px solid #d1d9e6; color: var(--text-main); font-weight: 500; }
.history-empty { color: var(--text-muted); padding: 30px 0; text-align: center; font-weight: 600; }

.badge { font-size: 13px; padding: 6px 12px; border-radius: 999px; font-weight: 700; box-shadow: var(--shadow-in); }
.badge.success { color: var(--success); }
.badge.error { color: var(--error); }
.badge.cancelled { color: var(--text-muted); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 24px; margin: 30px 0 50px; }
.stat-block {
  background: var(--bg-color); border-radius: var(--radius-l);
  padding: 24px; text-align: center; box-shadow: var(--shadow-out);
}
.stat-value { font-size: 36px; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 14px; font-weight: 600; color: var(--text-muted); margin-top: 8px; }

.bar-chart {
  display: flex; flex-direction: column; gap: 16px;
  background: var(--bg-color); padding: 30px; border-radius: var(--radius-l); box-shadow: var(--shadow-out);
}
.bar-row { display: grid; grid-template-columns: 100px 1fr 50px; gap: 16px; align-items: center; }
.bar-label { font-size: 14px; font-weight: 700; color: var(--text-muted); text-transform: capitalize; }
.bar-track { height: 12px; background: var(--bg-color); box-shadow: var(--shadow-in); border-radius: 6px; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; }
.bar-value { font-size: 14px; font-weight: 700; color: var(--text-main); text-align: right; }

.toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg-color); box-shadow: var(--shadow-out);
  color: var(--accent); font-weight: 700; font-size: 14px; padding: 16px 30px; border-radius: var(--radius-l);
  opacity: 0; pointer-events: none; transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 9999;
}
.toast.is-shown { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }

@media (max-width: 768px) {
  .body { padding: 0 16px 20px; }
  .topbar { margin: 16px; padding: 16px 20px; flex-direction: column; gap: 16px; }
  .preview, .result-card { flex-direction: column; padding: 16px; }
  .preview-thumb, .result-card img { width: 100%; height: auto; aspect-ratio: 16/9; }
  .stat-grid { grid-template-columns: 1fr; }
}
