/* ========================================
   Regex Library — Premium Dark Theme
   ======================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Design Tokens ── */
:root {
    --primary: #3B82F6;
    --primary-rgb: 59, 130, 246;
    --primary-hover: #2563EB;
    --primary-glow: rgba(59, 130, 246, 0.25);
    --accent: #10B981;
    --accent-rgb: 16, 185, 129;
    --accent-glow: rgba(16, 185, 129, 0.25);
    --warning: #F59E0B;
    --danger: #EF4444;
    --danger-hover: #DC2626;

    --bg-deep: #0B1120;
    --bg-base: #111827;
    --bg-surface: #1F2937;
    --bg-elevated: #374151;
    --bg-glass: rgba(17, 24, 39, 0.8);

    --text-primary: #F9FAFB;
    --text-secondary: #9CA3AF;
    --text-muted: #6B7280;
    --text-inverse: #0B1120;

    --border: rgba(75, 85, 99, 0.4);
    --border-hover: rgba(75, 85, 99, 0.7);

    --match-bg: rgba(16, 185, 129, 0.2);
    --match-border: rgba(16, 185, 129, 0.5);
    --no-match-bg: rgba(239, 68, 68, 0.1);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);

    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-deep);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── App Layout ── */
.app {
    display: grid;
    grid-template-rows: auto 1fr;
    min-height: 100vh;
}

/* ── Header ── */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 16px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-center {
    flex: 1;
    max-width: 480px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
    text-decoration: none;
    white-space: nowrap;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    box-shadow: 0 2px 8px var(--primary-glow);
}

/* ── Search ── */
.search-wrapper {
    position: relative;
    width: 100%;
}

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

.search-input {
    width: 100%;
    padding: 8px 12px 8px 38px;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--text-primary);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    outline: none;
    transition: all var(--transition-fast);
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 500;
    border: 1px solid var(--border);
    background: var(--bg-surface);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn:hover {
    background: var(--bg-elevated);
    border-color: var(--border-hover);
    transform: translateY(-1px);
}

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

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

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    box-shadow: 0 4px 12px var(--primary-glow);
}

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-hover);
    border-color: var(--danger-hover);
}

.btn-icon {
    padding: 7px;
    width: 34px;
    height: 34px;
}

.btn-icon svg {
    width: 16px;
    height: 16px;
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-secondary);
}

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

/* ── Main Layout ── */
.main-area {
    display: grid;
    grid-template-columns: 240px 1fr;
    overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
    background: var(--bg-base);
    border-right: 1px solid var(--border);
    padding: 16px 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.sidebar::-webkit-scrollbar {
    width: 3px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--bg-elevated);
    border-radius: var(--radius-full);
}

.sidebar-section {}

.sidebar-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 0 8px;
    margin-bottom: 8px;
}

.tag-filter {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
}

.tag-filter:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.tag-filter.active {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.25);
    color: var(--primary);
}

.tag-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tag-count {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--bg-surface);
    padding: 1px 6px;
    border-radius: var(--radius-full);
}

.tag-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-stats {}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.stat-row span:last-child {
    font-weight: 600;
    color: var(--text-primary);
}

/* ── Content ── */
.content {
    padding: 24px;
    overflow-y: auto;
}

.content::-webkit-scrollbar {
    width: 5px;
}

.content::-webkit-scrollbar-thumb {
    background: var(--bg-elevated);
    border-radius: var(--radius-full);
}

.content-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.content-title {
    font-size: 1.3rem;
    font-weight: 600;
}

.sort-select {
    padding: 6px 10px;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    cursor: pointer;
}

/* ── Pattern Cards ── */
.pattern-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.pattern-card {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    transition: all var(--transition-base);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.pattern-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    opacity: 0;
    transition: opacity var(--transition-base);
}

