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

/* CSS Variables - Light Theme (default) */
:root {
    --bg-body: #f4f6f9;
    --bg-panel: #ffffff;
    --bg-input: #fafafa;
    --bg-input-focus: #ffffff;
    --bg-input-disabled: #f0f0f0;
    --text-primary: #0D1321;
    --text-label: #444444;
    --text-result-label: #555555;
    --text-muted: #6c757d;
    --text-dimmed: #888888;
    --border: #d1d5db;
    --border-light: #f0f0f0;
    --border-subtle: #f8f8f8;
    --shadow: rgba(0, 0, 0, 0.08);
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-body: #121212;
    --bg-panel: #1e1e1e;
    --bg-input: #2a2a2a;
    --bg-input-focus: #333333;
    --bg-input-disabled: #1a1a1a;
    --text-primary: #e0e0e0;
    --text-label: #b0b0b0;
    --text-result-label: #999999;
    --text-muted: #888888;
    --text-dimmed: #666666;
    --border: #404040;
    --border-light: #2a2a2a;
    --border-subtle: #252525;
    --shadow: rgba(0, 0, 0, 0.4);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    min-height: 100vh;
}

header {
    background: #0D1321;
    color: #fff;
    padding: 1.5rem 2rem;
    border-bottom: 3px solid #D4A434;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

header .subtitle {
    margin-top: 0.25rem;
    font-size: 0.85rem;
    color: #a8b2c1;
}

.lang-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    align-self: flex-end;
    width: fit-content;
}

.lang-selector label {
    font-size: 0.8rem;
    color: #a8b2c1;
    font-weight: 500;
    margin-bottom: 0;
    white-space: nowrap;
}

.lang-selector select {
    width: auto;
    min-width: 110px;
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    background: #2c2c3e;
    color: #e0e0e0;
    border: 1px solid #444;
    border-radius: 4px;
    cursor: pointer;
}

.lang-selector select:focus {
    outline: none;
    border-color: #D4A434;
    background: #0D1321;
}

.container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    max-width: 900px;
    margin: 1rem auto;
    padding: 0 1.5rem;
}

.input-panel {
    background: var(--bg-panel);
    border-radius: 8px;
    padding: 1rem 1.5rem;
    box-shadow: 0 1px 4px var(--shadow);
}

h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
    padding-bottom: 0.5rem;
    border-bottom: 2px solid #D4A434;
}

.form-group {
    margin-bottom: 0.5rem;
}

label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-label);
    margin-bottom: 0.35rem;
}

input[type="text"] {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--bg-input);
    transition: border-color 0.15s, background-color 0.15s;
    font-family: inherit;
}

input[type="text"]:focus {
    outline: none;
    border-color: #D4A434;
    background: var(--bg-input-focus);
}

/* Character / byte counter */
.char-counter {
    margin-top: 0.3rem;
    text-align: right;
}

.counter-text {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.counter-warning .counter-text {
    color: #C43C32;
    font-weight: 700;
    font-size: 0.85rem;
}

.input-warning {
    border-color: #C43C32 !important;
    box-shadow: 0 0 0 2px rgba(196, 60, 50, 0.25);
    background-color: #fdf2f1 !important;
}

[data-theme="dark"] .input-warning {
    background-color: #2a1a19 !important;
}

.field-header .counter-warning .counter-text {
    color: #C43C32;
}

/* Field header: label left, counter right */
.field-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.field-header label {
    margin-bottom: 0;
}

.field-header .char-counter {
    margin-top: 0;
}

.field-header .search-counters {
    display: flex;
    gap: 1.5rem;
    margin-top: 0;
}

.field-header .search-counters .char-counter {
    margin-top: 0;
}

.instructions {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 0;
}

/* Search terms counters row */
.search-counters {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

.search-counters .char-counter {
    margin-top: 0;
}

/* Info icon and tooltip */
.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    background: #888;
    color: #fff;
    border-radius: 50%;
    font-size: 0.6rem;
    font-weight: 700;
    cursor: pointer;
    vertical-align: middle;
    position: relative;
    line-height: 1;
    flex-shrink: 0;
}

.info-icon::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: #2c2c3e;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 400;
    line-height: 1.45;
    white-space: pre-wrap;
    max-width: 280px;
    width: max-content;
    padding: 0.55rem 0.7rem;
    border-radius: 5px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 100;
    text-align: left;
}

.info-icon::after {
    content: "";
    position: absolute;
    bottom: calc(100% + 2px);
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #2c2c3e;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 100;
}

.info-icon:hover::before,
.info-icon:hover::after {
    opacity: 1;
}

/* Responsive */
@media (max-width: 600px) {
    header {
        flex-direction: column;
        align-items: flex-start;
    }
    .lang-selector {
        align-self: flex-end;
    }
    .search-counters {
        flex-direction: column;
        gap: 0.2rem;
    }
}
