:root {
    --primary: #007aff;
    --primary-hover: #005ecb;
    --primary-soft: rgba(0, 122, 255, 0.1);
    --success: #34c759;
    --success-hover: #248a3d;
    --info: #06b6d4;
    --info-hover: #0891b2;
    --danger: #ff3b30;
    --warning: #ff9500;
    --background: #f2f2f7;
    --surface: #ffffff;
    --surface-muted: #f8f9fb;
    --border: rgba(0, 0, 0, 0.1);
    --text: #111114;
    --text-secondary: #6e6e73;
    --text-tertiary: #9b9ba1;
    --shadow-light: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-medium: 0 8px 28px rgba(0, 0, 0, 0.12);
    --radius-small: 8px;
    --radius-medium: 12px;
    --radius-large: 18px;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    background: var(--background);
}

body {
    min-width: 320px;
    margin: 0;
    color: var(--text);
    background: var(--background);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button,
input,
select {
    font: inherit;
}

button {
    touch-action: manipulation;
}

.container {
    width: min(1600px, calc(100% - 32px));
    margin: 0 auto;
    padding: 16px 0 28px;
}

.card {
    overflow: hidden;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-medium);
    background: var(--surface);
    box-shadow: var(--shadow-light);
}

.card-content {
    padding: 20px 24px;
}

.tool-notice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
    padding: 16px 18px;
    border: 1px solid rgba(255, 59, 48, 0.18);
    border-radius: var(--radius-medium);
    background: rgba(255, 59, 48, 0.06);
}

.tool-notice h1 {
    margin: 0 0 4px;
    font-size: clamp(1.2rem, 2vw, 1.55rem);
    line-height: 1.25;
}

.tool-notice p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.92rem;
}

.tool-notice p.tool-policy-warning {
    margin-top: 8px;
    color: #ff3b30;
    font-weight: 700;
}

.account-summary {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.summary-item {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    white-space: nowrap;
    padding: 8px 12px;
    border: 1px solid rgba(0, 122, 255, 0.16);
    border-radius: 999px;
    color: var(--text-secondary);
    background: var(--primary-soft);
    font-size: 0.86rem;
}

.summary-item strong {
    color: var(--primary);
    font-size: 1rem;
}

.summary-cost {
    border-color: rgba(255, 149, 0, 0.2);
    background: rgba(255, 149, 0, 0.09);
}

.summary-cost strong {
    color: #c66f00;
}

.form-group + .form-group {
    margin-top: 14px;
}

.search-input-group {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--surface);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input-group:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.form-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
}

.search-input-group > .form-label {
    padding: 0 14px;
    border-right: 1px solid var(--border);
}

.form-control,
.form-select {
    min-height: 44px;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    outline: none;
    color: var(--text);
    background: var(--surface);
}

.form-control {
    width: 100%;
    border: 0;
    border-radius: 0;
    padding: 10px 14px;
}

.form-control::placeholder {
    color: var(--text-tertiary);
}

.form-select {
    min-width: 130px;
    padding: 8px 34px 8px 12px;
}

.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.syntax-link {
    align-self: stretch;
    padding: 0 16px;
    border: 0;
    border-left: 1px solid var(--border);
    color: var(--primary);
    background: transparent;
    cursor: pointer;
    white-space: nowrap;
}

.syntax-link:hover {
    background: var(--primary-soft);
}

.form-inline {
    display: flex;
    align-items: center;
    gap: 12px;
}

.button-group {
    display: flex;
    flex: 1;
    flex-wrap: wrap;
    gap: 8px;
}

.btn {
    min-height: 40px;
    padding: 8px 15px;
    border: 1px solid transparent;
    border-radius: var(--radius-small);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, background-color 0.2s, opacity 0.2s, box-shadow 0.2s;
}

.btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.btn:focus-visible,
.syntax-link:focus-visible,
.modal-close:focus-visible {
    outline: 3px solid rgba(0, 122, 255, 0.25);
    outline-offset: 2px;
}

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

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

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

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

.btn-success:hover:not(:disabled) {
    background: var(--success-hover);
}

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

.btn-info:hover:not(:disabled) {
    background: var(--info-hover);
}

.btn-secondary {
    border-color: var(--border);
    color: var(--text);
    background: var(--surface-muted);
}

.provider-button {
    flex: 1 1 118px;
}

.provider-button.is-exhausted,
.provider-button.is-exhausted:disabled {
    color: #6e6e73;
    background: #d1d1d6;
    opacity: 1;
    cursor: not-allowed;
}

.status-banner {
    margin-top: 16px;
    padding: 11px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-small);
    font-size: 0.92rem;
}

.status-banner.is-info {
    border-color: rgba(0, 122, 255, 0.18);
    color: #0056a6;
    background: rgba(0, 122, 255, 0.08);
}