.pattern-card:hover {
    border-color: var(--border-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.pattern-card:hover::before {
    opacity: 1;
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 10px;
}

.card-name {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.card-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.pattern-card:hover .card-actions {
    opacity: 1;
}

.card-regex {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--primary);
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.15);
    border-radius: 6px;
    padding: 8px 12px;
    word-break: break-all;
    margin-bottom: 10px;
}

.card-description {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-tags {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.card-tag {
    font-size: 0.68rem;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    background: var(--bg-surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.card-meta {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.card-fav {
    position: absolute;
    top: 14px;
    right: 14px;
    background: none;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    opacity: 0.3;
    transition: all var(--transition-fast);
    padding: 4px;
}

.card-fav:hover {
    opacity: 0.8;
}

.card-fav.active {
    opacity: 1;
}

/* ── Empty State ── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
    gap: 12px;
}

.empty-icon {
    font-size: 4rem;
    opacity: 0.2;
}

.empty-state h2 {
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-base);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-base);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 90%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px) scale(0.95);
    transition: transform var(--transition-base);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large {
    max-width: 640px;
}

.modal-overlay.active .modal {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-body {
    margin-bottom: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

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

.form-group {}

.form-group.full-width {
    width: 100%;
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-hint {
    font-weight: 400;
    color: var(--text-muted);
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 9px 12px;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--text-primary);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color var(--transition-fast);
}

.form-input:focus,
.form-textarea:focus {
    border-color: var(--primary);
}

.form-textarea {
    resize: vertical;
    font-family: var(--font-sans);
}

.regex-input-wrapper {
    display: flex;
    align-items: center;
    gap: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: border-color var(--transition-fast);
}

.regex-input-wrapper:focus-within {
    border-color: var(--primary);
}

.regex-delim {
    padding: 0 8px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 1.1rem;
    user-select: none;
}

.regex-input {
    flex: 1;
    border: none !important;
    background: transparent !important;
    font-family: var(--font-mono);
    padding: 9px 4px;
}

.flags-input {
    width: 50px;
    border: none !important;
    border-left: 1px solid var(--border) !important;
    background: transparent !important;
    font-family: var(--font-mono);
    text-align: center;
    padding: 9px 4px;
}

/* ── Live Tester ── */
.tester-section {
    border-top: 1px solid var(--border);
    padding-top: 16px;
    margin-top: 4px;
}

.tester-input {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    margin-bottom: 12px;
}

.tester-results {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    max-height: 200px;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

.tester-placeholder {
    color: var(--text-muted);
    font-family: var(--font-sans);
    text-align: center;
    padding: 16px;
}

.tester-line {
    padding: 4px 8px;
    border-radius: 4px;
    margin-bottom: 4px;
}

.tester-line.match {
    background: var(--match-bg);
    border-left: 3px solid var(--accent);
}

.tester-line.no-match {
    background: var(--no-match-bg);
    color: var(--text-muted);
    border-left: 3px solid rgba(239, 68, 68, 0.3);
}

.tester-match-highlight {
    background: rgba(16, 185, 129, 0.35);
    padding: 0 2px;
    border-radius: 2px;
    border-bottom: 1px solid var(--accent);
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 16px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-size: 0.85rem;
    color: var(--text-primary);
    animation: toast-in 0.3s ease-out;
    max-width: 340px;
}

.toast.success {
    border-left: 3px solid var(--accent);
}

.toast.error {
    border-left: 3px solid var(--danger);
}

.toast.info {
    border-left: 3px solid var(--primary);
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(40px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ── Responsive ── */
@media (max-width: 900px) {
    .main-area {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .header {
        padding: 10px 12px;
        gap: 8px;
    }

    .logo span {
        display: none;
    }

    .btn span {
        display: none;
    }

    .pattern-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .content {
        padding: 16px;
    }

    .header-center {
        display: none;
    }
}

/* ── Animations ── */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pattern-card {
    animation: fadeIn 0.3s ease-out backwards;
}

.pattern-card:nth-child(2) {
    animation-delay: 0.05s;
}

.pattern-card:nth-child(3) {
    animation-delay: 0.10s;
}

.pattern-card:nth-child(4) {
    animation-delay: 0.15s;
}

.pattern-card:nth-child(5) {
    animation-delay: 0.20s;
}

.pattern-card:nth-child(6) {
    animation-delay: 0.25s;
}