/* ============================================================
   TagSave — Estilos principales
   Mobile-first, CSS variables, sin dependencias externas
============================================================ */

/* ── Variables ──────────────────────────────────────────────── */
:root {
  --primary:      #6366f1;
  --primary-dark: #4f46e5;
  --primary-light:#ede9fe;
  --danger:       #ef4444;
  --success:      #10b981;
  --warning:      #f59e0b;

  --bg:           #f8fafc;
  --bg-card:      #ffffff;
  --bg-sidebar:   #f1f5f9;
  --border:       #e2e8f0;

  --text:         #1e293b;
  --text-muted:   #64748b;
  --text-light:   #94a3b8;

  --radius:       .75rem;
  --radius-sm:    .4rem;
  --shadow:       0 1px 4px rgba(0,0,0,.08), 0 2px 16px rgba(0,0,0,.06);
  --shadow-md:    0 4px 24px rgba(0,0,0,.12);

  --header-h:     56px;
  --sidebar-w:    220px;
  --font:         'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
button { cursor: pointer; font-family: var(--font); }
input, textarea, select { font-family: var(--font); }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .5rem 1rem; border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 500; border: 1.5px solid transparent;
  transition: background .15s, color .15s, border-color .15s, opacity .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost   { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-sidebar); }
.btn-danger  { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { opacity: .85; }
.btn-block   { display: flex; width: 100%; justify-content: center; }
.btn-sm      { padding: .3rem .7rem; font-size: .8rem; }
.btn-icon    { background: transparent; border: none; padding: .3rem; border-radius: var(--radius-sm); color: var(--text-muted); display: flex; align-items: center; }
.btn-icon:hover { background: var(--border); color: var(--text); }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .35rem; color: var(--text); }
.form-input, input[type=text], input[type=email], input[type=url], input[type=color], textarea, select {
  width: 100%; padding: .55rem .75rem;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; color: var(--text); font-size: .9rem;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-input:focus, input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
textarea { resize: vertical; min-height: 70px; }
.required { color: var(--danger); }

/* ── Alerts ─────────────────────────────────────────────────── */
.alert { padding: .65rem 1rem; border-radius: var(--radius-sm); font-size: .875rem; margin-bottom: 1rem; }
.alert-error   { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

/* ── Toggle switch ──────────────────────────────────────────── */
.toggle-label { display: flex; align-items: center; gap: .6rem; cursor: pointer; font-size: .875rem; font-weight: 500; }
.toggle-label input[type=checkbox] { display: none; }
.toggle-switch {
  width: 40px; height: 22px; background: var(--border); border-radius: 99px;
  position: relative; transition: background .2s; flex-shrink: 0;
}
.toggle-switch::after {
  content: ''; position: absolute; width: 16px; height: 16px;
  background: #fff; border-radius: 50%; top: 3px; left: 3px;
  transition: left .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
input[type=checkbox]:checked + .toggle-switch { background: var(--primary); }
input[type=checkbox]:checked + .toggle-switch::after { left: 21px; }
.visibility-toggle { padding: .75rem; background: var(--bg-sidebar); border-radius: var(--radius-sm); }
.visibility-toggle small { display: block; color: var(--text-muted); font-size: .78rem; margin-top: .3rem; margin-left: 2.5rem; }

/* ── Checkbox label ─────────────────────────────────────────── */
.checkbox-label { display: flex; align-items: center; gap: .5rem; cursor: pointer; font-size: .875rem; margin-top: .5rem; }
.checkbox-label input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }

/* ═══════════════════════════════════════════════════════════
   AUTH PAGE
═══════════════════════════════════════════════════════════ */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 1rem;
  background: linear-gradient(135deg, #ede9fe 0%, #e0e7ff 50%, #dbeafe 100%);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--bg-card); border-radius: var(--radius);
  padding: 2rem; box-shadow: var(--shadow-md);
}
.auth-logo { display: flex; align-items: center; gap: .6rem; margin-bottom: .5rem; color: var(--primary); }
.auth-logo h1 { font-size: 1.5rem; font-weight: 700; color: var(--text); }
.auth-logo svg { color: var(--primary); }
.auth-subtitle { color: var(--text-muted); font-size: .875rem; margin-bottom: 1.5rem; }
.auth-form { margin-top: 1rem; }

/* ═══════════════════════════════════════════════════════════
   APP LAYOUT
═══════════════════════════════════════════════════════════ */
.app-page { display: flex; flex-direction: column; min-height: 100vh; }

/* Header */
.app-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h); background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem; box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.header-left { display: flex; align-items: center; gap: .5rem; }
.app-logo-icon { color: var(--primary); }
.app-logo-text { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.header-right { display: flex; align-items: center; gap: .75rem; }
.user-email { font-size: .8rem; color: var(--text-muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Layout */
.app-layout { display: flex; flex: 1; height: calc(100vh - var(--header-h)); overflow: hidden; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: .85rem 1rem; font-size: .8rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted);
  position: sticky; top: 0; background: var(--bg-sidebar); border-bottom: 1px solid var(--border);
}

/* Tag list */
.tag-list { padding: .5rem 0; flex: 1; }
.tag-item {
  display: flex; align-items: center; gap: .5rem;
  width: 100%; padding: .5rem 1rem;
  background: transparent; border: none; text-align: left; font-size: .875rem;
  color: var(--text); border-radius: 0; transition: background .1s;
  cursor: pointer;
}
.tag-item:hover { background: rgba(0,0,0,.05); }
.tag-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.tag-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.tag-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-count { font-size: .75rem; color: var(--text-muted); background: rgba(0,0,0,.08); padding: .1rem .4rem; border-radius: 99px; }
.tag-item.active .tag-count { background: rgba(99,102,241,.15); color: var(--primary); }

/* Main */
.main-content { flex: 1; overflow-y: auto; padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.content-toolbar { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.search-wrap { position: relative; flex: 1; min-width: 180px; }
.search-icon { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search-input { padding-left: 2.2rem !important; }

/* Entries grid */
.entries-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }

/* Entry card */
.entry-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; display: flex; flex-direction: column;
  transition: transform .15s, box-shadow .15s; cursor: pointer;
}
.entry-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.entry-thumbnail { height: 160px; overflow: hidden; background: var(--bg-sidebar); }
.entry-thumbnail img { width: 100%; height: 100%; object-fit: cover; }
.entry-body { padding: .9rem; display: flex; flex-direction: column; gap: .4rem; flex: 1; }
.entry-source { display: flex; align-items: center; justify-content: space-between; }
.entry-date { font-size: .75rem; color: var(--text-muted); }
.entry-title { font-size: .95rem; font-weight: 600; line-height: 1.4; }
.entry-title a { color: var(--text); }
.entry-title a:hover { color: var(--primary); }
.entry-desc { font-size: .82rem; color: var(--text-muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.entry-link { font-size: .8rem; color: var(--primary); font-weight: 500; margin-top: auto; }
.entry-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .3rem; }
.entry-tag-chip {
  font-size: .72rem; padding: .15rem .5rem; border-radius: 99px;
  background: rgba(99,102,241,.1); color: var(--primary);
  white-space: nowrap;
}

/* Source chips */
.source-chip { font-size: .72rem; padding: .2rem .5rem; border-radius: var(--radius-sm); background: var(--bg-sidebar); color: var(--text-muted); font-weight: 500; }
.source-youtube   { background: #fff0f0; color: #cc0000; }
.source-spotify   { background: #f0fff4; color: #1db954; }
.source-instagram { background: #fff0f7; color: #c13584; }
.source-facebook  { background: #f0f4ff; color: #1877f2; }
.source-linkedin  { background: #f0f7ff; color: #0a66c2; }
.source-qr        { background: #f9fafb; color: #374151; }

/* Empty / loading states */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state p { margin-bottom: 1rem; }
.loading-state { display: flex; flex-direction: column; align-items: center; gap: 1rem; padding: 3rem; color: var(--text-muted); }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════════════════════════════════════
   MODALS
═══════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.45); backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center; padding: 1rem;
}
@media (min-width: 600px) { .modal-overlay { align-items: center; } }

.modal {
  background: var(--bg-card); border-radius: var(--radius);
  width: 100%; max-width: 540px; max-height: 90vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-md);
  animation: slideUp .2s ease;
}
.modal-sm  { max-width: 380px; }
.modal-wide { max-width: 680px; }

@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1rem; font-weight: 700; }
.modal-body { padding: 1.25rem; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 1rem 1.25rem; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: .5rem;
}

/* Source tabs */
.source-tabs { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: 1rem; }
.source-tab {
  padding: .3rem .65rem; border-radius: var(--radius-sm);
  font-size: .78rem; font-weight: 500; border: 1.5px solid var(--border);
  background: #fff; color: var(--text-muted); transition: all .1s;
}
.source-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.source-tab:hover:not(.active) { border-color: var(--primary); color: var(--primary); }

/* URL input + button */
.url-input-wrap { display: flex; gap: .5rem; }
.url-input-wrap input { flex: 1; }

/* Tags selector (checkboxes) */
.tags-selector { display: flex; flex-wrap: wrap; gap: .4rem; }
.tag-check-label {
  display: flex; align-items: center; gap: .3rem; padding: .3rem .65rem;
  border-radius: 99px; border: 1.5px solid var(--border); cursor: pointer;
  font-size: .8rem; font-weight: 500; transition: all .1s;
}
.tag-check-label input { display: none; }
.tag-check-label.selected { color: #fff; border-color: transparent; }
.tag-check-label:not(.selected):hover { border-color: var(--primary); }

/* QR Scanner */
.qr-viewport {
  position: relative; width: 100%; padding-top: 60%; background: #000;
  border-radius: var(--radius-sm); overflow: hidden; margin-bottom: .75rem;
}
#qr-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.qr-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(transparent 30%, rgba(0,0,0,.4) 100%);
  pointer-events: none;
}
.qr-overlay::before {
  content: ''; position: absolute; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  width: 55%; padding-top: 55%; border: 2.5px solid rgba(255,255,255,.8);
  border-radius: var(--radius-sm); box-shadow: 0 0 0 4000px rgba(0,0,0,.4);
}
.qr-status { font-size: .82rem; color: var(--text-muted); margin-bottom: .5rem; }

/* Color picker */
.color-picker-wrap { display: flex; align-items: center; gap: .75rem; }
.color-input { width: 44px; height: 38px; padding: 2px; cursor: pointer; flex-shrink: 0; }
.color-presets { display: flex; gap: .4rem; flex-wrap: wrap; }
.color-preset {
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 2.5px solid transparent; transition: transform .1s, border-color .1s;
}
.color-preset:hover, .color-preset.selected { transform: scale(1.15); border-color: var(--text); }

/* Tag opts modal */
.tag-opts-public { margin-bottom: 1.25rem; }
.tag-opts-danger { padding-top: 1rem; border-top: 1px solid var(--border); }
.public-url-wrap { display: flex; gap: .5rem; margin-top: .4rem; }
.public-url-wrap input { flex: 1; font-size: .8rem; }
.terms-box { background: var(--bg-sidebar); border-radius: var(--radius-sm); padding: .75rem; margin-top: .75rem; font-size: .82rem; color: var(--text-muted); }
.terms-box p { margin-bottom: .5rem; }

/* View modal */
#view-body .view-source { display: flex; align-items: center; gap: .5rem; margin-bottom: .75rem; }
#view-body .view-thumbnail { border-radius: var(--radius-sm); overflow: hidden; margin-bottom: .75rem; max-height: 220px; }
#view-body .view-thumbnail img { width: 100%; object-fit: cover; }
#view-body .view-url a { font-size: .85rem; color: var(--primary); word-break: break-all; }
#view-body .view-section { margin-top: .9rem; }
#view-body .view-section-label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: .3rem; }
#view-body .view-tags { display: flex; flex-wrap: wrap; gap: .3rem; }

/* ═══════════════════════════════════════════════════════════
   PUBLIC PAGE
═══════════════════════════════════════════════════════════ */
.public-page { background: var(--bg); }
.public-header { background: #fff; border-bottom: 1px solid var(--border); }
.public-header-inner { max-width: 900px; margin: 0 auto; padding: .75rem 1.25rem; display: flex; align-items: center; justify-content: space-between; }
.app-brand { display: flex; align-items: center; gap: .4rem; color: var(--text); font-weight: 700; }
.app-brand svg { color: var(--primary); }
.public-content { max-width: 900px; margin: 0 auto; padding: 2rem 1.25rem; }
.public-tag-header { text-align: center; padding: 2rem 0 1.5rem; }
.public-tag-header h1 { font-size: 1.75rem; font-weight: 800; margin: .75rem 0 .4rem; }
.public-tag-header p { color: var(--text-muted); }
.tag-badge-lg { display: inline-block; padding: .3rem 1rem; border-radius: 99px; border: 1.5px solid; font-weight: 600; font-size: .9rem; }
.public-notice {
  display: flex; align-items: flex-start; gap: .5rem;
  background: #f0f9ff; border: 1px solid #bae6fd; border-radius: var(--radius-sm);
  padding: .6rem .9rem; font-size: .8rem; color: #0369a1; margin-bottom: 1.5rem;
}
.public-grid { margin-top: .5rem; }
.public-error { text-align: center; padding: 4rem 1rem; }
.public-error h2 { font-size: 1.5rem; margin-bottom: .75rem; }
.public-error p  { color: var(--text-muted); margin-bottom: 1.5rem; }
.public-footer { text-align: center; padding: 2rem; color: var(--text-muted); font-size: .82rem; border-top: 1px solid var(--border); margin-top: 3rem; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 640px) {
  :root { --sidebar-w: 100%; }
  .sidebar { display: none; position: fixed; inset: 0; z-index: 150; width: 80%; max-width: 280px; top: var(--header-h); height: calc(100vh - var(--header-h)); box-shadow: var(--shadow-md); }
  .sidebar.open { display: flex; }
  #btn-toggle-sidebar { display: flex !important; }
  .user-email { display: none; }
  .entries-grid { grid-template-columns: 1fr; }
}
@media (min-width: 641px) {
  #btn-toggle-sidebar { display: none !important; }
}
