html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: #f5f5f5;
}

main {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-header {
    flex-shrink: 0;
    padding: 0.5rem 1rem;
    background: #333;
    color: white;
}

.app-header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 500;
}

.table-container {
    flex: 1;
    overflow: auto;
    min-height: 0; /* Allow shrinking in flexbox */
}

.capacity-table {
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;

    th, td {
        border-top: 1px solid #ddd;
        border-left: 1px solid #ddd;
        padding: 1px;
        text-align: center;
        white-space: nowrap;

        &:last-child {
            border-right: 1px solid #ddd;
        }
    }

    /* Left column (labels, resource names) */
    .label {
        text-align: left;
        background: #f0f0f0;
        padding: 3px 6px;
        width: var(--layout-left-column-width);
        min-width: var(--layout-left-column-width);
        max-width: var(--layout-left-column-width);
    }

    th {
        background: #f0f0f0;
    }

    thead th {
        height: var(--layout-header-row-height);
        box-sizing: border-box;
        position: sticky;
        z-index: 3;
        background: #888;
        color: white;
        border-left-color: #777;
        border-top-color: #777;
    }

    thead tr:last-child th {
        border-bottom: 1px solid #777;
    }

    tbody tr:last-child td {
        border-bottom: 1px solid #ddd;
    }

    /* Sticky first column */
    .label,
    .resource-name {
        position: sticky;
        left: 0;
        z-index: 2;
    }

    thead .label {
        z-index: 5;
        background: #888;
    }

    thead .row-total {
        z-index: 5;
        background: #888;
    }

    /* Header row positioning - each row stacks below the previous */
    .header-quarter th { top: 0; }
    .header-month th { top: var(--layout-header-row-height); }
    .header-date th { top: calc(var(--layout-header-row-height) * 2); }
    .header-week th {
        top: calc(var(--layout-header-row-height) * 3);
        font-weight: normal;
    }

    .section-header td {
        background: #666;
        color: white;
        font-weight: bold;
        border-left-color: #555;
        border-top-color: #555;
    }

    /* Resource tier colors */
    .tier-primary td {
        background: #D66CCB;
    }

    .tier-secondary td {
        background: #E49EDD;
    }

    .tier-tertiary td {
        background: #F2CEEF;
    }

    .resource-name {
        background: #D66CCB;
        font-weight: bold;
        text-align: left;
        padding: 3px 6px;
        width: var(--layout-left-column-width);
        min-width: var(--layout-left-column-width);
        max-width: var(--layout-left-column-width);
    }

    .activity-id {
        height: var(--layout-cell-activity-height);
        line-height: var(--layout-cell-activity-height);
    }

    .activity-units {
        font-size: 0.9em;
        opacity: 0.8;
        height: var(--layout-cell-units-height);
        line-height: var(--layout-cell-units-height);
    }

    tfoot td {
        position: sticky;
        bottom: 0;
        z-index: 2;
    }

    .totals-row td {
        background: #888;
        color: white;
        font-weight: bold;
        border-bottom: 1px solid #777;
        border-left-color: #777;
    }

    .totals-row td.label {
        z-index: 4;
    }

    /* Sticky right column for row totals */
    .row-total {
        position: sticky;
        right: 0;
        background: #f0f0f0;
        font-weight: bold;
        z-index: 2;
        width: var(--layout-right-column-width);
        min-width: var(--layout-right-column-width);
    }

    .totals-row .row-total {
        z-index: 5;
        background: #888;
    }
}

/* Footer toolbar */
.footer-toolbar {
    flex-shrink: 0;
    padding: 0.5rem 1rem;
    background: #666;
    border-top: 1px solid #555;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.reset-button {
    background: #dc3545;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.reset-button:hover {
    background: #c82333;
}

.reset-button:active {
    background: #bd2130;
}

.home-button {
    background: #4a90a4;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: inherit;
    text-decoration: none;
}

.home-button:hover {
    background: #3d7a8c;
}

.home-button:active {
    background: #356b7a;
}

/* Edit section buttons */
.edit-section-btn {
    margin-left: 0.5rem;
    padding: 2px 8px;
    font-size: 11px;
    background: #888;
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    font-weight: normal;
}

.edit-section-btn:hover {
    background: #aaa;
}

/* Modal overlay */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

/* Modal dialog */
.modal-dialog {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

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

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    padding: 0;
    line-height: 1;
}

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

.modal-body {
    padding: 1.5rem;
    overflow: auto;
    flex: 1;
}

/* Entity editor table */
.entity-editor {
    width: 100%;
}

.entity-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.entity-table th,
.entity-table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

.entity-table th:first-child,
.entity-table td:first-child {
    width: 80px;
}

.entity-table th:last-child,
.entity-table td:last-child {
    width: 70px;
}

.entity-table th {
    background: #f5f5f5;
    font-weight: 600;
}

.entity-table input,
.entity-table select {
    width: 100%;
    padding: 0.4rem 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    box-sizing: border-box;
}

.entity-table select {
    min-width: 150px;
}

.entity-table input:focus,
.entity-table select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

.entity-table .new-row {
    background: #f9f9f9;
}

.entity-table .new-row input::placeholder {
    color: #999;
}

.delete-btn {
    background: #dc3545;
    color: white;
    border: none;
    padding: 0.3rem 0.6rem;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
}

.delete-btn:hover {
    background: #c82333;
}

.add-btn {
    background: #28a745;
    color: white;
    border: none;
    padding: 0.3rem 0.6rem;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
}

.add-btn:hover {
    background: #218838;
}

/* Allocation cell editing */
.allocation-cell {
    cursor: pointer;
    width: var(--layout-cell-width);
    min-width: var(--layout-cell-width);
    max-width: var(--layout-cell-width);
    position: relative;
    /*
     * Scroll margins ensure the cell isn't hidden behind sticky elements.
     * Order: top right bottom left
     * - top: total header height (all 4 header rows)
     * - right: right totals column width
     * - bottom: footer totals row height
     * - left: left label column width
     */
    scroll-margin:
        var(--layout-total-header-height)
        var(--layout-right-column-width)
        var(--layout-footer-row-height)
        var(--layout-left-column-width);
}

.allocation-cell.editing {
    padding: 1px;
    overflow: visible;
}

.cell-edit-container {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.allocation-cell input {
    width: 100%;
    border: 1px solid #ccc;
    border-radius: 2px;
    font: inherit;
    text-align: center;
    box-sizing: border-box;
    padding: 1px;
}

.cell-activity-input {
    height: var(--layout-cell-activity-height);
}

.cell-units-input {
    font-size: 0.9em;
    height: var(--layout-cell-units-height);
}

.allocation-cell input:focus {
    outline: none;
    border-color: #007bff;
}

/* Activity dropdown */
.activity-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    min-width: 180px;
    max-height: 200px;
    overflow-y: auto;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
    margin-top: 2px;
}

.activity-option {
    display: flex;
    gap: 8px;
    padding: 6px 8px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
}

.activity-option:last-child {
    border-bottom: none;
}

.activity-option:hover {
    background: #f0f0f0;
}

.activity-option.selected {
    background: #e3f2fd;
}

.option-id {
    font-weight: bold;
    min-width: 40px;
}

.option-name {
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Resource name with tier buttons */
.resource-name-content {
    /* Name text is vertically centered by default table cell alignment */
}

.tier-buttons {
    position: absolute;
    bottom: 2px;
    right: 2px;
    display: flex;
    gap: 2px;
}

.tier-btn {
    width: 18px;
    height: 18px;
    padding: 0;
    font-size: 12px;
    line-height: 1;
    border: 1px solid rgba(0, 0, 0, 0.2);
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tier-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.5);
}

.tier-btn:disabled,
.tier-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Tiers input in resource editor */
.tiers-input {
    width: 60px !important;
    text-align: center;
}

/* Mobile modals */
@media (max-width: 600px) {
    .modal-dialog {
        width: 95%;
        max-height: 90vh;
        border-radius: 4px;
    }

    .modal-header {
        padding: 0.5rem 0.75rem;
    }

    .modal-header h2 {
        font-size: 1rem;
    }

    .modal-body {
        padding: 0.5rem;
    }

    .entity-table {
        font-size: 12px;
    }

    .entity-table th,
    .entity-table td {
        padding: 0.25rem;
    }

    .entity-table th:first-child,
    .entity-table td:first-child {
        width: 50px;
    }

    .entity-table th:last-child,
    .entity-table td:last-child {
        width: 50px;
    }

    .entity-table input,
    .entity-table select {
        padding: 0.25rem;
        font-size: 12px;
    }

    .entity-table select {
        min-width: 80px;
    }

    .tiers-input {
        width: 40px !important;
    }

    .delete-btn {
        padding: 0.2rem 0.4rem;
        font-size: 11px;
    }
}

/* Home page styles */
.home-page {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem;
}

.home-page .app-header {
    background: transparent;
    color: #333;
    padding: 0;
    margin-bottom: 2rem;
}

.home-page .app-header h1 {
    font-size: 2rem;
    font-weight: 600;
}

.storage-menu {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.storage-menu h2 {
    margin: 0 0 1rem 0;
    font-size: 1.25rem;
    font-weight: 500;
    color: #555;
}

.storage-menu ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.storage-menu li {
    margin: 0.5rem 0;
}

.storage-menu a {
    display: block;
    padding: 0.75rem 1rem;
    background: #f8f8f8;
    border-radius: 4px;
    color: #333;
    text-decoration: none;
    transition: background 0.15s;
}

.storage-menu a:hover {
    background: #e8e8e8;
}

/* Auth screen styles */
.auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #f5f5f5;
}

.auth-card {
    background: white;
    border-radius: 8px;
    padding: 2rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.auth-card h1 {
    margin: 0 0 1rem 0;
    font-size: 1.5rem;
    color: #333;
}

.auth-message {
    margin: 0 0 1.5rem 0;
    color: #666;
}

.sign-in-btn {
    display: inline-block;
    background: #4285f4;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    margin-bottom: 1rem;
}

.sign-in-btn:hover {
    background: #357abd;
}

.home-link {
    display: block;
    color: #666;
    text-decoration: none;
    font-size: 0.9rem;
}

.home-link:hover {
    color: #333;
    text-decoration: underline;
}

/* User bar (signed-in state) */
.user-bar {
    position: fixed;
    top: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 0.5rem 1rem;
    border-bottom-left-radius: 4px;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.85rem;
    z-index: 1000;
}

.user-info {
    opacity: 0.9;
}

.sign-out-btn {
    background: transparent;
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.5);
    padding: 0.25rem 0.75rem;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.8rem;
}

.sign-out-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: white;
}
