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

:root {
  --bg: #09090b;
  --bg-raised: #111113;
  --bg-surface: #18181b;
  --bg-hover: #1f1f23;
  --bg-active: #27272a;
  --text: #fafafa;
  --text-secondary: #a1a1aa;
  --text-muted: #71717a;
  --border: #27272a;
  --border-light: #3f3f46;
  --primary: #818cf8;
  --primary-hover: #6366f1;
  --primary-bg: rgba(99, 102, 241, 0.12);
  --danger: #f87171;
  --danger-bg: rgba(239, 68, 68, 0.12);
  --radius: 12px;
  --radius-lg: 16px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.5);
  --transition: 150ms ease;
  --font: 'Inter', -apple-system, system-ui, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

/* === Layout === */
#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 40px 0;
  gap: 16px;
}

header h1 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.03em;
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  font-size: 28px;
}

.subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
  font-weight: 400;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* === Main Grid === */
main {
  flex: 1;
  padding: 32px 40px 48px;
}

.category-section {
  margin-bottom: 36px;
}

.category-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 14px;
  padding-left: 2px;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

/* === App Card === */
.app-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: default;
  transition: all 200ms ease;
  position: relative;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.app-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--card-accent, var(--primary));
  opacity: 0;
  transition: opacity 200ms ease;
}

.app-card:hover {
  border-color: var(--border-light);
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}

.app-card:hover::before {
  opacity: 1;
}

.app-card-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.app-card-icon svg {
  width: 22px;
  height: 22px;
}

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

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

.app-card-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.app-card-links {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.app-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 4px;
  text-decoration: none;
  transition: all 150ms ease;
}

.app-link .icon-xs {
  width: 12px;
  height: 12px;
}

.app-link-ts {
  color: #60a5fa;
  background: rgba(96, 165, 250, 0.1);
}

.app-link-ts:hover {
  background: rgba(96, 165, 250, 0.25);
  color: #93bbfd;
}

.app-link-lan {
  color: #34d399;
  background: rgba(52, 211, 153, 0.1);
}

.app-link-lan:hover {
  background: rgba(52, 211, 153, 0.25);
  color: #6ee7b7;
}

.app-card-external {
  position: absolute;
  top: 12px;
  right: 12px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity var(--transition);
}

.app-card:hover .app-card-external {
  opacity: 0.6;
}

.app-card-edit {
  position: absolute;
  bottom: 10px;
  right: 10px;
  opacity: 0;
  transition: opacity var(--transition);
}

.app-card:hover .app-card-edit {
  opacity: 1;
}

/* === Empty State === */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state h2 {
  font-size: 20px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

/* === Modals === */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 150ms ease;
}

.modal {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp 200ms ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
}

.spacer { flex: 1; }

/* === Forms === */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-row {
  display: flex;
  gap: 14px;
}

.flex-1 { flex: 1; }

.input {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 8px 12px;
  font-family: var(--font);
  transition: border-color var(--transition);
}

.input:focus {
  border-color: var(--primary);
  outline: none;
}

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

.icon-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.icon-input-row .input { flex: 1; }

.icon-preview {
  width: 40px;
  height: 40px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--primary);
}

.icon-preview svg {
  width: 20px;
  height: 20px;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-row input[type="color"] {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  cursor: pointer;
  padding: 2px;
}

.color-presets {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.color-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
}

.color-dot:hover {
  transform: scale(1.15);
  border-color: rgba(255,255,255,0.3);
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

/* === Categories Settings === */
#category-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.category-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
}

.category-item span {
  flex: 1;
  font-size: 13px;
}

.add-category-row {
  display: flex;
  gap: 8px;
}

.add-category-row .input { flex: 1; }

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

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

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
}

.btn-danger:hover {
  background: var(--danger);
  color: white;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

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

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

.icon-sm {
  width: 16px;
  height: 16px;
}

/* === Utility === */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.link { color: var(--primary); text-decoration: none; }
.link:hover { text-decoration: underline; }

/* === Toast === */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 200ms ease, fadeOut 200ms ease 2.8s forwards;
}

/* === Animations === */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes cardIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

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

/* === Responsive === */
@media (max-width: 768px) {
  header { padding: 16px 20px 0; }
  main { padding: 24px 20px 32px; }
  header h1 { font-size: 20px; }
  .app-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .app-card { padding: 16px; }
  .form-row { flex-direction: column; gap: 0; }
}
