/* ============================================
   Tool Navigation Bar
   ============================================ */
.tool-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.back-home {
    color: var(--light-text-color);
    text-decoration: none;
    font-size: 0.9rem;
    transition: color 0.2s ease;
    touch-action: manipulation;
}
.back-home:hover { color: var(--primary-color); }
.lang-switcher { display: flex; gap: 0.5rem; }
.lang-switcher a {
    padding: 3px 8px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--light-text-color);
    transition: color 0.2s ease;
    touch-action: manipulation;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}
.lang-switcher a.active {
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
}
.lang-switcher a:hover { color: var(--primary-color); }

/* ============================================
   CSS Variables (Tool Pages)
   ============================================ */
:root {
    --primary-color: #005A9C;
    --secondary-color: #4CAF50;
    --accent-color: #D9534F;
    --background-color: #f4f7f9;
    --card-background: #ffffff;
    --text-color: #333333;
    --light-text-color: #666666;
    --border-color: #dfe4e8;
    --input-focus-border: #005A9C;
    --shadow-color: rgba(0, 0, 0, 0.08);
    --result-background: #eef5fc;
    --result-border: #cdddeb;
    --button-color: #005A9C;
    --button-text: #ffffff;
    --button-hover: #004b83;
    --copy-success: #4CAF50;
    --error-color: var(--accent-color);
    --history-item-hover-bg: #e9ecef;
}

[data-theme="dark"] {
    --primary-color: #4d94ff;
    --secondary-color: #6fbd72;
    --accent-color: #ff6b6b;
    --background-color: #121212;
    --card-background: #1e1e1e;
    --text-color: #e0e0e0;
    --light-text-color: #b0b0b0;
    --border-color: #2d2d2d;
    --input-focus-border: #4d94ff;
    --shadow-color: rgba(255, 255, 255, 0.1);
    --result-background: #252836;
    --result-border: #323644;
    --button-color: #4d94ff;
    --button-text: #ffffff;
    --button-hover: #3a7ad9;
    --copy-success: #6fbd72;
    --error-color: var(--accent-color);
    --history-item-hover-bg: #2c2f3d;
    color-scheme: dark;
}

/* Reset and Base */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; transition: background-color 0.3s ease; }
body {
    font-family: 'Lato', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--background-color);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding: 1rem;
    transition: color 0.3s ease, background-color 0.3s ease;
}
.container { max-width: 860px; margin: 2rem auto; flex-grow: 1; }
main { display: flex; flex-direction: column; gap: 2.5rem; }

/* Header */
header { text-align: center; margin-bottom: 2.5rem; }
header h1 { font-size: 2.2rem; color: var(--primary-color); margin-bottom: 0.5rem; font-weight: 700; transition: color 0.3s ease; text-wrap: balance; }
header p { font-size: 1.1rem; color: var(--light-text-color); transition: color 0.3s ease; }

/* Converter Tool Section */
.converter-tool, .explanation, .sharing-section, .history-section {
    background-color: var(--card-background);
    padding: 2rem 2.5rem;
    border-radius: 10px;
    box-shadow: 0 4px 15px var(--shadow-color);
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}
.converter-tool { text-align: center; }

label { display: block; margin-bottom: 0.8rem; font-weight: 700; font-size: 1.1rem; color: var(--text-color); transition: color 0.3s ease; }
input[type="text"] {
    padding: 0.8rem 1rem; width: 100%; max-width: 250px;
    border: 1px solid var(--border-color); border-radius: 6px;
    font-size: 1.2rem; text-align: center; text-transform: uppercase;
    transition: border-color 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease, color 0.3s ease;
    margin-bottom: 0.5rem;
    background-color: var(--card-background); color: var(--text-color);
}
input[type="text"]:focus-visible { outline: none; border-color: var(--input-focus-border); box-shadow: 0 0 0 3px rgba(77, 148, 255, 0.2); }
input[type="number"] {
    padding: 0.8rem 1rem; width: 100%; max-width: 250px;
    border: 1px solid var(--border-color); border-radius: 6px;
    font-size: 1.2rem; text-align: center;
    transition: border-color 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease, color 0.3s ease;
    margin-bottom: 0.5rem;
    background-color: var(--card-background); color: var(--text-color);
}
input[type="number"]:focus-visible { outline: none; border-color: var(--input-focus-border); box-shadow: 0 0 0 3px rgba(77, 148, 255, 0.2); }
input[type="date"] {
    padding: 0.8rem 1rem; width: 100%; max-width: 250px;
    border: 1px solid var(--border-color); border-radius: 6px;
    font-size: 1.1rem; text-align: center;
    transition: border-color 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease, color 0.3s ease;
    margin-bottom: 0.5rem;
    background-color: var(--card-background); color: var(--text-color);
}
input[type="date"]:focus-visible { outline: none; border-color: var(--input-focus-border); box-shadow: 0 0 0 3px rgba(77, 148, 255, 0.2); }
.input-group { margin-bottom: 1rem; position: relative; }

