/* Modern CSS Design System with light/dark theme support, glassmorphism, and responsive layouts */

:root {
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    
    /* Theme Light Constants */
    --bg-base: #f8fafc;
    --bg-surface: rgba(255, 255, 255, 0.7);
    --border-color: rgba(148, 163, 184, 0.15);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    /* Global Brand Colors */
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: rgba(99, 102, 241, 0.15);
    
    --success: #10b981;
    --success-light: rgba(16, 185, 129, 0.1);
    --danger: #ef4444;
    --danger-light: rgba(239, 68, 68, 0.1);
    --warning: #f59e0b;
    --warning-light: rgba(245, 158, 11, 0.1);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.15);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    --transition-all: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --glow-primary: 0 0 15px rgba(99, 102, 241, 0.3);
}

/* Dark Mode override class */
body.dark-mode {
    --bg-base: #090d16;
    --bg-surface: rgba(17, 24, 39, 0.65);
    --border-color: rgba(255, 255, 255, 0.07);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --primary-light: rgba(99, 102, 241, 0.25);
    
    --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-base);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, color 0.3s ease;
    line-height: 1.5;
    position: relative;
    overflow-x: hidden;
}

/* Background Gradients */
body::before {
    content: '';
    position: absolute;
    top: -20%;
    left: -10%;
    width: 60vw;
    height: 60vw;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.08) 0%, rgba(99, 102, 241, 0) 70%);
    z-index: -1;
    pointer-events: none;
}

body::after {
    content: '';
    position: absolute;
    bottom: -20%;
    right: -10%;
    width: 50vw;
    height: 50vw;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(165, 180, 252, 0.05) 0%, rgba(165, 180, 252, 0) 70%);
    z-index: -1;
    pointer-events: none;
}

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

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

a:hover {
    color: var(--primary-hover);
}

/* Navigation Bar */
header {
    padding: 24px 0;
    border-bottom: 1px solid var(--border-color);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 50;
    background-color: rgba(var(--bg-base), 0.8);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #818cf8 0%, #6366f1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.theme-toggle-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-sm);
    transition: var(--transition-all);
}

.theme-toggle-btn:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.theme-toggle-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.sun-icon { display: none; }
body.dark-mode .sun-icon { display: block; }
body.dark-mode .moon-icon { display: none; }

/* Main Wrapper layout */
main {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 40px 24px;
}

/* Glassmorphism Container Card */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow: var(--shadow-xl);
    padding: 40px;
    margin-bottom: 30px;
    transition: var(--transition-all);
}

/* Home Hero section styling */
.hero {
    text-align: center;
    max-width: 700px;
    margin: 0 auto 50px auto;
}

.hero h1 {
    font-size: 3rem;
    margin-bottom: 16px;
    background: linear-gradient(135deg, var(--text-primary) 40%, var(--primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero p {
    color: var(--text-secondary);
    font-size: 1.15rem;
}

/* Form Styles */
.shorten-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

@media(min-width: 768px) {
    .shorten-form {
        flex-direction: row;
    }
}

.input-wrapper {
    position: relative;
    flex: 1;
}

.input-wrapper svg {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 20px;
    height: 20px;
    pointer-events: none;
}

.input-field {
    width: 100%;
    padding: 18px 20px 18px 56px;
    background: rgba(15, 23, 42, 0.03);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1.1rem;
    transition: var(--transition-all);
}

body.dark-mode .input-field {
    background: rgba(15, 23, 42, 0.4);
}

.input-field:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--glow-primary);
    background-color: rgba(255,255,255, 0.02);
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
    border: none;
    padding: 16px 36px;
    border-radius: var(--radius-lg);
    font-weight: 600;
    font-size: 1.05rem;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
    transition: var(--transition-all);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Spinner */
.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
    display: none;
}

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

.loading .spinner {
    display: inline-block;
}
.loading .btn-text {
    display: none;
}

/* Error Banner */
.error-banner {
    display: none;
    margin-top: 15px;
    background: var(--danger-light);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--danger);
    padding: 12px 18px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    text-align: center;
}

/* Output Card styling */
.result-card {
    display: none;
    margin-top: 30px;
    border: 1px solid rgba(16, 185, 129, 0.2);
    background: var(--success-light);
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.result-header {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--success);
    font-size: 1.25rem;
    margin-bottom: 24px;
    font-weight: 600;
}

.result-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
}

