:root {
    --bg-flat: #f8fafc; /* Premium smooth backdrop */
    --card-surface: #ffffff;
    --text-dark: #0f172a;
    --text-muted: #64748b;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --border-color: #e2e8f0;
    --radius-smooth: 8px;
    --font-system: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Base Configuration */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100vh;
    background-color: var(--bg-flat);
    color: var(--text-dark);
    font-family: var(--font-system);
    box-sizing: border-box;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    width: 100%;
    max-width: 1100px; /* Enhanced width for desktop beauty */
    margin: 0 auto;
    padding: 2rem 1rem; /* Balanced padding since header is removed */
    box-sizing: border-box;
}

/* Unified Dashboard Card Layout */
.dashboard-card {
    background: var(--card-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-smooth);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    padding: 0;
    width: 100%;
    box-sizing: border-box;
}

.dashboard-section {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.row-divider {
    border-top: 1px solid #f1f5f9;
}

/* Compact File Upload Bar */
.compact-dropzone {
    border: 1px dashed #cbd5e1;
    background-color: #f8fafc;
    border-radius: var(--radius-smooth);
    padding: 0.65rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.compact-dropzone:hover {
    border-color: var(--primary);
    background-color: #eff6ff;
}

.icon-upload {
    width: 1.1rem;
    height: 1.1rem;
    color: var(--text-muted);
}

.dropzone-text {
    font-size: 0.85rem;
    font-weight: 500;
    color: #475569;
}

.link-text {
    color: var(--primary);
    text-decoration: underline;
    font-weight: 600;
}

/* Workspace Layout */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.input-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

label {
    font-weight: 700;
    font-size: 0.8rem;
    color: #334155;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.badge-status {
    font-size: 0.65rem;
    font-weight: 600;
    background-color: #f0fdf4;
    color: #166534;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    text-transform: none;
    letter-spacing: normal;
    border: 1px solid #bbf7d0;
}

.label-opt {
    text-transform: none;
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.75rem;
    letter-spacing: normal;
}

.meta-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    background: #f1f5f9;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
}

textarea {
    width: 100%;
    min-height: 220px;
    padding: 1rem;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-smooth);
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 0.9rem;
    line-height: 1.55;
    resize: vertical;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: #ffffff;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.08);
}

/* Custom Tags Area */
.compact-tags-wrapper {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-smooth);
    padding: 0.4rem 0.6rem;
    background: #ffffff;
    min-height: 38px;
    box-sizing: border-box;
}

.tags-holder {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background-color: #f0fdf4;
    color: #166534;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    border: 1px solid #bbf7d0;
}

.tag button {
    background: none;
    border: none;
    color: #86efac;
    cursor: pointer;
    padding: 0;
    font-size: 0.8rem;
}

#custom-filter-input {
    border: none;
    outline: none;
    font-size: 0.85rem;
    flex-grow: 1;
    min-width: 60px;
    padding: 0.1rem 0;
}

/* ACTION DECK: Sleek Row Layout with Flexible Primaries */
.action-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    width: 100%;
}

.btn {
    font-weight: 700;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-smooth);
    cursor: pointer;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: 1px solid transparent;
    box-sizing: border-box;
    min-height: 40px;
    transition: all 0.15s ease;
}

.btn-icon {
    width: 1.1rem;
    height: 1.1rem;
}

/* Secondary Buttons (Download, Copy All) */
.btn-secondary {
    background-color: #ffffff;
    border-color: #cbd5e1;
    color: #334155;
    flex: 0 1 auto;
    min-width: 130px;
}

.btn-secondary:hover {
    background-color: #f8fafc;
    border-color: #94a3b8;
}

/* Danger Button (Reset) */
.btn-danger {
    background-color: #ffffff;
    border-color: #fecdd3;
    color: #be123c;
    flex: 0 1 auto;
    min-width: 110px;
}

.btn-danger:hover {
    background-color: #fff1f2;
    border-color: #fda4af;
}

/* Main Action Button (Filter PII - Fills Desktop Row) */
.btn-primary {
    background-color: var(--primary);
    color: white;
    flex: 1 1 auto; /* Dynamically expands to fill remaining space */
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 1px 3px rgba(79, 70, 229, 0.2);
}

/* DETECTED SECTION: Space-Efficient Multi-Column Grid */
.detected-panel h3 {
    margin: 0 0 0.75rem 0;
    font-size: 0.85rem;
    font-weight: 750;
    color: #475569;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    letter-spacing: 0.02em;
}

.mini-count-badge {
    background-color: #e2e8f0;
    color: #1e293b;
    font-size: 0.7rem;
    padding: 0.05rem 0.45rem;
    border-radius: 9999px;
    font-weight: 700;
}

/* Desktop Fix: Multiple items sit comfortably side-by-side using grid auto-fill */
.pill-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); /* Multi-column array */
    gap: 0.5rem;
    width: 100%;
}

.empty-state {
    grid-column: 1 / -1; /* Spans full grid width when empty */
    padding: 1.25rem;
    color: #94a3b8;
    border: 1px dashed #e2e8f0;
    border-radius: var(--radius-smooth);
    font-size: 0.8rem;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    background: #fafafa;
}

.empty-icon {
    width: 1.1rem;
    height: 1.1rem;
}

/* PII List Pill Elements */
.pii-pill {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 0.45rem 0.65rem;
    gap: 0.4rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
    min-width: 0; /* Webkit text-overflow fix */
}

.pill-info {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    overflow: hidden;
    width: 100%;
}

.type-tag {
    font-size: 0.55rem;
    font-weight: 850;
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

.type-email { background: #dbeafe; color: #1e40af; }
.type-phone { background: #d1fae5; color: #065f46; }
.type-ip { background: #f3e8ff; color: #6b21a8; }
.type-card { background: #fef3c7; color: #92400e; }
.type-custom { background: #e0e7ff; color: #3730a3; }

.pill-value {
    font-family: ui-monospace, SFMono-Regular, monospace;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #475569;
}

.pill-close {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 0.1rem;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    border-radius: 3px;
}

.pill-close:hover {
    color: #ef4444;
    background: #fff1f2;
}

/* --- RESPONSIVE MOBILE OPTIMIZATION --- */

@media (max-width: 600px) {
    .app-container {
        padding: 0.75rem 0.5rem;
    }

    .dashboard-section {
        padding: 1.1rem;
    }

    textarea {
        min-height: 160px;
    }

    /* 2x2 Clean Grid Matrix for Mobile Devices */
    .action-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr); /* 2 balanced columns */
        gap: 0.5rem;
    }

    .btn, .btn-secondary, .btn-danger, .btn-primary {
        width: 100%; 
        min-width: 0; /* Reset desktop flex-basis defaults */
        flex: none;
        min-height: 42px;
        padding: 0.5rem;
        font-size: 0.8rem;
    }

    /* Detected items drop nicely to a unified column matrix on small viewports */
    .pill-grid {
        grid-template-columns: 1fr;
    }
}
