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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    color: #212529;
    background: linear-gradient(135deg, #E0E8FF 0%, #BFCFFF 100%);
    min-height: 100vh;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid #E9ECEF;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
    gap: 2rem;
}

.nav-brand {
    flex-shrink: 0;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: #007BFF;
    font-weight: 700;
    font-size: 1.25rem;
}

.brand-icon {
    flex-shrink: 0;
}

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

/* Breadcrumb */
.nav-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.breadcrumb-list {
    display: flex;
    list-style: none;
    gap: 0.5rem;
    align-items: center;
}

.breadcrumb-item {
    display: flex;
    align-items: center;
}

.breadcrumb-item:not(:last-child)::after {
    content: '›';
    margin-left: 0.5rem;
    color: #6C757D;
    font-weight: 600;
}

.breadcrumb-item a {
    text-decoration: none;
    color: #007BFF;
    font-size: 0.875rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    transition: background-color 0.2s ease;
}

.breadcrumb-item a:hover {
    background-color: #E7F3FF;
}

.breadcrumb-item.active span {
    color: #6C757D;
    font-size: 0.875rem;
    padding: 0.25rem 0.5rem;
}

/* Language Switch */
.nav-actions {
    flex-shrink: 0;
}

.lang-switch {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: #007BFF;
    color: white;
    border: none;
    border-radius: 0.375rem;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: background-color 0.2s ease;
}

.lang-switch:hover {
    background: #0056b3;
}

.lang-icon {
    transition: transform 0.2s ease;
}

.lang-switch.open .lang-icon {
    transform: rotate(180deg);
}

/* Main Content */
.main {
    padding: 2rem 0;
}

/* Hero Section */
.hero {
    text-align: center;
    margin-bottom: 3rem;
}

.hero-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: #1A2C4B;
    margin-bottom: 1rem;
}

.hero-subtitle {
    font-size: 1.125rem;
    color: #6C757D;
    max-width: 600px;
    margin: 0 auto;
}

/* Converter Section */
.converter-section {
    margin-bottom: 4rem;
}

.converter-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 2rem;
}

/* Conversion Toggle */
.conversion-toggle {
    display: flex;
    background: #F8F9FA;
    border-radius: 0.5rem;
    padding: 0.25rem;
    margin-bottom: 2rem;
    border: 1px solid #E9ECEF;
}

.toggle-btn {
    flex: 1;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: #6C757D;
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-btn.active {
    background: #007BFF;
    color: white;
    box-shadow: 0 2px 4px rgba(0, 123, 255, 0.2);
}

.toggle-btn:hover:not(.active) {
    background: #E9ECEF;
    color: #212529;
}

/* CMYK Inputs */
.cmyk-inputs {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}

.cmyk-input-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: #F8F9FA;
    border-radius: 0.375rem;
    border: 1px solid #E9ECEF;
}

.cmyk-input-group label {
    font-weight: 600;
    color: #1A2C4B;
    min-width: 1rem;
}

.cmyk-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 1rem;
    text-align: center;
    font-weight: 600;
    color: #212529;
    min-width: 0;
}

.cmyk-input:focus {
    outline: none;
}

/* Hex Results */
.hex-results {
    margin-bottom: 2rem;
}

.hex-value-display {
    text-align: center;
    padding: 1.5rem;
    background: #F8F9FA;
    border-radius: 0.5rem;
    border: 1px solid #E9ECEF;
}

.hex-label {
    display: block;
    font-size: 0.875rem;
    color: #6C757D;
    margin-bottom: 0.5rem;
}

.hex-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: #1A2C4B;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
}

/* Main Converter */
.converter-card {
    background: #FFFFFF;
    border-radius: 1rem;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(26, 44, 75, 0.1);
    border: 1px solid #E9ECEF;
}

/* Color Preview */
.color-preview-section {
    text-align: center;
    margin-bottom: 2rem;
}

.color-preview {
    width: 120px;
    height: 120px;
    border-radius: 12px;
    border: 1px solid #E9ECEF;
    margin: 0 auto 1rem;
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    transition: all 0.3s ease;
}

