/* Modern Professional Design - Next.js Style */

/* =====================================================
   CSS RESET & BASE STYLES - Best Practices
   ===================================================== */

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

/* Global overflow prevention */
* {
    max-width: 100%;
}

img, video, iframe, embed, object {
    max-width: 100%;
    height: auto;
}

:root {
    --primary: #0070f3;
    --primary-hover: #0051cc;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --bg: #fafafa;
    --surface: #ffffff;
    --border: #e5e7eb;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 8px;
    --radius-lg: 12px;
}

html {
    scroll-behavior: smooth;
    /* Prevent horizontal scrolling */
    overflow-x: hidden;
    /* Better font rendering on mobile */
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    min-height: -webkit-fill-available; /* iOS Safari fix */
    padding: 24px;
    padding-top: max(24px, env(safe-area-inset-top)); /* Safe area for notched devices */
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    /* Prevent horizontal scrolling */
    overflow-x: hidden;
    /* Better touch handling */
    touch-action: manipulation;
    /* Prevent text selection on buttons */
    -webkit-user-select: none;
    user-select: none;
}

/* Re-enable text selection for content areas */
input, textarea, [contenteditable], .log-entry, .unit-card, .form-hint {
    -webkit-user-select: text;
    user-select: text;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    /* Prevent container overflow */
    width: 100%;
    box-sizing: border-box;
    /* Ensure no horizontal scroll */
    overflow-x: hidden;
}

/* Header */
.header {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    /* Prevent overflow */
    overflow-x: hidden;
    box-sizing: border-box;
    max-width: 100%;
    /* Better word wrapping */
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Header Top - Contains title and actions */
.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    flex-wrap: wrap;
    width: 100%;
}

.header-text {
    flex: 1;
    min-width: 0;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

/* Header Actions - Language toggle and status badge */
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    margin-left: auto;
}

.header-text {
    flex: 1;
    min-width: 0;
}

.header-text h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.header-text .subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 400;
    line-height: 1.5;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    white-space: nowrap;
}

.status-badge.running {
    background: #dcfce7;
    color: #16a34a;
    border-color: #86efac;
}

.status-badge.stopped {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fca5a5;
}

.status-badge.success {
    background: #dcfce7;
    color: #16a34a;
    border-color: #86efac;
}

/* Testing Phase Badge */
.testing-phase-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    background: #fef3c7;
    color: #d97706;
    border: 1px solid #fcd34d;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    animation: pulse-gentle 2s ease-in-out infinite;
}

@keyframes pulse-gentle {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.85;
    }
}

/* Tab Navigation */
.tab-navigation {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 4px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    display: flex;
    gap: 4px;
}

.tab-button {
    flex: 1;
    padding: 12px 20px;
    min-height: 44px; /* WCAG 2.1: Minimum touch target */
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    border-radius: var(--radius);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    position: relative;
    will-change: background-color, color, transform;
}

.tab-button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    z-index: 1;
}

.tab-button:hover {
    background: var(--bg);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.tab-button.active {
    background: var(--text-primary);
    color: var(--surface);
    transform: scale(1.02);
    box-shadow: var(--shadow-sm);
}

.tab-content {
    display: none;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    will-change: opacity, transform;
}

.tab-content.active {
    display: block;
    opacity: 1;
    transform: translateY(0);
    animation: fadeInTab 0.3s ease-out;
}

@keyframes fadeInTab {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    will-change: transform;
    /* Prevent overflow */
    overflow-x: hidden;
    box-sizing: border-box;
    max-width: 100%;
}

.card-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
    letter-spacing: -0.01em;
}

/* Info Box */
.info-box {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-left: 3px solid var(--warning);
    padding: 16px 20px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.info-box-blue {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-left: 3px solid var(--info);
    padding: 16px 20px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.info-box h4 {
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    letter-spacing: -0.01em;
}

.info-box ul,
.info-box ol {
    margin: 8px 0 0 20px;
    color: var(--text-secondary);
    padding: 0;
}

.info-box li {
    margin: 6px 0;
    line-height: 1.6;
    font-size: 13px;
}

.info-box code {
    background: rgba(0, 0, 0, 0.06);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    color: var(--text-primary);
    font-weight: 500;
}

.info-box strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Form Styles */
.form-group {
    margin-bottom: 24px;
}

.form-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 12px;
    flex-wrap: wrap;
}

/* Ensure labels don't shrink */
.form-group-header label {
    flex: 1;
    min-width: 120px;
}

/* Ensure add buttons stay on the right */
.form-group-header .btn-add-small {
    flex-shrink: 0;
}

.form-group label {
    display: block;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 8px;
    font-size: 14px;
    line-height: 1.5;
}

/* Required field indicator */
.form-group label.required::after {
    content: ' *';
    color: var(--error);
    font-weight: 600;
}

.form-hint {
    display: block;
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 12px;
    line-height: 1.5;
}

.form-hint strong {
    color: var(--text-primary);
    font-weight: 500;
}

input[type="text"],
input[type="number"],
input[type="tel"],
textarea {
    width: 100%;
    padding: 12px 16px;
    min-height: 44px; /* WCAG 2.1: Minimum touch target size */
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--surface);
    color: var(--text-primary);
    line-height: 1.5;
    will-change: border-color, box-shadow;
    /* Prevent zoom on iOS when focusing input */
    -webkit-appearance: none;
    appearance: none;
    /* Prevent overflow */
    box-sizing: border-box;
    max-width: 100%;
    /* Better word wrapping */
    word-wrap: break-word;
    overflow-wrap: break-word;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="tel"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 112, 243, 0.1);
}

