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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #1a1a1a;
    color: #e0e0e0;
    margin: 0;
    min-height: 100vh;
    line-height: 1.45;
}

body:has(.login-container) {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
}

/* Login Page Styles */
.login-container {
    background-color: #2d2d2d;
    padding: 2rem;
    border-radius: 8px;
    border: 1px solid #3a3a3a;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    text-align: center;
    width: min(100%, 420px);
}

.login-container button {
    width: 100%;
}

input[type="text"],
input[type="number"],
input[type="password"] {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    border-radius: 4px;
    border: 1px solid #444;
    background-color: #333;
    color: white;
}

.form-group input,
.form-group select,
.form-grid input,
.form-grid select,
.modal-field input,
.modal-field select {
    width: 100%;
    margin: 0;
}

button {
    width: auto;
    max-width: 100%;
    padding: 8px 14px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
}

button:disabled {
    background-color: #555;
    cursor: not-allowed;
    opacity: 0.7;
}

button:hover:not(:disabled) {
    background-color: #45a049;
}

select {
    width: 100%;
    max-width: 100%;
    padding: 10px;
    margin: 10px 0;
    border-radius: 4px;
    border: 1px solid #444;
    background-color: #333;
    color: white;
    font-size: 16px;
}

input,
textarea {
    font-size: 16px;
}

/* Shared page shell. Every tool uses the full browser width. */
.container,
.container.full-width {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 20px clamp(12px, 2vw, 28px) 48px;
}

main {
    min-width: 0;
}

header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 2rem;
    border-bottom: 1px solid #444;
    padding-bottom: 1rem;
}

header h1 {
    margin: 0;
    font-size: 1.6rem;
    line-height: 1.2;
    min-width: 0;
    overflow-wrap: break-word;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    position: relative;
}

.nav-toggle {
    width: auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #333;
    border: 1px solid #555;
    border-radius: 6px;
    color: #eee;
    font-size: 14px;
    font-weight: 600;
}

.nav-toggle svg {
    width: 16px;
    height: 16px;
}

.nav-toggle:hover,
.nav-toggle[aria-expanded="true"] {
    background: #3d3d3d;
    border-color: #777;
}

.nav-current {
    color: #9ad7a4;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
}

.nav-panel {
    display: none;
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: min(440px, calc(100vw - 32px));
    background: #242424;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 8px;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    z-index: 30;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.nav-panel.is-open {
    display: grid;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border-radius: 6px;
    color: #ddd;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.92rem;
    margin: 0;
}

.nav-item svg {
    width: 16px;
    height: 16px;
    flex: none;
}

.nav-item:hover {
    background: #333;
    text-decoration: none;
}

.nav-item.active {
    background: #1e3a2f;
    color: #8ee6a0;
}

@media (max-width: 720px) {
    header {
        position: relative;
        align-items: center;
    }

    header h1 {
        font-size: 1.35rem;
        flex: 1 1 100%;
    }

    .site-nav {
        position: static;
        width: 100%;
        margin-left: 0;
        justify-content: flex-start;
    }

    .nav-panel {
        left: 0;
        right: 0;
        width: auto;
        grid-template-columns: 1fr;
    }

    .nav-current {
        display: none;
    }
}

.card {
    background-color: #2d2d2d;
    padding: 1.25rem 1.5rem;
    border-radius: 8px;
    border: 1px solid #3a3a3a;
    margin-bottom: 1rem;
    min-width: 0;
}

.card h2,
.card h3 {
    margin-top: 0;
}

.card h2 {
    font-size: 1.15rem;
}

.dashboard-actions {
    margin-top: 15px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.dashboard-btn {
    display: inline-block;
    padding: 10px 14px;
    background-color: #2196F3;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    font-weight: bold;
}

.dashboard-btn:hover {
    background-color: #0b7dda;
}

.logout-btn {
    color: #ff6b6b;
    text-decoration: none;
    padding: 5px 10px;
    border: 1px solid #ff6b6b;
    border-radius: 4px;
}

.logout-btn:hover {
    background-color: rgba(255, 107, 107, 0.1);
}

.key-remove-btn {
    width: auto;
    padding: 6px 10px;
    background-color: #f44336;
    font-size: 13px;
    font-weight: 600;
}

.key-remove-btn:hover {
    background-color: #d32f2f;
}

.key-remove-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Table Styles */
.full-width {
    max-width: none;
}

.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 1rem;
    max-width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #444;
    vertical-align: top;
}

