/* ============================================
   WindS-Sinanju Pro — PWA Design System
   Premium dark theme optimized for iPad
   ============================================ */

/* ---- CSS Custom Properties ---- */
:root {
    /* Light Mode - Base colors */
    --bg-primary: #F8FAFC;
    --bg-secondary: #F1F5F9;
    --bg-card: #FFFFFF;
    --bg-card-hover: #F8FAFC;
    --bg-input: #FFFFFF;
    --bg-surface: #F1F5F9;

    /* Accent Colors (Scientific Blue) */
    --accent-blue: #2563EB;
    --accent-cyan: #0EA5E9;
    --accent-green: #16A34A;
    --accent-red: #DC2626;
    --accent-orange: #EA580C;
    --accent-yellow: #CA8A04;
    --accent-purple: #9333EA;

    /* Text Colors */
    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;
    --text-accent: var(--accent-blue);

    /* Borders */
    --border-color: #E2E8F0;
    --border-focus: var(--accent-blue);

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-card: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-glow: 0 0 0 3px rgba(37, 99, 235, 0.2);

    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-xs: 11px;
    --font-sm: 13px;
    --font-md: 15px;
    --font-lg: 18px;
    --font-xl: 22px;

    /* Layout */
    --header-height: 60px;
    --tab-bar-height: 64px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #0f1923;
        --bg-secondary: #162230;
        --bg-card: #1a2d3d;
        --bg-card-hover: #213a4d;
        --bg-input: #0d1520;
        --bg-surface: #1e3347;

        --accent-cyan: #00d4ff;
        --accent-blue: #3b82f6;
        --accent-green: #22c55e;
        --accent-red: #ef4444;
        --accent-orange: #f97316;
        --accent-yellow: #eab308;
        --accent-purple: #a855f7;

        --text-primary: #e8edf3;
        --text-secondary: #8899aa;
        --text-muted: #5a6a7a;
        --text-accent: var(--accent-cyan);

        --border-color: #2a3f52;
        --border-focus: var(--accent-cyan);

        --shadow-card: 0 4px 20px rgba(0, 0, 0, 0.3);
        --shadow-glow: 0 0 20px rgba(0, 212, 255, 0.15);
    }
}

/* Focus Accessibility */
*:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

/* ---- Reset & Base ---- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ---- Header ---- */
.app-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    margin: var(--space-md) var(--space-md) 0 var(--space-md);
    flex-shrink: 0;
    padding: 0 var(--space-lg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: var(--shadow-card);
    z-index: 50;
}

.app-title {
    font-size: var(--font-lg);
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.title-accent {
    color: var(--accent-blue);
    font-weight: 600;
}

/* ---- Tab Bar (Bottom) ---- */
.tab-bar {
    height: calc(var(--tab-bar-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    display: flex;
    align-items: center;
    background: linear-gradient(180deg, var(--bg-card), var(--bg-secondary));
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: var(--font-family);
    font-size: var(--font-xs);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.tab-btn.active {
    color: var(--accent-cyan);
}

.tab-btn.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: 3px;
    background: var(--accent-cyan);
    border-radius: 0 0 4px 4px;
}

.tab-icon {
    font-size: 22px;
    line-height: 1;
}

.tab-label {
    font-size: var(--font-xs);
    font-weight: 600;
}

/* ---- Main Content Area ---- */
.app-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.tab-panel {
    display: none;
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: var(--space-md);
}

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

/* ---- Cards ---- */
.panel,
.conversion-card,
.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
}

.panel-header,
.card-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.panel-header h3 {
    font-size: var(--font-md);
    font-weight: 600;
    color: var(--text-primary);
}

.card-title {
    font-size: var(--font-md);
    font-weight: 700;
    color: var(--accent-cyan);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: var(--space-md);
}

/* ---- Textarea ---- */
.data-textarea {
    width: 100%;
    min-height: 120px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--font-base);
    line-height: 1.5;
    resize: none;
    /* Let flex handle resizing */
    transition: var(--transition-base);
    white-space: pre-wrap;
    word-break: break-all;
    flex: 1;
    /* Stretch to fill remaining panel space */
}

/* For standalone textareas like output */
.panel>.data-textarea {
    flex: 1;
}

.data-textarea:focus {
    outline: none;
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.2);
}

/* ==========================================================================
   TEXTAREA HIGHLIGHT OVERLAY (FOR INVALID / DUPLICATE MARKERS)
   ========================================================================== */
.textarea-highlight-container {
    display: grid;
    width: 100%;
    border-radius: var(--radius-md);
    flex: 1;
    /* Stretch container in the flex panel */
}

