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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-normal);
    line-height: var(--line-height-normal);
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

/* ============================================
   2. CSS Custom Properties
   ============================================ */
:root {
    /* Color palette */
    --primary-color: #667eea;
    --primary-dark: #5568d3;
    --secondary-color: #764ba2;
    --accent-color: #f093fb;
    --success-color: #4ade80;
    --warning-color: #fbbf24;
    --danger-color: #f87171;
    --info-color: #60a5fa;
    
    /* Neutral colors - Light theme */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --border-color: #e2e8f0;
    --border-color-hover: #cbd5e1;
    
    /* Highlight colors */
    --highlight-active: #fef08a;
    --highlight-excluded: #d1fae5;
    --highlight-warning: #fed7aa;
    
    /* Spacing scale */
    --spacing-xs: 0.25rem;    /* 4px */
    --spacing-sm: 0.5rem;     /* 8px */
    --spacing-md: 1rem;       /* 16px */
    --spacing-lg: 1.5rem;     /* 24px */
    --spacing-xl: 2rem;       /* 32px */
    --spacing-2xl: 3rem;      /* 48px */
    
    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    --font-size-xs: 0.75rem;   /* 12px */
    --font-size-sm: 0.875rem;  /* 14px */
    --font-size-base: 1rem;    /* 16px */
    --font-size-lg: 1.125rem;  /* 18px */
    --font-size-xl: 1.25rem;   /* 20px */
    --font-size-2xl: 1.5rem;   /* 24px */
    --font-size-3xl: 2rem;     /* 32px */
    
    --font-weight-normal: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;
    
    --line-height-tight: 1.25;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.75;
    
    /* Shadows */
    --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 -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    
    /* Border radius */
    --radius-sm: 0.375rem;  /* 6px */
    --radius-md: 0.5rem;    /* 8px */
    --radius-lg: 0.75rem;   /* 12px */
    --radius-xl: 1rem;      /* 16px */
    --radius-2xl: 1.5rem;   /* 24px */
    --radius-full: 9999px;
    
    /* Transitions */
    --transition-fast: 150ms ease-in-out;
    --transition-base: 250ms ease-in-out;
    --transition-slow: 350ms ease-in-out;
    
    /* Z-index scale */
    --z-base: 1;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-modal: 400;
    --z-tooltip: 500;
}

/* Dark theme */
[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    --border-color: #334155;
    --border-color-hover: #475569;
    
    /* Adjusted highlight colors for dark mode */
    --highlight-active: #854d0e;
    --highlight-excluded: #065f46;
    --highlight-warning: #9a3412;
}

/* ============================================
   3. Typography
   ============================================ */

h1, h2, h3, h4, h5, h6 {
    font-weight: var(--font-weight-bold);
    line-height: var(--line-height-tight);
    color: var(--text-primary);
}

h1 {
    font-size: var(--font-size-3xl);
}

h2 {
    font-size: var(--font-size-2xl);
}

h3 {
    font-size: var(--font-size-xl);
}

p {
    line-height: var(--line-height-relaxed);
}

/* ============================================
   4. Layout
   ============================================ */
body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ============================================
   5. App Container & Layout
   ============================================ */
.app-container {
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

[data-theme="dark"] .app-container {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

/* ============================================
   6. Header
   ============================================ */
.app-header {
    margin-bottom: var(--spacing-xl);
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--spacing-md);
}

.app-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    color: white;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    margin: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.title-icon {
    font-size: var(--font-size-3xl);
}

.theme-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-full);
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-base);
    backdrop-filter: blur(10px);
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.theme-toggle:active {
    transform: scale(0.95);
}

.theme-icon {
    font-size: var(--font-size-xl);
    transition: transform var(--transition-base);
}

.theme-toggle:hover .theme-icon {
    transform: rotate(20deg);
}

/* ============================================
   7. Main Content
   ============================================ */
.app-main {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
}

/* ============================================
   8. Utility Classes
   ============================================ */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* ============================================
   9. Input Section
   ============================================ */
