:root {
    /* Dark Theme (Default) */
    --bg-body-gradient: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    --bg-header-gradient: linear-gradient(135deg, #0f3460 0%, #16213e 100%);
    --text-primary: #eee;
    --text-secondary: #aaa;
    --accent-primary: #00d4aa;
    --accent-primary-gradient: linear-gradient(135deg, #00d4aa 0%, #0f9b8e 100%);
    --card-bg: rgba(255, 255, 255, 0.05);
    --card-border: rgba(255, 255, 255, 0.1);
    --card-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --input-bg: rgba(255, 255, 255, 0.05);
    --input-border: rgba(255, 255, 255, 0.1);
    --input-text: #eee;
    --success-color: #4CAF50;
    --error-color: #f44336;
    --warning-color: #ff9800;
    --offline-color: #333;
}

[data-theme="light"] {
    --bg-body-gradient: #f0f2f5;
    --bg-header-gradient: #ffffff;
    --text-primary: #333;
    --text-secondary: #666;
    --accent-primary: #007bff;
    /* Blue */
    --accent-primary-gradient: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
    --card-bg: #ffffff;
    --card-border: rgba(0, 0, 0, 0.05);
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    --input-bg: #f8f9fa;
    --input-border: #ced4da;
    --input-text: #333;
    --success-color: #28a745;
    --error-color: #dc3545;
    --warning-color: #ffc107;
    --offline-color: #ccc;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-body-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 15px;
    transition: background 0.3s ease, color 0.3s ease;
}

.container {
    width: 70%;
    max-width: 1600px;
    margin: 0 auto;
}

@media (max-width: 1400px) {
    .container {
        width: 80%;
    }
}

@media (max-width: 768px) {
    .container {
        width: 95%;
    }
}

/* Main Layout - Split Screen */
.main-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    align-items: stretch;
}

/* Sidebar (Left Column) */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 15px;
    height: 100%;
}

/* Header Grid (Small Cards in Sidebar) - 2 Columns */
.header-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

/* Main Content (Right Column) */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
    height: 100%;
}

.content-grid-vertical {
    display: flex;
    flex-direction: column;
    gap: 15px;
    height: 100%;
}

/* Remove margin from the last card to align bottoms perfectly */
.content-grid-vertical>.card:last-child {
    margin-bottom: 0;
}

/* Phone Card takes available space */
#phoneCard {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Tabs content takes remaining space inside Phone Card */
.tab-content {
    flex: 1;
}

/* Responsive: Stack on tablets/mobile */
@media (max-width: 1200px) {
    .main-layout {
        grid-template-columns: 1fr;
    }

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

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

header {
    margin-bottom: 20px;
    padding: 15px;
    background: var(--bg-header-gradient);
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

/* Light theme specific header text override if not gradient */
[data-theme="light"] header h1 {
    background: none;
    -webkit-text-fill-color: var(--text-primary);
    color: var(--text-primary);
}

.header-content {
    text-align: center;
}

header h1 {
    font-size: 2.2em;
    margin-bottom: 4px;
    background: var(--accent-primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.0em;
}

.header-logo {
    height: 50px;
    width: auto;
    max-width: 150px;
    object-fit: contain;
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
}

/* Logo Toggling Logic */
.logo-light {
    display: none;
}

[data-theme="light"] .logo-dark {
    display: none;
}

[data-theme="light"] .logo-light {
    display: block;
}

.card {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 15px;
    border: 1px solid var(--card-border);
    box-shadow: var(--card-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease, background 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.1);
}

.card h2 {
    margin-bottom: 15px;
    color: var(--accent-primary);
    font-size: 1.25em;
    border-bottom: 2px solid rgba(0, 0, 0, 0.1);
    /* Subtle generic border */
    padding-bottom: 8px;
}

[data-theme="dark"] .card h2 {
    border-bottom: 2px solid rgba(0, 212, 170, 0.3);
}


/* Fix for grid spacing: remove card margin inside grid so only gap applies */
.header-grid .card {
    margin-bottom: 0;
}

/* Connection Controls */
/* Connection Controls */
.connection-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    /* Allow wrapping on small screens */
    /* justify-content: space-between;  <-- Removed to keep items flow naturally left-to-right + margin-auto on right item */
    position: relative;
}

.connection-controls button {
    position: relative;
    z-index: 10;
}

.connection-controls label {
    position: relative;
    z-index: 10;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.1);
    /* Neutral */
    border-radius: 20px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--error-color);
    box-shadow: 0 0 10px rgba(255, 68, 68, 0.5);
    animation: pulse 2s infinite;
}

.status-dot.connected {
    background: var(--accent-primary);
    box-shadow: 0 0 10px rgba(0, 212, 170, 0.5);
    /* Keep green glow or adapt? Keeping generic for now */
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.info-box {
    background: rgba(0, 0, 0, 0.05);
    border-left: 4px solid var(--accent-primary);
    padding: 10px;
    border-radius: 6px;
    margin-top: 10px;
    color: var(--text-primary);
}

.info-box p {
    margin: 4px 0;
}

/* Form Elements */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--accent-primary);
    font-weight: 500;
}

input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 10px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 6px;
    color: var(--input-text);
    font-size: 1em;
    transition: all 0.3s ease;
}

input::placeholder {
    color: var(--text-secondary);
    opacity: 0.5;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.radio-group {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.05);
    /* Neutral */
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    color: var(--text-secondary);
    font-size: 0.85em;
}

.radio-label:hover {
    background: rgba(0, 0, 0, 0.1);
    color: var(--text-primary);
}

.radio-label:has(input:checked) {
    background: rgba(0, 123, 255, 0.1);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
    font-weight: 500;
}

.radio-label input[type="radio"] {
    cursor: pointer;
    accent-color: var(--accent-primary);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

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

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

.btn-secondary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-success {
    background: linear-gradient(135deg, #56ab2f 0%, #a8e063 100%);
    color: white;
}

.btn-warning {
    background: linear-gradient(135deg, #f2994a 0%, #f2c94c 100%);
    color: white;
}

.btn-info {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
}

.btn-sm {
    padding: 6px 14px;
    font-size: 0.9em;
}

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

/* Tabs */
.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    position: relative;
    z-index: 10;
}

.tab-btn {
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    border-radius: 6px 6px 0 0;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    z-index: 10;
}

.tab-btn.active {
    background: rgba(0, 123, 255, 0.1);
    color: var(--accent-primary);
    border-bottom: 2px solid var(--accent-primary);
}

.tab-content {
    display: none;
}

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

/* Phone Card Specifics */
.phone-card {
    min-height: 500px;
    display: flex;
    flex-direction: column;
}

/* Numbers Grid/List */
.numbers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    margin-bottom: 15px;
}

.numbers-list {
    flex-grow: 1;
    max-height: 450px;
    overflow-y: auto;
    padding-right: 8px;
}

.number-item {
    padding: 10px;
    background: var(--card-bg);
    /* Use card bg for items inside lists */
    border-radius: 6px;
    border: 1px solid var(--card-border);
    transition: all 0.3s ease;
}

.number-item:hover {
    background: rgba(0, 0, 0, 0.05);
    border-color: var(--accent-primary);
}

.number-item label {
    display: block;
    margin-bottom: 4px;
    font-size: 0.9em;
    color: var(--accent-primary);
}

.number-item input {
    width: 100%;
}

.search-box {
    margin-bottom: 12px;
}

.search-box input {
    width: 100%;
}

/* Actions Grid */
.actions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Progress */
.progress-container {
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 24px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: var(--accent-primary-gradient);
    width: 0%;
    transition: width 0.3s ease;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

#progressText {
    color: var(--accent-primary);
    font-weight: 500;
}

/* Log Area */
.log-area {
    background: rgba(0, 0, 0, 0.8);
    /* Keep dark for logs/terminal feel even in light mode? Or variable? Let's use variable but make it dark by default or specific. */
    background: rgba(0, 0, 0, 0.7);
    border-radius: 6px;
    padding: 8px;
    max-height: 200px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
    font-size: 0.80em;
    margin-bottom: 8px;
    line-height: 1.2;
    color: #eee;
    /* Logs usually look better white on black */
}

/* Light theme log area override */
[data-theme="light"] .log-area {
    background: #2d2d2d;
    color: #f0f0f0;
}


.log-entry {
    margin: 2px 0;
    padding: 2px 4px;
    border-left: 2px solid transparent;
}

.log-entry.info {
    border-color: #4facfe;
    color: #4facfe;
}

.log-entry.success {
    border-color: var(--success-color);
    color: var(--success-color);
}

.log-entry.error {
    border-color: var(--error-color);
    color: var(--error-color);
}

.log-entry.warning {
    border-color: var(--warning-color);
    color: var(--warning-color);
}

/* Footer */
footer {
    text-align: center;
    padding: 15px;
    color: var(--text-secondary);
    font-size: 0.9em;
}

footer p {
    margin: 4px 0;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 8px;
}

::-webkit-scrollbar-thumb {
    background: var(--accent-primary);
    border-radius: 8px;
    opacity: 0.5;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

/* Configuration Grid - 2 Columns (2x2) */
.config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

.config-grid h3 {
    color: var(--accent-primary);
    font-size: 1.2em;
    margin-bottom: 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    padding-bottom: 6px;
}

/* Responsive - config grid */
@media (max-width: 768px) {
    .config-grid {
        grid-template-columns: 1fr;
    }
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.8em;
    }

    .connection-controls {
        flex-direction: column;
        align-items: stretch;
    }

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

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

    header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }

    .header-content {
        text-align: center;
    }

    .header-logo {
        position: static;
        transform: none;
        margin-bottom: 10px;
        left: auto;
        top: auto;
    }

    .theme-switch {
        position: static !important;
        margin-top: 10px;
    }
}