@media(min-width: 768px) {
    .result-grid {
        grid-template-columns: 1fr 200px;
    }
}

.result-fields {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-group label {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    font-weight: 600;
}

.field-control {
    display: flex;
    background: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.field-control input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 12px 16px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
}

.field-control input:focus {
    outline: none;
}

.btn-action {
    background: var(--primary-light);
    border: none;
    border-left: 1px solid var(--border-color);
    color: var(--primary);
    padding: 12px 20px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-all);
    display: flex;
    align-items: center;
    gap: 6px;
}

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

.btn-action svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.qr-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-left: 1px solid var(--border-color);
    padding-left: 0;
}

@media(min-width: 768px) {
    .qr-wrapper {
        padding-left: 30px;
    }
}

#qrcode-container {
    background: white;
    padding: 12px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#qrcode-container canvas, #qrcode-container img {
    max-width: 150px;
    max-height: 150px;
}

/* History Card */
.history-section {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.history-section h2 {
    font-size: 1.35rem;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    gap: 10px;
    transition: var(--transition-all);
}

.history-item:hover {
    transform: translateX(4px);
    border-color: var(--primary);
}

@media (min-width: 768px) {
    .history-item {
        flex-direction: row;
        align-items: center;
    }
}

.history-urls {
    flex: 1;
    overflow: hidden;
}

.history-short {
    font-weight: 600;
    color: var(--primary);
    font-size: 1.05rem;
    display: block;
    margin-bottom: 4px;
}

.history-long {
    color: var(--text-secondary);
    font-size: 0.85rem;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    max-width: 100%;
}

.history-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn-history-stats {
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.15);
    color: var(--primary);
    padding: 8px 14px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    transition: var(--transition-all);
}

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

/* ==========================================================================
   Analytics Dashboard Layout
   ========================================================================== */
.stats-header-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 35px;
}

@media(min-width: 768px) {
    .stats-header-container {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }
}

.stats-title h1 {
    font-size: 2.2rem;
    margin-bottom: 6px;
}

.stats-title p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    word-break: break-all;
}

.stats-actions {
    display: flex;
    gap: 12px;
}

.btn-secondary {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.95rem;
    font-family: inherit;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: var(--transition-all);
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-secondary:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Metric Cards Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

@media(min-width: 992px) {
    .metrics-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.metric-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.metric-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
}

.metric-card.success::after { background: var(--success); }
.metric-card.danger::after { background: var(--danger); }
.metric-card.warning::after { background: var(--warning); }

.metric-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: 8px;
}

.metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.1;
}

.metric-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* Dashboard Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

@media(min-width: 992px) {
    .charts-grid {
        grid-template-columns: 2fr 1fr;
    }
}

.chart-card {
    display: flex;
    flex-direction: column;
}

.chart-card-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chart-wrapper {
    flex: 1;
    position: relative;
    min-height: 300px;
    max-height: 400px;
    width: 100%;
}

/* Summary Grid: Top Locations, Browsers, Referrers */
.summaries-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
    margin-bottom: 30px;
}

@media(min-width: 992px) {
    .summaries-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.summary-card {
    padding: 24px;
}

.summary-card-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.summary-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
}

.summary-label {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
}

.summary-count {
    font-weight: 600;
    background: var(--primary-light);
    color: var(--primary);
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
}

/* Visitor Details Table */
.table-card {
    overflow: hidden;
    padding: 0;
}

.table-header-area {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.table-header-area h2 {
    font-size: 1.25rem;
}

.table-wrapper {
    overflow-x: auto;
}

.analytics-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.9rem;
}

.analytics-table th, .analytics-table td {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
}

.analytics-table th {
    background: rgba(15, 23, 42, 0.02);
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.05em;
}

body.dark-mode .analytics-table th {
    background: rgba(15, 23, 42, 0.2);
}

.analytics-table tr:last-child td {
    border-bottom: none;
}

.analytics-table tr:hover td {
    background-color: rgba(99, 102, 241, 0.02);
}

.badge-device {
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
}

.badge-device.desktop { background: rgba(99, 102, 241, 0.1); color: var(--primary); }
.badge-device.mobile { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.badge-device.tablet { background: rgba(245, 158, 11, 0.1); color: var(--warning); }

/* Footer */
footer {
    padding: 30px 0;
    border-top: 1px solid var(--border-color);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    color: var(--text-muted);
}