.input-section {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    padding: var(--spacing-xl);
    box-shadow: var(--shadow-xl);
    transition: all var(--transition-base);
}

.input-wrapper {
    margin-bottom: var(--spacing-lg);
}

.input-textarea {
    width: 100%;
    min-height: 200px;
    padding: var(--spacing-md);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: var(--line-height-relaxed);
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    resize: vertical;
    transition: all var(--transition-base);
    outline: none;
}

.input-textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    background-color: var(--bg-primary);
}

.input-textarea::placeholder {
    color: var(--text-tertiary);
}

/* Results display - styled to match textarea */
.results-display {
    width: 100%;
    min-height: 200px;
    padding: var(--spacing-md);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: var(--line-height-relaxed);
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    white-space: pre-line;
    word-wrap: break-word;
    overflow-wrap: break-word;
    transition: all var(--transition-base);
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--spacing-sm);
    padding: 0 var(--spacing-xs);
}

.char-count {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    font-weight: var(--font-weight-medium);
}

.clear-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-md);
    font-size: var(--font-size-lg);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    transform: scale(1.1);
}

.clear-btn:active {
    transform: scale(0.95);
}

.edit-btn {
    background: transparent;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
}

.edit-btn:hover {
    background: var(--bg-tertiary);
    color: var(--primary-dark);
    transform: scale(1.05);
}

.edit-btn:active {
    transform: scale(0.95);
}

.check-btn {
    width: 100%;
    padding: var(--spacing-md) var(--spacing-xl);
    font-family: var(--font-family);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: white;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-base);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    position: relative;
    overflow: hidden;
}

.check-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--secondary-color) 100%);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.check-btn:hover::before {
    opacity: 1;
}

.check-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

.check-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
    transform: none;
}

.btn-text,
.btn-loader {
    position: relative;
    z-index: 1;
}

.btn-loader {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   9.5. Progress Bar
   ============================================ */
.progress-container {
    margin-top: var(--spacing-lg);
    animation: fadeIn 0.3s ease-in-out;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
    position: relative;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    border-radius: var(--radius-full);
    transition: width 0.3s ease-out;
    width: 0%;
    position: relative;
    overflow: hidden;
}

.progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.3) 50%,
        transparent 100%
    );
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

.progress-text {
    margin-top: var(--spacing-sm);
    text-align: center;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    font-weight: var(--font-weight-medium);
}

/* ============================================
   10. Results Section
   ============================================ */
.results-section {
    background: var(--bg-primary);
    border-radius: var(--radius-xl);
    padding: var(--spacing-xl);
    box-shadow: var(--shadow-xl);
}

.results-heading {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
    margin-bottom: var(--spacing-lg);
}

.results-content {
    white-space: pre-wrap;
    line-height: var(--line-height-relaxed);
    font-size: var(--font-size-base);
    color: var(--text-primary);
    background: var(--bg-secondary);
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    min-height: 150px;
}

/* ============================================
   11. Summary Card
   ============================================ */
.results-summary {
    margin-bottom: var(--spacing-lg);
}

.summary-card {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border: 2px solid var(--primary-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
}

[data-theme="dark"] .summary-card {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.15) 0%, rgba(118, 75, 162, 0.15) 100%);
}

.summary-clean {
    background: linear-gradient(135deg, rgba(74, 222, 128, 0.1) 0%, rgba(34, 197, 94, 0.1) 100%);
    border-color: var(--success-color);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.summary-icon {
    font-size: var(--font-size-3xl);
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--success-color);
    color: white;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.summary-header {
    margin-bottom: var(--spacing-md);
}

.summary-title {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    margin: 0;
}

.summary-description {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    margin: var(--spacing-xs) 0 0 0;
}

.summary-stats {
    display: flex;
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-md);
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.stat-label {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    font-weight: var(--font-weight-medium);
}

.stat-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 var(--spacing-sm);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    color: white;
}

.stat-badge-active {
    background: var(--warning-color);
}

.stat-badge-excluded {
    background: var(--success-color);
}