/* --- GSM Signal Icon --- */
.signal-container {
    position: absolute;
    right: 20px;
    top: 15px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 5px 10px;
    background: var(--card-bg);
    border-radius: 6px;
    border: 1px solid var(--card-border);
}

.signal-text {
    font-size: 0.9em;
    font-weight: bold;
    color: var(--success-color);
    min-width: 40px;
    text-align: right;
}

.bars-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 20px;
    margin-bottom: 2px;
}

.signal-bar {
    width: 5px;
    background-color: var(--offline-color);
    border-radius: 1px;
    transition: background-color 0.3s ease;
}

.signal-bar.active {
    background-color: var(--success-color);
}

/* Signal Strength Levels */
.signal-bar.bar-1 {
    height: 8px;
}

.signal-bar.bar-2 {
    height: 11px;
}

.signal-bar.bar-3 {
    height: 14px;
}

.signal-bar.bar-4 {
    height: 17px;
}

.signal-bar.bar-5 {
    height: 20px;
}

/* Status Colors */

/* We use CSS variables effectively here by mapping generic color classes */
/* These specific overrides might need updates to use vars if we want full theming but solid colors are usually ok */

.signal-container.weak .signal-bar.active,
.signal-container.weak .signal-text {
    color: var(--error-color);
    background-color: var(--error-color);
}

.signal-container.weak .signal-text {
    background-color: transparent;
}

.signal-container.medium .signal-bar.active,
.signal-container.medium .signal-text {
    color: var(--warning-color);
    background-color: var(--warning-color);
}

.signal-container.medium .signal-text {
    background-color: transparent;
}

.signal-container.strong .signal-bar.active,
.signal-container.strong .signal-text {
    color: var(--success-color);
    background-color: var(--success-color);
}

.signal-container.strong .signal-text {
    background-color: transparent;
}

/* Hide completely when offline or no signal (class .offline added by JS) */
.signal-container.offline {
    display: none !important;
}

/* Footer Icons Container */
.footer-icons {
    display: flex;
    justify-content: center;
    gap: 25px;
    margin: 15px 0;
    flex-wrap: wrap;
}

/* Resource Links */
.resource-link {
    text-decoration: none;
    transition: transform 0.2s, opacity 0.2s;
    opacity: 0.8;
    display: flex;
    align-items: center;
}

