/**
 * Base Styles - Reset & Typography
 * Local First Tools v2
 */

/* ========================================
   CSS RESET
   ======================================== */

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -moz-tab-size: 4;
    tab-size: 4;
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background-color: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Remove default button styles */
button {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
}

/* Remove default input styles */
input,
select,
textarea {
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    color: inherit;
}

/* Remove default list styles */
ul,
ol {
    list-style: none;
}

/* Remove default anchor styles */
a {
    color: inherit;
    text-decoration: none;
}

/* Images */
img,
svg,
video,
canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Tables */
table {
    border-collapse: collapse;
    border-spacing: 0;
}

/* ========================================
   TYPOGRAPHY
   ======================================== */

h1, h2, h3, h4, h5, h6 {
    font-weight: var(--font-semibold);
    line-height: var(--leading-tight);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); }

p {
    margin-bottom: var(--space-4);
}

p:last-child {
    margin-bottom: 0;
}

small {
    font-size: var(--text-sm);
}

strong {
    font-weight: var(--font-semibold);
}

code {
    font-family: var(--font-mono);
    font-size: 0.875em;
    background: var(--bg-tertiary);
    padding: 0.125em 0.375em;
    border-radius: var(--radius-sm);
}

/* ========================================
   FOCUS STYLES
   ======================================== */

:focus {
    outline: none;
}

:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* ========================================
   SCROLLBAR
   ======================================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

/* ========================================
   SELECTION
   ======================================== */

::selection {
    background: var(--color-accent);
    color: var(--bg-primary);
}

/* ========================================
   LAYOUT
   ======================================== */

#app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    display: flex;
    align-items: center;
    gap: var(--space-5);
    padding: var(--space-4) var(--space-5);
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border-primary);
    height: var(--header-height);
}

.header-brand {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    flex-shrink: 0;
}

.header-title {
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    background: linear-gradient(135deg, var(--color-accent), var(--color-accent-tertiary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-version {
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    color: var(--text-tertiary);
    padding: var(--space-1) var(--space-2);
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
}

.header-search {
    flex: 1;
    max-width: 500px;
}

.header-actions {
    display: flex;
    gap: var(--space-2);
}

/* Search */
.search-container {
    position: relative;
}

.search-input {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    padding-left: var(--space-10);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    transition: border-color var(--duration-150) var(--ease-out),
                box-shadow var(--duration-150) var(--ease-out);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(6, 255, 165, 0.1);
}

.search-icon {
    position: absolute;
    left: var(--space-4);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
}

.search-suggestions {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: var(--space-2);
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-height: 400px;
    overflow-y: auto;
    z-index: var(--z-dropdown);
}

.search-suggestions.active {
    display: block;
}

/* Icon Button */
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    transition: background var(--duration-150) var(--ease-out),
                color var(--duration-150) var(--ease-out);
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.icon-btn:focus-visible {
    outline-offset: 0;
}

/* Category Navigation */
.category-nav {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.category-nav::-webkit-scrollbar {
    display: none;
}

.category-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    white-space: nowrap;
    color: var(--text-secondary);
    transition: all var(--duration-150) var(--ease-out);
}

.category-btn:hover {
    border-color: var(--color-accent);
    color: var(--text-primary);
}

.category-btn.active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: var(--bg-primary);
}

.category-count {
    font-size: var(--text-xs);
    padding: 2px 6px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-full);
}

.category-btn.active .category-count {
    background: rgba(0, 0, 0, 0.3);
}

/* Filter Bar */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-5);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-secondary);
}

.filter-group {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.filter-label {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
}

.filter-select {
    padding: var(--space-2) var(--space-3);
    padding-right: var(--space-8);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    cursor: pointer;
    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='rgba(255,255,255,0.5)' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    transition: border-color var(--duration-150) var(--ease-out);
}

.filter-select:hover {
    border-color: var(--color-accent);
}

.filter-select:focus {
    border-color: var(--color-accent);
    outline: none;
}

/* Active Filters */
.active-filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-5);
    min-height: 0;
}

.active-filters:empty {
    display: none;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-2);
    padding-left: var(--space-3);
    background: var(--color-accent);
    color: var(--bg-primary);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
}

.filter-chip-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    font-size: 10px;
    cursor: pointer;
    transition: background var(--duration-150);
}

.filter-chip-remove:hover {
    background: rgba(0, 0, 0, 0.4);
}

/* Stats Bar */
.stats-bar {
    display: flex;
    gap: var(--space-4);
    padding: var(--space-2) var(--space-5);
    font-size: var(--text-sm);
    color: var(--text-tertiary);
}

.stat-item span {
    color: var(--text-primary);
    font-weight: var(--font-medium);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: var(--space-5);
    padding-bottom: calc(var(--bottom-nav-height) + var(--space-5));
}

/* Tools Container */
.tools-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--card-min-width), 1fr));
    gap: var(--grid-gap);
}

/* Loading Container */
.loading-container {
    padding: var(--space-5);
}

.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--card-min-width), 1fr));
    gap: var(--grid-gap);
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-10);
    text-align: center;
}

.empty-icon {
    color: var(--text-tertiary);
    margin-bottom: var(--space-5);
}

.empty-title {
    font-size: var(--text-2xl);
    margin-bottom: var(--space-2);
}

.empty-description {
    color: var(--text-secondary);
    margin-bottom: var(--space-5);
}

/* Bottom Navigation (Mobile) */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-top: 1px solid var(--border-primary);
    z-index: var(--z-fixed);
    padding-bottom: env(safe-area-inset-bottom);
}

@media (max-width: 768px) {
    .bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }

    .header-actions {
        display: none;
    }
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2);
    color: var(--text-tertiary);
    transition: color var(--duration-150);
    -webkit-tap-highlight-color: transparent;
}

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

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-label {
    font-size: var(--text-xs);
}

/* Modal */
.modal-container {
    display: none;
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
}

.modal-container[aria-hidden="false"] {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-elevated);
    border-radius: var(--modal-radius);
    max-width: var(--modal-max-width);
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-2xl);
}

/* Toast Container */
.toast-container {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--space-4));
    right: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    z-index: var(--z-toast);
}

@media (max-width: 768px) {
    .toast-container {
        left: var(--space-4);
        right: var(--space-4);
    }
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 768px) {
    .header {
        padding: var(--space-3) var(--space-4);
    }

    .header-brand {
        display: none;
    }

    .header-search {
        max-width: none;
    }

    .filter-bar {
        padding: var(--space-3) var(--space-4);
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .filter-group {
        flex-shrink: 0;
    }

    .main-content {
        padding: var(--space-4);
    }

    .tools-container {
        grid-template-columns: 1fr;
    }
}