.status-banner.is-success {
    border-color: rgba(52, 199, 89, 0.22);
    color: #187b31;
    background: rgba(52, 199, 89, 0.1);
}

.status-banner.is-error {
    border-color: rgba(255, 59, 48, 0.2);
    color: #b42318;
    background: rgba(255, 59, 48, 0.08);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
}

.card-header h2 {
    margin: 0;
    font-size: 1.08rem;
}

#result-count {
    color: var(--text-secondary);
    font-size: 0.84rem;
}

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

.table-wrapper,
.syntax-table-wrapper {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrapper {
    max-height: 68vh;
}

.results-table,
.syntax-table {
    width: 100%;
    border-collapse: collapse;
}

.results-table {
    min-width: 980px;
    table-layout: fixed;
}

.results-table th,
.results-table td,
.syntax-table th,
.syntax-table td {
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.results-table th,
.results-table td {
    padding: 11px 13px;
    font-size: 0.85rem;
}

.results-table th {
    position: sticky;
    z-index: 2;
    top: 0;
    color: var(--text-secondary);
    background: var(--surface-muted);
    font-weight: 700;
}

.results-table th:nth-child(1) { width: 25%; }
.results-table th:nth-child(2) { width: 14%; }
.results-table th:nth-child(3) { width: 25%; }
.results-table th:nth-child(4) { width: 8%; }
.results-table th:nth-child(5) { width: 18%; }
.results-table th:nth-child(6) { width: 10%; }

.results-table tbody tr:hover {
    background: rgba(0, 122, 255, 0.035);
}

.results-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.results-table a {
    color: var(--primary);
    text-decoration: none;
}

.results-table a:hover {
    text-decoration: underline;
}

.empty-row td {
    padding: 52px 16px;
    color: var(--text-tertiary);
    text-align: center;
}

.modal {
    position: fixed;
    z-index: 1000;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(16, 16, 20, 0.46);
    backdrop-filter: blur(5px);
}

.modal-panel {
    display: flex;
    max-height: min(88vh, 900px);
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: var(--radius-large);
    background: var(--surface);
    box-shadow: var(--shadow-medium);
}

.modal-small {
    width: min(470px, 100%);
}

.modal-large {
    width: min(980px, 100%);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.18rem;
}

.modal-header p {
    margin: 4px 0 0;
    color: var(--text-secondary);
    font-size: 0.86rem;
}

.modal-close {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 50%;
    color: var(--text-secondary);
    background: var(--surface-muted);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
}

.modal-close:hover {
    color: var(--text);
    background: #ececf0;
}

.modal-body {
    overflow: auto;
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
}

.confirm-cost {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 5px;
    margin: 2px 0 14px;
    color: var(--primary);
}

.confirm-cost span {
    font-size: 2.6rem;
    font-weight: 750;
    line-height: 1;
}

.confirm-cost small {
    color: var(--text-secondary);
    font-weight: 600;
}

.confirm-message {
    margin: 0 0 16px;
    text-align: center;
}

.confirm-details {
    margin: 0;
    padding: 12px 14px;
    border-radius: var(--radius-small);
    background: var(--surface-muted);
}

.confirm-details div {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 6px 0;
}

.confirm-details dt {
    color: var(--text-secondary);
}

.confirm-details dd {
    margin: 0;
    text-align: right;
    font-weight: 600;
}

.syntax-tip {
    margin-bottom: 14px;
    padding: 11px 13px;
    border: 1px solid rgba(0, 122, 255, 0.16);
    border-radius: var(--radius-small);
    color: #0056a6;
    background: var(--primary-soft);
    font-size: 0.88rem;
}

code {
    padding: 2px 6px;
    border-radius: 5px;
    color: var(--primary);
    background: var(--primary-soft);
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.86em;
}

.syntax-table {
    min-width: 700px;
}

.syntax-table th,
.syntax-table td {
    padding: 10px 12px;
    font-size: 0.86rem;
}

.syntax-table th {
    color: var(--text-secondary);
    background: var(--surface-muted);
}

.syntax-table tbody tr:hover {
    background: rgba(0, 122, 255, 0.035);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body.modal-open {
    overflow: hidden;
}

@media (max-width: 780px) {
    .container {
        width: min(100% - 20px, 1600px);
        padding-top: 10px;
    }

    .card-content {
        padding: 14px;
    }

    .tool-notice,
    .card-header {
        align-items: stretch;
        flex-direction: column;
    }

    .account-summary {
        justify-content: flex-start;
    }

    .search-input-group {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .search-input-group > .form-label {
        display: none;
    }

    .form-inline {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .form-inline > .form-label {
        display: flex;
        align-items: center;
    }

    .button-group {
        flex-basis: 100%;
    }

    .header-actions .btn {
        flex: 1;
    }

    .modal {
        padding: 10px;
    }

    .modal-panel {
        max-height: 94vh;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