.resource-link:hover {
    transform: scale(1.15);
    opacity: 1;
}

/* Adjust black icon for dark mode */
.resource-link svg[style*="color: #000000;"] {
    color: var(--text-primary) !important;
}

/* Theme Switcher Styles (Restored) */
.theme-switch {
    display: flex;
    gap: 10px;
    position: absolute;
    right: 20px;
    bottom: 15px;
    background: rgba(0, 0, 0, 0.2);
    padding: 5px;
    border-radius: 20px;
    backdrop-filter: blur(2px);
}

[data-theme="light"] .theme-switch {
    background: rgba(255, 255, 255, 0.5);
    border-left: none;
    /* Reset if previously set */
}

[data-theme="light"] .theme-switch {
    background: rgba(0, 0, 0, 0.05);
}

.theme-switch label {
    cursor: pointer;
    font-size: 1.2em;
    padding: 2px 6px;
    border-radius: 50%;
    transition: background 0.2s;
}

.theme-switch input {
    display: none;
}

.theme-switch label:has(input:checked) {
    background: rgba(255, 255, 255, 0.2);
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}

[data-theme="light"] .theme-switch label:has(input:checked) {
    background: white;
}

/* --- Browser Support Modal --- */
.modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    margin: auto;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 5px 30px rgba(0, 0, 0, 0.3);
    text-align: center;
    position: relative;
    animation: slideIn 0.3s ease;
}

[data-theme="light"] .modal-content {
    background: #ffffff;
}

.modal-content h2 {
    margin-bottom: 40px;
    font-size: 1.8rem;
    color: var(--text-primary);
}

.close-modal {
    color: var(--text-secondary);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    position: absolute;
    right: 20px;
    top: 15px;
    transition: color 0.3s ease;
}

.close-modal:hover,
.close-modal:focus {
    color: var(--text-primary);
    text-decoration: none;
}

.browser-icons {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-top: 25px;
    flex-wrap: wrap;
}

.browser-icons a {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--text-primary);
    transition: transform 0.3s ease;
}

.browser-icons a:hover {
    transform: translateY(-5px);
}

.browser-icons img {
    margin-bottom: 10px;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}

.browser-icons span {
    font-weight: 500;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* --- Global Help Mode Styles --- */
/* Added for Global Help System - [User Request: Cloud Tooltips] */

.card,
.has-tooltip {
    position: relative;
    /* Ensure tooltip positions relative to this container */
}

/* Generic Help Tooltip (Hidden by default) */
.help-tooltip {
    display: none;
    background-color: #ffd700;
    /* Nice Yellow */
    color: #333;
    text-align: center;
    border-radius: 12px;
    padding: 15px;
    position: absolute;
    z-index: 1000;

    /* Position "cloud" above the element */
    bottom: 105%;
    left: 50%;
    transform: translateX(-50%);
    width: 250px;
    max-width: 90vw;

    font-size: 0.9em;
    font-weight: 500;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    border: 1px solid #e1b12c;
    pointer-events: none;
    /* Allow clicking through the tooltip */

    /* Animation */
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Tooltip Tail (Arrow down) */
.help-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -8px;
    border-width: 8px;
    border-style: solid;
    border-color: #ffd700 transparent transparent transparent;
}

/* 
 * VISIBILITY LOGIC: 
 * Tooltip appears ONLY when:
 * 1. body has class 'help-mode' (checkbox checked)
 * 2. element with class 'has-tooltip' is HOVERED
 */
body.help-mode .has-tooltip:hover .help-tooltip {
    display: block;
    opacity: 1;
    transform: translateX(-50%) translateY(-5px);
}

/* Cursor indication when in help mode */
/* --- Loading Spinner Overlay --- */
.spinner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(5px);
}

.spinner-content {
    text-align: center;
}

.spinner-ring {
    display: inline-block;
    width: 64px;
    height: 64px;
    border: 6px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent-primary);
    animation: spin 1s ease-in-out infinite;
    box-shadow: 0 0 20px rgba(0, 212, 170, 0.4);
}

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