:root {
    /* Light Mode Variables */
    --bg-gradient: linear-gradient(135deg, #f6f8fd 0%, #f1f5f9 100%);
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --card-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
    --input-bg: rgba(255, 255, 255, 0.9);
    --border-color: #e2e8f0;
}

[data-theme="dark"] {
    /* Dark Mode Variables */
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --glass-bg: rgba(15, 23, 42, 0.6);
    --glass-border: rgba(255, 255, 255, 0.1);
    --primary-color: #60a5fa;
    --primary-hover: #3b82f6;
    --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    --input-bg: rgba(30, 41, 59, 0.8);
    --border-color: #334155;
}

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

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Theme Switcher */
.theme-switch-wrapper {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
}

.theme-switch {
    display: inline-block;
    height: 34px;
    position: relative;
    width: 60px;
}

.theme-switch input {
    display: none;
}

.slider {
    background-color: #ccc;
    bottom: 0;
    cursor: pointer;
    left: 0;
    position: absolute;
    right: 0;
    top: 0;
    transition: .4s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 8px;
}

.slider.round {
    border-radius: 34px;
}

.slider:before {
    background-color: #fff;
    bottom: 4px;
    content: "";
    height: 26px;
    left: 4px;
    position: absolute;
    transition: .4s;
    width: 26px;
    border-radius: 50%;
    z-index: 2;
}

input:checked + .slider {
    background-color: #1e293b;
}

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

.sun-icon { color: #f59e0b; font-size: 14px; }
.moon-icon { color: #f1f5f9; font-size: 14px; }

/* Layout & Components */
.container {
    width: 100%;
    max-width: 900px;
    padding: 40px 20px;
    margin-top: 40px;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

header {
    text-align: center;
    margin-bottom: 20px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 10px;
}

#ai-loading p {
    color: var(--text-secondary);
    font-weight: 500;
    transition: opacity 0.3s ease;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 30px;
    box-shadow: var(--card-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* Tabs */
.tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.tab-btn {
    padding: 12px 24px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.3s ease;
}

.tab-btn:hover {
    color: var(--primary-color);
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom: 3px solid var(--primary-color);
}

.tab-content {
    display: none;
    animation: fadeIn 0.5s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

h2 {
    margin-bottom: 10px;
    font-size: 1.5rem;
}

.desc {
    color: var(--text-secondary);
    margin-bottom: 20px;
    font-size: 0.95rem;
}

/* Forms & Inputs */
.input-group {
    width: 100%;
    margin-bottom: 20px;
}

textarea, input[type="text"], select {
    width: 100%;
    padding: 15px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.3s ease;
    resize: vertical;
}

textarea:focus, input[type="text"]:focus, select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.search-filters {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
}

.filter-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.filter-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.search-bar {
    display: flex;
    gap: 10px;
}

/* Buttons */
.primary-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.primary-btn:active {
    transform: translateY(0);
}

.search-bar .primary-btn {
    width: auto;
    white-space: nowrap;
}

/* Loader */
.loader {
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-left-color: var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

#ai-loading, #normal-loading {
    text-align: center;
    color: var(--text-secondary);
    padding: 20px;
}

/* Results */
.result-box {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.result-box h3 {
    margin-bottom: 20px;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.keywords-box {
    background: var(--input-bg);
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 20px;
    border-left: 4px solid var(--primary-color);
}

.badge {
    background: var(--primary-color);
    color: white;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.9rem;
}

.law-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.law-list li {
    background: var(--input-bg);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease;
}

.law-list li:hover {
    transform: translateX(5px);
    border-color: var(--primary-color);
}

.law-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

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

.law-title a:hover {
    color: var(--primary-color);
}

.law-meta {
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

/* Markdown Styles */
.markdown-body h1, .markdown-body h2, .markdown-body h3 {
    margin-top: 24px;
    margin-bottom: 16px;
    font-weight: 600;
    line-height: 1.25;
}
.markdown-body p {
    margin-bottom: 16px;
    line-height: 1.6;
}
.markdown-body ul, .markdown-body ol {
    margin-bottom: 16px;
    padding-left: 2em;
}
.markdown-body li {
    margin-bottom: 8px;
    line-height: 1.6;
}
.markdown-body strong {
    font-weight: 600;
    color: var(--primary-color);
}

footer {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: auto;
    padding: 20px;
}

/* Responsive */
@media (max-width: 600px) {
    .search-filters {
        flex-direction: column;
    }
    .search-bar {
        flex-direction: column;
    }
    .search-bar .primary-btn {
        width: 100%;
    }
}

/* Category Tree Layout */
.search-layout {
    display: flex;
    gap: 20px;
    margin-top: 20px;
    align-items: flex-start;
}
.category-tree {
    flex: 0 0 200px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 15px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
}
.category-tree h3 {
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}
#tree-root {
    list-style: none;
    padding: 0;
}
#tree-root li {
    margin-bottom: 8px;
}
.tree-node {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.95rem;
    color: var(--text-primary);
}
.tree-node:hover {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary-color);
}
.tree-node.active {
    background: var(--primary-color);
    color: #fff;
    font-weight: 600;
}
.tree-node i {
    font-size: 1rem;
}
.search-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Law Group Cards */
.law-list-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.law-group-card {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 15px 20px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.law-group-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.08);
}
.law-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 10px;
}
.base-law-title {
    font-size: 1.2rem;
    color: var(--primary-color);
    font-weight: 700;
}
.law-group-body {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.law-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    color: #fff;
    transition: filter 0.2s ease;
}
.law-pill:hover {
    filter: brightness(1.1);
}
.pill-law { background: #3b82f6; }
.pill-decree { background: #10b981; }
.pill-rule { background: #f59e0b; }
.pill-default { background: #64748b; }

@media (max-width: 768px) {
    .search-layout {
        flex-direction: column;
    }
    .category-tree {
        flex: none;
        width: 100%;
    }
}
