:root {
    /* GitHub Dark High Contrast Palette */
    --bg-app: #0A0C10;
    --bg-panel: #0D1117;
    --bg-sidebar: #010409;
    --bg-hover: #161B22;
    --bg-input: #010409;
    
    --border-subtle: #30363D;
    --border-active: #8B949E;
    
    --text-main: #FFFFFF;
    --text-muted: #8B949E;
    
    --accent-blue: #58A6FF;
    --accent-green: #238636;
    --accent-green-hover: #2EA043;
    --accent-red: #DA3633;
    --accent-yellow: #D29922;
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
    
    --radius: 6px;
    --transition: all 0.2s ease;
}

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

body {
    background-color: var(--bg-app);
    color: var(--text-main);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
}

/* Utilities */
.hidden { display: none !important; }
.flex-col { display: flex; flex-direction: column; }
.h-full { height: 100%; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-auto { margin-top: auto; }
.mt-lg { margin-top: 24px; }
.text-danger { color: var(--accent-red); }
.text-success { color: var(--accent-green); }
.text-warning { color: var(--accent-yellow); }
.text-muted { color: var(--text-muted); }

/* Layout */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.brand {
    padding: 20px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border-subtle);
}

.brand-icon {
    width: 24px;
    height: 24px;
    color: var(--text-main);
}

.brand h1 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.nav-section {
    padding: 16px 8px;
}

.nav-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0 8px 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.nav-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 8px;
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    transition: var(--transition);
    text-align: left;
}

.nav-item:hover {
    background-color: var(--bg-hover);
    color: var(--text-main);
}

.nav-item.active {
    background-color: rgba(88, 166, 255, 0.1);
    color: var(--accent-blue);
    font-weight: 500;
}

.stats-box {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 16px;
}
.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-value { font-size: 24px; font-family: var(--font-mono); font-weight: 600; line-height: 1; margin-top: 4px; }

/* Main Content */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* fixes flex child overflow */
}

.toolbar {
    height: 65px;
    padding: 0 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-subtle);
    background-color: var(--bg-panel);
}

.toolbar-title {
    font-size: 16px;
    font-weight: 600;
}

.toolbar-actions {
    display: flex;
    gap: 12px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 16px;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    white-space: nowrap;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
    border: 1px solid;
    border-radius: var(--radius);
    transition: var(--transition);
    font-family: inherit;
    height: 32px;
}

.btn-primary {
    color: #ffffff;
    background-color: var(--accent-green);
    border-color: rgba(240, 246, 252, 0.1);
}
.btn-primary:hover { background-color: var(--accent-green-hover); }

.btn-secondary {
    color: #c9d1d9;
    background-color: #21262d;
    border-color: rgba(240, 246, 252, 0.1);
}
.btn-secondary:hover { background-color: #30363d; border-color: #8b949e; }

.btn-danger {
    color: var(--accent-red);
    background-color: transparent;
    border-color: transparent;
}
.btn-danger:hover { background-color: rgba(218, 54, 51, 0.1); border-color: var(--accent-red); }

.btn-icon {
    padding: 4px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
    height: auto;
}
.btn-icon:hover { color: var(--text-main); background: var(--bg-hover); }

.btn-sm { height: 28px; padding: 3px 12px; font-size: 12px; }

/* Content Wrapper */
.content-wrapper {
    flex-grow: 1;
    padding: 24px;
    overflow-y: auto;
    position: relative;
}

.tab-pane {
    height: 100%;
}

/* Visual Builder Grid */
.builder-grid {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 24px;
    height: 100%;
}

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.panel-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-sidebar);
}
.panel-header h3 { font-size: 14px; font-weight: 600; }

.badge {
    padding: 2px 8px;
    border-radius: 2em;
    font-size: 12px;
    font-weight: 500;
    line-height: normal;
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
}
.badge.valid { color: var(--accent-green); border-color: var(--accent-green); background: rgba(35, 134, 54, 0.1); }
.badge.invalid { color: var(--accent-red); border-color: var(--accent-red); background: rgba(218, 54, 51, 0.1); }

/* Rules List */
.rules-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rule-item {
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    border: 1px solid transparent;
    background: transparent;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.rule-item:hover { background: var(--bg-hover); }
.rule-item.active { background: var(--border-subtle); border-color: var(--border-active); }
.rule-item.invalid { border-left: 3px solid var(--accent-red); }

.rule-pattern { font-family: var(--font-mono); font-size: 13px; font-weight: 500; color: var(--text-main); word-break: break-all; }
.rule-owners { font-size: 12px; color: var(--accent-blue); display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }

/* Editor Form */
.rule-editor {
    flex-grow: 1;
    padding: 24px;
    overflow-y: auto;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
    padding: 20px;
}

.form-group { margin-bottom: 20px; }
.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 14px;
}

.input-with-icon {
    position: relative;
    display: flex;
    align-items: center;
}

input[type="text"] {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-subtle);
    color: var(--text-main);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 14px;
    font-family: var(--font-mono);
    outline: none;
    transition: var(--transition);
}
input[type="text"]:focus {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.3);
}

.input-with-icon input { padding-right: 30px; }
.help-icon {
    position: absolute;
    right: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: help;
    font-weight: bold;
}

.help-text {
    font-size: 12px;
    color: var(--text-muted);
}

.terminal-test {
    background: #000;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    padding: 12px;
    font-family: var(--font-mono);
}
.terminal-test input {
    background: transparent;
    border: none;
    padding: 0;
    color: var(--text-main);
    margin-bottom: 8px;
    width: 100%;
}
.terminal-test input:focus { box-shadow: none; border: none; }
.test-result {
    font-size: 12px;
    color: var(--text-muted);
    padding-top: 8px;
    border-top: 1px dashed var(--border-subtle);
}
.test-match { color: var(--accent-green); }
.test-nomatch { color: var(--text-muted); }

.form-actions {
    display: flex;
    justify-content: flex-end;
    padding-top: 20px;
    border-top: 1px solid var(--border-subtle);
}

/* Raw Editor */
.editor-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}
#raw-editor {
    flex-grow: 1;
    background: var(--bg-input);
    color: var(--text-main);
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.6;
    padding: 16px;
    border: none;
    resize: none;
    outline: none;
}
.validation-panel {
    border-top: 1px solid var(--border-subtle);
    background: rgba(218, 54, 51, 0.05);
    max-height: 150px;
    overflow-y: auto;
}
.validation-header {
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    color: var(--accent-red);
    border-bottom: 1px solid rgba(218, 54, 51, 0.2);
    background: rgba(218, 54, 51, 0.1);
}
#error-list {
    list-style: none;
    padding: 8px 16px;
}
#error-list li {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-main);
    margin-bottom: 4px;
    display: flex;
    gap: 8px;
}
.err-line { color: var(--text-muted); width: 30px; text-align: right; }

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 20px;
    background: var(--accent-green);
    color: white;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    z-index: 1000;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
}
.toast.show {
    opacity: 1;
    transform: translateY(0);
}
.toast-error { background: var(--accent-red); }

@media (max-width: 900px) {
    .builder-grid { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
}
@media (max-width: 600px) {
    .app-layout { flex-direction: column; }
    .sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--border-subtle); flex-direction: row; align-items: center; padding-right: 16px;}
    .nav-section { display: flex; align-items: center; padding: 0; margin-left: auto; gap: 8px;}
    .nav-title { display: none; }
    .nav-item { padding: 8px 12px; }
    .stats-box { display: none; }
    .toolbar-title { display: none; }
}
