:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --text-color: #1e293b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --error-color: #ef4444;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    line-height: 1.6;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 1.25rem 1.5rem;
}

/* Header & Nav */
.main-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
}

.logo a {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    text-decoration: none;
}

.main-nav ul {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    margin: 0;
    padding: 0;
}

.main-nav a {
    text-decoration: none;
    color: var(--text-color);
    font-weight: 500;
    transition: color 0.2s;
}

.main-nav a:hover {
    color: var(--primary-color);
}

.user-display {
    font-weight: bold;
    margin-right: 1rem;
    color: var(--secondary-color);
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

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

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

#submit-btn.btn-primary.btn-submit-busy,
#submit-btn.btn-primary:disabled,
#free-query-submit-btn.btn-primary.btn-submit-busy,
#free-query-submit-btn.btn-primary:disabled {
    cursor: wait;
    opacity: 0.88;
}

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

.btn-secondary:hover {
    background-color: var(--border-color);
}

.btn-outline {
    background: transparent;
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-outline:hover {
    background: var(--primary-color);
    color: white;
}

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

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

/* Auth Pages */
.auth-body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 1rem;
}

.auth-container {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: 0.75rem;
    box-shadow: 0 10px 25px rgba(0,0,0,0.05);
    width: 100%;
    max-width: 400px;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h1 {
    margin: 0;
    color: var(--primary-color);
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    box-sizing: border-box;
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.alert {
    padding: 0.75rem;
    border-radius: 0.375rem;
    margin-bottom: 1.5rem;
    font-size: 0.875rem;
}

.alert-error {
    background-color: #fee2e2;
    color: var(--error-color);
    border: 1px solid #fecaca;
}

.info-box {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    font-size: 0.875rem;
    color: var(--secondary-color);
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 0.75rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
    margin-bottom: 2rem;
    overflow: hidden;
}

.card-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: #fdfdfd;
}

.card-header h2 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-color);
}

.card-body {
    padding: 1.5rem;
}

/* Query Form */
#query_text {
    width: 100%;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
    box-sizing: border-box;
    margin-bottom: 1rem;
}

#query_text:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Results */
.sql-display {
    background: #1e293b;
    color: #f8fafc;
    padding: 0.75rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.75rem;
    position: relative;
    transition: max-height 0.1s steps(10), padding 0.1s ease-in-out;
    max-height: 500px;
    overflow: hidden;
}

.sql-display.minimized {
    max-height: 1.5rem;
    padding: 0.4rem 0.75rem;
    background: #334155;
    cursor: pointer;
}

.sql-display pre, 
.sql-display strong {
    transition: opacity 0.1s ease;
    opacity: 1;
}

.sql-display.minimized pre, 
.sql-display.minimized strong {
    opacity: 0;
    pointer-events: none;
}

.sql-display.minimized::after {
    content: 'SQL Query (Expand)';
    font-size: 0.7rem;
    color: #94a3b8;
    position: absolute;
    left: 4.5rem;
    top: 0.4rem;
}

.sql-display pre {
    margin: 0.5rem 0 0 0;
    white-space: pre-wrap;
    word-break: break-all;
}

.sql-toggle {
    position: absolute;
    top: 0.5rem;
    left: 0.75rem;
    cursor: pointer;
    background: #334155;
    border: none;
    color: #f8fafc;
    font-size: 0.7rem;
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    z-index: 10;
}

.sql-toggle:hover {
    background: #475569;
}

.table-container {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 500px; /* Approximately 20 rows in compact mode */
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    background: linear-gradient(to right, white 30%, rgba(255,255,255,0)), 
                linear-gradient(to right, rgba(255,255,255,0), white 70%) 0 100%, 
                radial-gradient(farthest-side at 0 50%, rgba(0,0,0,0.1), rgba(0,0,0,0)), 
                radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,0.1), rgba(0,0,0,0)) 0 100%;
    background-repeat: no-repeat;
    background-color: white;
    background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
    background-attachment: local, local, scroll, scroll;
}

/* Make headers sticky when vertical scrolling is active */
.data-table thead th {
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: inset 0 -1px 0 var(--border-color);
}

.data-table thead tr:nth-child(2) th {
    top: 1.5rem; /* Adjust based on hebrew-header height */
}

