/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
    background-color: #f8fafc;
    color: #0f172a;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Top Navigation */
.top-nav {
    background: white;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 40;
    backdrop-filter: blur(8px);
    background-color: rgba(255, 255, 255, 0.95);
}

.nav-content {
    max-width: none;
    padding: 0 1.5rem;
    height: 4rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 600;
    font-size: 1.125rem;
    color: #0f172a;
}

.brand-icon {
    font-size: 1.5rem;
}

.brand-text {
    font-weight: 600;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: none;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.nav-btn.primary {
    background-color: #3b82f6;
    color: white;
}

.nav-btn.primary:hover {
    background-color: #2563eb;
}

.nav-btn.secondary {
    background-color: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
}

.nav-btn.secondary:hover {
    background-color: #e2e8f0;
}

.btn-icon {
    font-size: 1rem;
}

.btn-text {
    display: inline;
}

/* Dashboard Layout */
.dashboard {
    min-height: calc(100vh - 4rem);
    background-color: #f8fafc;
}

.dashboard-content {
    padding: 1.5rem;
    max-width: none;
}

/* Compact Header */
.compact-header {
    background: white;
    border-radius: 0.75rem;
    border: 1px solid #e2e8f0;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.stats-bar {
    display: flex;
    gap: 2rem;
    align-items: center;
}

.stat-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: #0f172a;
}

.stat-name {
    font-size: 0.75rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-group.success .stat-value {
    color: #059669;
}

.stat-group.danger .stat-value {
    color: #dc2626;
}

.stat-group.warning .stat-value {
    color: #d97706;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.tracking-period {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tracking-period label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    white-space: nowrap;
}

.period-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    background: white;
    color: #374151;
    cursor: pointer;
    transition: border-color 0.15s ease;
}

