/* ============================================================
   Personal Platform — Design System (shadcn-inspired)
   ============================================================ */

/* --- CSS Variables / Theme --- */
:root {
    --background: 0 0% 100%;
    --foreground: 240 10% 3.9%;
    --card: 0 0% 100%;
    --card-foreground: 240 10% 3.9%;
    --popover: 0 0% 100%;
    --popover-foreground: 240 10% 3.9%;
    --primary: 240 5.9% 10%;
    --primary-foreground: 0 0% 98%;
    --secondary: 240 4.8% 95.9%;
    --secondary-foreground: 240 5.9% 10%;
    --muted: 240 4.8% 95.9%;
    --muted-foreground: 240 3.8% 46.1%;
    --accent: 240 4.8% 95.9%;
    --accent-foreground: 240 5.9% 10%;
    --destructive: 0 84.2% 60.2%;
    --destructive-foreground: 0 0% 98%;
    --success: 142 76% 36%;
    --success-foreground: 0 0% 98%;
    --warning: 38 92% 50%;
    --warning-foreground: 0 0% 98%;
    --border: 240 5.9% 90%;
    --input: 240 5.9% 90%;
    --ring: 240 5.9% 10%;
    --radius: 0.5rem;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --background: 240 10% 3.9%;
        --foreground: 0 0% 98%;
        --card: 240 10% 3.9%;
        --card-foreground: 0 0% 98%;
        --popover: 240 10% 3.9%;
        --popover-foreground: 0 0% 98%;
        --primary: 0 0% 98%;
        --primary-foreground: 240 5.9% 10%;
        --secondary: 240 3.7% 15.9%;
        --secondary-foreground: 0 0% 98%;
        --muted: 240 3.7% 15.9%;
        --muted-foreground: 240 5% 64.9%;
        --accent: 240 3.7% 15.9%;
        --accent-foreground: 0 0% 98%;
        --destructive: 0 62.8% 30.6%;
        --destructive-foreground: 0 0% 98%;
        --border: 240 3.7% 15.9%;
        --input: 240 3.7% 15.9%;
        --ring: 240 4.9% 83.9%;
    }
}

[data-theme="dark"] {
    --background: 240 10% 3.9%;
    --foreground: 0 0% 98%;
    --card: 240 10% 3.9%;
    --card-foreground: 0 0% 98%;
    --popover: 240 10% 3.9%;
    --popover-foreground: 0 0% 98%;
    --primary: 0 0% 98%;
    --primary-foreground: 240 5.9% 10%;
    --secondary: 240 3.7% 15.9%;
    --secondary-foreground: 0 0% 98%;
    --muted: 240 3.7% 15.9%;
    --muted-foreground: 240 5% 64.9%;
    --accent: 240 3.7% 15.9%;
    --accent-foreground: 0 0% 98%;
    --destructive: 0 62.8% 30.6%;
    --destructive-foreground: 0 0% 98%;
    --border: 240 3.7% 15.9%;
    --input: 240 3.7% 15.9%;
    --ring: 240 4.9% 83.9%;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-sans);
    background: hsl(var(--background));
    color: hsl(var(--foreground));
    line-height: 1.5;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    padding-bottom: 4.5rem; /* space for bottom nav */
}

a {
    color: hsl(var(--primary));
    text-decoration: none;
}

img {
    max-width: 100%;
    height: auto;
}

/* --- Typography --- */
h1, h2, h3, h4 {
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.125rem; }

.text-muted {
    color: hsl(var(--muted-foreground));
}

.text-sm {
    font-size: 0.875rem;
}

.text-xs {
    font-size: 0.75rem;
}

/* --- Layout --- */
.container {
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
    padding: 0 1rem;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
    gap: 0.5rem;
}

.page-header h1 {
    flex: 1;
}

/* --- Card --- */
.card {
    background: hsl(var(--card));
    color: hsl(var(--card-foreground));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    transition: box-shadow 0.15s ease;
}