th {
    background-color: #333;
    font-weight: bold;
}

tr:hover {
    background-color: #3a3a3a;
}

.nav-link {
    color: #4CAF50;
    text-decoration: none;
    margin-right: 15px;
    font-weight: bold;
}

.nav-link:hover {
    text-decoration: underline;
}

/* Pagination Styles */
.pagination-controls {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.controls-container {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 1rem;
}

.filters {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    flex: 1 1 280px;
    min-width: 0;
}

.filters select,
.toolbar select,
.filter-group select {
    width: auto;
    min-width: 9rem;
    max-width: 100%;
    margin: 0;
}

.filter-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.filter-group[hidden] {
    display: none;
}

.filters select {
    padding: 6px;
    border-radius: 4px;
    border: 1px solid #444;
    background-color: #333;
    color: white;
}

.pagination-controls button {
    width: auto;
    padding: 8px 16px;
    background-color: #4CAF50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.pagination-controls button:disabled {
    background-color: #555;
    cursor: not-allowed;
    opacity: 0.7;
}

.pagination-controls button:hover:not(:disabled) {
    background-color: #45a049;
}

/* Glow Classes */
.glow-yellow {
    color: #ffff00;
    text-shadow: 0 0 5px #ffff00;
}

.glow-orange {
    color: #ff9f00;
    text-shadow: 0 0 5px #ff9f00;
}

.glow-red {
    color: #ff0000;
    text-shadow: 0 0 5px #ff0000;
}

/* Delete Button Styles */
.delete-btn {
    width: auto;
    background-color: #f44336;
    padding: 6px 12px;
    margin-left: 10px;
    font-size: 14px;
}

.delete-btn:hover {
    background-color: #d32f2f;
}

/* Cache Sales Styles */
.stats-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
}

.stat-pill {
    background-color: #333;
    border: 1px solid #444;
    border-radius: 999px;
    padding: 6px 12px;
    font-weight: bold;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 15px;
    align-items: end;
}

.form-grid label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.form-actions,
.scan-actions,
.modal-actions,
.policy-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.form-status {
    font-size: 0.9em;
    color: #4caf50;
}

.form-status.error {
    color: #f44336;
}

.scan-info {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-top: 10px;
}

.scan-actions {
    margin-top: 15px;
}

.scan-actions button {
    width: auto;
}

.modal {
    display: none;
    position: fixed;
    z-index: 10;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
}

.modal-content {
    background-color: #2a2a2a;
    margin: 8vh auto;
    padding: 20px;
    border: 1px solid #444;
    width: min(500px, calc(100% - 24px));
    border-radius: 8px;
    position: relative;
    max-height: calc(100vh - 24px);
    overflow: auto;
}

.modal-content.modal-wide {
    width: min(900px, calc(100% - 24px));
}

.resizable-modal {
    resize: both;
    overflow: auto;
}

.modal-hint {
    color: #bdbdbd;
    margin-top: 4px;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    color: #ccc;
    font-size: 24px;
    cursor: pointer;
}

.modal-close:hover {
    color: #fff;
}

.modal-field {
    margin-top: 12px;
}

.modal-field label {
    display: block;
    margin-bottom: 6px;
    font-weight: bold;
}

.modal-actions {
    margin-top: 16px;
}

.danger-btn {
    background-color: #f44336;
}

.danger-btn:hover {
    background-color: #d32f2f;
}

.sell-btn {
    width: auto;
    padding: 6px 12px;
    background-color: #2196F3;
}

.sell-btn:hover {
    background-color: #0b7dda;
}

.edit-btn {
    width: auto;
    padding: 6px 12px;
    background-color: #4caf50;
}

.edit-btn:hover {
    background-color: #45a049;
}

.price-btn {
    width: auto;
    padding: 6px 12px;
    background-color: #ff9800;
}

.price-btn:hover {
    background-color: #fb8c00;
}

.pay-btn {
    width: auto;
    padding: 6px 12px;
    background-color: #2196F3;
}

