body {
    margin: 0;
    font-family: 'Roboto', sans-serif;
    background: #FFFFFF;
    color: #455A64;
    font-size: 16px;
    line-height: 1.6;
}

header {
    background: #1565C0;
    color: #FFFFFF;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    height: 48px;
}

h1 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 500;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#server-status {
    font-size: 0.8rem;
    background: rgba(255, 255, 255, 0.2);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

#dark-mode-toggle, #high-contrast-toggle {
    background: none;
    border: 1px solid #FFFFFF;
    color: #FFFFFF;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#dark-mode-toggle:hover, #high-contrast-toggle:hover {
    background: #0D47A1;
}

#dark-mode-toggle:active, #high-contrast-toggle:active {
    background: #002171;
}

nav {
    background: #F5F5F5;
    padding: 0.5rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

#nav-toggle {
    display: block;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
}

#nav-menu {
    list-style: none;
    padding: 0;
    margin: 0;
}

#nav-menu li {
    margin: 0.5rem 0;
}

#nav-menu button {
    background: none;
    border: none;
    font-size: 1rem;
    color: #1565C0;
    cursor: pointer;
    width: 100%;
    text-align: left;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

main {
    padding: 1rem;
}

.card {
    background: #FFFFFF;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 1rem;
    margin-bottom: 1rem;
}

h2 {
    margin: 0 0 1rem;
    font-size: 1.4rem;
    font-weight: 500;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.controls input, .controls select {
    flex: 1;
    min-width: 150px;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
    overflow-x: auto;
    display: block;
}

th, td {
    border: 1px solid #E0E0E0;
    padding: 0.75rem;
    text-align: left;
}

th {
    background: #F5F5F5;
    font-weight: 500;
    cursor: pointer;
}

th:hover {
    background: #E0E0E0;
}

td input[type="checkbox"] {
    margin: 0;
}

td .actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: nowrap;
}

form {
    display: grid;
    gap: 0.5rem;
    max-width: 100%;
}

label {
    font-size: 0.9rem;
    color: #455A64;
}

input, select, button {
    padding: 0.75rem;
    font-size: 1rem;
    border: 1px solid #B0BEC5;
    border-radius: 4px;
    width: 100%;
    box-sizing: border-box;
    min-height: 48px;
}

textarea {
    padding: 0.75rem;
    font-size: 1rem;
    border: 1px solid #B0BEC5;
    border-radius: 4px;
    width: 100%;
    box-sizing: border-box;
    min-height: 100px;
    resize: vertical;
}

input[type="radio"] {
    width: auto;
    margin-right: 0.5rem;
}

button {
    background: #1565C0;
    color: #FFFFFF;
    border: none;
    cursor: pointer;
    min-height: 48px;
    border-radius: 4px;
    font-weight: 500;
    position: relative;
}

button:hover {
    background: #0D47A1;
}

button:active {
    background: #002171;
}

button:disabled {
    background: #B0BEC5;
    cursor: not-allowed;
}

button.loading::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #FFFFFF;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error {
    color: #D32F2F;
    font-size: 0.8rem;
    margin-top: 0.2rem;
    display: block;
}

.pagination {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1rem;
}

.pagination button {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

#toast {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #FFFFFF;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#toast.show {
    opacity: 1;
}

#toast.error {
    background: #D32F2F;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    overflow: hidden;
}

.modal-content {
    background: #FFFFFF;
    padding: 1.5rem;
    border-radius: 8px;
    max-width: 90%;
    width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-sizing: border-box;
}

#tenant-modules-table {
    margin: 1rem 0;
}

#tenant-modules-table th, #tenant-modules-table td {
    padding: 0.5rem;
}

#tenant-modules-table input, #tenant-modules-table select {
    padding: 0.5rem;
    font-size: 0.9rem;
    min-height: 36px;
}

#tenant-modules-table .remove-btn {
    background: #D32F2F;
    padding: 0.5rem;
    font-size: 0.8rem;
}

#tenant-modules-table .remove-btn:hover {
    background: #B71C1C;
}

#add-module-row {
    background: #4CAF50;
    margin-bottom: 1rem;
}

#add-module-row:hover {
    background: #388E3C;
}

#auth-error {
    color: #D32F2F;
    margin-top: 0.5rem;
    font-size: 0.9rem;
}

footer {
    text-align: center;
    padding: 1rem;
    background: #F5F5F5;
    color: #455A64;
}

footer a {
    color: #1565C0;
    text-decoration: none;
}

.hidden {
    display: none;
}

body.modal-open {
    overflow: hidden !important;
}

