:root {
    --primary: #2d5a27;
    --primary-dark: #1e3d1a;
    --primary-light: #4a7c43;
    --accent: #8fbc8f;
    --bg: #ffffff;
    --bg-alt: #f8faf8;
    --bg-card: #ffffff;
    --text: #1a1a1a;
    --text-secondary: #555555;
    --text-muted: #777777;
    --border: #e0e0e0;
    --shadow: rgba(0, 0, 0, 0.1);
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(255, 255, 255, 0.3);
    --success: #2d5a27;
    --warning: #b8860b;
    --info: #4682b4;
    --danger: #c0392b;
}

[data-theme="dark"] {
    --primary: #4a7c43;
    --primary-dark: #2d5a27;
    --primary-light: #6b9e64;
    --accent: #8fbc8f;
    --bg: #0f1a0e;
    --bg-alt: #1a2a18;
    --bg-card: #1e2d1c;
    --text: #e8f0e8;
    --text-secondary: #b8c8b8;
    --text-muted: #8a9a8a;
    --border: #2d3d2b;
    --shadow: rgba(0, 0, 0, 0.3);
    --glass-bg: rgba(30, 45, 28, 0.85);
    --glass-border: rgba(74, 124, 67, 0.2);
    --success: #6b9e64;
    --warning: #daa520;
    --info: #5a9fd4;
    --danger: #e74c3c;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Header */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: var(--glass-bg);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--glass-border);
    transition: all 0.3s ease;
}

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

.logo-link {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text);
}

.logo-link svg {
    width: 28px;
    height: 28px;
    fill: var(--primary);
}

.logo-text {
    font-weight: 600;
    font-size: 1rem;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.control-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

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

.control-btn svg {
    width: 16px;
    height: 16px;
}

/* Main */
.main {
    padding-top: 60px;
    min-height: 100vh;
}

/* Tool Hero */
.tool-hero {
    text-align: center;
    padding: 2rem 1rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
}

.tool-hero h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.tool-hero p {
    font-size: 1rem;
    opacity: 0.9;
}

/* App Container */
.app-container {
    display: flex;
    max-width: 1400px;
    margin: 0 auto;
    min-height: calc(100vh - 200px);
}

/* Control Panel */
.control-panel {
    width: 320px;
    background: var(--bg-alt);
    padding: 1rem;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
}

.panel-card {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 1rem;
    overflow: hidden;
    box-shadow: 0 2px 10px var(--shadow);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0.875rem 1rem;
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text);
}

.panel-header svg {
    width: 18px;
    height: 18px;
    fill: var(--primary);
}

.panel-content {
    padding: 1rem;
}

/* Form Elements */
.form-row {
    display: flex;
    align-items: center;
    margin-bottom: 0.75rem;
    gap: 0.75rem;
}

.form-row label {
    width: 110px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.form-row input,
.form-row select {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    background: var(--bg);
    color: var(--text);
    transition: all 0.2s ease;
}

.form-row input:focus,
.form-row select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(45, 90, 39, 0.15);
}

[data-theme="dark"] .form-row input:focus,
[data-theme="dark"] .form-row select:focus {
    box-shadow: 0 0 0 3px rgba(74, 124, 67, 0.2);
}

.form-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    flex: none;
    accent-color: var(--primary);
}

/* Buttons */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 0.5rem;
}

.btn:last-child {
    margin-bottom: 0;
}

.btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(45, 90, 39, 0.3);
}

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

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

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

.btn-danger:hover {
    opacity: 0.9;
}

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

.btn-success:hover {
    opacity: 0.9;
}

.btn-sm {
    width: auto;
    padding: 8px 14px;
    font-size: 0.85rem;
}

/* Preview Panel */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    min-width: 0;
}

/* Tabs */
.tabs {
    display: flex;
    background: var(--bg-alt);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.tab {
    padding: 0.875rem 1.25rem;
    cursor: pointer;
    border: none;
    background: transparent;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    white-space: nowrap;
    position: relative;
}

.tab:hover {
    color: var(--text);
    background: var(--bg);
}

.tab.active {
    color: var(--primary);
    background: var(--bg);
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary);
}

/* Tab Content */
.tab-content {
    flex: 1;
    padding: 1rem;
    overflow: auto;
}

.hidden {
    display: none !important;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th, td {
    padding: 10px 12px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--bg-alt);
    font-weight: 600;
    color: var(--text);
    position: sticky;
    top: 0;
}

tr:hover td {
    background: var(--bg-alt);
}

.selected {
    background: var(--primary) !important;
    color: white !important;
}

.selected:hover td {
    background: var(--primary) !important;
}

/* Measurement Controls */
.measurement-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

/* Preview Text */
#preview-text {
    font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    white-space: pre;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    height: calc(100vh - 240px);
    overflow: auto;
    font-size: 0.8rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

/* Visualization */
#visualization {
    height: calc(100vh - 240px);
    border-radius: 8px;
    overflow: hidden;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
}

.modal.active {
    display: block;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    border-radius: 16px;
    box-shadow: 0 20px 50px var(--shadow);
    min-width: 340px;
    max-width: 90vw;
    border: 1px solid var(--border);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

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

.modal-body {
    padding: 1.25rem;
}

.modal-body .form-row {
    margin-bottom: 1rem;
}

.modal-body .form-row:last-child {
    margin-bottom: 0;
}

.modal-footer {
    display: flex;
    gap: 10px;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    justify-content: flex-end;
}

.modal-footer .btn {
    width: auto;
    min-width: 80px;
    margin-bottom: 0;
}

/* Footer */
.footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    background: var(--bg-alt);
}

.footer a {
    color: var(--primary);
    text-decoration: none;
}

.footer a:hover {
    text-decoration: underline;
}

/* Responsive */
@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
    }

    .control-panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 50vh;
    }

    .preview-panel {
        min-height: 50vh;
    }

    #preview-text,
    #visualization {
        height: 400px;
    }
}

@media (max-width: 640px) {
    .header-content {
        padding: 0.5rem 1rem;
    }

    .logo-text {
        display: none;
    }

    .tool-hero {
        padding: 1.5rem 1rem;
    }

    .tool-hero h1 {
        font-size: 1.5rem;
    }

    .control-panel {
        padding: 0.75rem;
    }

    .panel-content {
        padding: 0.75rem;
    }

    .form-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .form-row label {
        width: 100%;
    }

    .tabs {
        justify-content: stretch;
    }

    .tab {
        flex: 1;
        padding: 0.75rem 0.5rem;
        font-size: 0.8rem;
        text-align: center;
    }

    .measurement-controls {
        flex-direction: column;
    }

    .measurement-controls .btn {
        width: 100%;
    }
}