.summary-types {
    display: flex;
    flex-wrap: nowrap;
    gap: var(--spacing-sm);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--border-color);
    overflow-x: auto;
}

.type-badge {
    display: inline-block;
    padding: var(--spacing-xs) var(--spacing-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    color: var(--text-primary);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Colored type badges for 4 categories */
.type-badge-highlight-terrorist {
    background: #F2B2B2;
    border-color: #d97979;
    color: #8b4545;
}

.type-badge-highlight-extremist {
    background: #F6C8A6;
    border-color: #e5a876;
    color: #8b6345;
}

.type-badge-highlight-undesirable {
    background: #FAF0B6;
    border-color: #e8d88a;
    color: #8b8245;
}

.type-badge-highlight-foreign {
    background: #C8DAF8;
    border-color: #9bb8e8;
    color: #3d5a8b;
}

[data-theme="dark"] .type-badge-highlight-terrorist {
    background: #8b4545;
    border-color: #d97979;
    color: #F2B2B2;
}

[data-theme="dark"] .type-badge-highlight-extremist {
    background: #8b6345;
    border-color: #e5a876;
    color: #F6C8A6;
}

[data-theme="dark"] .type-badge-highlight-undesirable {
    background: #8b8245;
    border-color: #e8d88a;
    color: #FAF0B6;
}

[data-theme="dark"] .type-badge-highlight-foreign {
    background: #3d5a8b;
    border-color: #9bb8e8;
    color: #C8DAF8;
}

/* ============================================
   12. Highlights & Tooltips
   ============================================ */
.highlight {
    position: relative;
    cursor: help;
    border-radius: var(--radius-sm);
    padding: 2px 4px;
    margin: 0 1px;
    transition: all var(--transition-fast);
}

/* 4 main categories with custom colors */

/* 1. Террористическая организация - светло-красный */
.highlight-terrorist {
    background-color: #F2B2B2;
    border-bottom: 2px solid #d97979;
}

/* 2. Экстремистская организация - персиковый */
.highlight-extremist {
    background-color: #F6C8A6;
    border-bottom: 2px solid #e5a876;
}

/* 3. Нежелательная организация - светло-желтый */
.highlight-undesirable {
    background-color: #FAF0B6;
    border-bottom: 2px solid #e8d88a;
}

/* 4. Иностранный агент - светло-голубой */
.highlight-foreign {
    background-color: #C8DAF8;
    border-bottom: 2px solid #9bb8e8;
}

/* Dark theme adjustments */
[data-theme="dark"] .highlight-terrorist {
    background-color: #8b4545;
    color: #F2B2B2;
}

[data-theme="dark"] .highlight-extremist {
    background-color: #8b6345;
    color: #F6C8A6;
}

[data-theme="dark"] .highlight-undesirable {
    background-color: #8b8245;
    color: #FAF0B6;
}

[data-theme="dark"] .highlight-foreign {
    background-color: #3d5a8b;
    color: #C8DAF8;
}

.highlight:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.tooltip {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    z-index: var(--z-tooltip);
    bottom: calc(100% + 10px);
    left: 0;
    transform: translateY(5px);
    width: 400px;
    max-width: calc(100vw - 2rem);
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    padding: var(--spacing-md);
    transition: all var(--transition-base);
    pointer-events: none;
}

.highlight:hover .tooltip {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

/* Touch device support for tooltips */
@media (hover: none) and (pointer: coarse) {
    .highlight {
        cursor: pointer;
    }
    
    .tooltip {
        pointer-events: auto;
    }
}

.tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: var(--spacing-lg);
    border-width: 8px;
    border-style: solid;
    border-color: var(--bg-primary) transparent transparent transparent;
}

.tooltip-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--border-color);
}

.tooltip-title {
    font-weight: var(--font-weight-bold);
    font-size: var(--font-size-base);
    color: var(--text-primary);
    flex: 1;
}

.tooltip-badge {
    display: inline-block;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: white;
    flex-shrink: 0;
}

.badge-active {
    background: var(--warning-color);
}

.badge-excluded {
    background: var(--success-color);
}

