:root {
  --border: #999;
  --bg-header: #d4d0c8;
  --bg-row-alt: #f0f0f0;
  --accent: #2a5db0;
  --font: "Segoe UI", Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: #222;
  background: #ece9d8;
}

/* ---------- Login ---------- */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(180deg, #2a5db0, #163b73);
}
.login-card {
  background: #fff;
  padding: 32px;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { margin: 0 0 8px; font-size: 20px; text-align: center; }
.login-card label { display: flex; flex-direction: column; font-size: 12px; gap: 4px; }
.login-card input { padding: 8px; border: 1px solid var(--border); border-radius: 3px; font-size: 14px; }
.login-card button { padding: 10px; background: var(--accent); color: #fff; border: none; border-radius: 3px; cursor: pointer; font-size: 14px; }
.error-text { color: #b00020; font-size: 12px; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  position: sticky;
  top: 0; z-index: 1000;
}
.brand { font-weight: bold; }
.breadcrumb { flex: 1; display: flex; gap: 4px; flex-wrap: wrap; }
.breadcrumb a { color: var(--accent); text-decoration: none; cursor: pointer; }
.breadcrumb span.sep { color: #666; }
.top-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.selection-actions { display: inline-flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px; background: #fff; border: 1px solid var(--border);
  border-radius: 3px; cursor: pointer; font-size: 13px; text-decoration: none; color: #222;
}
.btn:active { background: #ddd; }
.btn-primary { background: var(--accent); color: #fff; border-color: #1a428a; }
.btn-primary:active { background: #163b73; }
.btn-danger { color: #b00020; border-color: #d32f2f; }
.btn-danger:hover { background: #ffebee; }

/* ---------- Toast Notifications ---------- */
.ui-toast-container {
  position: fixed; top: 16px; right: 16px; z-index: 3000;
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.ui-toast {
  background: #323232; color: #fff; padding: 10px 16px; border-radius: 4px;
  font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  pointer-events: auto; transition: opacity 0.3s ease;
}
.ui-toast.fade-out { opacity: 0; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: calc(100vh - 48px); }
.sidebar {
  width: 200px; background: #f4f2ec; border-right: 1px solid var(--border);
  padding: 8px; overflow-y: auto;
}
.sidebar h2 { font-size: 12px; text-transform: uppercase; color: #666; margin: 4px 0; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { padding: 6px 8px; cursor: pointer; border-radius: 3px; }
.sidebar li:hover, .sidebar li.active { background: var(--accent); color: #fff; }
.content { flex: 1; padding: 8px; overflow-x: auto; }

/* ---------- File Table ---------- */
.file-table { width: 100%; border-collapse: collapse; background: #fff; }
.file-table th, .file-table td { padding: 6px 8px; border-bottom: 1px solid #ddd; text-align: left; white-space: nowrap; }
.file-table th { background: var(--bg-header); position: sticky; top: 0; }
.file-table tbody tr:nth-child(even) { background: var(--bg-row-alt); }
.file-table tbody tr:hover { background: #dbe8ff; }
.file-table .name-cell { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.col-check { width: 28px; }
.empty-message { padding: 16px; color: #666; }

/* ---------- Floating Widgets ---------- */
.floating-widget {
  position: fixed; width: 340px;
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25); z-index: 1000; max-height: 50vh;
  display: flex; flex-direction: column;
}
#download-queue-widget { bottom: 12px; right: 12px; }
#upload-queue-widget { bottom: 12px; right: 364px; }
.widget-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px; background: var(--bg-header); border-radius: 6px 6px 0 0; font-weight: bold;
}
.widget-header button { border: none; background: transparent; cursor: pointer; font-size: 14px; }
.widget-header-actions { display: flex; align-items: center; gap: 6px; }
.widget-control-label {
  font-size: 11px; font-weight: normal; display: inline-flex; align-items: center; gap: 3px; color: #333;
}
.widget-select {
  font-size: 11px; padding: 2px 4px; border: 1px solid var(--border); border-radius: 3px; background: #fff; cursor: pointer;
}
.widget-select-sm {
  font-size: 11px; padding: 1px 4px; border: 1px solid var(--border); border-radius: 3px; background: #fff; cursor: pointer;
}
.widget-toolbar {
  display: flex; justify-content: space-between; align-items: center; padding: 4px 10px;
  background: #f7f6f2; border-bottom: 1px solid #ddd; font-size: 11px; gap: 6px;
}
.widget-toolbar-actions {
  display: flex; align-items: center; gap: 4px;
}
.speed-limit-label {
  display: inline-flex; align-items: center; gap: 4px; color: #555;
}
.widget-body { padding: 8px; overflow-y: auto; flex: 1; max-height: 45vh; }
.widget-footer {
  padding: 6px 10px; background: #f7f6f2; border-top: 1px solid #ddd;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.widget-footer button:only-child, .widget-footer label:only-child {
  margin-left: auto;
}
.widget-upload-btn {
  margin: 0; cursor: pointer;
}
.btn-sm {
  padding: 3px 8px; font-size: 11px;
}
.queue-item { margin-bottom: 10px; font-size: 12px; padding: 4px 0; border-bottom: 1px dashed #eee; transition: background 0.3s ease, border-color 0.3s ease; }
.queue-item:last-child { border-bottom: none; }
.queue-item.has-conflict {
  background: #fffbeb; border: 1px solid #f59e0b; border-radius: 4px;
  padding: 8px; animation: conflict-pulse 2.5s infinite ease-in-out;
}
@keyframes conflict-pulse {
  0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); }
  50% { box-shadow: 0 0 6px 2px rgba(245, 158, 11, 0.25); }
  100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); }
}
.conflict-panel {
  margin-top: 6px; padding: 6px 8px; background: #fef3c7; border-radius: 4px; border: 1px solid #fde68a;
  display: flex; flex-direction: column; gap: 6px;
}
.conflict-header {
  display: flex; align-items: center; gap: 5px; font-size: 11px; color: #92400e; word-break: break-all;
}
.conflict-icon { font-size: 13px; }
.conflict-title strong { color: #78350f; }
.conflict-buttons {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.btn-conflict {
  padding: 3px 8px; font-size: 11px; font-weight: 500; border-radius: 3px; cursor: pointer; border: 1px solid #d97706; background: #fff;
}
.btn-conflict:hover { background: #fef9c3; }
.btn-conflict-overwrite { color: #b45309; border-color: #d97706; }
.btn-conflict-rename { color: #1d4ed8; border-color: #3b82f6; }
.btn-conflict-skip { color: #4b5563; border-color: #9ca3af; }
.conflict-apply-all-label {
  font-size: 11px; color: #78350f; display: inline-flex; align-items: center; gap: 4px; cursor: pointer; user-select: none;
}
.queue-item .item-name { display: flex; justify-content: space-between; margin-bottom: 3px; font-weight: 500; }
.progress-bar { height: 8px; background: #eee; border-radius: 4px; overflow: hidden; }
.progress-bar .fill { height: 100%; background: var(--accent); width: 0%; transition: width .15s; }
.item-meta { display: flex; justify-content: space-between; align-items: center; color: #666; margin-top: 3px; font-size: 11px; }
.item-actions { display: inline-flex; gap: 4px; }
.btn-item-action {
  border: 1px solid var(--border); background: #fff; border-radius: 3px;
  cursor: pointer; font-size: 10px; padding: 1px 5px; line-height: 1.2;
}
.btn-item-action:hover { background: #e0e0e0; }
.btn-pause { color: #d97706; }
.btn-stop { color: #dc2626; }
.btn-resume { color: #16a34a; }
.btn-cancel { color: #6b7280; font-weight: bold; }

@media (max-width: 760px) {
  .sidebar { display: none; }
  .floating-widget { width: calc(100vw - 24px); right: 12px !important; }
  #download-queue-widget { bottom: 12px; }
  #upload-queue-widget { bottom: calc(48vh + 20px); }
}
