/* ============================================
   URL-Management — Modern Frontend Stylesheet
   Clean, responsive design with CSS variables.
   ============================================ */

:root {
  /* Light theme (default) */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-card: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #6c757d;
  --accent: #4361ee;
  --accent-hover: #3a56d4;
  --border: #e9ecef;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --radius: 8px;
  --success: #2ec4b6;
  --danger: #e63946;
  --warning: #f77f0b;

  /* Layout */
  --max-width: 1100px;
  --sidebar-width: 240px;
}

[data-theme="dark"] {
  --bg-primary: #0f0f23;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --text-primary: #edf2f4;
  --text-secondary: #9ca3af;
  --accent: #4cc9f0;
  --accent-hover: #3db8dd;
  --border: #2d3748;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ───────────────────────────────────── */
.app-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.header-logo {
  height: 48px;
  width: auto;
  object-fit: contain;
  border-radius: 6px;
  margin-right: -4px;
}

.header h1 { font-size: 1.5rem; }

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

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

/* ── Admin Dropdown ─────────────────────────── */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  min-width: 220px;
  padding: 6px 0;
  z-index: 1001;
}

.dropdown-menu.open {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s ease;
}

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

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

/* ── Buttons ──────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover { box-shadow: var(--shadow); }

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

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

.btn-sm { padding: 4px 10px; font-size: 0.8rem; }

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

.btn-check {
  background: rgba(67, 97, 238, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}
.btn-check:hover:not(:disabled) {
  background: rgba(67, 97, 238, 0.2);
}

.btn-meta {
  background: rgba(46, 196, 182, 0.1);
  border-color: var(--success);
  color: var(--success);
}
.btn-meta:hover:not(:disabled) {
  background: rgba(46, 196, 182, 0.2);
}

.btn-cooldown {
  opacity: 0.5;
  cursor: not-allowed;
  color: var(--text-secondary);
}
.btn-edit {
  background: rgba(99, 132, 255, 0.1);
  border-color: var(--accent);
  color: var(--accent);
}
.btn-edit:hover:not(:disabled) {
  background: rgba(99, 132, 255, 0.2);
}

/* ── Inputs ───────────────────────────────────── */
input[type="text"],
input[type="password"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.9rem;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(67, 97, 238, 0.15);
}

/* ── Cards / URL Items ───────────────────────── */
.url-list { display: flex; flex-direction: column; gap: 8px; }

.url-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
  transition: transform 0.1s ease;
}

.url-card:hover { transform: translateY(-1px); }

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

.url-title { font-weight: 600; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.url-desc {
  color: var(--text-secondary);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.url-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  background: var(--bg-secondary);
  color: var(--text-secondary);
}

.badge-success { background: rgba(46, 196, 182, 0.15); color: var(--success); }
.badge-danger { background: rgba(230, 57, 70, 0.15); color: var(--danger); }
.badge-subgroup {
  opacity: 0.7;
  font-style: italic;
}

.url-actions { display: flex; gap: 4px; margin-left: 12px; flex-shrink: 0; }

/* ── Category Sections ──────────────────────── */
.category-section { margin-bottom: 16px; }

.category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  font-weight: 600;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
}

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

.category-arrow {
  font-size: 0.7rem;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.category-section.collapsed .category-arrow {
  transform: rotate(-90deg);
}

.category-count {
  margin-left: auto;
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-secondary);
}

.category-body {
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.2s ease;
  max-height: 5000px;
  opacity: 1;
}

.category-section.collapsed .category-body {
  max-height: 0;
  opacity: 0;
}

/* ── Modal / Forms ─────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  width: 90%; max-width: 480px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.modal h2 { margin-bottom: 16px; }

.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 4px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* ── Login Screen ─────────────────────────────── */
.login-container {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
}

.login-box {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px; width: 90%; max-width: 380px;
  box-shadow: var(--shadow);
}

.login-logo {
  display: block;
  margin: 0 auto 16px;
  height: 56px;
  width: auto;
  object-fit: contain;
  border-radius: 8px;
}

.login-box h2 { text-align: center; margin-bottom: 24px; }
.login-error { color: var(--danger); font-size: 0.85rem; text-align: center; margin-top: 8px; }

/* ── Stats Bar ─────────────────────────────── */
.stats-bar { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }

.stat-chip {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 14px; font-size: 0.85rem;
}

.stat-value { font-weight: 700; color: var(--accent); }

/* ── Utilities ─────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--text-secondary); }
.mt-2 { margin-top: 8px; }
.mb-2 { margin-bottom: 8px; }

/* ── Toast Notifications ──────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  max-width: 380px;
  font-size: 0.875rem;
  line-height: 1.4;
  pointer-events: auto;
  animation: toast-in 0.25s ease-out forwards;
}

.toast.hiding {
  animation: toast-out 0.3s ease-in forwards;
}

.toast-success { border-left: 4px solid var(--success); }
.toast-warning { border-left: 4px solid var(--warning); }
.toast-error   { border-left: 4px solid var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(-8px) scale(0.97); }
}

/* ── Permissions Config Modal ─────────────────── */
.modal-wide {
  max-width: 640px;
}

.perm-matrix {
  overflow-x: auto;
  margin-top: 8px;
}

/* ── Permission list layout (per-category text input) ── */
.perm-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-surface);
}

.perm-cat-label {
  font-weight: bold;
  min-width: 140px;
  color: var(--text-primary);
  flex-shrink: 0;
}

.perm-input {
  flex: 1;
  padding: .4rem .6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.perm-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(136, 148, 255, 0.15);
}

/* ── Scrollbar for #perm-list ── */
#perm-list::-webkit-scrollbar { width: 8px; }
#perm-list::-webkit-scrollbar-track { background: transparent; }
#perm-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}
#perm-list::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}
