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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, rgba(96, 120, 255, 0.12), transparent 28%),
    radial-gradient(circle at bottom right, rgba(95, 125, 255, 0.08), transparent 28%),
    #080a13;
  color: #e0e0e0;
  display: flex;
  align-items: stretch;
}

/* ---- Layout ---- */
.container {
  display: grid;
  grid-template-columns: 300px 1fr;
  width: 100%;
  height: 100vh;
}

/* ---- Sidebar ---- */
.panel {
  background: rgba(12, 16, 34, 0.98);
  border-right: 1px solid rgba(70, 80, 150, 0.18);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.panel-header {
  padding: 24px 20px 18px;
  border-bottom: 1px solid rgba(71, 88, 197, 0.2);
  background: linear-gradient(180deg, rgba(30, 37, 74, 0.98), rgba(11, 14, 30, 0.98));
  flex-shrink: 0;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand-logo {
  width: 96px;
  height: auto;
  min-width: 96px;
  border-radius: 18px;
  padding: 8px;
  filter: drop-shadow(0 0 18px rgba(95, 125, 255, 0.35));
}

.brand-label {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #8ea0ff;
  margin-bottom: 4px;
}

.panel-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -0.3px;
  margin: 0;
}

.tool-tagline {
  margin: 6px 0 0;
  font-size: 12px;
  color: #b5bfff;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: #2a2a2a transparent;
}

.panel-body::-webkit-scrollbar { width: 4px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: #2a2a2a; border-radius: 4px; }

/* ---- Section title ---- */
.section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #444;
  margin-bottom: 8px;
}

/* ---- Divider ---- */
hr { border: none; border-top: 1px solid #1c1c1c; }

/* ---- Status ---- */
.status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  display: inline-block;
}
.status-badge.idle     { background: rgba(100,100,120,0.2); color: #555; border: 1px solid #222; }
.status-badge.loading  { background: rgba(95,125,255,0.12); color: #8ea0ff; border: 1px solid rgba(95,125,255,0.25); }
.status-badge.ok       { background: rgba(0,200,120,0.12); color: #00c878; border: 1px solid rgba(0,200,120,0.25); }
.status-badge.invalid  { background: rgba(255,80,80,0.12); color: #ff6060; border: 1px solid rgba(255,80,80,0.25); }
.status-badge.training { background: rgba(255,179,64,0.12); color: #ffb340; border: 1px solid rgba(255,179,64,0.25); }

.status-hint {
  margin-top: 7px;
  font-size: 11px;
  color: #3a3a5a;
  line-height: 1.5;
}
.status-hint strong { color: #555; font-weight: 600; }

/* ---- Class list (sidebar) ---- */
.class-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.class-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: rgba(95, 125, 255, 0.04);
  border: 1px solid rgba(95, 125, 255, 0.1);
  border-radius: 7px;
}

.class-color-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.class-list-name {
  flex: 1;
  font-size: 12px;
  color: #c0c8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.class-list-count {
  font-size: 11px;
  color: #333;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.class-list-count.enough { color: #00c878; }

.btn-remove-class {
  background: none;
  border: none;
  color: #2a2a3a;
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color 0.15s;
  flex-shrink: 0;
}
.btn-remove-class:hover { color: #ff6060; }

/* ---- Buttons ---- */
.action-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(95,125,255,0.1);
  color: #8ea0ff;
  border: 1px solid rgba(95,125,255,0.2);
  border-radius: 7px;
  padding: 5px 12px;
  font-size: 11px;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.action-btn:hover { background: rgba(95,125,255,0.2); color: #fff; }

.train-btn {
  width: 100%;
  padding: 11px;
  background: linear-gradient(135deg, #5f7dff, #7a60ff);
  border: none;
  border-radius: 9px;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .2s, transform .1s, box-shadow .2s;
  letter-spacing: 0.2px;
  box-shadow: 0 4px 16px rgba(95, 125, 255, 0.25);
}
.train-btn:hover:not(:disabled) {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(95, 125, 255, 0.35);
}
.train-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  box-shadow: none;
}

.reset-btn {
  background: rgba(255,80,80,0.08);
  color: #ff6060;
  border-color: rgba(255,80,80,0.2);
}
.reset-btn:hover { background: rgba(255,80,80,0.15); color: #ff8080; }

/* ---- Output side ---- */
.output-side {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---- Classes area ---- */
.classes-area {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
  align-content: start;
  scrollbar-width: thin;
  scrollbar-color: #1e1e1e transparent;
}
.classes-area::-webkit-scrollbar { width: 6px; }
.classes-area::-webkit-scrollbar-track { background: transparent; }
.classes-area::-webkit-scrollbar-thumb { background: #1e1e1e; border-radius: 4px; }

/* ---- Class card ---- */
.class-card {
  background: rgba(10, 13, 28, 0.85);
  border: 1px solid rgba(70, 80, 150, 0.18);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 180px;
  transition: border-color .2s;
}
.class-card:hover { border-color: rgba(95, 125, 255, 0.28); }

.class-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-bottom: 1px solid rgba(70, 80, 150, 0.12);
  background: rgba(8, 10, 22, 0.8);
  flex-shrink: 0;
}

.class-card-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.class-name-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #e0e0e0;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  min-width: 0;
}
.class-name-input::placeholder { color: #2a2a3a; }

.class-count-badge {
  font-size: 10px;
  color: #333;
  padding: 2px 7px;
  background: rgba(255,255,255,0.03);
  border-radius: 10px;
  border: 1px solid #1a1a2a;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
  transition: color .2s, border-color .2s, background .2s;
}
.class-count-badge.enough {
  color: #00c878;
  border-color: rgba(0,200,120,0.2);
  background: rgba(0,200,120,0.07);
}

/* ---- Card drop zone ---- */
.card-drop-zone {
  margin: 8px;
  border: 1px dashed rgba(95, 125, 255, 0.2);
  border-radius: 7px;
  padding: 10px;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: border-color .15s, background .15s, color .15s;
  color: #2a2a3a;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
}
.card-drop-zone:hover, .card-drop-zone.drag-over {
  border-color: #5f7dff;
  background: rgba(95,125,255,0.05);
  color: #6a80ff;
}
.card-drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* ---- Thumbnails ---- */
.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: 4px;
  padding: 0 8px 8px;
}

.thumb-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 5px;
  overflow: hidden;
  background: #0c1020;
  border: 1px solid rgba(70,80,150,0.12);
}
.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 15px;
  height: 15px;
  background: rgba(0,0,0,0.75);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: none;
  color: #ccc;
  font-size: 11px;
  line-height: 1;
  padding: 0;
}
.thumb-item:hover .thumb-remove { display: flex; }

/* ---- Predict area ---- */
.predict-area {
  border-top: 1px solid rgba(70, 80, 150, 0.15);
  display: flex;
  flex-direction: column;
  height: 240px;
  flex-shrink: 0;
  background: rgba(6, 8, 18, 0.6);
}

.io-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 7px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(70,80,150,0.1);
  background: rgba(8, 10, 22, 0.7);
}

.io-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #333;
}

.output-meta {
  font-size: 11px;
  color: #333;
}

.predict-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* Drop zone (predict) */
.predict-drop {
  flex: 0 0 180px;
  border-right: 1px solid rgba(70,80,150,0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #2a2a3a;
  cursor: pointer;
  position: relative;
  transition: background .15s, color .15s;
  padding: 16px;
  text-align: center;
}
.predict-drop:not(.disabled):hover {
  background: rgba(95,125,255,0.04);
  color: #5f7dff;
}
.predict-drop input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.predict-drop p {
  font-size: 11px;
  line-height: 1.5;
}
.predict-drop p span {
  display: block;
  font-size: 10px;
  margin-top: 2px;
  color: #1e1e2a;
}
.predict-drop.disabled {
  pointer-events: none;
  opacity: 0.4;
}
.predict-drop.drag-over {
  background: rgba(95,125,255,0.06);
  color: #5f7dff;
}

/* Result */
.predict-result {
  flex: 1;
  display: flex;
  gap: 16px;
  padding: 14px 16px;
  overflow: hidden;
}

.predict-image-wrap {
  width: 100px;
  height: 100px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
  background: #0c1020;
  border: 1px solid rgba(70,80,150,0.2);
  align-self: center;
}
.predict-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.predict-bars {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: center;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #1e1e1e transparent;
}

.predict-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #1e1e2a;
  font-size: 12px;
}

.predict-bar-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.predict-bar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}

.predict-bar-name {
  font-size: 12px;
  color: #666;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.predict-bar-pct {
  font-size: 11px;
  color: #444;
  font-variant-numeric: tabular-nums;
}

.predict-bar-track {
  height: 5px;
  background: rgba(255,255,255,0.04);
  border-radius: 3px;
  overflow: hidden;
}

.predict-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.predict-bar-item.winner .predict-bar-name { color: #e8ecff; font-weight: 700; }
.predict-bar-item.winner .predict-bar-pct  { color: #00c878; font-weight: 700; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: rgba(20, 24, 48, 0.96);
  border: 1px solid rgba(95, 125, 255, 0.25);
  color: #c0c8ff;
  font-size: 12px;
  padding: 8px 18px;
  border-radius: 20px;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 100;
  backdrop-filter: blur(8px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Mobile ---- */
@media (max-width: 740px) {
  html, body { overflow: auto; height: auto; }
  .container { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .panel { height: auto; overflow: visible; border-right: none; border-bottom: 1px solid rgba(70,80,150,0.18); }
  .panel-body { overflow: visible; }
  .output-side { height: auto; }
  .classes-area { overflow: visible; min-height: 300px; }
  .predict-area { height: auto; min-height: 220px; }
  .predict-body { flex-direction: column; }
  .predict-drop { flex: 0 0 100px; border-right: none; border-bottom: 1px solid rgba(70,80,150,0.1); }
}