/* Focus-visible for keyboard navigation */
input[type="text"]:focus-visible,
input[type="number"]:focus-visible,
input[type="tel"]:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Error states */
input[type="text"]:invalid:not(:placeholder-shown),
input[type="number"]:invalid:not(:placeholder-shown),
input[type="tel"]:invalid:not(:placeholder-shown),
textarea:invalid:not(:placeholder-shown) {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

textarea {
    resize: vertical;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
    /* Better mobile handling */
    width: 100%;
    box-sizing: border-box;
    max-width: 100%;
    /* Better word wrapping */
    word-wrap: break-word;
    overflow-wrap: break-word;
    overflow-x: hidden;
}

/* Buttons */
.button-group {
    display: flex;
    gap: 12px;
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

/* Primary action button should be more prominent */
.button-group .btn-start {
    order: 1; /* Start button first */
    font-weight: 600; /* Make primary action more prominent */
}

.button-group .btn-stop {
    order: 2;
}

/* Ensure buttons have consistent sizing */
.button-group button {
    min-width: 120px; /* Prevent buttons from being too narrow */
}

button {
    padding: 12px 24px;
    min-height: 44px; /* WCAG 2.1: Minimum touch target size */
    min-width: 44px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    display: inline-flex;
    will-change: transform, background-color, box-shadow;
    /* Mobile optimizations */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: relative;
}

/* Focus states for accessibility */
button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-start {
    background: var(--success);
    color: white;
    flex: 1;
}

.btn-start:hover:not(:disabled) {
    background: #059669;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-start:disabled {
    background: var(--text-tertiary);
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-stop {
    background: var(--error);
    color: white;
    flex: 1;
}

.btn-stop:hover:not(:disabled) {
    background: #dc2626;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-stop:disabled {
    background: var(--text-tertiary);
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-search {
    background: var(--primary);
    color: white;
    padding: 10px 24px;
    white-space: nowrap;
}

.btn-search:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 112, 243, 0.3);
}

.btn-search:disabled {
    background: var(--text-tertiary);
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-add-small {
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 16px;
    min-height: 36px; /* Smaller but still accessible */
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.btn-add-small:hover {
    background: var(--bg);
    border-color: var(--text-secondary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

button:active:not(:disabled) {
    transform: translateY(0) scale(0.98);
}

.btn-remove {
    background: var(--error);
    color: white;
    padding: 10px 18px;
    min-height: 40px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    align-self: flex-start;
    margin-top: auto; /* Better alignment */
    flex-shrink: 0;
}

.btn-remove:hover {
    background: #dc2626;
    transform: translateY(-1px) scale(1.05);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

/* Entry Rows */
.entry-container {
    margin-bottom: 12px;
}

.entry-row {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 16px;
    padding: 20px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform, box-shadow, border-color;
    /* Prevent overflow */
    overflow-x: hidden;
    box-sizing: border-box;
    max-width: 100%;
    /* Better word wrapping */
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Better alignment for entry rows */
.entry-row .entry-row-content {
    flex: 1;
    min-width: 0; /* Prevent overflow */
    max-width: 100%;
    overflow-x: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.entry-row:hover {
    border-color: var(--text-tertiary);
    box-shadow: var(--shadow-sm);
    transform: translateY(-2px);
}

.entry-row-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0; /* Prevent overflow */
}

.entry-row-content textarea,
.entry-row-content input {
    margin-bottom: 0;
    width: 100%;
}

/* Ensure textarea in entry rows has proper min-height */
.entry-row-content textarea {
    min-height: 80px; /* Better for multi-line input */
}

.entry-row-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.entry-number {
    background: var(--text-primary);
    color: var(--surface);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.empty-entries-message {
    text-align: center;
    padding: 32px 20px;
    background: var(--bg);
    border-radius: var(--radius);
    border: 1px dashed var(--border);
    color: var(--text-secondary);
    font-size: 14px;
}

.empty-entries-message .icon {
    font-size: 32px;
    margin-bottom: 8px;
    opacity: 0.5;
}

/* Unit Search Box */
.unit-search-box {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
    align-items: stretch; /* Ensure buttons align properly */
}

.unit-search-box input {
    flex: 1 1 auto;
    min-width: 200px; /* Ensure visible width */
    max-width: 100%;
    width: auto;
    display: block;
    visibility: visible;
    opacity: 1;
    box-sizing: border-box;
}

.unit-search-box .btn-search {
    flex-shrink: 0;
}

/* Unit Info Display */
.unit-info-display {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    border: 1px solid var(--border);
    margin-top: 20px;
    box-shadow: var(--shadow-md);
}

.unit-info-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 12px;
}

.unit-info-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.01em;
}

.unit-status-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

.unit-status-badge.available {
    background: #dcfce7;
    color: #16a34a;
    border: 1px solid #86efac;
}

.unit-status-badge.reserved {
    background: #fee2e2;
    color: #dc2626;
    border: 1px solid #fca5a5;
}

.unit-status-badge.open-for-reservation {
    background: #dbeafe;
    color: #2563eb;
    border: 1px solid #93c5fd;
}

.unit-status-badge.not-open {
    background: #f3f4f6;
    color: #6b7280;
    border: 1px solid var(--border);
}

.unit-info-body {
    padding: 0;
}

.unit-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.unit-info-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

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

.unit-info-item-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 4px;
}

.unit-info-item-value {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 400;
    line-height: 1.5;
}

.unit-info-footer {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    text-align: center;
}

.unit-info-link {
    color: var(--primary);
    font-weight: 500;
    text-decoration: none;
    font-size: 14px;
    transition: color 0.2s ease;
}

.unit-info-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Monitor Panels */
.monitor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-top: 24px;
}

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

.monitor-panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.monitor-header {
    background: var(--text-primary);
    color: var(--surface);
    padding: 14px 20px;
    font-weight: 500;
    font-size: 14px;
}

.monitor-header.units-header {
    background: var(--info);
}

.monitor-content {
    height: 400px;
    overflow-y: auto;
    overflow-x: hidden; /* Prevent horizontal scroll */
    padding: 16px;
    background: var(--bg);
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    will-change: scroll-position;
    overscroll-behavior: contain;
    /* Better word wrapping */
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
}

.monitor-content:empty::before {
    content: '';
    display: block;
    height: 100%;
}

.monitor-content::-webkit-scrollbar {
    width: 6px;
}

.monitor-content::-webkit-scrollbar-track {
    background: transparent;
}

.monitor-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.monitor-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-tertiary);
}

/* Log Entries */
.log-entry {
    padding: 12px 16px;
    margin-bottom: 10px;
    background: var(--surface);
    border-radius: var(--radius);
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    border-left: 3px solid var(--border);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    opacity: 1;
    transform: translateY(0);
    will-change: transform, opacity;
    animation: fadeInUp 0.3s ease-out;
    /* Prevent overflow */
    overflow-x: hidden;
    max-width: 100%;
    box-sizing: border-box;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.log-entry .log-message strong {
    font-weight: 600;
    color: var(--text-primary);
}

.log-entry:hover {
    box-shadow: var(--shadow-md);
    transform: translateX(2px);
}

body.rtl .log-entry:hover {
    transform: translateX(-2px); /* Move left in RTL (opposite direction) */
}

.log-entry .log-time {
    font-size: 11px;
    color: var(--primary);
    font-weight: 600;
    margin-bottom: 6px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    font-family: 'Courier New', monospace;
}

.log-entry .log-message {
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 400;
    word-break: break-word;
}

.log-entry.log-success {
    background: #f0fdf4;
    border-left-color: var(--success);
}

.log-entry.log-success .log-message {
    color: #065f46;
}

.log-entry.log-error {
    background: #fef2f2;
    border-left-color: var(--error);
}

.log-entry.log-error .log-message {
    color: #991b1b;
}

.log-entry.log-warning {
    background: #fffbeb;
    border-left-color: var(--warning);
}

.log-entry.log-warning .log-message {
    color: #92400e;
}

.log-entry.log-info {
    background: #eff6ff;
    border-left-color: var(--info);
}

.log-entry.log-info .log-message {
    color: #1e40af;
}

.log-entry.log-scanning {
    background: #f0fdfa;
    border-left-color: #14b8a6;
}

.log-entry.log-scanning .log-message {
    color: #115e59;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-icon {
    font-size: 40px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-state .text {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* Unit Cards */
.unit-card {
    background: var(--surface);
    padding: 16px;
    margin-bottom: 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
    /* Prevent horizontal overflow */
    overflow-x: hidden;
    box-sizing: border-box;
    max-width: 100%;
    /* Better word wrapping */
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.unit-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--info);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.unit-card:hover {
    border-color: var(--info);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.unit-card:hover::before {
    opacity: 1;
}

.unit-card-header {
    font-weight: 600;
    color: var(--info);
    margin-bottom: 10px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.unit-card-header::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--info);
    display: inline-block;
}

.unit-card-info {
    font-size: 13px;
    color: #000000;
    line-height: 1.7;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.unit-card-info strong {
    color: var(--primary);
    font-weight: 600;
    margin-right: 6px;
}

.unit-card-info span {
    color: #000000;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
}

/* Monitor Status Card */
.monitor-status-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    margin-bottom: 24px;
    box-shadow: var(--shadow-md);
    padding: 24px;
}

.monitor-status-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-wrap: wrap;
}

.monitor-status-icon {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--info);
    animation: pulse 2s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.monitor-status-title {
    font-weight: 600;
    font-size: 18px;
    color: var(--text-primary);
    flex: 1;
    letter-spacing: -0.01em;
}

.monitor-status-badge {
    background: var(--bg);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border);
    white-space: nowrap;
}

.monitor-status-body {
    padding: 0;
}

.monitor-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.monitor-stat-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

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

.monitor-stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 4px;
}

.monitor-stat-value {
    font-size: 16px;
    color: var(--text-primary);
    font-weight: 600;
}

/* Monitor Log Panel */
.monitor-log-panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.monitor-log-header {
    background: var(--surface);
    color: var(--text-primary);
    padding: 16px 20px;
    font-weight: 600;
    font-size: 18px;
    border-bottom: 1px solid var(--border);
    letter-spacing: -0.01em;
}

.monitor-log-content {
    height: 300px;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg);
}

.monitor-log-entry {
    padding: 12px 16px;
    margin-bottom: 10px;
    background: var(--surface);
    border-radius: var(--radius);
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    border-left: 3px solid var(--border);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    opacity: 1;
    transform: translateY(0);
    will-change: transform, opacity;
    animation: fadeInUp 0.3s ease-out;
    overflow-x: hidden;
    max-width: 100%;
    box-sizing: border-box;
}

.monitor-log-entry:hover {
    box-shadow: var(--shadow-md);
    transform: translateX(2px);
}

body.rtl .monitor-log-entry:hover {
    transform: translateX(-2px);
}

.monitor-log-entry.status-change {
    background: #f0fdf4;
    border-left-color: var(--success);
}

.monitor-log-entry.status-change .monitor-log-message {
    color: #065f46;
}

.monitor-log-entry.error {
    background: #fef2f2;
    border-left-color: var(--error);
}

.monitor-log-entry.error .monitor-log-message {
    color: #991b1b;
}

.monitor-log-time {
    font-size: 11px;
    color: var(--primary);
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    font-family: 'Courier New', monospace;
}

.monitor-log-message {
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 400;
    word-break: break-word;
}

.monitor-log-message strong {
    font-weight: 600;
    color: var(--text-primary);
}

/* Loading Spinner */
.loading-spinner {
    text-align: center;
    padding: 40px;
    color: var(--text-secondary);
}

.loading-spinner .spinner {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

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

/* Error Message */
.error-message {
    background: #fef2f2;
    border-left: 3px solid var(--error);
    padding: 16px 20px;
    border-radius: var(--radius);
    color: #991b1b;
    margin-bottom: 20px;
}

/* Footer */
.footer {
    text-align: center;
    margin-top: 32px;
    color: var(--text-secondary);
    font-size: 13px;
}

/* Language Toggle - Now in Header */
.lang-toggle {
    position: relative;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 8px 16px;
    min-height: 36px;
    min-width: 90px;
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    color: var(--text-secondary);
    /* Prevent text selection */
    -webkit-user-select: none;
    user-select: none;
    /* Touch optimizations */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    box-shadow: none;
}

.lang-toggle:hover {
    background: var(--surface);
    border-color: var(--text-tertiary);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.lang-toggle:active {
    transform: translateY(0) scale(0.98);
}

.lang-toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
    z-index: 1;
}

/* Tooltip */
.tooltip {
    position: relative;
    display: inline-block;
    cursor: help;
    margin-left: 6px;
}

.tooltip-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 200px;
    background-color: var(--text-primary);
    color: var(--surface);
    text-align: center;
    border-radius: var(--radius);
    padding: 8px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    margin-left: -100px;
    font-size: 12px;
    opacity: 0;
    transition: opacity 0.2s;
}

.tooltip:hover .tooltiptext,
.tooltip:active .tooltiptext,
.tooltip:focus .tooltiptext {
    visibility: visible;
    opacity: 1;
}

/* Touch-friendly tooltips on mobile */
@media (max-width: 768px) {
    .tooltip {
        cursor: pointer;
    }
    
    .tooltip .tooltiptext {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100% - 40px);
        max-width: 300px;
        margin-left: 0;
        bottom: auto;
        top: auto;
        z-index: 1000;
        box-shadow: var(--shadow-lg);
    }

    /* RTL tooltip positioning on mobile */
    body.rtl .tooltip .tooltiptext {
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        margin-right: 0;
        margin-left: 0;
    }
}

/* =====================================================
   COMPREHENSIVE RTL SUPPORT (Arabic)
   ===================================================== */

body.rtl {
    direction: rtl;
    text-align: right;
}

/* Language toggle in header - RTL adjustments */
body.rtl .header-actions {
    flex-direction: row-reverse;
}

/* Headers and Content Areas */
body.rtl .header-top,
body.rtl .header-content,
body.rtl .header-actions,
body.rtl .form-group-header,
body.rtl .entry-row,
body.rtl .unit-search-box,
body.rtl .monitor-status-header,
body.rtl .button-group {
    flex-direction: row-reverse;
}

/* Text Alignment */
body.rtl,
body.rtl .text,
body.rtl .form-hint,
body.rtl .card-title,
body.rtl label,
body.rtl .log-entry,
body.rtl .log-message,
body.rtl .empty-state,
body.rtl .footer,
body.rtl .unit-card-info,
body.rtl .unit-info-item-label,
body.rtl .unit-info-item-value,
body.rtl .monitor-stat-label,
body.rtl .monitor-stat-value,
body.rtl .monitor-log-entry,
body.rtl .header-text,
body.rtl .header-text h1,
body.rtl .header-text .subtitle {
    text-align: right;
}

body.rtl .empty-state,
body.rtl .footer {
    text-align: center; /* Keep centered for empty states and footer */
}

/* Lists */
body.rtl .info-box ul,
body.rtl .info-box ol {
    margin-right: 20px;
    margin-left: 0;
    padding-right: 0;
    padding-left: 0;
}

body.rtl .info-box li {
    text-align: right;
}

/* Borders - Swap left to right */
body.rtl .log-entry,
body.rtl .monitor-log-entry,
body.rtl .entry-row .entry-number {
    border-left: none;
    border-right: 3px solid var(--border);
}

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

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

body.rtl .monitor-log-entry.status-change {
    border-right-color: var(--success);
}

body.rtl .monitor-log-entry.error {
    border-right-color: var(--error);
}

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

body.rtl .log-entry.log-info {
    border-right-color: var(--info);
}

body.rtl .log-entry.log-scanning {
    border-right-color: #14b8a6;
}

body.rtl .unit-card::before {
    left: auto;
    right: 0;
}

body.rtl .unit-card-header {
    flex-direction: row-reverse;
    text-align: right;
}

body.rtl .unit-card-header::before {
    order: 2;
}

body.rtl .unit-card-info {
    text-align: right;
}

body.rtl .unit-card-info strong {
    margin-right: 6px;
    margin-left: 0;
}

body.rtl .monitor-stat-item {
    text-align: right;
}

/* Unit Info Display */
body.rtl .unit-info-header {
    text-align: right;
}

body.rtl .unit-info-body {
    text-align: right;
}

/* Monitor Status */
body.rtl .monitor-status-header {
    flex-direction: row-reverse;
}

body.rtl .monitor-status-icon {
    margin-right: 0;
    margin-left: 12px;
}

/* Scrollbar for RTL */
body.rtl .monitor-content::-webkit-scrollbar {
    direction: rtl;
}

/* Error and Success Messages */
body.rtl .error-message {
    text-align: right;
}

/* Links in RTL */
body.rtl a {
    text-align: right;
    direction: rtl;
}

/* Arrow in links - reverse direction in RTL */
body.rtl a[href*="sakani.sa"]::after {
    content: " ←";
}

body.rtl a[href*="sakani.sa"] {
    unicode-bidi: embed;
}

/* Code elements - keep LTR but align container */
body.rtl .form-hint code {
    direction: ltr;
    text-align: left;
    display: inline-block;
}

/* Loading Spinner */
body.rtl .loading-spinner {
    text-align: center; /* Keep centered */
}

/* Card Titles */
body.rtl .card-title {
    text-align: right;
}

/* Labels - Comprehensive RTL */
body.rtl .form-group label {
    text-align: right;
    display: block;
    width: 100%;
}

body.rtl .form-group {
    direction: rtl;
    text-align: right;
}

/* Form Hints */
body.rtl .form-hint {
    text-align: right;
    direction: rtl;
}

body.rtl .form-hint strong {
    text-align: right;
}

/* All Form Elements */
body.rtl .form-group input,
body.rtl .form-group textarea,
body.rtl .form-group select {
    text-align: right;
    direction: rtl;
}

body.rtl .form-group input::placeholder,
body.rtl .form-group textarea::placeholder {
    text-align: right;
    direction: rtl;
}

/* Entry Number Badge */
body.rtl .entry-number {
    margin-right: 0;
    margin-left: 6px;
}

body.rtl .info-box {
    border-left: 1px solid #fde68a;
    border-right: 3px solid var(--warning);
}

body.rtl .info-box-blue {
    border-left: 1px solid #bfdbfe;
    border-right: 3px solid var(--info);
}

body.rtl .error-message {
    border-left: 1px solid var(--error);
    border-right: 3px solid var(--error);
}

/* Margins and Padding Swaps */
body.rtl .tooltip {
    margin-right: 6px;
    margin-left: 0;
}

body.rtl .entry-row-label {
    margin-right: 0;
    margin-left: 8px;
}

/* Tooltip Positioning */
body.rtl .tooltip .tooltiptext {
    right: 50%;
    left: auto;
    margin-right: -100px;
    margin-left: 0;
    transform: translateX(50%);
}

/* Status Badge */
body.rtl .status-badge {
    margin-right: 0;
    margin-left: auto;
}

/* Tab Navigation */
body.rtl .tab-navigation {
    flex-direction: row;
}

body.rtl .tab-button:first-child {
    border-top-left-radius: 0;
    border-top-right-radius: var(--radius);
}

body.rtl .tab-button:last-child {
    border-top-right-radius: 0;
    border-top-left-radius: var(--radius);
}

/* Unit Search Box - Button first in RTL */
body.rtl .unit-search-box {
    flex-direction: row-reverse;
    direction: rtl;
    gap: 12px;
}

body.rtl .unit-search-box input {
    flex: 1 1 auto;
    min-width: 200px; /* Ensure minimum width so it's visible */
    max-width: 100%;
    width: auto;
    text-align: right;
    direction: rtl;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    background: var(--surface) !important;
    border: 1px solid var(--border) !important;
    padding: 12px 16px !important;
    min-height: 44px !important;
    box-sizing: border-box;
}

body.rtl .unit-search-box .btn-search {
    flex-shrink: 0;
    order: -1; /* Button appears first (left side) in RTL */
}

/* Unit Info Result Container */
body.rtl #unitInfoResult {
    direction: rtl;
    text-align: right;
}