/* Error feedback */
.error-feedback {
    color: var(--error-color);
    font-size: 0.9em;
    min-height: 1.4em;
    margin-top: 0.3rem;
    margin-bottom: 0.8rem;
    text-align: center;
    display: block;
}

/* Result area */
#resultArea {
    margin-top: 1rem; font-size: 1.3rem; color: var(--text-color);
    min-height: 60px; background-color: var(--result-background);
    border-radius: 6px; padding: 0.8rem; display: inline-block;
    border: 1px solid var(--result-border);
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
    margin-bottom: 15px;
}
#columnNumber {
    color: var(--accent-color); font-weight: 700; font-size: 2rem;
    display: block; margin-top: 0.3rem; transition: color 0.3s ease;
}
#columnNumber.invalid { font-size: 1.4rem; }
.example { font-size: 0.95rem; color: var(--light-text-color); margin-top: 1rem; transition: color 0.3s ease; }
.dynamic-title { font-size: 1.6rem; color: var(--primary-color); margin-top: 1.5rem; margin-bottom: 0; transition: color 0.3s ease; }
.dynamic-title span { color: var(--accent-color); font-weight: 700; transition: color 0.3s ease; }

/* Explanation section */
.explanation { text-align: left; }
.explanation h2 { color: var(--primary-color); margin-bottom: 1rem; font-size: 1.5rem; border-bottom: 2px solid var(--secondary-color); padding-bottom: 0.3rem; display: inline-block; transition: color 0.3s ease, border-color 0.3s ease; }
.explanation p { margin-bottom: 0.8rem; color: var(--text-color); transition: color 0.3s ease; }
.explanation p:last-child { margin-bottom: 0; }
.explanation a { color: var(--primary-color); text-decoration: none; transition: color 0.3s ease; }
.explanation a:hover { text-decoration: underline; color: var(--button-hover); }
[data-theme="dark"] .explanation a { color: var(--primary-color); }
[data-theme="dark"] .explanation a:hover { color: var(--button-hover); }

/* History section */
.history-section { display: none; }
.history-section h2 { color: var(--primary-color); margin-bottom: 1rem; font-size: 1.4rem; text-align: center; transition: color 0.3s ease; }
#historyList { list-style: none; padding: 0; max-height: 200px; overflow-y: auto; }
#historyList li {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s ease;
    text-align: center;
    font-size: 0.95rem;
    color: var(--text-color);
}
#historyList li:last-child { border-bottom: none; }
#historyList li:hover { background-color: var(--history-item-hover-bg); }
#historyList li .hist-input { font-weight: bold; color: var(--primary-color); }
#historyList li .hist-start { color: var(--light-text-color); font-size: 0.9em; }
#historyList li .hist-result { font-weight: bold; color: var(--accent-color); }
[data-theme="dark"] #historyList li .hist-input { color: var(--primary-color); }
[data-theme="dark"] #historyList li .hist-result { color: var(--accent-color); }

