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

:root {
  --sidebar-bg:     #1e1e2e;
  --sidebar-hover:  #2a2a3e;
  --sidebar-active: #313150;
  --accent:         #7c5cbf;
  --accent-hover:   #9370db;
  --txt-dim:        #a6adc8;
  --txt-light:      #cdd6f4;
  --main-bg:        #f4f5f7;
  --card-bg:        #ffffff;
  --border:         #e2e4e9;
  --red:            #e74c3c;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--main-bg);
  height: 100vh;
  overflow: hidden;
}

/* ── Layout ───────────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────── */
.sidebar {
  width: 255px;
  min-width: 255px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 18px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  gap: 8px;
}

.sidebar-header h2 {
  color: var(--txt-light);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  flex: 1;
}

.folder-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.app-version {
  font-size: 10px;
  color: var(--txt-dim);
  opacity: 0.45;
  font-weight: 500;
  flex-shrink: 0;
}

.folder-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  cursor: pointer;
  color: var(--txt-dim);
  border-radius: 6px;
  margin: 1px 6px;
  transition: background 0.12s, color 0.12s;
  position: relative;
}
.folder-item:hover  { background: var(--sidebar-hover); color: var(--txt-light); }
.folder-item.active { background: var(--sidebar-active); color: var(--txt-light); }

.folder-icon { font-size: 15px; flex-shrink: 0; }
.folder-name { flex: 1; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.btn-folder-del {
  display: none;
  background: none;
  border: none;
  color: #e74c3c;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  padding: 0 2px;
  border-radius: 3px;
}
.folder-item:hover .btn-folder-del { display: block; }

/* ── Main ─────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-header {
  padding: 18px 24px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.main-header h1 {
  font-size: 18px;
  font-weight: 600;
  color: #1a1a2e;
}

/* ── Content area ─────────────────────────────────── */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  position: relative;
}

/* ── Empty state ──────────────────────────────────── */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #aaa;
  text-align: center;
  gap: 10px;
  pointer-events: none;
}
.empty-state .empty-icon { font-size: 52px; opacity: 0.4; }
.empty-state p { font-size: 15px; }

/* ── Box grid ─────────────────────────────────────── */
.boxes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
  align-content: start;
}

/* ── Box card ─────────────────────────────────────── */
.box-card {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  overflow: hidden;
  transition: transform 0.18s, box-shadow 0.18s;
  display: flex;
  flex-direction: column;
}
.box-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 10px 28px rgba(0,0,0,0.14);
}

.card-cover {
  width: 100%;
  height: 155px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  flex-shrink: 0;
  overflow: hidden;
}
.card-cover img { width: 100%; height: 100%; object-fit: cover; }