body.rtl #unitInfoResult * {
    text-align: right;
}

body.rtl #unitInfoResult .loading-spinner,
body.rtl #unitInfoResult .error-message {
    text-align: center;
}

/* Unit Info Display - Comprehensive RTL */
body.rtl .unit-info-display {
    direction: rtl;
}

body.rtl .unit-info-header {
    flex-direction: row-reverse;
    text-align: right;
}

body.rtl .unit-info-title {
    text-align: right;
}

body.rtl .unit-info-body {
    direction: rtl;
    text-align: right;
}

body.rtl .unit-info-grid {
    direction: rtl;
}

body.rtl .unit-info-item {
    text-align: right;
}

body.rtl .unit-info-item-label {
    text-align: right;
}

body.rtl .unit-info-item-value {
    text-align: right;
}

/* Fix inline styles in dynamically generated content */
body.rtl [style*="text-align: left"],
body.rtl [style*="text-align:center"] {
    text-align: right !important;
}

body.rtl [style*="text-align: center"] {
    text-align: center !important; /* Keep centered elements centered */
}

/* Links in unit info */
body.rtl .unit-info-body a {
    text-align: center;
    display: inline-block;
}

/* Monitor Status Display */
body.rtl .monitor-status-display {
    direction: rtl;
}

body.rtl .monitor-status-card {
    direction: rtl;
}

body.rtl .monitor-log-panel {
    direction: rtl;
}

body.rtl .monitor-log-header {
    text-align: right;
}

/* Form Groups */
body.rtl .form-group-header label {
    text-align: right;
}

body.rtl .form-group-header .btn-add-small {
    margin-right: 0;
    margin-left: auto;
}

/* Entry Rows */
body.rtl .entry-row .btn-remove {
    margin-right: 0;
    margin-left: auto;
}

/* Monitor Content */
body.rtl .monitor-content {
    direction: rtl;
}

body.rtl .monitor-log-content {
    direction: rtl;
}

/* Unit Info Grid */
body.rtl .unit-info-grid {
    direction: rtl;
}

body.rtl .monitor-stats-grid {
    direction: rtl;
}

/* Code and Pre Elements */
body.rtl code,
body.rtl pre {
    direction: ltr; /* Code should stay LTR */
    text-align: left;
    display: inline-block;
}

/* Input Fields - Keep LTR for URLs, codes, etc. */
body.rtl input[type="text"],
body.rtl input[type="number"],
body.rtl input[type="tel"],
body.rtl textarea {
    text-align: right;
    direction: rtl;
}

body.rtl input[type="text"]::placeholder,
body.rtl input[type="number"]::placeholder,
body.rtl input[type="tel"]::placeholder,
body.rtl textarea::placeholder {
    text-align: right;
    direction: rtl;
}

