* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #f5f5f5;
    --bg-secondary: white;
    --text-primary: #333;
    --text-secondary: #555;
    --border-color: #ddd;
    --input-bg: white;
    --input-border: #ddd;
    --button-bg: #747190ff;
    --button-hover: #68658eff;
    --shadow: rgba(0,0,0,0.1);
}

body.dark-mode {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --border-color: #444;
    --input-bg: #3a3a3a;
    --input-border: #555;
    --button-bg: #5a5770;
    --button-hover: #4a4760;
    --shadow: rgba(0,0,0,0.5);
}

body {
    font-family: Arial, sans-serif;
    background: var(--bg-primary);
    padding: 20px;
    transition: background 0.3s ease;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 2px 10px var(--shadow);
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

h1 {
    color: var(--text-primary);
    transition: color 0.3s ease;
}

h2 {
    color: var(--text-secondary);
    margin-bottom: 15px;
    transition: color 0.3s ease;
}

/* Dark Mode Toggle Switch */
.dark-mode-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-label {
    color: var(--text-secondary);
    font-size: 14px;
    transition: color 0.3s ease;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

.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: 0.4s;
    border-radius: 24px;
}

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

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

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

.main-layout {
    display: grid;
    grid-template-columns: 30% 15% 55%;
    gap: 10px;
    height: calc(100vh - 100px);
}

.calculator-section, .history-section, .right-container {
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px var(--shadow);
    overflow-y: auto;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.right-container {
    display: flex;
    gap: 10px;
    padding: 0;
    background: none;
    box-shadow: none;
}

.tables-section {
    flex: 3;
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px var(--shadow);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.hasse-widget {
    flex: 1;
    background: var(--bg-secondary);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px var(--shadow);
    overflow-y: auto;
    min-width: 250px;
    max-width: 350px;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.hasse-widget h3 {
    text-align: center;
    margin-top: 0;
    font-size: 14px;
    font-weight: bold;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

.table-display {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-bottom: 20px;
}

.table-display:last-of-type {
    margin-bottom: 0;
}

.table-display label {
    font-weight: bold;
    margin-bottom: 5px;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

.table-display select {
    margin-bottom: 10px;
    padding: 8px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    min-height: 30px;
    background: var(--input-bg);
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.table-content {
    flex: 1;
    overflow: auto;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 10px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    background: var(--input-bg);
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-secondary);
    font-size: 14px;
    transition: color 0.3s ease;
}

.form-group input[type="text"],
.form-group input[type="number"] {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    font-size: 14px;
    background: var(--input-bg);
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.form-group input[readonly] {
    background: var(--input-bg);
    font-weight: bold;
    opacity: 0.7;
}

button {
    padding: 10px 15px;
    background: var(--button-bg);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s ease;
}

button:hover {
    background: var(--button-hover);
}

.button-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin: 20px 0;
}

.button-grid button {
    height: 45px;
    font-size: 16px;
}

.clear-btn {
    width: 100%;
    background: #68658eff;
    margin-top: 10px;
}

.clear-btn:hover {
    background: #524e75;
}

.history-list {
    max-height: 500px;
    overflow-y: auto;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 10px;
}

.history-item {
    padding: 8px;
    margin-bottom: 5px;
    background: var(--input-bg);
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: var(--text-primary);
    transition: background 0.3s ease;
}

.history-item:hover {
    background: var(--border-color);
}

.table-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.table-controls select {
    flex: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

#tableDisplay {
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 15px;
    overflow: auto;
    max-height: 600px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: var(--text-primary);
}

table th, table td {
    padding: 8px;
    border: 1px solid var(--border-color);
    text-align: center;
}

table th {
    background: var(--button-bg);
    color: white;
}

.hasse-diagram {
    text-align: center;
    padding: 20px;
    font-family: 'Courier New', monospace;
}

.hasse-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    overflow: auto;
    max-height: 600px;
}

.hasse-container svg {
    display: block;
    margin: 0 auto;
}

.hasse-empty {
    text-align: center;
    padding: 40px;
    color: #999;
    font-size: 14px;
    line-height: 1.6;
}

.error {
    color: #d32f2f;
    padding: 10px;
    background: #ffebee;
    border-radius: 4px;
    margin: 10px 0;
}

.success {
    color: #388e3c;
    padding: 10px;
    background: #e8f5e9;
    border-radius: 4px;
    margin: 10px 0;
}

@media (max-width: 1024px) {
    .main-layout {
        grid-template-columns: 1fr;
    }
}