.card-body { padding: 14px 16px; flex: 1; }
.card-title { font-size: 14px; font-weight: 600; color: #1a1a2e; margin-bottom: 5px; }
.card-desc  { font-size: 12px; color: #777; line-height: 1.45;
              display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.card-actions {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid #f0f0f0;
}

.btn-play {
  flex: 1;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: background 0.14s;
}
.btn-play:hover    { background: var(--accent-hover); }
.btn-play:disabled { background: #ccc; cursor: default; }

.btn-del-card {
  background: none;
  border: 1px solid #e8b4b8;
  color: #e74c3c;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.14s, color 0.14s;
}
.btn-del-card:hover { background: var(--red); color: #fff; border-color: var(--red); }

/* ── Buttons ──────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.14s;
}
.btn-primary:hover    { background: var(--accent-hover); }
.btn-primary:disabled { background: #ccc; cursor: default; }

.btn-secondary {
  background: #f0f0f0;
  color: #333;
  border: none;
  padding: 8px 16px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.14s;
}
.btn-secondary:hover { background: #e2e2e2; }

.btn-icon {
  background: none;
  border: 1px solid rgba(255,255,255,0.12);
  color: var(--txt-dim);
  width: 28px;
  height: 28px;
  border-radius: 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
  transition: background 0.14s, color 0.14s;
}
.btn-icon:hover { background: rgba(255,255,255,0.1); color: var(--txt-light); }

/* ── Modal ────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(3px);
}

.modal {
  background: #fff;
  border-radius: 14px;
  width: 460px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.25);
  display: flex;
  flex-direction: column;
}

.modal-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head h3 { font-size: 17px; font-weight: 600; color: #1a1a2e; }

.btn-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: #999;
  line-height: 1;
  padding: 0 2px;
  border-radius: 4px;
  transition: color 0.14s;
}
.btn-close:hover { color: #333; }

.modal-body {
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-body label {
  font-size: 12px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.modal-body input[type="text"],
.modal-body textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.14s;
  font-family: inherit;
}
.modal-body input[type="text"]:focus,
.modal-body textarea:focus { border-color: var(--accent); }

.modal-body textarea { min-height: 80px; resize: vertical; }

.img-preview { border-radius: 8px; overflow: hidden; max-height: 130px; }
.img-preview img { width: 100%; max-height: 130px; object-fit: cover; display: block; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 22px 16px;
  text-align: center;
  cursor: pointer;
  color: #aaa;
  font-size: 13px;
  position: relative;
  transition: border-color 0.14s, background 0.14s;
}
.drop-zone:hover,
.drop-zone.drag-over { border-color: var(--accent); background: rgba(124,92,191,0.04); color: var(--accent); }
.drop-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }

.file-chosen {
  font-size: 12px;
  color: var(--accent);
  background: rgba(124,92,191,0.08);
  border-radius: 5px;
  padding: 5px 10px;
}

.modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Toast ────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  background: #1a1a2e;
  color: #fff;
  padding: 11px 18px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  z-index: 200;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  animation: toastIn 0.25s ease;
  pointer-events: none;
}
.toast.ok  { background: #27ae60; }
.toast.err { background: var(--red); }

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

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

::-webkit-scrollbar       { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }
.content-area::-webkit-scrollbar-thumb { background: #ccc; }

@media (max-width: 580px) {
  .sidebar { width: 200px; min-width: 200px; }
  .boxes-grid { grid-template-columns: 1fr; }
  .content-area { padding: 14px; }
}

/* ── Main header actions ──────────────────────────────── */
.main-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── View toggle ──────────────────────────────────────── */
.view-toggle {
  display: flex;
  align-items: center;
  gap: 2px;
  background: #f0f0f0;
  border-radius: 7px;
  padding: 3px;
}

.btn-view {
  background: none;
  border: none;
  width: 30px;
  height: 28px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 16px;
  color: #888;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.14s, color 0.14s;
}
.btn-view:hover { background: #e0e0e0; color: #444; }
.btn-view.active { background: #fff; color: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,0.12); }

/* ── List view container ──────────────────────────────── */
.boxes-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── List search input ────────────────────────────────── */
.list-search {
  width: 100%;
  max-width: 360px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
  transition: border-color 0.14s;
}
.list-search:focus { border-color: var(--accent); }

/* ── Boxes table ──────────────────────────────────────── */
.boxes-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  font-size: 13px;
}

.boxes-table thead {
  background: #f8f8fb;
  border-bottom: 1px solid var(--border);
}

.boxes-table th {
  padding: 11px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.boxes-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.14s;
}
.boxes-table th.sortable:hover { color: var(--accent); }
.boxes-table th.sortable.active-sort { color: var(--accent); }

.sort-arrow { font-size: 13px; margin-left: 3px; }

.boxes-table td {
  padding: 10px 14px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
  color: #333;
}

.boxes-table tr:last-child td { border-bottom: none; }
.boxes-table tbody tr:hover td { background: #fafafa; }

.boxes-table .td-desc {
  color: #777;
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.boxes-table .td-date {
  color: #999;
  white-space: nowrap;
  font-size: 12px;
}

.td-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.btn-tbl {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 9px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
  color: #555;
}
.btn-tbl:hover { background: #f0f0f0; }
.btn-tbl.play  { color: var(--accent); border-color: #c9b8e8; }
.btn-tbl.play:hover  { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-tbl.edit  { color: #4a7fc1; border-color: #b8d0e8; }
.btn-tbl.edit:hover  { background: #4a7fc1; color: #fff; border-color: #4a7fc1; }
.btn-tbl.del   { color: var(--red); border-color: #e8b4b8; }
.btn-tbl.del:hover   { background: var(--red); color: #fff; border-color: var(--red); }
.btn-tbl:disabled { opacity: 0.4; cursor: default; }
.btn-tbl:disabled:hover { background: none; color: #555; border-color: var(--border); }

/* ── Edit button on cards ─────────────────────────────── */
.btn-edit-card {
  background: none;
  border: 1px solid #b8d0e8;
  color: #4a7fc1;
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.btn-edit-card:hover { background: #4a7fc1; color: #fff; border-color: #4a7fc1; }

/* ── Build log ────────────────────────────────────────── */
.build-log-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-building {
  font-size: 12px;
  font-weight: 600;
  color: #555;
}

.build-log {
  background: #1a1a2e;
  color: #4ade80;
  font-family: 'Courier New', Consolas, monospace;
  font-size: 11px;
  max-height: 220px;
  overflow-y: auto;
  padding: 10px;
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
}

.build-log::-webkit-scrollbar { width: 4px; }
.build-log::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }
