@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --bg-base: #000000;
    --bg-card: #0a0a0a;
    --bg-input: #111111;
    --border-soft: #222222;
    --border-hover: #333333;
    --text-main: #ededed;
    --text-muted: #888888;
    --primary: #ffffff;
    --primary-text: #000000;
    --accent: #3291ff;
    --radius: 8px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-base);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.background-blobs {
    display: none; /* Removed for minimalistic look */
}

.container {
    width: 100%;
    max-width: 1200px;
    padding: 3rem 2rem;
    z-index: 1;
    transition: max-width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.container.full-width {
    max-width: 96vw;
}

header {
    margin-bottom: 3.5rem;
    text-align: left;
    animation: fadeIn 0.8s ease-out;
}

.mapping-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.icon {
    font-size: 1.8rem;
    filter: brightness(1.2);
    text-shadow: 0 0 15px rgba(255, 255, 255, 0.1);
}

h1 {
    font-family: 'Outfit', var(--font-sans);
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: -0.04em;
    color: var(--text-main);
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 400;
    letter-spacing: -0.01em;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 2.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.6s ease-out;
}

.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-soft);
    padding-bottom: 0px;
}

.tab-btn {
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
    margin-bottom: -1px;
}

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

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

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

.input-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.6rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-main);
}

input[type="text"], input[type="url"], input[type="number"], select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    appearance: none;
}

select {
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23888888%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem top 50%;
    background-size: 0.65rem auto;
    padding-right: 2.5rem;
}

input[type="text"]:focus, input[type="url"]:focus, input[type="number"]:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.input-with-action {
    display: flex;
    gap: 0.5rem;
}

.input-with-action input {
    flex: 1;
}

.btn-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-input);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    color: var(--text-main);
    font-size: 1.2rem;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.btn-icon:hover {
    border-color: var(--border-hover);
}

.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.btn-primary {
    width: 100%;
    padding: 0.875rem;
    background: var(--primary);
    color: var(--primary-text);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

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

.btn-primary:active {
    transform: scale(0.98);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Robust Mapping Results Layout */
#mapping-results-container {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-soft);
}

.resource-list {
    display: block !important;
    max-height: 500px;
    overflow-y: auto;
    margin-top: 1.5rem;
}

.resource-group {
    background: #0d0d0d;
    border: 1px solid #222;
    border-radius: 8px;
    margin-bottom: 1rem;
    overflow: hidden;
    display: block !important;
}

.group-header {
    background: #1a1a1a;
    padding: 10px 15px;
    border-bottom: 1px solid #222;
    display: flex;
    align-items: center;
    gap: 12px;
}

.group-title {
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    flex: 1;
}

.resource-item {
    padding: 12px 15px;
    border-bottom: 1px solid #1a1a1a;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
}

.resource-item:last-child {
    border-bottom: none;
}

.resource-link {
    color: #ffffff !important;
    font-size: 13px;
    text-decoration: none;
    word-break: break-all;
    flex: 1;
    display: block;
    line-height: 1.5;
}

/* Custom Checkbox */
.custom-checkbox {
    width: 20px;
    height: 20px;
    min-width: 20px;
    border-radius: 4px;
    border: 1px solid var(--border-soft);
    background: var(--bg-base);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.custom-checkbox.checked {
    background: var(--primary);
    border-color: var(--primary);
}

.custom-checkbox svg {
    width: 12px;
    height: 12px;
    color: var(--primary-text);
    display: none;
}

.custom-checkbox.checked svg {
    display: block;
}


/* Status UI */
#status-container {
    margin-top: 2rem;
}

.status-card {
    background: transparent;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.status-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

#status-message {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.progress-bar {
    height: 4px;
    background: var(--border-soft);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    width: 0%;
    transition: width 0.4s ease;
}

footer {
    margin-top: 4rem;
    text-align: left;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border-soft);
    padding-top: 2rem;
}

.hidden {
    display: none !important;
}

/* Custom Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--border-soft);
    transition: .3s;
    border-radius: 20px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: var(--text-muted);
    transition: .3s;
    border-radius: 50%;
}
input:checked + .slider {
    background-color: var(--primary);
}
input:checked + .slider:before {
    transform: translateX(16px);
    background-color: var(--primary-text);
}

/* Secondary Button */
.btn-secondary {
    padding: 0.5rem 1rem;
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-secondary:hover {
    background: var(--border-soft);
    border-color: var(--text-muted);
}

/* Table Enhancements */
tbody tr:hover {
    background: rgba(255, 255, 255, 0.02) !important;
}

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

.loader {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-top: 3px solid currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
    flex-shrink: 0; /* Prevents shrinking */
}

/* Ensure white track on dark buttons */
.btn-primary[disabled] .loader,
.crawl-btn[disabled] .loader {
    border-color: rgba(255, 255, 255, 0.2);
    border-top-color: currentColor;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Groups Dashboard */
.groups-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}

.group-card {
    background: #0f172a;
    border: 1px solid #1e293b;
    border-radius: 12px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.group-card:hover {
    transform: translateY(-5px);
    border-color: #3b82f6;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
}

.group-card h4 {
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
    color: #fff;
}

.group-progress {
    font-size: 0.875rem;
    color: #94a3b8;
    margin-bottom: 1.5rem;
}

.group-card .btn-primary {
    background: #3b82f6;
    border-color: #3b82f6;
    color: white;
    margin-top: 1rem;
    font-size: 0.875rem;
    padding: 0.625rem;
}

.group-card .btn-primary:hover {
    background: #2563eb;
}

.group-card .btn-primary:disabled {
    background: #1e293b;
    border-color: #1e293b;
    cursor: wait;
}

.group-items {
    max-height: 250px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-soft) transparent;
}

.group-items::-webkit-scrollbar {
    width: 6px;
}

.group-items::-webkit-scrollbar-thumb {
    background-color: var(--border-soft);
    border-radius: 10px;
}

/* ═══ Group Crawl Modal ═══ */
.gcm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(6px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: fadeIn 0.2s ease;
}

.gcm-overlay.hidden {
    display: none;
}

.gcm-box {
    background: #0d0d0d;
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    width: 100%;
    max-width: 680px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 25px 60px rgba(0,0,0,0.6);
    position: relative;
    min-height: 200px; /* Ensure a minimum size */
}

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

.gcm-header span {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

.gcm-close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 0 0.25rem;
    transition: color 0.2s;
}
.gcm-close-btn:hover { color: var(--text-main); }

#gcm-picker, #gcm-progress-container {
    display: flex;
    flex-direction: column;
    min-height: 0; /* Crucial for flex scrolling */
}

#gcm-progress-container {
    flex: 1;
    overflow: hidden; /* Contains the scrollable list */
}

.gcm-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 0.75rem 1.5rem 0.5rem;
    flex-shrink: 0;
}

.gcm-overall-bar {
    margin: 0 1.5rem 0;
    height: 4px;
    background: var(--border-soft);
    border-radius: 4px;
    overflow: hidden;
    flex-shrink: 0;
}

.gcm-overall-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.4s ease;
}

.gcm-overall-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0.4rem 1.5rem 0.75rem;
    flex-shrink: 0;
}

.gcm-url-list {
    overflow-y: auto;
    flex: 1;
    padding: 0.5rem 1.5rem;
    min-height: 0; /* Ensures it can shrink and scroll */
    scrollbar-width: thin;
    scrollbar-color: var(--border-hover) transparent;
}

.gcm-url-list::-webkit-scrollbar { width: 6px; }
.gcm-url-list::-webkit-scrollbar-track { background: transparent; }
.gcm-url-list::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 10px; }
.gcm-url-list::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.gcm-url-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0;
    border-bottom: 1px solid #111;
    font-size: 0.78rem;
}

.gcm-url-row:last-child { border-bottom: none; }

.gcm-url-text {
    flex: 1;
    color: var(--text-muted);
    word-break: break-all;
    line-height: 1.4;
}

.gcm-status-dot {
    width: 10px;
    height: 10px;
    min-width: 10px;
    border-radius: 50%;
    background: var(--border-soft);
    transition: background 0.3s;
}

.gcm-status-dot.pending  { background: #333; }
.gcm-status-dot.crawling { background: var(--accent); animation: pulse-dot 1s ease-in-out infinite; }
.gcm-status-dot.done     { background: #22c55e; }
.gcm-status-dot.failed   { background: #ef4444; }

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.5; transform: scale(0.8); }
}

.gcm-status-label {
    font-size: 0.7rem;
    min-width: 56px;
    text-align: right;
    color: var(--text-muted);
}
.gcm-status-label.crawling { color: var(--accent); }
.gcm-status-label.done     { color: #22c55e; }
.gcm-status-label.failed   { color: #ef4444; }

.gcm-actions {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-soft);
    flex-shrink: 0;
}

/* Pagination Controls */
.pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    padding: 1.5rem;
    border-top: 1px solid var(--border-soft);
    margin-top: 1rem;
}

.pagination-btn {
    padding: 0.5rem 0.875rem;
    background: var(--bg-input);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    color: var(--text-main);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pagination-btn:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

.pagination-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination-info {
    font-size: 0.875rem;
    color: var(--text-muted);
}
