/* ============================================================
   Regex Tester — Styles
   ============================================================ */

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

:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #273548;
    --surface-raised: #263347;
    --accent: #60a5fa;
    --accent-solid: #3b82f6;
    --accent-dim: rgba(96, 165, 250, 0.15);
    --accent-dim2: rgba(96, 165, 250, 0.08);
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-dim: #64748b;
    --border: rgba(255, 255, 255, 0.08);
    --border-accent: rgba(96, 165, 250, 0.3);
    --error: #f87171;
    --error-bg: rgba(248, 113, 113, 0.1);
    --success: #4ade80;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);

    /* Match highlight colors — alternating */
    --match-1: rgba(96, 165, 250, 0.30);
    --match-2: rgba(139, 92, 246, 0.30);
    --match-3: rgba(52, 211, 153, 0.30);
    --match-4: rgba(251, 191, 36, 0.30);
    --match-1-solid: rgba(96, 165, 250, 0.50);
    --match-2-solid: rgba(139, 92, 246, 0.50);
    --match-3-solid: rgba(52, 211, 153, 0.50);
    --match-4-solid: rgba(251, 191, 36, 0.50);
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--text-dim);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font);
    font-size: 0.867rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 8px 14px;
    transition: all 0.2s ease;
    white-space: nowrap;
    color: var(--text);
    background: transparent;
}
.btn:active { transform: scale(0.97); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid transparent;
}
.btn-ghost:hover {
    background: var(--accent-dim2);
    color: var(--text);
    border-color: var(--border);
}

.btn-accent {
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid var(--border-accent);
}
.btn-accent:hover {
    background: rgba(96, 165, 250, 0.25);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 0.8rem;
}

/* --- Header --- */
.header {
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #7c3aed 100%);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-inner {
    max-width: 1600px;
    margin: 0 auto;
    padding: 16px 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}
.header-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.12);
    border-radius: var(--radius);
    color: white;
}
.header-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.3px;
}
.header-subtitle {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.65);
    font-weight: 400;
    margin-top: 1px;
}
.header-actions {
    display: flex;
    gap: 8px;
}
.header-actions .btn-ghost {
    color: rgba(255, 255, 255, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(4px);
}
.header-actions .btn-ghost:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.25);
}

/* --- Main Content --- */
.main-content {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px 28px 40px;
}

/* --- Regex Input Section --- */
.regex-input-section {
    margin-bottom: 20px;
}
.regex-input-row {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    transition: border-color 0.2s;
}
.regex-input-row:focus-within {
    border-color: var(--border-accent);
    box-shadow: 0 0 0 3px var(--accent-dim2);
}
.regex-field-wrapper {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 4px;
    min-width: 0;
}
.regex-delimiter {
    font-family: var(--mono);
    font-size: 1.25rem;
    color: var(--accent);
    font-weight: 600;
    line-height: 1;
    user-select: none;
    flex-shrink: 0;
}
.regex-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-family: var(--mono);
    font-size: 1rem;
    color: var(--text);
    padding: 6px 4px;
    min-width: 0;
}
.regex-input::placeholder {
    color: var(--text-dim);
}

/* Flags */
.flags-group {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    padding-left: 12px;
    border-left: 1px solid var(--border);
}
.flag-toggle {
    cursor: pointer;
    user-select: none;
}
.flag-toggle input { display: none; }
.flag-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    font-family: var(--mono);
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-dim);
    background: transparent;
    border: 1px solid transparent;
    transition: all 0.15s ease;
}
.flag-toggle input:checked + .flag-label {
    color: var(--accent);
    background: var(--accent-dim);
    border-color: var(--border-accent);
}
.flag-label:hover {
    background: var(--accent-dim2);
}

.regex-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    padding-left: 8px;
    border-left: 1px solid var(--border);
}

/* Error */
.regex-error {
    display: none;
    margin-top: 8px;
    padding: 10px 14px;
    background: var(--error-bg);
    border: 1px solid rgba(248, 113, 113, 0.25);
    border-radius: var(--radius-sm);
    color: var(--error);
    font-family: var(--mono);
    font-size: 0.82rem;
    line-height: 1.5;
}
.regex-error.visible {
    display: block;
}

/* Stats */
.regex-stats {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
    padding-left: 4px;
}
.stat-item {
    font-size: 0.8rem;
    color: var(--text-dim);
    font-weight: 500;
}
.stat-item.has-matches {
    color: var(--success);
}
.stat-separator {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--text-dim);
}

/* --- Workspace Grid --- */
.workspace {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 20px;
    align-items: start;
}

/* --- Panels --- */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.panel-title svg {
    color: var(--text-dim);
}

/* --- Test String --- */
.test-string-container {
    position: relative;
    min-height: 240px;
    max-height: 500px;
}
.highlight-layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 16px 18px;
    font-family: var(--mono);
    font-size: 0.9rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-y: auto;
    pointer-events: none;
    color: transparent;
}
.test-string-input {
    position: relative;
    width: 100%;
    min-height: 240px;
    max-height: 500px;
    padding: 16px 18px;
    background: transparent;
    border: none;
    outline: none;
    font-family: var(--mono);
    font-size: 0.9rem;
    line-height: 1.65;
    color: var(--text);
    resize: vertical;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-y: auto;
    caret-color: var(--accent);
}
.test-string-input::placeholder {
    color: var(--text-dim);
}