.preview-label {
    background: rgba(255, 255, 255, 0.9);
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #212529;
}

/* Input Section */
.input-section {
    margin-bottom: 2rem;
}

.input-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #1A2C4B;
}

.input-wrapper {
    position: relative;
    display: flex;
}

.hex-input {
    flex: 1;
    padding: 0.75rem 3rem 0.75rem 1rem;
    border: 1px solid #DEE2E6;
    border-radius: 0.375rem;
    font-size: 1rem;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: #FFFFFF;
}

.hex-input:focus {
    outline: none;
    border-color: #007BFF;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.hex-input.error {
    border-color: #DC3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

.paste-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: #6C757D;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.25rem;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.paste-btn:hover {
    color: #007BFF;
    background-color: #F8F9FA;
}

.input-help {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: #6C757D;
}

.input-error {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: #DC3545;
    display: none;
}

.input-error.show {
    display: block;
}

/* Results Section */
.results-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: #1A2C4B;
    margin-bottom: 1.5rem;
    text-align: center;
}

.cmyk-values {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.cmyk-item {
    text-align: center;
    padding: 1rem;
    background: #F8F9FA;
    border-radius: 0.5rem;
    border: 1px solid #E9ECEF;
}

.cmyk-label {
    display: block;
    font-size: 0.875rem;
    color: #6C757D;
    margin-bottom: 0.5rem;
}

.cmyk-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 600;
    color: #1A2C4B;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
}

/* Copy Button */
.copy-btn {
    width: 100%;
    padding: 0.75rem 1.5rem;
    background: #007BFF;
    color: white;
    border: none;
    border-radius: 0.375rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.copy-btn:hover {
    background: #0056b3;
    transform: translateY(-1px);
}

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

.copy-btn.success {
    background: #28A745;
}

.copy-success {
    display: none;
}

.copy-btn.success .copy-text {
    display: none;
}

.copy-btn.success .copy-success {
    display: inline;
}

.copy-icon,
.success-icon {
    margin-left: 0.5rem;
    vertical-align: middle;
}

.success-icon {
    display: none;
}

.copy-btn.success .copy-icon {
    display: none;
}

.copy-btn.success .success-icon {
    display: inline;
}

/* Sidebar */
.converter-sidebar {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.sidebar-card {
    background: #FFFFFF;
    border-radius: 0.75rem;
    padding: 1.5rem;
    box-shadow: 0 4px 16px rgba(26, 44, 75, 0.08);
    border: 1px solid #E9ECEF;
}

/* Enhanced preset colors container for better space utilization */
.converter-sidebar {
    min-width: 0; /* Allow flexible shrinking */
}

.sidebar-card .preset-colors {
    min-height: 520px; /* Increased height to accommodate all 80+ colors */
    padding-bottom: 1rem; /* Extra padding at bottom */
}

.sidebar-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: #1A2C4B;
    margin-bottom: 1rem;
    text-align: center;
}

/* Preset Colors */
.preset-colors {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.25rem; /* Reduced gap from 0.5rem */
}

.preset-color {
    aspect-ratio: 1;
    max-width: 40px; /* Added max-width to prevent overflow */
    border-radius: 0.375rem; /* Slightly smaller border radius */
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.preset-color:hover {
    border-color: #007BFF;
    transform: scale(1.02); /* Reduced scale from 1.05 to prevent overflow */
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.preset-color::after {
    content: attr(data-hex);
    position: absolute;
    bottom: -2rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.75rem;
    color: #6C757D;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s ease;
    background: rgba(255, 255, 255, 0.9);
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    border: 1px solid #E9ECEF;
}

.preset-color:hover::after {
    opacity: 1;
}

/* History */
.history-actions {
    margin-bottom: 1rem;
}

.clear-btn {
    padding: 0.375rem 0.75rem;
    background: transparent;
    color: #DC3545;
    border: 1px solid #DC3545;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.clear-btn:hover {
    background: #DC3545;
    color: white;
}

.history-list {
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.375rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    margin-bottom: 0.5rem;
}

.history-item:hover {
    background: #F8F9FA;
}

.history-color {
    width: 24px;
    height: 24px;
    border-radius: 0.25rem;
    border: 1px solid #E9ECEF;
    flex-shrink: 0;
}

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

.history-hex {
    font-size: 0.875rem;
    font-weight: 600;
    color: #1A2C4B;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
}

.history-cmyk {
    font-size: 0.75rem;
    color: #6C757D;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
}

.history-empty {
    text-align: center;
    color: #6C757D;
    font-size: 0.875rem;
    padding: 2rem 0;
}

/* Info Sections */
.info-sections {
    margin-top: 4rem;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
}

.info-card {
    background: #FFFFFF;
    border-radius: 0.75rem;
    padding: 2rem;
    box-shadow: 0 4px 16px rgba(26, 44, 75, 0.08);
    border: 1px solid #E9ECEF;
}

.info-card h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #1A2C4B;
    margin-bottom: 1rem;
}

.info-card h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: #1A2C4B;
    margin-bottom: 0.75rem;
}

.info-card ul,
.info-card ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.info-card li {
    margin-bottom: 0.5rem;
}

.info-card p {
    margin-bottom: 1rem;
    color: #212529;
}

.tip {
    background: #E7F3FF;
    padding: 1rem;
    border-radius: 0.5rem;
    border-left: 4px solid #007BFF;
    margin-top: 1rem;
}

.knowledge-grid {
    display: grid;
    gap: 1.5rem;
    margin-top: 1rem;
}

.knowledge-item {
    padding: 1rem;
    border: 1px solid #E9ECEF;
    border-radius: 0.5rem;
    background: #F8F9FA;
}

/* Color Reference Table */
.color-reference-table {
    overflow-x: auto;
    margin-top: 1rem;
}

.reference-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.reference-table th,
.reference-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #E9ECEF;
}