/* Empty State */
body.rtl .empty-state .text {
    text-align: center; /* Keep centered */
}

/* Mobile RTL Adjustments */
@media (max-width: 768px) {
    /* Header actions RTL on mobile */
    body.rtl .header-actions {
        flex-direction: row-reverse;
    }

    body.rtl .button-group {
        flex-direction: column;
    }

    body.rtl .form-group-header {
        flex-direction: column;
        align-items: flex-end;
    }

    body.rtl .form-group-header .btn-add-small {
        margin-right: 0;
        margin-left: 0;
        width: 100%;
    }

    body.rtl .entry-row {
        flex-direction: column;
    }

    /* Unit search box on mobile RTL - stack vertically */
    body.rtl .unit-search-box {
        flex-direction: column !important;
        direction: ltr; /* Normal stacking order on mobile */
        gap: 10px;
    }

    body.rtl .unit-search-box input {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
        order: 2; /* Input appears second (below button) */
        text-align: right;
        direction: rtl;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        background: var(--surface) !important;
        border: 1px solid var(--border) !important;
        padding: 12px 16px !important;
        min-height: 44px !important;
        font-size: 16px !important;
        box-sizing: border-box !important;
    }

    body.rtl .unit-search-box .btn-search {
        width: 100% !important;
        order: 1; /* Button appears first (on top) */
        flex: none !important;
    }

    /* Header on mobile RTL */
    body.rtl .header-top {
        flex-direction: column;
        align-items: stretch;
    }

    body.rtl .header-text {
        text-align: right;
    }

    body.rtl .header-actions {
        width: 100%;
        flex-direction: row-reverse;
        justify-content: flex-start;
    }

    /* Form groups on mobile RTL */
    body.rtl .form-group {
        direction: rtl;
        text-align: right;
    }

    body.rtl .form-group label {
        text-align: right;
        width: 100%;
        display: block;
    }

    body.rtl .form-hint {
        text-align: right;
        direction: rtl;
    }
}