.pay-btn:hover:not(:disabled) {
    background-color: #0b7dda;
}

.pay-btn:disabled {
    background-color: #555;
    cursor: not-allowed;
    opacity: 0.7;
}

.status-pending {
    color: #ff9800;
    font-weight: bold;
}

.target-max-price-cell {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 180px;
}

.target-max-price-input {
    width: 120px;
    min-width: 0;
    flex: 1 1 120px;
}

.lede,
.cache-meta,
.war-note,
.scan-status,
.status-note {
    color: #bbb;
    font-size: 0.95em;
}

.lede,
.war-note {
    margin: 0 0 12px;
}

.cache-meta {
    margin: 0 0 14px;
}

.toolbar,
.scan-row,
.inline-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}

.toolbar button,
.stat-switch button,
.column-btn {
    background: #333;
    border: 1px solid #555;
    color: #eee;
}

.toolbar button.active,
.stat-switch button.active,
.column-btn.active {
    background: #2196F3;
    border-color: #2196F3;
    color: white;
}

.toolbar button:hover,
.stat-switch button:hover,
.column-btn:hover {
    background: #3d3d3d;
}

.toolbar button.active:hover,
.stat-switch button.active:hover,
.column-btn.active:hover {
    background: #0b7dda;
}

.toolbar input[type="text"] {
    width: min(100%, 220px);
    margin: 0;
}

.toolbar select.war-select {
    width: min(100%, 420px);
    margin: 0;
}

.refresh-btn,
.toolbar button.refresh-btn {
    background-color: #2196F3;
    border-color: #2196F3;
    color: white;
}

.refresh-btn:hover,
.toolbar button.refresh-btn:hover {
    background-color: #0b7dda;
}

.refresh-btn:disabled,
.toolbar button.refresh-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.summary-tile {
    background: #242424;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 12px;
    min-width: 0;
}

.summary-tile .label {
    color: #aaa;
    font-size: 0.85em;
    margin-bottom: 4px;
}

.summary-tile .value {
    font-size: 1.25em;
    font-weight: bold;
    overflow-wrap: anywhere;
}

.stat-value,
.sort-mark {
    font-variant-numeric: tabular-nums;
}

.stat-gain {
    font-size: 0.85em;
    color: #888;
    font-variant-numeric: tabular-nums;
}