.reference-table th {
    background: #F8F9FA;
    font-weight: 600;
    color: #1A2C4B;
}

.reference-table tbody tr:hover {
    background: #F8F9FA;
}

.reference-preview {
    width: 24px;
    height: 24px;
    border-radius: 0.25rem;
    border: 1px solid #E9ECEF;
}

.reference-hex {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-weight: 600;
}

.reference-cmyk {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    color: #6C757D;
}

/* Footer */
.footer {
    background: #1A2C4B;
    color: white;
    padding: 2rem 0;
    margin-top: 4rem;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.footer-nav {
    display: flex;
    gap: 2rem;
}

.footer-link {
    color: #BFCFFF;
    text-decoration: none;
    font-size: 0.875rem;
    transition: color 0.2s ease;
}

.footer-link:hover {
    color: white;
}

.footer-note {
    text-align: center;
    padding-top: 1rem;
    border-top: 1px solid #2A3F5F;
    color: #BFCFFF;
    font-size: 0.875rem;
}

/* Responsive Design */
@media (max-width: 1024px) {
    .converter-grid {
        grid-template-columns: 1fr;
    }
    
    .converter-sidebar {
        order: -1; /* Show presets first on tablet */
    }
    
    .preset-colors {
        grid-template-columns: repeat(10, 1fr);
        gap: 0.2rem; /* Reduced gap for tablet */
    }
    
    .preset-color {
        max-width: 32px; /* Smaller for tablet */
    }
    
    .sidebar-card .preset-colors {
        min-height: 450px; /* Adjusted for 10-column layout */
    }
}

@media (max-width: 768px) {
    .container {
        padding: 0 0.75rem;
    }
    
    .main {
        padding: 1rem 0;
    }
    
    /* Key Change: Make converter appear FIRST on mobile */
    .converter-grid {
        display: flex;
        flex-direction: column;
    }
    
    .converter-main {
        order: 1; /* Converter goes FIRST */
    }
    
    .converter-sidebar {
        order: 2; /* Sidebar (presets) goes SECOND */
        margin-bottom: 1.5rem;
    }
    
    .nav {
        flex-direction: column;
        gap: 1rem;
    }
    
    .nav-center {
        order: 1;
    }
    
    .nav-actions {
        order: 2;
    }
    
    .breadcrumb-list {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.25rem;
    }
    
    .hero {
        margin-bottom: 1.5rem;
    }
    
    .hero-title {
        font-size: 1.75rem;
    }
    
    .hero-subtitle {
        font-size: 1rem;
    }
    
    .converter-section {
        margin-bottom: 2rem;
    }
    
    .converter-card {
        padding: 1.5rem;
    }
    
    .sidebar-card {
        margin-bottom: 1rem;
    }
    
    .cmyk-values {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .cmyk-inputs {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .preset-colors {
        grid-template-columns: repeat(6, 1fr);
        gap: 0.25rem; /* Reduced gap for mobile */
    }
    
    .preset-color {
        max-width: 36px; /* Optimized for mobile */
    }
    
    .sidebar-card .preset-colors {
        min-height: 560px; /* Adjusted for 6-column layout on mobile */
    }
    
    .info-sections {
        margin-top: 2rem;
    }
    
    .info-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }
    
    .info-card {
        padding: 1.5rem;
    }
    
    .footer-content {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }
    
    .footer-nav {
        justify-content: center;
        flex-wrap: wrap;
        gap: 1rem;
    }
}

@media (max-width: 480px) {
    .hero-title {
        font-size: 1.5rem;
    }
    
    .converter-card {
        padding: 1rem;
    }
    
    .sidebar-card {
        padding: 1rem;
    }
    
    .info-card {
        padding: 1rem;
    }
    
    .color-preview {
        width: 100px;
        height: 100px;
    }
    
    .toggle-btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
    }
    
    .cmyk-inputs {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .preset-colors {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.2rem; /* Reduced gap for small screens */
    }
    
    .preset-color {
        max-width: 42px; /* Optimized for small screens */
    }
    
    .sidebar-card .preset-colors {
        min-height: 720px; /* Adjusted for 4-column layout on small screens */
    }
    
    .reference-table {
        font-size: 0.75rem;
    }
    
    .reference-table th,
    .reference-table td {
        padding: 0.5rem;
    }
}

/* Print Styles */
@media print {
    .header,
    .footer,
    .converter-sidebar,
    .copy-btn,
    .paste-btn,
    .clear-btn {
        display: none;
    }
    
    body {
        background: white;
    }
    
    .converter-card,
    .info-card {
        box-shadow: none;
        border: 1px solid #ccc;
    }
}

/* Enhanced info card styles for SEO content */
.comparison-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin: 1.5rem 0;
}

.comparison-item {
    padding: 1.5rem;
    background: #F8F9FA;
    border-radius: 0.5rem;
    border: 1px solid #E9ECEF;
}

.comparison-item h3 {
    color: #007BFF;
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.comparison-item ul {
    margin: 0;
    padding-left: 1.2rem;
}

.comparison-item li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.faq-item {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: #F8F9FA;
    border-radius: 0.5rem;
    border-left: 4px solid #007BFF;
    transition: all 0.2s ease;
}

.faq-item:hover {
    background: #E7F3FF;
    transform: translateX(4px);
}

.faq-item h3 {
    color: #1A2C4B;
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
}

.faq-item p {
    margin: 0;
    color: #495057;
    line-height: 1.6;
}

@media (max-width: 768px) {
    .comparison-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .comparison-item {
        padding: 1rem;
    }
    
    .faq-item {
        padding: 1rem;
        margin-bottom: 1rem;
    }
}

/* Accessibility improvements */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus visible for better accessibility */
.hex-input:focus-visible,
.copy-btn:focus-visible,
.clear-btn:focus-visible,
.lang-switch:focus-visible {
    outline: 2px solid #007BFF;
    outline-offset: 2px;
}

/* Animation for smooth transitions */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.converter-card,
.sidebar-card,
.info-card {
    animation: fadeIn 0.5s ease-out;
}

/* Loading animation */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}