.highlight-backdrop,
.textarea-highlight-container .data-textarea {
    grid-area: 1 / 1;
    width: 100%;
    height: 100%;
    /* Must explicitly fill the grid cell */
    margin: 0;
    box-sizing: border-box;
}

.highlight-backdrop {
    pointer-events: none;
    z-index: 1;
    overflow: hidden;
    background-color: var(--bg-primary);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
}

.highlight-content {
    width: 100%;
    height: auto;
    min-height: 100%;
    padding: var(--space-md);
    font-family: inherit;
    font-size: var(--font-base);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    color: transparent;
    /* hide real text, show marks */
    box-sizing: border-box;
}

.textarea-highlight-container .data-textarea {
    z-index: 2;
    background-color: transparent !important;
    color: var(--text-primary);
    caret-color: var(--text-primary);
    resize: vertical;
}

/* Highlighting styles */
mark.hl-duplicate {
    background-color: rgba(253, 126, 20, 0.35);
    /* Orange hint */
    border-radius: 2px;
    color: transparent;
}

mark.hl-invalid {
    background-color: rgba(220, 53, 69, 0.35);
    /* Red hint */
    border-radius: 2px;
    color: transparent;
}

.light-mode mark.hl-duplicate {
    background-color: rgba(253, 126, 20, 0.45);
}

.light-mode mark.hl-invalid {
    background-color: rgba(220, 53, 69, 0.45);
}

.data-textarea::placeholder {
    color: var(--text-muted);
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: var(--font-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
}

.btn:active {
    transform: scale(0.95);
}

.btn-primary {
    background: var(--accent-blue);
    color: white;
}

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

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

.btn-accent {
    background: var(--accent-cyan);
    color: var(--bg-primary);
}

.btn-sm {
    padding: 6px 12px;
    font-size: var(--font-xs);
}

.btn-group {
    display: flex;
    gap: var(--space-sm);
}

/* ---- Chips / Chip Buttons ---- */
.btn-chip {
    padding: 8px 18px;
    border-radius: var(--radius-full);
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    font-size: var(--font-sm);
    font-weight: 600;
}

.btn-chip.active {
    background: var(--accent-cyan);
    color: var(--bg-primary);
    border-color: var(--accent-cyan);
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.3);
}

/* ---- Select / Dropdown ---- */
select {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    font-family: var(--font-family);
    font-size: var(--font-xs);
    outline: none;
    cursor: pointer;
}

select:focus {
    border-color: var(--accent-cyan);
}

/* ---- Inputs ---- */
.conv-input {
    width: 100%;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-family: var(--font-family);
    font-size: var(--font-md);
    font-weight: 500;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.conv-input:focus {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

.conv-input::placeholder {
    color: var(--text-muted);
}

/* Remove number input spinners on iOS */
.conv-input::-webkit-inner-spin-button,
.conv-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.conv-input[type=number] {
    -moz-appearance: textfield;
}

/* ---- Panel Footer (Stats / Buttons) ---- */
.panel-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: var(--space-md);
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.stats-row {
    display: flex;
    gap: var(--space-sm);
}

.stat-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: var(--font-xs);
    font-weight: 600;
    background: var(--bg-surface);
    color: var(--text-secondary);
}

.stat-keep {
    color: var(--accent-cyan);
}

.stat-unique {
    color: var(--accent-purple);
}

/* ---- Digit Stats ---- */
.digit-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

.digit-stat {
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    padding: var(--space-sm) var(--space-md);
    text-align: center;
}

.digit-label {
    display: block;
    font-size: var(--font-xs);
    color: var(--text-muted);
    margin-bottom: 2px;
}

.digit-value {
    display: block;
    font-size: var(--font-lg);
    font-weight: 700;
    color: var(--accent-cyan);
}

/* ---- Duplicates ---- */
.duplicates-section {
    margin-top: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
}

.duplicates-section h4 {
    font-size: var(--font-sm);
    color: var(--accent-orange);
    margin-bottom: var(--space-sm);
}

.duplicates-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.duplicate-group {
    background: var(--bg-primary);
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent-orange);
    font-size: var(--font-sm);
    line-height: 1.5;
}

.dup-label {
    font-weight: 600;
    color: var(--accent-orange);
    margin-right: 6px;
}

.dup-vals {
    color: var(--text-primary);
}

/* ============================================
   TAB 1: THỐNG KÊ — Split View
   ============================================ */
.split-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
    height: 100%;
}