/* Responsive */
/* Tablet and below */
@media (max-width: 968px) {
    .monitor-grid {
        grid-template-columns: 1fr;
    }
    
    .unit-info-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
    
    .monitor-stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
}

/* Mobile devices */
@media (max-width: 768px) {
    body {
        padding: 12px;
        padding-top: max(12px, env(safe-area-inset-top, 12px));
        padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
        padding-left: max(12px, env(safe-area-inset-left, 12px));
        padding-right: max(12px, env(safe-area-inset-right, 12px));
        font-size: 14px;
    }

    .container {
        max-width: 100%;
    }

    .header {
        padding: 20px;
        margin-bottom: 16px;
    }

    .header-top {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }

    .header-text {
        width: 100%;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .header-actions {
        width: 100%;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        gap: 12px;
        margin-left: 0;
    }

    .header-text h1 {
        font-size: 22px;
    }

    .header-text .subtitle {
        font-size: 13px;
    }

    .card {
        padding: 20px;
        margin-bottom: 16px;
    }

    .card-title {
        font-size: 16px;
        margin-bottom: 16px;
    }

    .button-group {
        flex-direction: column;
        gap: 10px;
        margin-top: 24px;
        padding-top: 20px;
    }

    .button-group button {
        width: 100%;
        min-width: 100%;
    }

    .monitor-content {
        height: 300px;
    }

    .monitor-grid {
        gap: 16px;
        margin-top: 16px;
    }

    /* Language toggle in header - mobile */
    .lang-toggle {
        min-width: 85px;
        padding: 8px 14px;
        font-size: 12px;
        min-height: 36px;
    }

    .header-actions {
        flex-wrap: nowrap;
        gap: 10px;
        justify-content: flex-end;
    }

    .header-actions .status-badge {
        font-size: 11px;
        padding: 5px 10px;
    }

    .header-actions .testing-phase-badge {
        font-size: 10px;
        padding: 5px 10px;
        letter-spacing: 0.3px;
    }

    /* Better mobile form spacing */
    .form-group {
        margin-bottom: 20px;
    }

    .form-group-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .form-group-header label {
        min-width: 100%;
        width: 100%;
    }

    .form-group-header .btn-add-small {
        width: 100%;
        justify-content: center;
    }

    .entry-row {
        flex-direction: column;
        gap: 12px;
        padding: 16px;
    }

    .entry-row .entry-row-content {
        width: 100%;
    }

    .entry-row .btn-remove {
        margin-top: 0;
        width: 100%;
        align-self: stretch;
    }

    /* Unit search box on mobile */
    .unit-search-box {
        flex-direction: column !important;
        gap: 10px;
        direction: ltr; /* Normal order on mobile: button on top */
    }

    .unit-search-box input {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        flex: none !important;
        order: 2; /* Input appears second (below button) */
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        background: var(--surface) !important;
        border: 1px solid var(--border) !important;
        padding: 12px 16px !important;
        min-height: 44px !important;
        font-size: 16px !important;
        box-sizing: border-box !important;
        color: var(--text-primary) !important;
    }

    .unit-search-box .btn-search {
        width: 100% !important;
        order: 1; /* Button appears first (on top) */
        flex: none !important;
    }

    /* Tab navigation on mobile */
    .tab-navigation {
        flex-wrap: wrap;
        gap: 8px;
        padding: 4px;
        margin-bottom: 16px;
    }

    .tab-button {
        flex: 1;
        min-width: 0;
        font-size: 13px;
        padding: 10px 12px;
        min-height: 44px; /* Maintain touch target size */
    }

    /* Unit info grid on mobile */
    .unit-info-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .unit-info-item {
        padding: 14px;
    }

    /* Monitor stats grid on mobile */
    .monitor-stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .monitor-stat-item {
        padding: 12px 0;
    }

    .monitor-status-header {
        padding: 16px 20px;
        margin-bottom: 20px;
        padding-bottom: 16px;
        gap: 10px;
    }

    .monitor-status-title {
        font-size: 16px;
    }

    .monitor-status-badge {
        font-size: 11px;
        padding: 5px 10px;
    }

    .monitor-status-body {
        padding: 0;
    }

    /* Info boxes on mobile */
    .info-box {
        padding: 14px 16px;
        margin-bottom: 16px;
    }

    .info-box h4 {
        font-size: 13px;
        margin-bottom: 10px;
    }

    .info-box ul,
    .info-box ol {
        margin-left: 16px;
    }

    .info-box li {
        font-size: 12px;
        margin: 5px 0;
    }

    /* Footer on mobile */
    .footer {
        font-size: 12px;
        padding: 16px;
        margin-top: 16px;
    }

    /* Monitor log panel on mobile */
    .monitor-log-panel {
        margin-top: 16px;
    }

    .monitor-log-header {
        padding: 12px 16px;
        font-size: 13px;
    }

    .monitor-log-content {
        height: 250px;
        padding: 12px;
    }

    .monitor-log-entry {
        padding: 10px 14px;
        font-size: 12px;
        margin-bottom: 6px;
    }

    .monitor-log-time {
        font-size: 11px;
    }

    /* Tooltips on mobile - show on tap */
    .tooltip .tooltiptext {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        width: calc(100% - 40px);
        max-width: 300px;
        z-index: 1000;
    }

    /* Empty states on mobile */
    .empty-state {
        padding: 20px;
    }

    .empty-state .text {
        font-size: 13px;
    }

    /* Ensure inputs are 16px to prevent iOS zoom on all mobile devices */
    input[type="text"],
    input[type="number"],
    input[type="tel"],
    textarea {
        font-size: 16px !important; /* Prevents zoom on iOS */
        box-sizing: border-box;
        max-width: 100%;
    }

    /* Better word wrapping on mobile */
    * {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Prevent horizontal overflow */
    body, html, .container, .card {
        overflow-x: hidden;
        max-width: 100%;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    body {
        padding: 8px;
        padding-top: max(8px, env(safe-area-inset-top, 8px));
        padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
        padding-left: max(8px, env(safe-area-inset-left, 8px));
        padding-right: max(8px, env(safe-area-inset-right, 8px));
        font-size: 13px;
    }

    .header {
        padding: 16px;
    }

    .header-top {
        gap: 12px;
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
        gap: 8px;
    }

    .header-text h1 {
        font-size: 20px;
    }

    .lang-toggle {
        min-width: 75px;
        padding: 6px 10px;
        font-size: 11px;
    }

    .status-badge {
        font-size: 11px;
        padding: 4px 8px;
    }

    .card {
        padding: 16px;
    }

    .card-title {
        font-size: 15px;
    }

    .tab-button {
        font-size: 12px;
        padding: 8px 10px;
    }

    .monitor-content {
        height: 250px;
        padding: 12px;
    }

    .button-group {
        gap: 8px;
    }

    input[type="text"],
    input[type="number"],
    input[type="tel"],
    textarea {
        font-size: 16px !important; /* Prevents zoom on iOS - must be 16px minimum */
        padding: 12px 16px !important;
        min-height: 44px !important;
        /* Ensure proper sizing */
        box-sizing: border-box !important;
        max-width: 100% !important;
        width: 100% !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* Unit search box input - ensure visible */
    .unit-search-box input {
        font-size: 16px !important;
        padding: 12px 16px !important;
        min-height: 44px !important;
        width: 100% !important;
        min-width: 100% !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        background: var(--surface) !important;
        border: 1px solid var(--border) !important;
        box-sizing: border-box !important;
    }

    .form-hint {
        font-size: 12px;
    }

    .monitor-status-header {
        padding: 16px;
        margin-bottom: 16px;
        padding-bottom: 12px;
    }

    .monitor-status-title {
        font-size: 15px;
    }

    .monitor-status-body {
        padding: 0;
    }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .monitor-content {
        height: 200px;
    }
}

/* Monitor Status Display */
.monitor-status-display {
    margin-top: 25px;
}