.tooltip-body {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.tooltip-row {
    display: flex;
    gap: var(--spacing-sm);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.tooltip-category-item {
    padding-left: var(--spacing-md);
    color: var(--text-primary);
}

.tooltip-label {
    font-weight: var(--font-weight-semibold);
    color: var(--text-primary);
}

/* ============================================
   13. Animations
   ============================================ */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ============================================
   14. Error Messages
   ============================================ */
.error-message {
    padding: var(--spacing-lg);
    background: rgba(248, 113, 113, 0.1);
    border: 2px solid var(--danger-color);
    border-radius: var(--radius-lg);
    color: var(--danger-color);
    font-weight: var(--font-weight-medium);
    text-align: center;
}

/* ============================================
   15. Responsive Design
   ============================================ */

/* Tablets and smaller desktops */
@media (max-width: 1024px) {
    .app-container {
        padding: var(--spacing-md);
    }
    
    .app-title {
        font-size: var(--font-size-xl);
        line-height: var(--line-height-tight);
    }
    
    .db-status {
        flex-wrap: wrap;
    }
    
    .db-status-text {
        flex-wrap: wrap;
    }
    
    .tooltip {
        width: 320px;
    }
}

/* Mobile landscape and tablets portrait */
@media (max-width: 768px) {
    .app-container {
        padding: var(--spacing-sm);
    }
    
    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-md);
    }
    
    .app-title {
        font-size: var(--font-size-lg);
        line-height: var(--line-height-normal);
    }
    
    .title-icon {
        font-size: var(--font-size-xl);
    }
    
    .theme-toggle {
        width: 44px;
        height: 44px;
        position: absolute;
        top: var(--spacing-md);
        right: var(--spacing-md);
    }
    
    .db-status {
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-xs);
        padding: var(--spacing-md);
    }
    
    .db-status-text {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-xs);
    }
    
    .db-status-separator {
        display: none;
    }
    
    #dbMd5 {
        word-break: break-all;
        max-width: 100%;
    }
    
    .input-section,
    .results-section {
        padding: var(--spacing-md);
    }
    
    .input-textarea,
    .results-display {
        min-height: 150px;
        font-size: var(--font-size-sm);
        padding: var(--spacing-sm);
    }
    
    .check-btn {
        font-size: var(--font-size-base);
        padding: var(--spacing-sm) var(--spacing-lg);
    }
    
    .summary-card {
        padding: var(--spacing-md);
    }
    
    .summary-clean {
        flex-direction: column;
        text-align: center;
    }
    
    .summary-icon {
        width: 50px;
        height: 50px;
        font-size: var(--font-size-2xl);
    }
    
    .summary-title {
        font-size: var(--font-size-lg);
    }
    
    .summary-stats {
        flex-direction: column;
        gap: var(--spacing-sm);
    }
    
    .summary-types {
        gap: var(--spacing-xs);
    }
    
    .type-badge {
        font-size: var(--font-size-xs);
        padding: var(--spacing-xs);
    }
    
    .tooltip {
        width: 280px;
        left: 50%;
        transform: translateX(-50%) translateY(5px);
        bottom: auto;
        top: calc(100% + 10px);
    }
    
    .highlight:hover .tooltip {
        transform: translateX(-50%) translateY(0);
    }
    
    .tooltip::after {
        top: auto;
        bottom: 100%;
        left: 50%;
        transform: translateX(-50%);
        border-color: transparent transparent var(--bg-primary) transparent;
    }
    
    .results-heading {
        font-size: var(--font-size-lg);
    }
    
    .results-content {
        font-size: var(--font-size-sm);
        padding: var(--spacing-md);
    }
}