.card:hover {
    box-shadow: 0 1px 3px hsla(var(--foreground), 0.08);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.card-description {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-footer {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.card-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
}

/* --- Button --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    white-space: nowrap;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    height: 2.25rem;
    padding: 0 1rem;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    font-family: inherit;
}

.btn:disabled {
    opacity: 0.5;
    pointer-events: none;
}

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

.btn-primary:hover {
    opacity: 0.9;
}

.btn-secondary {
    background: hsl(var(--secondary));
    color: hsl(var(--secondary-foreground));
}

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

.btn-outline {
    border: 1px solid hsl(var(--input));
    background: transparent;
    color: hsl(var(--foreground));
}

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

.btn-destructive {
    background: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
}

.btn-destructive:hover {
    opacity: 0.9;
}

.btn-ghost {
    background: transparent;
    color: hsl(var(--foreground));
    border: none;
}

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

.btn-sm {
    height: 1.75rem;
    padding: 0 0.75rem;
    font-size: 0.75rem;
}

.btn-icon {
    width: 2.25rem;
    padding: 0;
}

.btn-icon.btn-sm {
    width: 1.75rem;
}

.btn-block {
    width: 100%;
}

/* --- Input --- */
.input-group {
    margin-bottom: 1rem;
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
}

.input, input[type="text"], input[type="password"], input[type="email"],
input[type="number"], input[type="url"], input[type="search"], textarea, select {
    width: 100%;
    height: 2.5rem;
    padding: 0 0.75rem;
    border: 1px solid hsl(var(--input));
    border-radius: var(--radius);
    background: transparent;
    color: hsl(var(--foreground));
    font-size: 1rem; /* 16px — previene auto-zoom su iOS */
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}

textarea {
    height: auto;
    min-height: 5rem;
    padding: 0.5rem 0.75rem;
    resize: vertical;
}

select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

.input:focus, input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 2px hsla(var(--ring), 0.2);
}

.input::placeholder, input::placeholder, textarea::placeholder {
    color: hsl(var(--muted-foreground));
}

/* --- Badge --- */
.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 9999px;
    padding: 0.125rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
}

.badge-default {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}

.badge-secondary {
    background: hsl(var(--secondary));
    color: hsl(var(--secondary-foreground));
}

.badge-outline {
    border: 1px solid hsl(var(--border));
    color: hsl(var(--foreground));
}

.badge-destructive {
    background: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
}

.badge-success {
    background: hsl(var(--success));
    color: hsl(var(--success-foreground));
}

.badge-warning {
    background: hsl(var(--warning));
    color: hsl(var(--warning-foreground));
}

