:root {
    --bg-color: #f8f9fa;
    --surface-color: #ffffff;
    --text-color: #111827;
    --text-muted: #6b7280;
    --primary-color: #0f172a;
    --primary-hover: #334155;
    --border-color: #e5e7eb;
    --accent-color: #3b82f6;
    --pill-bg: #f3f4f6;
    --pill-hover: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --text-color: #f8fafc;
    --text-muted: #94a3b8;
    --primary-color: #f8fafc;
    --primary-hover: #cbd5e1;
    --border-color: #334155;
    --accent-color: #60a5fa;
    --pill-bg: #334155;
    --pill-hover: #475569;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4), 0 2px 4px -2px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.4), 0 4px 6px -4px rgb(0 0 0 / 0.4);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color var(--transition), color var(--transition);
}

/* Screens */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    display: flex;
    flex-direction: column;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s ease;
    z-index: 1;
    overflow-y: auto;
}

#main-screen {
    transform: translateX(0);
}

#settings-screen {
    transform: translateX(100%);
    z-index: 10;
}

#settings-screen.active {
    transform: translateX(0);
}

body.settings-open #main-screen {
    transform: translateX(-30%);
    opacity: 0.5;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: var(--surface-color);
    box-shadow: var(--shadow-sm);
    z-index: 2;
    transition: background-color var(--transition);
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.025em;
}

header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--transition), color var(--transition);
}

.icon-btn:hover {
    background-color: var(--pill-bg);
}

/* Main Section */
.amount-section {
    padding: 1rem 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.input-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    width: 100%;
    max-width: 320px;
}

.amount-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--surface-color);
    border-radius: 1.5rem;
    padding: 0.25rem 0.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    flex: 1;
    min-width: 0;
}

.amount-btn {
    background: none;
    border: none;
    color: var(--text-color);
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    transition: background-color var(--transition), transform 0.08s ease;
}

.amount-btn svg {
    pointer-events: none;
}

.amount-btn:hover {
    background-color: var(--pill-bg);
}

.amount-btn:active {
    transform: scale(0.92);
    background-color: var(--pill-bg);
}

.amount-input-group {
    display: flex;
    align-items: baseline;
    justify-content: center;
    padding: 0;
    flex: 1;
    min-width: 0;
}

#amount-input {
    font-size: 2.25rem;
    font-weight: 700;
    font-family: inherit;
    font-variant-numeric: tabular-nums;
    background: none;
    border: none;
    color: var(--text-color);
    text-align: right;
    width: 130px;
    max-width: 130px;
    outline: none;
    padding: 0;
    margin: 0;
}

/* Hide native number spinners */
#amount-input::-webkit-outer-spin-button,
#amount-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
#amount-input[type=number] {
    -moz-appearance: textfield;
}

#amount-input::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

.currency {
    font-size: 1.25rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-left: 0.35rem;
    user-select: none;
    white-space: nowrap;
    width: 30px;
    text-align: left;
}

.favorite-btn {
    color: var(--text-muted);
    padding: 0.5rem;
}

.favorite-btn.saved {
    color: #fbbf24;
    fill: #fbbf24;
}

.favorites-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    min-height: 40px;
}

.pill {
    background-color: var(--pill-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 9999px;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: var(--transition);
    animation: scaleIn 0.2s ease-out;
}

.pill:hover {
    background-color: var(--pill-hover);
}

.pill-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 2px;
    border-radius: 50%;
}

.pill-delete:hover {
    color: #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
}

@keyframes scaleIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* QR Section */
.qr-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem 1.5rem 1rem;
    gap: 1.5rem;
}

.qr-container {
    width: 100%;
    max-width: 320px;
    aspect-ratio: 1;
    background-color: #ffffff; /* Always white for good scanning */
    border-radius: 1.5rem;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    transition: transform var(--transition);
    position: relative;
    overflow: hidden;
}

.qr-container canvas {
    display: none !important; /* Skrytý export canvas */
}

.qr-container img {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
    display: block;
    image-rendering: pixelated;  /* Ostré hrany QR modulů */
    image-rendering: crisp-edges; /* Fallback pro Firefox */
}

.qr-placeholder {
    color: #9ca3af;
    font-weight: 500;
    text-align: center;
    font-size: 1.125rem;
}

/* Buttons */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    max-width: 320px;
    padding: 1rem;
    border-radius: 1rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: var(--transition);
}

.primary-btn {
    background-color: var(--primary-color);
    color: var(--bg-color);
}

.primary-btn:hover {
    background-color: var(--primary-hover);
}

.primary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

[data-theme="dark"] .primary-btn {
    color: #0f172a;
}

/* Settings Forms */
.settings-content {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-color);
}

.form-group input[type="text"] {
    padding: 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    background-color: var(--surface-color);
    color: var(--text-color);
    font-size: 1rem;
    font-family: inherit;
    transition: var(--transition);
}

.form-group input[type="text"]:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    background-color: var(--pill-bg);
}

.form-group input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.input-clear-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-clear-wrapper input {
    width: 100%;
    padding-right: 2.5rem !important; /* Space for the clear button */
}

.clear-btn {
    position: absolute;
    right: 0.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 50%;
    transition: background-color var(--transition), color var(--transition);
    opacity: 0;
    pointer-events: none;
}

/* Show clear button when input is not empty (handled by JS class or sibling selector if we used required/valid) */
.input-clear-wrapper.has-value .clear-btn {
    opacity: 1;
    pointer-events: auto;
}

.clear-btn:hover {
    background-color: var(--pill-bg);
    color: var(--text-color);
}

.form-group small {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.toggle-group {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent-color);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

[data-theme="dark"] .slider {
    background-color: var(--border-color);
}