/* Dark Mode */
body.dark-mode {
    background: #263238;
    color: #CFD8DC;
}

body.dark-mode header {
    background: #0D47A1;
}

body.dark-mode nav, body.dark-mode footer {
    background: #37474F;
}

body.dark-mode .card {
    background: #37474F;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

body.dark-mode table th {
    background: #455A64;
}

body.dark-mode table th:hover {
    background: #546E7A;
}

body.dark-mode table td, body.dark-mode table th {
    border-color: #546E7A;
}

body.dark-mode input, body.dark-mode select, body.dark-mode textarea {
    background: #455A64;
    border-color: #78909C;
    color: #CFD8DC;
}

body.dark-mode .modal-content {
    background: #37474F;
}

body.dark-mode #toast.error {
    background: #EF5350;
}

body.dark-mode #dark-mode-toggle, body.dark-mode #high-contrast-toggle {
    border-color: #CFD8DC;
}

body.dark-mode #dark-mode-toggle:hover, body.dark-mode #high-contrast-toggle:hover {
    background: #546E7A;
}

body.dark-mode #tenant-modules-table .remove-btn {
    background: #EF5350;
}

body.dark-mode #tenant-modules-table .remove-btn:hover {
    background: #D81B60;
}

body.dark-mode #add-module-row {
    background: #388E3C;
}

body.dark-mode #add-module-row:hover {
    background: #2E7D32;
}

/* High Contrast Mode */
body.high-contrast {
    background: #000000;
    color: #FFFFFF;
}

body.high-contrast header, body.high-contrast nav, body.high-contrast footer {
    background: #000000;
    color: #FFFFFF;
}

body.high-contrast .card {
    background: #000000;
    border: 1px solid #FFFFFF;
}

body.high-contrast table th, body.high-contrast table td {
    border-color: #FFFFFF;
}

body.high-contrast input, body.high-contrast select, body.high-contrast button, body.high-contrast textarea {
    background: #000000;
    color: #FFFFFF;
    border: 1px solid #FFFFFF;
}

body.high-contrast button {
    background: #FFFF00;
    color: #000000;
}

body.high-contrast #toast.error {
    background: #FF0000;
}

body.high-contrast #dark-mode-toggle, body.high-contrast #high-contrast-toggle {
    border-color: #FFFFFF;
    background: #000000;
}

body.high-contrast #dark-mode-toggle:hover, body.high-contrast #high-contrast-toggle:hover {
    background: #FFFF00;
    color: #000000;
}

body.high-contrast #tenant-modules-table .remove-btn {
    background: #FF0000;
}

body.high-contrast #tenant-modules-table .remove-btn:hover {
    background: #CC0000;
}

body.high-contrast #add-module-row {
    background: #00FF00;
}

body.high-contrast #add-module-row:hover {
    background: #00CC00;
}

/* Mobile Optimization */
@media (max-width: 768px) {
    h1 {
        font-size: 1rem;
    }

    header {
        padding: 0.3rem 0.5rem;
        height: 40px;
    }

    #server-status {
        font-size: 0.7rem;
        padding: 0.1rem 0.3rem;
    }

    #dark-mode-toggle, #high-contrast-toggle {
        font-size: 0.9rem;
        padding: 0.2rem 0.4rem;
        min-width: 32px;
        min-height: 32px;
    }

    #nav-menu {
        display: none;
    }

    #nav-menu.active {
        display: block;
    }

    table {
        font-size: 0.9rem;
    }

    th, td {
        padding: 0.5rem;
    }

    .hide-mobile {
        display: none;
    }

    .controls {
        flex-direction: column;
    }

    .modal-content {
        width: 95%;
    }

    button {
        min-height: 48px;
        font-size: 0.9rem;
    }

    td .actions {
        gap: 0.3rem;
    }

    td .actions button {
        padding: 0.5rem;
        font-size: 0.8rem;
    }

    #tenant-modules-table {
        font-size: 0.8rem;
    }

    #tenant-modules-table th, #tenant-modules-table td {
        padding: 0.3rem;
    }

    #tenant-modules-table input, #tenant-modules-table select {
        padding: 0.3rem;
        font-size: 0.8rem;
        min-height: 32px;
    }

    #license-form textarea {
        min-height: 80px;
    }
}

@media (min-width: 769px) {
    #nav-toggle {
        display: none;
    }

    #nav-menu {
        display: flex !important;
        justify-content: space-around;
    }

    main {
        max-width: 1200px;
        margin: 0 auto;
    }

    .controls {
        flex-direction: row;
        align-items: center;
    }
}