:root {
    --rf-navy: #0a2540;
    --rf-blue: #1f6fe5;
    --rf-blue-dark: #1559c4;
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #f1f5f9;
    --border: #e2e8f0;
    --text: #1e293b;
    --muted: #64748b;
    --heading: #0a2540;
    --shadow: rgba(10, 37, 64, 0.08);
    --success: #27ae60;
    --danger: #e74c3c;
    --warning: #f39c12;
}

[data-theme="dark"] {
    --rf-navy: #e6edf6;
    --rf-blue: #5b9bf3;
    --rf-blue-dark: #78acf5;
    --bg: #0e1726;
    --surface: #16202e;
    --surface-2: #1d2a3a;
    --border: #2a3a4f;
    --text: #d8e0ea;
    --muted: #93a1b3;
    --heading: #e6edf6;
    --shadow: rgba(0, 0, 0, 0.45);
    --success: #2ecc71;
    --danger: #ff6b5e;
    --warning: #f5b041;
}

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

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand {
    font-weight: 700;
    color: var(--heading);
    text-decoration: none;
    font-size: 1.1rem;
}

.topnav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-toggle {
    display: none;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.35rem 0.7rem;
    font-size: 1.3rem;
    line-height: 1;
    color: var(--text);
    cursor: pointer;
}

@media (max-width: 640px) {
    .nav-toggle {
        display: inline-flex;
    }
    .topnav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0.35rem;
        padding: 0.6rem;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        box-shadow: 0 6px 16px var(--shadow);
    }
    .topnav.is-open {
        display: flex;
    }
    .topnav .btn {
        width: 100%;
        justify-content: flex-start;
    }
    .topnav .icon-btn {
        align-self: flex-start;
    }
}

.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 1rem;
}

h1, h2, h3 {
    color: var(--heading);
    margin-bottom: 0.75rem;
}

a {
    color: var(--rf-blue);
    text-decoration: none;
}

a:hover {
    color: var(--rf-blue-dark);
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px var(--shadow);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.7rem 1.1rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--rf-blue);
    color: #fff;
    text-decoration: none;
}

.btn:hover {
    background: var(--rf-blue-dark);
    color: #fff;
}

.btn-block {
    width: 100%;
}

.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--surface-2);
    color: var(--text);
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.45rem 0.6rem;
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
}

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

label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 600;
    color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="number"] {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

.flash {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
}

.flash-error {
    background: rgba(231, 76, 60, 0.12);
    border-color: var(--danger);
    color: var(--danger);
}

.flash-success {
    background: rgba(39, 174, 96, 0.12);
    border-color: var(--success);
    color: var(--success);
}

.auth-wrap {
    max-width: 360px;
    margin: 3rem auto;
}

.text-center {
    text-align: center;
}

.muted {
    color: var(--muted);
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    background: var(--danger);
    opacity: 0.9;
    color: #fff;
}

.tag {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    margin-left: 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 999px;
    background: var(--rf-blue);
    color: #fff;
}

.user-row {
    margin-bottom: 0.75rem;
}

.inline-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.inline-form input {
    flex: 1;
    min-width: 140px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--text);
}

.checkbox-label input {
    width: auto;
}

select {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

.segmented {
    display: flex;
    gap: 0.5rem;
}

.seg-option {
    flex: 1;
    margin: 0;
}

.seg-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.seg-option span {
    display: block;
    text-align: center;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    cursor: pointer;
}

.seg-option input:checked + span {
    background: var(--rf-blue);
    border-color: var(--rf-blue);
    color: #fff;
}

.group-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.group-flags {
    display: flex;
    gap: 0.3rem;
}

.tag-muted {
    background: var(--muted);
}

.group-settings {
    border-top: 1px solid var(--border);
    margin-top: 0.75rem;
    padding-top: 0.75rem;
}

.items-title {
    margin-top: 1rem;
    font-size: 1rem;
}

.item-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.item-row .inline-form {
    flex: 1;
    margin-bottom: 0;
}

.add-item {
    margin-top: 0.75rem;
    border-top: 1px dashed var(--border);
    padding-top: 0.75rem;
}

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.page-head h1 {
    margin-bottom: 0;
}

.row-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.inventory-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding-bottom: 0.6rem;
    margin-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
}

.inventory-meta {
    display: flex;
    flex-direction: column;
}

.sum-section {
    margin-top: 0.75rem;
}

.sum-title {
    font-size: 1rem;
    margin-bottom: 0.4rem;
}

.sum-group {
    font-weight: 600;
    color: var(--muted);
    font-size: 0.85rem;
    margin: 0.5rem 0 0.25rem;
}

.sum-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.4rem 0.2rem;
    border-bottom: 1px solid var(--border);
}

.sum-row:last-child {
    border-bottom: none;
}

.sum-name {
    color: var(--text);
}

.layout-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
    align-items: start;
}

.layout-columns .card {
    margin-bottom: 0;
}

.item-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 1.05rem;
    cursor: pointer;
    text-align: left;
}

.item-btn:active {
    background: var(--border);
}

.item-count {
    min-width: 2.5rem;
    text-align: center;
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--rf-blue);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.2rem 0.5rem;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(10, 37, 64, 0.55);
    align-items: flex-end;
    justify-content: center;
    padding: 0;
}

.modal.is-open {
    display: flex;
}

.modal-box {
    background: var(--surface);
    width: 100%;
    max-width: 480px;
    border-radius: 16px 16px 0 0;
    padding: 1rem;
    box-shadow: 0 -4px 20px var(--shadow);
}

@media (min-width: 560px) {
    .modal {
        align-items: center;
    }
    .modal-box {
        border-radius: 16px;
    }
}

.modal-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--heading);
    text-align: center;
    margin-bottom: 0.75rem;
}

.calc-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.calc-pm {
    width: 3.2rem;
    height: 3.2rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 1.8rem;
    font-weight: 700;
    cursor: pointer;
}

.calc-pm:active {
    background: var(--border);
}

.calc-value {
    flex: 1;
    text-align: center;
    font-size: 2.4rem;
    font-weight: 700;
    color: var(--rf-blue);
}

.calc-display {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.6rem 0.8rem;
    margin-bottom: 0.75rem;
    min-height: 3.4rem;
    text-align: right;
}

.calc-expr {
    font-size: 1.1rem;
    color: var(--text);
    min-height: 1.4rem;
    word-break: break-all;
}

.calc-result {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--muted);
    min-height: 1.6rem;
}

.calc-keys {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.calc-key {
    height: 3.4rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font-size: 1.4rem;
    font-weight: 600;
    cursor: pointer;
}

.calc-key:active {
    background: var(--surface-2);
}

.calc-op {
    background: var(--surface-2);
    color: var(--rf-blue);
}

.calc-fn {
    background: var(--surface-2);
    color: var(--muted);
}

.calc-zero {
    grid-column: span 2;
}

.calc-actions {
    display: flex;
    gap: 0.5rem;
}

.calc-actions .btn {
    flex: 1;
    height: 3.2rem;
    font-size: 1.1rem;
}

.sync-status {
    display: inline-block;
    margin-left: 0.5rem;
    padding: 0.1rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.sync-status.is-ok {
    background: rgba(39, 174, 96, 0.15);
    color: var(--success);
}

.sync-status.is-pending {
    background: rgba(243, 156, 18, 0.15);
    color: var(--warning);
}

.sync-status.is-offline {
    background: rgba(231, 76, 60, 0.15);
    color: var(--danger);
}