/* Highlight marks */
.hl-match {
    border-radius: 3px;
    padding: 1px 0;
}
.hl-match-0 { background: var(--match-1); }
.hl-match-1 { background: var(--match-2); }
.hl-match-2 { background: var(--match-3); }
.hl-match-3 { background: var(--match-4); }
.hl-match-active {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* --- Replace Panel --- */
.replace-content {
    display: none;
    padding: 14px 18px;
}
.replace-content.open {
    display: block;
}
.replace-input-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}
.replace-input {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 9px 14px;
    font-family: var(--mono);
    font-size: 0.875rem;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}
.replace-input:focus {
    border-color: var(--border-accent);
}
.replace-input::placeholder {
    color: var(--text-dim);
}
.replace-result {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    max-height: 200px;
    overflow-y: auto;
}
.replace-output {
    padding: 12px 14px;
    font-family: var(--mono);
    font-size: 0.875rem;
    line-height: 1.65;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-wrap: break-word;
    min-height: 40px;
}

.toggle-btn {
    display: flex;
    align-items: center;
    gap: 4px;
}
.chevron-icon {
    transition: transform 0.2s;
}
.chevron-icon.open {
    transform: rotate(180deg);
}

/* --- Match Details Panel --- */
.match-details-panel {
    position: sticky;
    top: 90px;
    max-height: calc(100vh - 110px);
    display: flex;
    flex-direction: column;
}
.match-details-body {
    overflow-y: auto;
    flex: 1;
    padding: 12px;
    min-height: 240px;
}
.match-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 20px;
    text-align: center;
}
.empty-icon {
    color: var(--text-dim);
    opacity: 0.4;
}
.match-empty-state p {
    color: var(--text-dim);
    font-size: 0.85rem;
    line-height: 1.5;
    max-width: 220px;
}

/* Match card */
.match-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    transition: border-color 0.2s, background 0.2s;
    cursor: pointer;
}
.match-card:hover {
    border-color: var(--border-accent);
    background: var(--surface-raised);
}
.match-card.active {
    border-color: var(--accent);
    background: var(--accent-dim2);
}
.match-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
.match-index {
    font-family: var(--mono);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.match-position {
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--text-dim);
}
.match-card-body {
    padding: 10px 14px;
}
.match-value {
    font-family: var(--mono);
    font-size: 0.85rem;
    color: var(--accent);
    background: var(--accent-dim2);
    padding: 4px 8px;
    border-radius: 4px;
    word-break: break-all;
    display: inline-block;
    max-width: 100%;
}
.match-groups {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}
.match-group-item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 3px 0;
    font-size: 0.8rem;
}
.match-group-label {
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--text-dim);
    flex-shrink: 0;
    min-width: 60px;
}
.match-group-value {
    font-family: var(--mono);
    font-size: 0.82rem;
    color: var(--text-secondary);
    word-break: break-all;
}

/* --- Overlays & Slide Panels --- */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}
.overlay.open {
    display: flex;
    justify-content: flex-end;
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.slide-panel {
    width: 580px;
    max-width: 90vw;
    height: 100vh;
    background: var(--surface);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    animation: slideIn 0.25s ease;
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.4);
}
@keyframes slideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}
.slide-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 1;
}
.slide-panel-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
}
.slide-panel-body {
    padding: 20px 24px;
}

/* Cheat Sheet */
.cheat-category {
    margin-bottom: 24px;
}
.cheat-category-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.cheat-table {
    width: 100%;
    border-collapse: collapse;
}
.cheat-table tr {
    border-bottom: 1px solid var(--border);
}
.cheat-table tr:last-child {
    border-bottom: none;
}
.cheat-table td {
    padding: 7px 10px;
    vertical-align: top;
    font-size: 0.82rem;
}
.cheat-table td:first-child {
    font-family: var(--mono);
    color: var(--accent);
    font-weight: 500;
    white-space: nowrap;
    width: 140px;
}
.cheat-table td:last-child {
    color: var(--text-secondary);
}

/* Patterns Library */
.pattern-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s;
}
.pattern-card:hover {
    border-color: var(--border-accent);
    background: var(--surface-raised);
}
.pattern-card-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}
.pattern-card-desc {
    font-size: 0.78rem;
    color: var(--text-dim);
    margin-bottom: 8px;
}
.pattern-card-regex {
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--accent);
    background: var(--accent-dim2);
    padding: 6px 10px;
    border-radius: 4px;
    word-break: break-all;
    line-height: 1.5;
}
.pattern-card-sample {
    margin-top: 8px;
    font-size: 0.75rem;
    color: var(--text-dim);
    font-style: italic;
}

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--surface-raised);
    color: var(--text);
    padding: 10px 22px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 999;
    pointer-events: none;
}
.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* --- Responsive --- */
@media (max-width: 1100px) {
    .workspace {
        grid-template-columns: 1fr;
    }
    .match-details-panel {
        position: static;
        max-height: none;
    }
}
@media (max-width: 700px) {
    .header-inner {
        padding: 14px 16px;
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
    .main-content {
        padding: 16px;
    }
    .regex-input-row {
        flex-wrap: wrap;
    }
    .flags-group {
        border-left: none;
        padding-left: 0;
        border-top: 1px solid var(--border);
        padding-top: 8px;
        width: 100%;
    }
    .regex-actions {
        border-left: none;
        padding-left: 0;
    }
    .header-actions .btn span {
        display: none;
    }
}