/* Mobile portrait */
@media (max-width: 480px) {
    .app-container {
        padding: var(--spacing-xs);
    }
    
    .app-header {
        margin-bottom: var(--spacing-lg);
    }
    
    .header-content {
        padding-right: 60px;
    }
    
    .app-title {
        font-size: var(--font-size-base);
        gap: var(--spacing-xs);
    }
    
    .title-icon {
        font-size: var(--font-size-lg);
    }
    
    .theme-toggle {
        width: 40px;
        height: 40px;
        top: var(--spacing-sm);
        right: var(--spacing-sm);
    }
    
    .theme-icon {
        font-size: var(--font-size-base);
    }
    
    .db-status {
        font-size: var(--font-size-xs);
        padding: var(--spacing-sm);
    }
    
    .db-status-icon {
        font-size: var(--font-size-sm);
    }
    
    .input-section,
    .results-section {
        padding: var(--spacing-sm);
        border-radius: var(--radius-lg);
    }
    
    .input-textarea,
    .results-display {
        min-height: 120px;
        font-size: var(--font-size-xs);
        padding: var(--spacing-sm);
    }
    
    .input-footer {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--spacing-xs);
    }
    
    .char-count {
        font-size: var(--font-size-xs);
    }
    
    .check-btn {
        font-size: var(--font-size-sm);
        padding: var(--spacing-sm) var(--spacing-md);
    }
    
    .summary-card {
        padding: var(--spacing-sm);
    }
    
    .summary-icon {
        width: 40px;
        height: 40px;
        font-size: var(--font-size-xl);
    }
    
    .summary-title {
        font-size: var(--font-size-base);
    }
    
    .summary-description {
        font-size: var(--font-size-sm);
    }
    
    .stat-item {
        gap: var(--spacing-xs);
    }
    
    .stat-label {
        font-size: var(--font-size-xs);
    }
    
    .stat-badge {
        min-width: 28px;
        height: 28px;
        font-size: var(--font-size-xs);
    }
    
    .type-badge {
        font-size: 0.625rem;
        padding: 2px var(--spacing-xs);
    }
    
    .tooltip {
        width: calc(100vw - 2rem);
        max-width: 280px;
        font-size: var(--font-size-xs);
        padding: var(--spacing-sm);
    }
    
    .tooltip-title {
        font-size: var(--font-size-sm);
    }
    
    .tooltip-row {
        font-size: var(--font-size-xs);
    }
    
    .results-heading {
        font-size: var(--font-size-base);
        margin-bottom: var(--spacing-md);
    }
    
    .results-content {
        font-size: var(--font-size-xs);
        padding: var(--spacing-sm);
    }
    
    .progress-text {
        font-size: var(--font-size-xs);
    }
}

/* Very small screens */
@media (max-width: 360px) {
    .app-title {
        font-size: var(--font-size-sm);
    }
    
    .summary-stats {
        gap: var(--spacing-xs);
    }
    
    .type-badge {
        font-size: 0.5rem;
        padding: 1px var(--spacing-xs);
    }
}

/* ============================================
   16. Database Status
   ============================================ */
.db-status {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
    margin-top: var(--spacing-md);
    max-width: 100%;
    overflow-x: auto;
}

.db-status-icon {
    font-size: var(--font-size-base);
}

.db-status-text {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.db-status-separator {
    color: var(--text-tertiary);
    margin: 0 var(--spacing-xs);
}

#dbPatternCount,
#dbUpdateDate {
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
}

#dbMd5 {
    font-family: 'Courier New', monospace;
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--text-primary);
}

.db-history-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: var(--font-weight-semibold);
    transition: all var(--transition-fast);
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--radius-sm);
}

.db-history-link:hover {
    background: rgba(102, 126, 234, 0.1);
    text-decoration: underline;
}

[data-theme="dark"] .db-history-link {
    color: #9bb8e8;
}

[data-theme="dark"] .db-history-link:hover {
    background: rgba(155, 184, 232, 0.1);
}

/* ============================================
   17. Focus Styles for Accessibility
   ============================================ */
*:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 2px;
}

button:focus-visible {
    outline-offset: 4px;
}

/* ============================================
   18. Print Styles
   ============================================ */
@media print {
    .app-header,
    .input-section,
    .theme-toggle,
    .db-status {
        display: none;
    }
    
    .results-section {
        box-shadow: none;
        border: 1px solid #000;
    }
}
