/* Theme Variables */
:root {
    --portal-bg: var(--md-default-bg-color, #ffffff);
    --portal-fg: var(--md-default-fg-color, #24292e);
    --portal-border: var(--md-default-fg-color--lightest, #e1e4e8);
    --portal-primary: #2ea44f;
    --portal-primary-hover: #2c974b;
    --portal-header-bg: var(--md-code-bg-color, #f6f8fa);
    --portal-zebra: #fafbfc;
}

/* Global Resets and Layout Overrides */
.md-grid {
    max-width: 95% !important;
}

.md-content__inner {
    max-width: 100% !important;
}

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

/* Main Layout Containers */
.portal-wrapper {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    margin-top: 20px;
    width: 100%;
}

.portal-sidebar {
    background: var(--portal-header-bg);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--portal-border);
}

.portal-preview {
    border: 1px solid var(--portal-border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--portal-bg);
    min-height: 400px;
    display: flex;
    flex-direction: column;
    /* Prevent overflow in grid/flex layouts */
    min-width: 0;
}

/* Form Controls and Grid Layouts */
.control-group {
    margin-bottom: 12px;
}

.control-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--md-default-fg-color--light);
}

.control-input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--portal-border);
    border-radius: 6px;
    background: var(--portal-bg);
    color: var(--portal-fg);
    font-size: 0.95rem;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

.lang-cat-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 12px;
}

.year-range-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 8px;
    align-items: center;
}

.year-separator {
    color: var(--md-default-fg-color--light);
    font-weight: bold;
}

/* Buttons and Quick Actions */
.quick-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    flex-wrap: wrap;
}

.chip-btn {
    font-size: 0.75rem;
    padding: 6px 12px;
    border: 1px solid var(--portal-border);
    border-radius: 12px;
    background: transparent;
    cursor: pointer;
    color: var(--md-default-fg-color--light);
    transition: all 0.2s;
}

.chip-btn:hover {
    background: var(--portal-border);
    color: var(--portal-fg);
}

.btn-download {
    width: 100%;
    padding: 12px;
    background-color: var(--portal-primary);
    color: white;
    font-weight: 700;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    margin-top: 16px;
    transition: background 0.2s;
}

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

.btn-download:disabled {
    background-color: #94d3a2;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Preview Table Styles */
.table-scroll-area {
    overflow-y: auto;
    overflow-x: auto;
    /* Smooth scrolling for iOS devices */
    -webkit-overflow-scrolling: touch;
    max-height: 70vh;
    scrollbar-width: thin;
    width: 100%;
}

.preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.preview-table th {
    text-align: left;
    padding: 12px 16px;
    background: var(--portal-header-bg);
    box-shadow: inset 0 -2px 0 var(--portal-border);
    position: sticky;
    top: 0;
    z-index: 10;
    white-space: nowrap;
    height: 48px;
    box-sizing: border-box;
}

.preview-table td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--portal-border);
    color: var(--portal-fg);
    white-space: normal;
    word-wrap: break-word;
}

.preview-table td:first-child {
    color: #57606a;
    font-weight: 500;
    white-space: nowrap;
    width: 140px;
}

.preview-table td a {
    color: inherit;
    text-decoration: none;
}

.preview-table tr:nth-child(even) {
    background-color: var(--portal-zebra);
}

.year-divider {
    background-color: var(--portal-header-bg);
    font-weight: 800;
    color: var(--portal-fg);
    text-align: center;
    padding: 12px 10px;
    position: sticky;
    top: 48px;
    z-index: 5;
    border: none;
    box-shadow: inset 0 -2px 0 var(--portal-border);
}

/* Empty State */
.empty-state {
    padding: 40px;
    text-align: center;
    color: var(--md-default-fg-color--lighter);
    font-style: italic;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Desktop Responsive Settings */
@media (min-width: 768px) {
    .portal-wrapper {
        grid-template-columns: 300px minmax(0, 1fr);
        align-items: start;
    }

    /* Lock sidebar position on larger screens */
    .portal-sidebar {
        position: sticky;
        top: 20px;
    }
}