/* Custom Scrollbar for better visibility */
.table-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.table-container::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.table-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.table-container::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th, .data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background: #f8fafc;
    font-weight: 600;
    color: var(--secondary-color);
}

.data-table tr:hover {
    background: #f1f5f9;
}

.alert-info {
    background-color: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    border: 3px solid rgba(37, 99, 235, 0.2);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s ease-in-out infinite;
    margin-right: 0.75rem;
    vertical-align: middle;
}

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

/* Compact Table */
.data-table.compact {
    font-size: 0.75rem;
}

.data-table.compact th, 
.data-table.compact td {
    padding: 0.4rem 0.6rem;
    white-space: nowrap;
}

.data-table td .company-profile-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.data-table td .company-profile-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.hebrew-header {
    background-color: #f1f5f9 !important;
    color: #475569 !important;
    font-size: 0.7rem;
    font-weight: 500;
    border-bottom: none !important;
}

.english-header {
    border-top: none !important;
}

.query-card {
    border-left: 4px solid var(--primary-color);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.query-card.pending {
    border-left-color: #fbbf24;
}

.query-card.failed {
    border-left-color: var(--error-color);
}

.query-card.cancelled {
    border-left-color: #94a3b8;
}

.free-query-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.error-text {
    color: var(--error-color);
    font-weight: 500;
}

.query-stats {
    display: flex;
    gap: 1rem;
    padding: 0.25rem 0.5rem;
    background: #f1f5f9;
    border-radius: 0.25rem;
    font-weight: 500;
}

.query-stats-bar {
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.query-stats-bar .query-stats-left {
    font-size: 0.8rem;
    color: var(--secondary-color);
    font-weight: 500;
}

.query-stats-bar .export-excel-btn {
    flex-shrink: 0;
    font-size: 0.75rem;
    padding: 0.28rem 0.65rem;
}

/* Dashboard Stats */
.stats-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
    border: 1px solid var(--border-color);
}

.stat-card h3 {
    margin: 0 0 0.5rem 0;
    font-size: 0.875rem;
    color: var(--secondary-color);
}

.stat-card p {
    margin: 0;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
}

/* Static Prompts Management */
.static-prompts-section {
    margin-bottom: 2rem;
}

.static-prompts-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
}

.static-prompt-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    transition: all 0.2s;
}

.static-prompt-item:hover {
    border-color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.static-prompt-info {
    flex-grow: 1;
}

.static-prompt-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.static-prompt-content {
    font-size: 0.8rem;
    color: var(--secondary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 400px;
}

.static-prompt-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 20px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

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

.modal-content {
    background-color: var(--card-bg);
    margin: 10% auto;
    padding: 2rem;
    border-radius: 0.75rem;
    width: 100%;
    max-width: 600px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h2 {
    margin: 0;
}

.close-modal {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--secondary-color);
}

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

/* Company Details page */
.company-filter-bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.company-filter-bar .form-control {
    min-width: 220px;
    padding: 0.5rem 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 0.9rem;
}

.company-table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.results-meta {
    font-size: 0.875rem;
    color: var(--secondary-color);
}

.company-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

.query-sql-input {
    width: 100%;
    min-height: 260px;
    padding: 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.8rem;
    line-height: 1.35;
    box-sizing: border-box;
}

.sql-placeholders-section {
    margin-bottom: 1rem;
}

.sql-placeholders-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
}

.sql-placeholder-item label {
    display: block;
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
    color: var(--secondary-color);
    font-weight: 600;
}

.sql-placeholder-item .form-control {
    width: 100%;
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 0.85rem;
    box-sizing: border-box;
}

.query-header-tools {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.query-header-tools .form-control {
    min-width: 320px;
    padding: 0.5rem 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 0.9rem;
}

.query-selects {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.stats-overview .stat-card-compact {
    padding: 0.75rem 1rem;
}

.stats-overview .stat-card-compact h3 {
    margin-bottom: 0.25rem;
    font-size: 0.8rem;
}

.stats-overview .stat-card-compact p {
    font-size: 1.15rem;
    line-height: 1.2;
}

.col-filter-input {
    width: 100%;
    box-sizing: border-box;
    padding: 0.25rem 0.4rem;
    font-size: 0.78rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-color);
    color: var(--text-color);
}
.col-filter-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.filter-row th {
    background: var(--card-bg);
}