.period-select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Items Container */
.items-container {
    background: white;
    border-radius: 0.75rem;
    border: 1px solid #e2e8f0;
    overflow: hidden;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

/* Forms */
.add-form {
    width: 100%;
}

.add-form .form-group {
    margin-bottom: 1rem;
}

.add-form .form-group:last-of-type {
    margin-bottom: 0;
}

.form-row {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 1rem;
    align-items: end;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group.flex-1 {
    flex: 1;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
}

.form-group input,
.form-group select,
.filter-select {
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    transition: border-color 0.15s ease;
    background: white;
}

.form-group input:focus,
.form-group select:focus,
.filter-select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group small {
    font-size: 0.75rem;
    color: #6b7280;
    margin-top: 0.25rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
    justify-content: center;
}

.btn-primary {
    background-color: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background-color: #2563eb;
}

.btn-primary:disabled {
    background-color: #9ca3af;
    cursor: not-allowed;
}

.btn-secondary {
    background-color: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
}

.btn-secondary:hover {
    background-color: #e2e8f0;
}

/* Items List */
.items-list {
    min-height: 12rem;
}

.item-row {
    display: flex;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #f1f5f9;
    transition: background-color 0.15s ease;
}

.item-row:hover {
    background-color: #f8fafc;
}

.item-row:last-child {
    border-bottom: none;
}

.item-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

.item-type-indicator {
    font-size: 1.25rem;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.item-type-indicator.link {
    background-color: #dbeafe;
    color: #1d4ed8;
}

.item-type-indicator.keyword {
    background-color: #dcfce7;
    color: #166534;
}

.item-details {
    min-width: 0;
    flex: 1;
}

.item-value {
    font-weight: 500;
    color: #0f172a;
    font-size: 0.875rem;
    word-break: break-all;
    line-height: 1.4;
}

.item-meta {
    font-size: 0.75rem;
    color: #64748b;
    margin-top: 0.125rem;
}

.item-metrics {
    display: flex;
    gap: 2rem;
    margin: 0 1.5rem;
    flex-shrink: 0;
}

.metric {
    text-align: center;
    min-width: 3.5rem;
}

.metric-value {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
    color: #0f172a;
}

.metric-label {
    display: block;
    font-size: 0.75rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.125rem;
}

.item-actions {
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.action-btn {
    padding: 0.5rem;
    border: none;
    border-radius: 0.375rem;
    background-color: #f1f5f9;
    color: #475569;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 0.875rem;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:hover {
    background-color: #e2e8f0;
    transform: translateY(-1px);
}

.action-btn.danger:hover {
    background-color: #fee2e2;
    color: #991b1b;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: #64748b;
}

.empty-state h3 {
    font-size: 1.125rem;
    margin-bottom: 0.5rem;
    color: #374151;
    font-weight: 600;
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2.5rem 1.5rem;
    color: #64748b;
}

.loading-spinner {
    width: 1.5rem;
    height: 1.5rem;
    border: 2px solid #e5e7eb;
    border-top: 2px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 0.75rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 50;
    max-width: 42rem;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal.large {
    max-width: 64rem;
}

.modal-content {
    background: white;
    border-radius: 0.75rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid #e2e8f0;
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: #0f172a;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #64748b;
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: all 0.15s ease;
}

.modal-close:hover {
    background-color: #f1f5f9;
    color: #374151;
}

.modal-body {
    padding: 1.5rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid #e2e8f0;
}

.overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 40;
    backdrop-filter: blur(4px);
}

/* Settings */
.settings-section {
    margin-bottom: 2rem;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section h4 {
    font-size: 1rem;
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 1rem;
}

/* Charts */
.charts-container {
    display: grid;
    gap: 1.5rem;
}

.chart-wrapper {
    background: white;
    padding: 1.25rem;
    border-radius: 0.5rem;
    border: 1px solid #e2e8f0;
    height: 18.75rem;
}

.performance-controls {
    margin-bottom: 1.5rem;
}

.performance-controls select {
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    background: white;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .compact-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .stats-bar {
        align-self: stretch;
        justify-content: space-between;
        gap: 1rem;
    }

    .form-row {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .item-metrics {
        margin: 0;
        gap: 1rem;
    }
}

@media (max-width: 768px) {
    .dashboard-content {
        padding: 1rem;
    }

    .nav-content {
        padding: 0 1rem;
    }

    .btn-text {
        display: none;
    }

    .stats-bar {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .item-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        padding: 1rem;
    }

    .item-metrics {
        align-self: stretch;
        justify-content: space-between;
    }

    .item-value {
        max-width: none;
    }
}

@media (max-width: 640px) {
    .stats-bar {
        grid-template-columns: 1fr;
    }

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

    .item-metrics {
        gap: 0.75rem;
    }

    .metric {
        min-width: auto;
    }
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 24rem;
    pointer-events: none;
}

.toast {
    background: white;
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    border: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 20rem;
    pointer-events: auto;
    transform: translateX(100%);
    transition: all 0.3s ease;
    opacity: 0;
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast.success {
    border-left: 4px solid #10b981;
}

.toast.error {
    border-left: 4px solid #ef4444;
}

.toast.warning {
    border-left: 4px solid #f59e0b;
}

.toast.info {
    border-left: 4px solid #3b82f6;
}

.toast-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.toast.success .toast-icon {
    color: #10b981;
}

.toast.error .toast-icon {
    color: #ef4444;
}

.toast.warning .toast-icon {
    color: #f59e0b;
}

.toast.info .toast-icon {
    color: #3b82f6;
}

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

.toast-message {
    color: #0f172a;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    font-size: 1.125rem;
    padding: 0.25rem;
    border-radius: 0.25rem;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.toast-close:hover {
    color: #374151;
    background-color: #f1f5f9;
}

/* Mobile adjustments for toasts */
@media (max-width: 640px) {
    .toast-container {
        top: 0.5rem;
        right: 0.5rem;
        left: 0.5rem;
        max-width: none;
    }

    .toast {
        min-width: auto;
    }
}

/* Quick URL Add Styles */
.quick-url-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e2e8f0;
    gap: 1rem;
}

.url-stats {
    font-size: 0.875rem;
    color: #64748b;
}

.url-list-container {
    max-height: 32rem;
    overflow-y: auto;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
}

.url-list {
    display: flex;
    flex-direction: column;
}

.url-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #f1f5f9;
    gap: 1rem;
    transition: background-color 0.15s ease;
}

.url-item:hover {
    background-color: #f8fafc;
}

.url-item:last-child {
    border-bottom: none;
}

.url-item.tracked {
    background-color: #f0fdf4;
    border-left: 4px solid #22c55e;
}

.url-item.tracked:hover {
    background-color: #dcfce7;
}

.url-checkbox {
    width: 1.25rem;
    height: 1.25rem;
    margin: 0;
    cursor: pointer;
}

.url-checkbox:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.url-title {
    font-weight: 500;
    color: #0f172a;
    font-size: 0.875rem;
    line-height: 1.4;
    margin-bottom: 0.25rem;
}

.url-link {
    font-size: 0.75rem;
    color: #3b82f6;
    word-break: break-all;
    line-height: 1.3;
}

.url-meta {
    display: flex;
    gap: 1rem;
    font-size: 0.75rem;
    color: #64748b;
    margin-top: 0.25rem;
}

.url-status {
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.url-status.available {
    background-color: #dbeafe;
    color: #1d4ed8;
}

.url-status.tracked {
    background-color: #dcfce7;
    color: #166534;
}

.quick-url-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    padding: 1rem;
    border-top: 1px solid #e2e8f0;
    background-color: #f8fafc;
    margin-top: 1.5rem;
    border-radius: 0 0 0.75rem 0.75rem;
}

.quick-url-actions .btn {
    padding: 0.75rem 1.5rem;
}

.selection-count {
    font-size: 0.875rem;
    color: #64748b;
    margin-left: auto;
}

/* Position Trend Indicators */
.trend-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

.trend-improvement {
    background-color: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.trend-decline {
    background-color: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.trend-arrow {
    font-size: 0.875rem;
    font-weight: bold;
}

.trend-arrow.up {
    color: #16a34a;
}

.trend-arrow.down {
    color: #dc2626;
}

.trend-change {
    font-size: 0.6875rem;
    opacity: 0.9;
}

/* Position metric styling with trend awareness */
.metric-value.has-trend {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Tooltip for trend details */
.trend-tooltip {
    position: relative;
    cursor: help;
}

.trend-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #1f2937;
    color: white;
    padding: 0.5rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 50;
    margin-bottom: 0.25rem;
}

.trend-tooltip::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: #1f2937;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 50;
}

.trend-tooltip:hover::after,
.trend-tooltip:hover::before {
    opacity: 1;
}

/* Mobile adjustments for Quick URL */
@media (max-width: 768px) {
    .quick-url-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .url-item {
        padding: 0.75rem;
    }

    .url-meta {
        flex-direction: column;
        gap: 0.25rem;
    }

    .trend-indicator {
        margin-left: 0;
        margin-top: 0.25rem;
    }
}