.gain-up { color: #4caf50; }
.gain-down { color: #f44336; }

.member-row { cursor: pointer; }
.member-row.selected { background: #1e3a2f; }
.error-text { color: #ff9800; font-size: 0.9em; }

.chart-wrap {
    background: #242424;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 12px;
    margin-top: 8px;
    overflow-x: auto;
}

.chart-wrap svg {
    width: 100%;
    height: auto;
    display: block;
}

.stat-switch {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0;
}

.chart-note {
    color: #999;
    font-size: 0.85em;
    margin-top: 8px;
}

th.sortable { cursor: pointer; }
th.sortable:hover,
th.sortable.active { color: #8ec5ff; }
.sort-mark { color: #80cbc4; font-size: 0.78em; font-weight: normal; white-space: nowrap; }

.num-col { text-align: right; font-variant-numeric: tabular-nums; }
.money-col { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.success-rate-high { color: #4caf50; font-weight: bold; }
.success-rate-mid { color: #ff9800; font-weight: bold; }
.success-rate-low { color: #f44336; font-weight: bold; }

.build-status {
    background: #243044;
    border: 1px solid #3d5a80;
    border-radius: 6px;
    padding: 14px 16px;
    margin-bottom: 16px;
}

.build-status h3 {
    margin: 0 0 6px;
    font-size: 1.05em;
}

.build-status p {
    margin: 0;
    color: #d5dbe3;
}

.form-group {
    margin-bottom: 15px;
    min-width: 0;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.two-columns {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(0, 2fr);
    gap: 20px;
    min-width: 0;
}

.two-columns > .form-group {
    margin-bottom: 0;
}

.add-btn {
    width: 100%;
    margin-top: 12px;
}

.section-form {
    margin-bottom: 16px;
}

.section-form .add-btn {
    margin-top: 12px;
}

.toolbar label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.view-btn {
    width: auto;
    background-color: #2196F3;
    margin: 2px 6px 2px 0;
}

.view-btn:hover {
    background-color: #0b7dda;
}

.api-keys-info {
    background-color: #2a2a2a;
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 20px;
    border: 1px solid #444;
}

.unavailable-row {
    background-color: rgba(244, 67, 54, 0.2) !important;
}

.unavailable-row:hover {
    background-color: rgba(244, 67, 54, 0.3) !important;
}

.status-online { color: #4caf50; font-weight: bold; }
.status-idle { color: #ff9800; font-weight: bold; }
.status-offline { color: #9e9e9e; }
.status-state-hospital { color: #ff5252; font-weight: bold; }
.status-state-traveling { color: #03a9f4; font-weight: bold; }
.status-state-federal { color: #ff7043; font-weight: bold; }
.status-details { display: block; font-size: 0.85em; color: #bdbdbd; }
.clothing-store { color: #e91e63; font-weight: bold; }
.mugged { color: #ff9800; font-weight: bold; }
.countdown-soon { color: #ff5252; font-weight: bold; }
.player-link { color: #81c784; }

.scan-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.close {
    color: #ccc;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover,
.close:focus {
    color: #fff;
}

.inset-panel {
    background: #333;
    padding: 12px;
    margin-bottom: 16px;
    border-radius: 6px;
}

.inset-panel h3 {
    margin-top: 0;
}

.field-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.field-row input[type="text"] {
    flex: 2 1 180px;
    width: auto;
    min-width: 0;
    margin: 0;
}

.field-row input[type="number"] {
    flex: 1 1 120px;
    width: auto;
    min-width: 0;
    margin: 0;
}

.field-row .add-btn {
    width: auto;
    margin-top: 0;
    flex: 0 0 auto;
}

.log-output {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    background: #111;
    border: 1px solid #333;
    padding: 12px;
    border-radius: 8px;
    max-height: 70vh;
    overflow: auto;
    margin: 0;
    font-size: 0.82rem;
    line-height: 1.45;
}

.policy-table {
    table-layout: fixed;
}

.policy-table th,
.policy-table td {
    border: 1px solid #555;
    overflow-wrap: anywhere;
}

.policy-actions button {
    min-width: 140px;
}

#declineBtn {
    background: #8d2a2a;
}

#declineBtn:hover {
    background: #a33;
}

#policyMessage {
    min-height: 1.2em;
    margin-top: 12px;
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
}

@media (max-width: 800px) {
    .two-columns {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .container,
    .container.full-width {
        padding: 12px 12px 32px;
    }

    .card,
    .login-container {
        padding: 1rem;
    }

    th, td {
        padding: 8px;
        font-size: 0.88rem;
    }

    .controls-container {
        flex-direction: column;
        align-items: stretch;
    }

    .filters,
    .filter-group,
    .pagination-controls,
    .form-actions,
    .scan-actions,
    .modal-actions,
    .policy-actions {
        width: 100%;
    }

    .filters,
    .filter-group {
        align-items: stretch;
        flex-direction: column;
    }

    .filters select,
    .filter-group select,
    .toolbar select,
    .toolbar input[type="text"],
    .toolbar select.war-select {
        width: 100%;
        min-width: 0;
    }

    .pagination-controls {
        justify-content: stretch;
    }

    .pagination-controls button {
        flex: 1 1 auto;
    }

    .modal-content,
    .modal-content.modal-wide,
    .resizable-modal {
        width: calc(100% - 16px) !important;
        max-width: none;
        margin: 8px auto;
        max-height: calc(100vh - 16px);
        resize: none;
    }

    .field-row input[type="text"],
    .field-row input[type="number"],
    .field-row .add-btn {
        flex: 1 1 100%;
        width: 100%;
    }

    .summary-grid {
        grid-template-columns: 1fr 1fr;
    }

    .policy-actions button {
        flex: 1 1 100%;
    }

    .target-max-price-input {
        width: 100%;
    }
}

@media (max-width: 420px) {
    .summary-grid {
        grid-template-columns: 1fr;
    }
}

.hosp-ok { color: #81c784; font-weight: bold; }
.hosp-war { color: #ffb74d; font-weight: bold; }
.row-just-out { background: rgba(79, 195, 247, 0.12); }
