/* ============================================================
   KYMADEX VAULT — Dark Premium Theme
   ============================================================ */

:root {
  --bg-deep: #08080d;
  --bg-base: #0e0e16;
  --bg-surface: #151520;
  --bg-elevated: #1c1c2e;
  --bg-hover: #24243a;
  --bg-active: #2a2a45;

  --border: #2a2a3d;
  --border-light: #1e1e30;

  --text-primary: #e8e8f0;
  --text-secondary: #9494a8;
  --text-muted: #5e5e72;
  --text-accent: #6ea8fe;

  --accent: #4d8fea;
  --accent-hover: #5a9af5;
  --accent-glow: rgba(77, 143, 234, 0.15);
  --accent-dim: rgba(77, 143, 234, 0.08);

  --danger: #e85454;
  --success: #4ade80;
  --warning: #f5b942;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.6);

  --sidebar-width: 280px;
  --topbar-height: 56px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   AUTH OVERLAY
   ============================================================ */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
}

.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  width: 72px;
  height: 72px;
  margin-bottom: 16px;
  border-radius: var(--radius-md);
}

.auth-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -0.3px;
}

.auth-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 32px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 15px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s;
}

.auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.auth-form input::placeholder {
  color: var(--text-muted);
}

.auth-buttons {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.auth-status {
  font-size: 13px;
  color: var(--danger);
  min-height: 20px;
}

.auth-status.success { color: var(--success); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  flex: 1;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  flex: 1;
}

.btn-secondary:hover { background: var(--bg-hover); }

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

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

.btn-sm { padding: 7px 14px; font-size: 13px; }

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

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

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

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-base);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

.topbar-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-toggle { display: none; }

.user-menu { position: relative; }

.dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-width: 200px;
  padding: 6px;
  box-shadow: var(--shadow-lg);
  z-index: 200;
}

.dropdown-info {
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 4px;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  text-align: left;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
}

.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: rgba(232,84,84,0.1); }

.dropdown hr {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: 4px 0;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.layout {
  display: flex;
  height: calc(100vh - var(--topbar-height));
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-base);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
}

.sidebar-header h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sidebar-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 16px 12px;
}

.filter-chip {
  padding: 5px 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-chip:hover {
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.filter-chip.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--text-accent);
}

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

.bucket-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.12s;
  margin-bottom: 2px;
}

.bucket-item:hover { background: var(--bg-hover); }
.bucket-item.active { background: var(--bg-active); }

.bucket-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  overflow: hidden;
}

.bucket-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

.bucket-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bucket-meta {
  font-size: 12px;
  color: var(--text-muted);
}

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

.vault-stats {
  font-size: 13px;
  color: var(--text-muted);
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-deep);
  position: relative;
}

.view { padding: 24px; }

/* ── Card Row (landing) ── */
.card-row {
  margin-bottom: 32px;
}

.row-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text-primary);
}

/* ── Card Grid ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.card-grid.full {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}

.empty-row {
  grid-column: 1 / -1;
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border);
}

/* ── Card Tile ── */
.card-tile {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
}

.card-tile:hover {
  border-color: var(--border);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.card-tile-img {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  background: var(--bg-elevated);
  display: block;
}

.card-tile-img.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 32px;
}

.card-tile-body {
  padding: 10px 12px;
}

.card-tile-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-tile-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.card-tile-grade {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(8px);
  color: var(--success);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
}

/* ── Bucket Header ── */
.bucket-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.bucket-header h2 { font-size: 20px; font-weight: 700; }

.bucket-count {
  font-size: 14px;
  color: var(--text-muted);
  margin-left: auto;
}

/* ============================================================
   CARD DETAIL
   ============================================================ */
.card-detail { max-width: 900px; }

.card-detail-layout {
  display: flex;
  gap: 32px;
  margin-top: 20px;
}

.card-detail-image {
  flex: 0 0 300px;
}

.card-detail-image img {
  width: 100%;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
}

.card-detail-info {
  flex: 1;
}

.card-detail-info h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.card-meta {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.8;
}

.card-grade-display {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
}

.grade-score {
  font-size: 48px;
  font-weight: 800;
  color: var(--success);
  letter-spacing: -2px;
}

.grade-breakdown {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 12px;
  font-size: 13px;
}

.grade-item {
  display: flex;
  justify-content: space-between;
  color: var(--text-secondary);
}

.grade-item span:last-child {
  color: var(--text-primary);
  font-weight: 600;
}

.card-actions {
  display: flex;
  gap: 10px;
}

/* ============================================================
   UPLOAD MODAL
   ============================================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  padding: 28px;
  box-shadow: var(--shadow-lg);
}

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

.modal-header h2 { font-size: 18px; font-weight: 700; }

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  text-align: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.upload-zone:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--text-secondary);
}

.upload-zone svg { margin-bottom: 12px; }
.upload-zone p { font-size: 15px; margin-bottom: 4px; }
.upload-hint { font-size: 12px; }

.upload-preview {
  display: flex;
  gap: 16px;
  padding: 16px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

.upload-preview img {
  width: 80px;
  height: 106px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

.upload-info { flex: 1; }

.upload-filename {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
}

.upload-fingerprint {
  font-size: 12px;
  color: var(--text-muted);
  font-family: monospace;
  word-break: break-all;
}

.modal-footer {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.status-msg {
  font-size: 13px;
  margin-top: 12px;
  color: var(--text-secondary);
}

.status-msg.error { color: var(--danger); }
.status-msg.success { color: var(--success); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .sidebar-toggle { display: flex; }

  .sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    bottom: 0;
    z-index: 90;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
  }

  .view { padding: 16px; }

  .card-detail-layout {
    flex-direction: column;
  }

  .card-detail-image {
    flex: none;
    max-width: 250px;
    margin: 0 auto;
  }

  .topbar-title { display: none; }

  .btn-accent span { display: none; }

  .modal-content {
    margin: 16px;
    padding: 20px;
  }
}

@media (max-width: 480px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .auth-card {
    margin: 16px;
    padding: 32px 24px;
  }
}