@media (max-width: 768px) {
    .split-view {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   TAB 2: DÀN-BỘ
   ============================================ */
.category-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: var(--space-md);
}

.category-chip {
    padding: 8px 16px;
    border-radius: var(--radius-full);
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    font-size: var(--font-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    -webkit-user-select: none;
    user-select: none;
}

.category-chip:active {
    transform: scale(0.95);
}

.category-chip.active {
    background: var(--accent-cyan);
    color: var(--bg-primary);
    border-color: var(--accent-cyan);
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.2);
}

/* Category-specific colors */
.category-chip[data-cat="Kép"] {
    --chip-color: var(--accent-purple);
}

.category-chip[data-cat="Tổng"] {
    --chip-color: var(--accent-blue);
}

.category-chip[data-cat="Chạm (19 số)"] {
    --chip-color: var(--accent-orange);
}

.category-chip[data-cat="Đặc biệt"] {
    --chip-color: var(--accent-red);
}

.category-chip[data-cat="Kết hợp"] {
    --chip-color: var(--accent-yellow);
}

.category-chip[data-cat="Bộ"] {
    --chip-color: var(--accent-green);
}

.category-chip[data-cat="Sát"] {
    --chip-color: #e879f9;
}

.category-chip[data-cat="Đầu - Đuôi"] {
    --chip-color: var(--accent-green);
}

.category-chip.active[data-cat] {
    background: var(--chip-color, var(--accent-cyan));
    border-color: var(--chip-color, var(--accent-cyan));
}

.dan-bo-content {
    flex: 1;
}

.buttons-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.num-btn {
    min-width: 80px;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    font-family: var(--font-family);
    font-size: var(--font-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}

.num-btn:active {
    transform: scale(0.95);
}

.num-btn.selected {
    background: var(--accent-cyan);
    color: var(--bg-primary);
    border-color: var(--accent-cyan);
    box-shadow: 0 0 10px rgba(0, 212, 255, 0.25);
}

.result-card {
    margin-top: var(--space-md);
}

.result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.result-header h3 {
    font-size: var(--font-md);
    color: var(--accent-cyan);
}

.result-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.result-numbers {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.result-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    height: 36px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    color: var(--accent-cyan);
    font-size: var(--font-sm);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ============================================
   TAB 3: QUY ĐỔI
   ============================================ */
.quick-jump-bar {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: var(--space-sm);
    padding-top: var(--space-sm);
    /* -- STICKY CONFIG -- */
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-primary);
}

.quick-jump-label {
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.conversion-panels {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding-bottom: var(--space-xl);
}

.conversion-card {
    transition: box-shadow 0.2s;
}

.conversion-card:focus-within {
    box-shadow: var(--shadow-glow);
    border-color: var(--accent-cyan);
}

.sub-tabs {
    display: flex;
    gap: var(--space-xs);
    margin-bottom: var(--space-md);
}

.sub-tab {
    padding: 6px 16px;
    border-radius: var(--radius-full);
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    font-family: var(--font-family);
    font-size: var(--font-xs);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.sub-tab.active {
    background: var(--accent-blue);
    color: white;
    border-color: var(--accent-blue);
}

.sub-panel {
    display: none;
}

.sub-panel.active {
    display: block;
}

.multiplier-info {
    background: var(--bg-surface);
    color: var(--text-secondary);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: var(--font-xs);
    font-weight: 500;
    margin-bottom: var(--space-md);
    border-left: 3px solid var(--accent-blue);
}

.input-row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-sm);
}

.input-row label {
    min-width: 160px;
    font-size: var(--font-sm);
    font-weight: 500;
    color: var(--text-secondary);
    flex-shrink: 0;
}

@media (max-width: 500px) {
    .input-row {
        flex-direction: column;
        align-items: stretch;
    }

    .input-row label {
        min-width: auto;
        margin-bottom: 4px;
    }
}

.conversion-result {
    margin-top: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent-cyan);
}

.result-label {
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--accent-cyan);
}

.result-value {
    font-size: var(--font-xl);
    font-weight: 700;
    color: var(--accent-cyan);
    font-variant-numeric: tabular-nums;
    margin-left: var(--space-sm);
}

.result-extra {
    margin-top: var(--space-xs);
    font-size: var(--font-xs);
}

.result-bu {
    color: var(--accent-red);
    font-weight: 600;
}

.result-lo1k {
    color: var(--accent-green);
    font-weight: 600;
}

.result-lot {
    color: var(--accent-green);
    font-size: var(--font-sm);
    font-weight: 600;
}

/* ============================================
   Toast Notification
   ============================================ */
.toast {
    position: fixed;
    bottom: calc(var(--tab-bar-height) + var(--safe-bottom) + 16px);
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 10px 24px;
    border-radius: var(--radius-full);
    font-size: var(--font-sm);
    font-weight: 600;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    border-color: var(--accent-green);
    color: var(--accent-green);
}

.toast.error {
    border-color: var(--accent-red);
    color: var(--accent-red);
}

/* ============================================
   Scrollbar styling
   ============================================ */
.tab-panel::-webkit-scrollbar {
    width: 6px;
}

.tab-panel::-webkit-scrollbar-track {
    background: transparent;
}

.tab-panel::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* ============================================
   Responsive iPad landscape
   ============================================ */
@media (min-width: 1024px) {
    .split-view {
        grid-template-columns: 1fr 1fr;
    }

    .input-row label {
        min-width: 180px;
    }

    .digit-stats {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* iPad portrait */
@media (min-width: 768px) and (max-width: 1023px) {
    .split-view {
        grid-template-columns: 1fr 1fr;
    }
}

/* iPhone */
@media (max-width: 767px) {
    .split-view {
        grid-template-columns: 1fr;
    }

    .digit-stats {
        grid-template-columns: repeat(2, 1fr);
    }

    .num-btn {
        min-width: 65px;
        padding: 8px 12px;
    }
}

/* =========================================================================
   7. TAB TẠO DÀN STYLES
   ========================================================================= */

.tao-dan-layout .input-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.setup-group {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 16px;
    border-radius: var(--radius-md);
    margin-bottom: 12px;
}

.td-row {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    gap: 12px;
}

.td-row:last-child {
    margin-bottom: 0;
}

.td-col.type {
    width: 100px;
    flex-shrink: 0;
}

.td-col.value {
    flex-grow: 1;
}

.td-col select,
.td-col input[type="text"] {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-family: var(--font-family);
    font-size: var(--font-sm);
    outline: none;
    transition: border-color var(--transition-fast);
}

.td-col select:focus,
.td-col input[type="text"]:focus {
    border-color: var(--accent-cyan);
}

.td-col label {
    display: block;
    font-size: var(--font-xs);
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-weight: 500;
}

.td-col.label .wide-label {
    display: inline-block;
    width: 100px;
}

.td-divider {
    border: 0;
    height: 1px;
    background: var(--border-color);
    margin: 16px 0;
}

/* Các nút Tạo dàn */
.tao-dan-actions {
    display: flex;
    gap: var(--space-sm);
    margin-top: 16px;
    flex-wrap: wrap;
}

.tao-dan-actions .btn {
    flex: 1;
    justify-content: center;
}

/* Advanced Filter */
.advanced-filter {
    margin-top: var(--space-sm);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
}

.advanced-filter h4 {
    font-size: var(--font-sm);
    margin: 0 0 16px 0;
    color: var(--accent-cyan);
}

.filter-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
}

.filter-label {
    display: block;
    font-size: var(--font-xs);
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.radio-group,
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: var(--font-sm);
}

.radio-group label,
.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
}

.mt-2 {
    margin-top: 16px;
}

.limit-group {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: var(--font-sm);
    color: var(--text-primary);
}

.limit-group input {
    width: 80px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-family: inherit;
}

.taodan-output {
    font-size: var(--font-lg);
    line-height: 1.6;
    letter-spacing: 1px;
}

/* -- SUB TAB TẠO DÀN -- */
.tao-dan-layout .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sub-tabs {
    display: flex;
    gap: 8px;
    background: var(--bg-surface);
    padding: 4px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.sub-tab {
    background: transparent;
    border: none;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: var(--font-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sub-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.sub-tab.active {
    background: var(--accent-blue);
    color: white;
}

.sub-panel {
    display: none;
    animation: fadeIn 0.15s ease-out;
}

.sub-panel.active {
    display: block;
}

/* -- DÀN GHÉP GRID -- */
.dg-panel h4 {
    font-size: var(--font-sm);
    color: var(--accent-blue);
    margin: 0 0 10px 0;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 5px;
}

.dg-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 15px;
}

.dg-num {
    min-width: unset;
    padding: 8px 0;
    border-radius: var(--radius-sm);
    font-size: var(--font-md);
    font-weight: bold;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.dg-num:hover {
    border-color: var(--accent-blue);
    background: rgba(47, 128, 237, 0.1);
}

.dg-num.active {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
    color: white;
    box-shadow: 0 2px 8px rgba(47, 128, 237, 0.4);
}

.dg-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
}

.btn-chip {
    flex: 1;
    padding: 5px 0;
    font-size: var(--font-xs);
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-chip:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

@media (max-width: 500px) {
    .tao-dan-actions {
        flex-direction: column;
    }

    .filter-grid {
        grid-template-columns: 1fr;
    }
}