/* --- Tabs --- */
.tabs {
    display: flex;
    border-bottom: 1px solid hsl(var(--border));
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab {
    flex-shrink: 0;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: hsl(var(--muted-foreground));
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
    white-space: nowrap;
}

.tab:hover {
    color: hsl(var(--foreground));
}

.tab.active {
    color: hsl(var(--foreground));
    border-bottom-color: hsl(var(--primary));
}

/* Sub-tabs (category selector) */
.sub-tabs {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.sub-tabs::-webkit-scrollbar {
    display: none;
}

.sub-tab {
    flex-shrink: 0;
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: var(--radius);
    background: hsl(var(--secondary));
    color: hsl(var(--secondary-foreground));
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

.sub-tab:hover {
    background: hsl(var(--accent));
}

.sub-tab.active {
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
}

/* --- Bottom Navigation --- */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: hsl(var(--card));
    border-top: 1px solid hsl(var(--border));
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 3.5rem;
    z-index: 50;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
    padding: 0.375rem 0.75rem;
    color: hsl(var(--muted-foreground));
    text-decoration: none;
    font-size: 0.625rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
    position: relative;
    transition: color 0.15s;
}

.nav-item:hover, .nav-item.active {
    color: hsl(var(--primary));
}

.nav-item svg {
    width: 1.25rem;
    height: 1.25rem;
}

.nav-badge {
    position: absolute;
    top: 0;
    right: 0.25rem;
    background: hsl(var(--destructive));
    color: hsl(var(--destructive-foreground));
    font-size: 0.625rem;
    min-width: 1rem;
    height: 1rem;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

/* --- FAB (Floating Action Button) --- */
.fab {
    position: fixed;
    bottom: 4.5rem;
    right: 1rem;
    width: 3rem;
    height: 3rem;
    border-radius: 9999px;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px hsla(var(--foreground), 0.15);
    transition: transform 0.15s, box-shadow 0.15s;
    z-index: 40;
}

.fab:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px hsla(var(--foreground), 0.2);
}

.fab svg {
    width: 1.5rem;
    height: 1.5rem;
}

/* --- Dialog / Modal --- */
.dialog-overlay {
    position: fixed;
    inset: 0;
    background: hsla(var(--foreground), 0.5);
    z-index: 100;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: fadeIn 0.15s ease;
}

@media (min-width: 640px) {
    .dialog-overlay {
        align-items: center;
    }
}

.dialog {
    background: hsl(var(--card));
    border-radius: var(--radius) var(--radius) 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 90dvh;
    overflow-y: auto;
    padding: 1.5rem;
    animation: slideUp 0.2s ease;
}

@media (min-width: 640px) {
    .dialog {
        border-radius: var(--radius);
    }
}

.dialog-header {
    margin-bottom: 1rem;
}

.dialog-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.dialog-description {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
    margin-top: 0.25rem;
}

.dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

@media (min-width: 640px) {
    @keyframes slideUp {
        from { transform: scale(0.95); opacity: 0; }
        to { transform: scale(1); opacity: 1; }
    }
}

/* --- Toast --- */
.toast-container {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: calc(100% - 2rem);
    max-width: 400px;
    pointer-events: none;
}

.toast {
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    box-shadow: 0 4px 12px hsla(var(--foreground), 0.1);
    animation: toastIn 0.3s ease;
    pointer-events: auto;
}

.toast-error {
    border-color: hsl(var(--destructive));
}

.toast-success {
    border-color: hsl(var(--success));
}

@keyframes toastIn {
    from { transform: translateY(-1rem); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* --- Link Preview --- */
.link-preview {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    margin-top: 0.5rem;
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}

.link-preview:hover {
    background: hsl(var(--accent));
}

.link-preview-image {
    width: 4rem;
    height: 4rem;
    border-radius: calc(var(--radius) - 2px);
    object-fit: cover;
    flex-shrink: 0;
}

.link-preview-content {
    flex: 1;
    min-width: 0;
}

.link-preview-title {
    font-size: 0.8125rem;
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.link-preview-description {
    font-size: 0.75rem;
    color: hsl(var(--muted-foreground));
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 0.125rem;
}

.link-preview-url {
    font-size: 0.6875rem;
    color: hsl(var(--muted-foreground));
    margin-top: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* --- Tag chips --- */
.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius);
    background: hsl(var(--secondary));
    color: hsl(var(--secondary-foreground));
    font-size: 0.75rem;
}

.tag-remove {
    cursor: pointer;
    opacity: 0.5;
    font-size: 0.875rem;
    line-height: 1;
}

.tag-remove:hover {
    opacity: 1;
}

/* --- Vote display --- */
.vote-score {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    font-weight: 600;
}

.vote-score-value {
    font-size: 1.25rem;
}

.vote-pending {
    font-size: 0.8125rem;
    color: hsl(var(--muted-foreground));
    font-style: italic;
}

/* --- Search bar --- */
.search-bar {
    position: relative;
    margin-bottom: 0.75rem;
}

.search-bar input {
    padding-left: 2.25rem;
}

.search-bar svg {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1rem;
    height: 1rem;
    color: hsl(var(--muted-foreground));
}

/* --- Ranking list (drag & drop) --- */
.ranking-list {
    list-style: none;
}

.ranking-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    background: hsl(var(--card));
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.ranking-item:active {
    cursor: grabbing;
}

.ranking-item.dragging {
    opacity: 0.5;
    box-shadow: 0 4px 12px hsla(var(--foreground), 0.1);
}

.ranking-number {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 9999px;
    background: hsl(var(--primary));
    color: hsl(var(--primary-foreground));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.ranking-handle {
    color: hsl(var(--muted-foreground));
    flex-shrink: 0;
}

/* --- Empty state --- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: hsl(var(--muted-foreground));
}

.empty-state svg {
    width: 3rem;
    height: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state p {
    font-size: 0.875rem;
}

/* --- Loading spinner --- */
.spinner {
    width: 1.5rem;
    height: 1.5rem;
    border: 2px solid hsl(var(--muted));
    border-top-color: hsl(var(--primary));
    border-radius: 9999px;
    animation: spin 0.6s linear infinite;
}

.loading-center {
    display: flex;
    justify-content: center;
    padding: 2rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Auth pages --- */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 1rem;
}

.auth-card {
    width: 100%;
    max-width: 360px;
}

.auth-card .card {
    padding: 2rem;
}

.auth-title {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-title h1 {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.auth-title p {
    font-size: 0.875rem;
    color: hsl(var(--muted-foreground));
}

/* PIN input */
.pin-input-group {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    margin: 1.5rem 0;
}

.pin-digit {
    width: 3rem;
    height: 3.5rem;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 600;
    border: 1px solid hsl(var(--input));
    border-radius: var(--radius);
    background: transparent;
    color: hsl(var(--foreground));
}

.pin-digit:focus {
    outline: none;
    border-color: hsl(var(--ring));
    box-shadow: 0 0 0 2px hsla(var(--ring), 0.2);
}

/* --- Utility classes --- */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.p-2 { padding: 0.5rem; }
.p-4 { padding: 1rem; }
.w-full { width: 100%; }
.text-center { text-align: center; }
.font-semibold { font-weight: 600; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
