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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
    padding: 20px;
    color: #333;
}

.container { max-width: 1200px; margin: 0 auto; }

h1 { font-size: 24px; margin-bottom: 20px; }
h2 { font-size: 18px; margin-bottom: 15px; color: #333; }

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.header-row h1 { margin-bottom: 0; }

.header-links {
    display: flex;
    gap: 10px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 20px;
    border-bottom: 2px solid #ddd;
    padding-bottom: 0;
}

.tab {
    padding: 10px 20px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: #666;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.tab:hover { color: #333; }
.tab.active { color: #007bff; border-bottom-color: #007bff; }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Search/Filter Bar */
.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.toolbar input, .toolbar select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.toolbar input:focus, .toolbar select:focus {
    outline: none;
    border-color: #007bff;
}

.toolbar input[type="text"] { flex: 1; min-width: 200px; }

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: opacity 0.2s;
}

.btn-primary { background: #007bff; color: #fff; }
.btn-secondary { background: #6c757d; color: #fff; }
.btn-danger { background: #dc3545; color: #fff; }
.btn-success { background: #28a745; color: #fff; }
.btn-sm { padding: 4px 8px; font-size: 12px; }
.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Table */
.table-wrapper {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    overflow: hidden;
    margin-bottom: 20px;
}

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

th, td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

th {
    background: #f8f9fa;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    color: #666;
}

tr:hover { background: #f8f9fa; }

td.actions { white-space: nowrap; }
td.actions .btn { margin-right: 5px; }

td.price { font-weight: 500; }

.empty-state {
    padding: 40px;
    text-align: center;
    color: #666;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-top: 1px solid #eee;
    font-size: 14px;
    color: #666;
}

.pagination-btns { display: flex; gap: 5px; }

/* Loading */
.loading {
    padding: 40px;
    text-align: center;
    color: #666;
}

/* Messages */
.message {
    padding: 12px 15px;
    border-radius: 4px;
    margin-bottom: 15px;
    font-size: 14px;
}

.message.success { background: #d4edda; color: #155724; }
.message.error { background: #f8d7da; color: #721c24; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active { display: flex; }

.modal-content {
    background: #fff;
    border-radius: 8px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 5px 30px rgba(0,0,0,0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
}

.modal-header h3 { font-size: 18px; margin: 0; }

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    line-height: 1;
}

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

.modal-body { padding: 20px; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid #eee;
}

/* Form */
.form-group {
    margin-bottom: 15px;
}

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

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #007bff;
}

.form-group small {
    display: block;
    margin-top: 5px;
    color: #666;
    font-size: 12px;
}

.form-row {
    display: flex;
    gap: 15px;
}

.form-row .form-group { flex: 1; }

/* Checkbox list for cars */
.checkbox-list {
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
}

.checkbox-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    cursor: pointer;
    font-weight: normal;
}

.checkbox-list input[type="checkbox"] { width: auto; }

/* Simple list for management */
.simple-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.simple-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: #f8f9fa;
    border-radius: 4px;
}

.simple-list-item span { font-size: 14px; }

.inline-form {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.inline-form input { flex: 1; }

/* Footer */
.app-footer {
    margin-top: 40px;
    padding: 20px 0;
    border-top: 1px solid #ddd;
    text-align: center;
}

.app-footer a {
    color: #666;
    text-decoration: none;
    font-size: 13px;
    margin: 0 15px;
}

.app-footer a:hover {
    color: #007bff;
}

/* Input with Button */
.input-with-button {
    display: flex;
    gap: 8px;
}

.input-with-button input {
    flex: 1;
}

.btn-fetch {
    white-space: nowrap;
    padding: 8px 12px;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-fetch .fetch-icon {
    font-size: 14px;
}

.btn-fetch:disabled {
    opacity: 0.6;
}

.btn-fetch.loading {
    pointer-events: none;
}

.btn-fetch.loading .fetch-icon {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ===========================================
   RESPONSIVE / MOBILE STYLES
   =========================================== */

/* Mobile-first adjustments */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    h1 {
        font-size: 20px;
    }

    /* Header row stacks on mobile */
    .header-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .header-links {
        width: 100%;
        flex-wrap: wrap;
    }

    .header-links .btn {
        flex: 1;
        min-width: calc(50% - 5px);
        text-align: center;
    }

    /* Tabs scroll horizontally */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        flex-wrap: nowrap;
        padding-bottom: 2px;
    }

    .tabs::-webkit-scrollbar {
        display: none;
    }

    .tab {
        padding: 8px 14px;
        font-size: 13px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Toolbar stacks */
    .toolbar {
        flex-direction: column;
    }

    .toolbar input[type="text"] {
        min-width: 100%;
    }

    .toolbar select {
        width: 100%;
    }

    /* Inline forms stack */
    .inline-form {
        flex-direction: column;
    }

    .inline-form input,
    .inline-form select {
        width: 100%;
    }

    /* Form rows stack on mobile */
    .form-row {
        flex-direction: column;
        gap: 0;
    }

    /* Modal full width on mobile */
    .modal-content {
        margin: 10px;
        max-width: calc(100% - 20px);
        max-height: calc(100vh - 20px);
    }

    /* Pagination stacks */
    .pagination {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }

    /* ================================
       RESPONSIVE TABLE - CARD LAYOUT
       ================================ */

    .table-wrapper {
        background: transparent;
        box-shadow: none;
        overflow: visible;
    }

    table {
        display: block;
    }

    thead {
        display: none; /* Hide table header on mobile */
    }

    tbody {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    tr {
        display: flex;
        flex-direction: column;
        background: #fff;
        border-radius: 8px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        padding: 15px;
        position: relative;
    }

    tr:hover {
        background: #fff;
    }

    td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        padding: 8px 0;
        border-bottom: 1px solid #eee;
        text-align: right;
    }

    td:last-child {
        border-bottom: none;
    }

    /* Data label - shows column name */
    td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 12px;
        text-transform: uppercase;
        color: #666;
        text-align: left;
        flex-shrink: 0;
        margin-right: 15px;
    }

    /* Actions cell - full width, centered */
    td.actions {
        justify-content: center;
        padding-top: 12px;
        margin-top: 5px;
        border-top: 1px solid #eee;
        border-bottom: none;
    }

    td.actions::before {
        display: none;
    }

    td.actions .btn {
        padding: 8px 16px;
        margin: 0 4px;
    }

    /* Hide less important columns on mobile */
    td[data-priority="low"] {
        display: none;
    }

    /* ID column - show as badge */
    td[data-label="ID"] {
        position: absolute;
        top: 10px;
        right: 10px;
        padding: 0;
        border: none;
        font-size: 11px;
        color: #999;
    }

    td[data-label="ID"]::before {
        content: "#";
        margin-right: 0;
        font-weight: normal;
    }

    /* Price styling */
    td.price,
    td[data-label="Price"],
    td[data-label="Market Price"],
    td[data-label="Max Bid ($4k)"] {
        font-weight: 600;
        color: #28a745;
    }

    /* Link cells */
    td[data-label="Link"] a {
        word-break: break-all;
        font-size: 13px;
    }

    /* Simple list mobile */
    .simple-list-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .simple-list-item > span:first-child {
        font-weight: 500;
    }

    .simple-list-item > div {
        width: 100%;
        display: flex;
        justify-content: flex-end;
        gap: 8px;
    }
}

/* Small mobile (< 480px) */
@media (max-width: 480px) {
    .header-links .btn {
        min-width: 100%;
        padding: 10px;
    }

    td.actions {
        flex-wrap: wrap;
        gap: 8px;
    }

    td.actions .btn {
        flex: 1;
        min-width: calc(50% - 8px);
        text-align: center;
    }

    /* Input with button stacks */
    .input-with-button {
        flex-direction: column;
    }

    .btn-fetch {
        width: 100%;
        justify-content: center;
        padding: 10px;
    }
}

/* Tablet landscape and up - show table normally */
@media (min-width: 769px) {
    /* Ensure table displays normally on larger screens */
    table {
        display: table;
    }

    thead {
        display: table-header-group;
    }

    tbody {
        display: table-row-group;
    }

    tr {
        display: table-row;
        background: transparent;
        box-shadow: none;
        padding: 0;
    }

    td {
        display: table-cell;
        text-align: left;
    }

    td::before {
        display: none;
    }

    td[data-priority="low"] {
        display: table-cell;
    }

    td[data-label="ID"] {
        position: static;
    }
}