/* Sharing section */
.sharing-section { text-align: center; }
.sharing-section h2 { color: var(--primary-color); margin-bottom: 1.5rem; font-size: 1.4rem; transition: color 0.3s ease; }
.sharing-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.8rem; }
.share-button {
    display: inline-flex; align-items: center; padding: 0.6rem 1.0rem;
    border: none; border-radius: 5px; text-decoration: none; color: #ffffff;
    font-weight: 600; transition: opacity 0.3s ease, transform 0.2s ease;
    font-size: 0.90rem; cursor: pointer; touch-action: manipulation;
}
.share-button i { margin-right: 0.6rem; font-size: 1.2em; line-height: 1; }
.share-button:hover { opacity: 0.85; transform: translateY(-2px); }
.share-button.linkedin { background-color: #0077b5; }
.share-button.twitter { background-color: #000000; }
.share-button.facebook { background-color: #1877F2; }
.share-button.bluesky { background-color: #0077FF; }
.share-button.email { background-color: #777777; }

/* Footer */
footer { text-align: center; margin-top: auto; padding-top: 1.5rem; border-top: 1px solid var(--border-color); font-size: 0.9rem; color: var(--light-text-color); transition: color 0.3s ease, border-color 0.3s ease; }

/* Theme toggle button */
.theme-switch { background-color: var(--primary-color); color: white; border: none; border-radius: 50%; width: 44px; height: 44px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 1.2rem; transition: background-color 0.3s ease, transform 0.2s ease; box-shadow: 0 2px 5px var(--shadow-color); flex-shrink: 0; touch-action: manipulation; }
.theme-switch:hover { background-color: var(--button-hover); transform: scale(1.05); }
.theme-switch:focus-visible { outline: 3px solid var(--primary-color); outline-offset: 3px; }

/* Copy button */
.copy-button { display: block; margin: 15px auto 0; background-color: var(--button-color); color: var(--button-text); border: none; border-radius: 6px; padding: 0.6rem 1.2rem; font-size: 1rem; cursor: pointer; transition: background-color 0.3s ease, transform 0.2s ease; font-weight: 600; touch-action: manipulation; }
.copy-button:hover { background-color: var(--button-hover); transform: scale(1.02); }
.copy-button:focus-visible { outline: 3px solid var(--primary-color); outline-offset: 3px; }
.copy-button.success { background-color: var(--copy-success); }

/* Mode tabs */
.mode-tabs { display: flex; justify-content: center; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.mode-tab {
    padding: 0.5rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    background: var(--card-background);
    color: var(--light-text-color);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
    touch-action: manipulation;
}
.mode-tab.active {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--result-background);
}
.mode-tab:hover { border-color: var(--primary-color); color: var(--primary-color); }

/* Result display for new tools */
.result-display {
    margin-top: 1rem;
    background-color: var(--result-background);
    border: 1px solid var(--result-border);
    border-radius: 6px;
    padding: 1rem 1.5rem;
    transition: background-color 0.3s ease, border-color 0.3s ease;
    margin-bottom: 15px;
    display: inline-block;
    min-width: 250px;
}
.result-label { font-size: 1rem; color: var(--text-color); }
.result-value {
    color: var(--accent-color);
    font-weight: 700;
    font-size: 2rem;
    display: block;
    margin-top: 0.2rem;
    transition: color 0.3s ease;
}
.result-value.invalid { font-size: 1.4rem; }

/* Copy cell button (VAT calculator) */
.copy-cell-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--light-text-color);
    font-size: 0.8rem;
    padding: 8px 12px;
    margin-top: 4px;
    transition: color 0.2s ease;
    display: block;
    margin-left: auto;
    margin-right: auto;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.copy-cell-btn:hover { color: var(--primary-color); }
.copy-cell-btn:focus-visible { outline: 3px solid var(--primary-color); outline-offset: 2px; border-radius: 4px; }

/* VAT result grid */
.vat-results {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
    margin-top: 1rem;
    margin-bottom: 15px;
}
.vat-result-item {
    background-color: var(--result-background);
    border: 1px solid var(--result-border);
    border-radius: 6px;
    padding: 0.8rem 1.2rem;
    min-width: 140px;
    text-align: center;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}
.vat-result-item.highlight {
    border-color: var(--primary-color);
    background-color: var(--result-background);
}
.vat-result-label { font-size: 0.85rem; color: var(--light-text-color); font-weight: 700; text-transform: uppercase; }
.vat-result-value { font-size: 1.6rem; font-weight: 700; color: var(--accent-color); display: block; margin-top: 0.2rem; }

/* Select input */
select {
    padding: 0.8rem 1rem;
    width: 100%;
    max-width: 250px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1.1rem;
    background-color: var(--card-background);
    color: var(--text-color);
    transition: border-color 0.3s ease, background-color 0.3s ease, color 0.3s ease;
    cursor: pointer;
    margin-bottom: 0.5rem;
}
select:focus-visible { outline: none; border-color: var(--input-focus-border); box-shadow: 0 0 0 3px rgba(77, 148, 255, 0.2); }

/* Skip link */
.skip-link {
    position: absolute;
    top: -50px;
    left: 1rem;
    background: var(--primary-color);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: 0 0 4px 4px;
    text-decoration: none;
    font-weight: 700;
    z-index: 9999;
    transition: top 0.2s ease;
}
.skip-link:focus-visible { top: 0; }

/* Mode tab focus */
.mode-tab:focus-visible { outline: 3px solid var(--primary-color); outline-offset: 2px; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
    html { scroll-behavior: auto !important; }
}

/* Responsive */
@media (max-width: 600px) {
    html { font-size: 15px; }
    header h1 { font-size: 1.9rem; }
    .container { margin: 1rem auto; }
    main { gap: 1.5rem; }
    .converter-tool, .explanation, .sharing-section, .history-section { padding: 1.5rem; }
    input[type="text"], input[type="number"], input[type="date"], select { max-width: 90%; font-size: 1.1rem; }
    #resultArea { font-size: 1.2rem; }
    #columnNumber { font-size: 1.8rem; }
    #columnNumber.invalid { font-size: 1.3rem; }
    .explanation h2, .sharing-section h2, .history-section h2 { font-size: 1.3rem; }
    .sharing-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; }
    .share-button { padding: 0.5rem 1rem; font-size: 0.9rem; }
    .theme-switch { width: 44px; height: 44px; font-size: 1rem; }
    #historyList li { padding: 0.5rem 0.8rem; font-size: 0.9rem; }
    .vat-results { gap: 0.8rem; }
    .vat-result-item { min-width: 110px; padding: 0.6rem 0.8rem; }
    .vat-result-value { font-size: 1.3rem; }
    .result-value { font-size: 1.6rem; }
}
