/* ==========================================================================
   Form fields, buttons, switch, table, toast, modal, footer
   ========================================================================== */

/* ---------- Field groups ---------- */
.field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: var(--space-12);
}

.field-group label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    letter-spacing: 0.01em;
}

.cost-spacing {
    margin-bottom: var(--space-16);
}

/* ---------- Inputs & selects ---------- */
input[type="text"],
input[type="number"],
select {
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--color-text);
    background: var(--color-input-bg);
    border: 1px solid var(--color-input-border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    width: 100%;
    transition: border-color var(--dur-fast) var(--ease),
                box-shadow var(--dur-fast) var(--ease),
                background-color var(--dur-fast) var(--ease);
    appearance: none;
    -webkit-appearance: none;
}

input[type="text"]::placeholder,
input[type="number"]::placeholder {
    color: var(--color-text-tertiary);
}

input:hover:not(:disabled):not([readonly]),
select:hover {
    border-color: var(--color-border-strong);
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: var(--shadow-focus);
}

input[readonly] {
    background: var(--color-input-readonly-bg);
    color: var(--color-text-secondary);
    cursor: default;
}

input[readonly]:focus {
    box-shadow: none;
    border-color: var(--color-input-border);
}

/* Hide number spinners for a flatter, ledger-like look */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* -moz-appearance removed to fix error (standard Firefox behavior) */

select {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none'%3e%3cpath d='M5.5 7.5L10 12l4.5-4.5' stroke='%236e6e73' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' opacity='0.6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
    cursor: pointer;
}

/* Key output fields (money results) get a touch more presence */
#profit, #vatAmount, #vatAmountEach, #vatAmountEachPricing, #costEachDisplay,
#porPercentDisplay, #porValueDisplay {
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

#profit.value-positive {
    color: var(--color-success);
}

#profit.value-negative {
    color: var(--color-danger);
}

/* ---------- Buttons ---------- */
.btn-secondary {
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text);
    background: var(--color-surface-solid);
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    padding: 10px 18px;
    cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease),
                border-color var(--dur-fast) var(--ease),
                transform var(--dur-fast) var(--ease),
                box-shadow var(--dur-fast) var(--ease);
}

.btn-secondary:hover {
    border-color: var(--color-accent);
    color: var(--color-accent);
    box-shadow: var(--shadow-xs);
}

.btn-secondary:active {
    transform: scale(0.98);
}

.full-width-btn {
    width: 100%;
    margin-top: var(--space-4);
}

/* Settings row */
.settings-row {
    display: flex;
    gap: 12px;
    align-items: end;
    min-width: 0;
}

.settings-row .half-tile {
    flex: 1;
    min-width: 0;
}

/* The currency field is wrapped in a .field-group, which normally carries
   bottom margin for vertical rhythm between stacked fields. Inside the
   settings row that margin would push the select's baseline above the
   Reset button (which has no label/margin), breaking the inline alignment.
   Zeroing it here keeps both controls' bottoms perfectly level. */
.settings-row .field-group {
    margin-bottom: 0;
}

.settings-row select,
.settings-row button {
    height: 44px;
    margin: 0;
}

/* ---------- History table ---------- */
.history-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-divider);
    -webkit-overflow-scrolling: touch;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.83rem;
    min-width: 920px;
}

.history-table thead th {
    position: sticky;
    top: 0;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-secondary);
    background: var(--color-bg-alt);
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-divider);
    white-space: nowrap;
}

.history-table tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-divider);
    color: var(--color-text);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.history-table tbody tr:last-child td {
    border-bottom: none;
}

.history-table tbody tr:hover {
    background: var(--color-accent-soft);
}

.history-table tbody tr.history-empty-row:hover {
    background: transparent;
}

.history-empty-row td {
    color: var(--color-text-tertiary);
    text-align: center;
    padding: var(--space-24) var(--space-12);
    white-space: normal;
    font-style: italic;
}

.history-buttons {
    display: flex;
    gap: var(--space-8);
    margin-top: var(--space-12);
}

.history-buttons .btn-secondary {
    flex: 1;
}

/* ---------- Toast ---------- */
toast-bubble {
    position: fixed;
    left: 50%;
    bottom: var(--space-24);
    transform: translate(-50%, 16px);
    background: var(--color-text);
    color: var(--color-bg);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 12px 22px;
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-med) var(--ease), transform var(--dur-med) var(--ease-spring);
    z-index: 500;
    max-width: calc(100vw - 32px);
    text-align: center;
}

toast-bubble[data-visible="true"] {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ---------- Popup modal ---------- */
popup-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-med) var(--ease);
    z-index: 600;
    padding: var(--space-16);
}

popup-modal[data-visible="true"] {
    opacity: 1;
    pointer-events: auto;
}

.por-modal {
    max-width: 420px;
    width: 100%;
    margin: 0 auto;
    padding: var(--space-16) var(--space-16) var(--space-20, var(--space-16));
    background: var(--color-surface-raised);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    color: var(--color-text);
    transform: scale(0.96) translateY(6px);
    transition: transform var(--dur-med) var(--ease-spring);
}

popup-modal[data-visible="true"] .por-modal {
    transform: scale(1) translateY(0);
}

.por-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-8);
}

.por-modal-header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--color-text);
}

.por-modal p {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--color-text-secondary);
}

.por-close-btn {
    background: var(--color-accent-soft);
    color: var(--color-accent);
    border: none;
    font-size: 1.1rem;
    line-height: 1;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.por-close-btn:hover {
    background: var(--color-accent);
    color: var(--color-on-accent);
}

/* ---------- Footer ---------- */
.app-footer {
    text-align: center;
    padding: var(--space-24) var(--space-16) var(--space-32);
    color: var(--color-text-tertiary);
    font-size: 0.8rem;
}

.app-footer p {
    margin: 4px 0;
}

.app-footer a {
    color: var(--color-text-secondary);
    font-weight: 500;
}

.app-footer a:hover {
    color: var(--color-accent);
}

/* ---------- Static legal/privacy pages ---------- */
.app-container {
    max-width: 720px;
    margin: var(--space-32) auto;
    padding: var(--space-24);
    background: var(--color-surface-solid);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.app-container-brand {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-secondary) !important;
    text-decoration: none !important;
    margin-bottom: var(--space-16);
}

.app-container-brand img {
    border-radius: 7px;
}

.app-container-brand:hover {
    color: var(--color-accent) !important;
}

.app-container h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-top: 0;
}

.app-container p {
    color: var(--color-text-secondary);
    line-height: 1.65;
    font-size: 0.95rem;
}

.toggle-button {
    display: inline-block;
    margin-top: var(--space-12);
    padding: 10px 20px;
    background: var(--color-accent);
    color: var(--color-on-accent) !important;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none !important;
}

.toggle-button:hover {
    background: var(--color-accent-hover);
}