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

/* Modal Overlay Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

html, body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 10px; /* Mobile first - will be overridden for desktop */
    direction: rtl;
    overflow-x: hidden !important; /* Prevent horizontal scroll */
    max-width: 100vw;
    width: 100%;
    margin: 0;
    box-sizing: border-box;
}

* {
    box-sizing: border-box;
}

/* Desktop padding */
@media (min-width: 769px) {
    body {
        padding: 20px;
    }
}

#app {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
}

.container {
    max-width: 100%; /* Mobile first */
    width: 100%; /* Mobile first - full width */
    margin: 0 auto;
    background: white;
    border-radius: 8px; /* Mobile first */
    padding: 20px 15px; /* Mobile first */
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    overflow-x: hidden;
}

/* Desktop container */
@media screen and (min-width: 769px) {
    .container {
        max-width: 600px;
        width: auto;
        border-radius: 10px;
        padding: 30px;
    }
}

.screen {
    display: none !important;
    width: 100%;
    max-width: 100%;
}

.screen.active {
    display: block !important;
}

#dashboard-screen {
    width: 100%;
    max-width: 100%;
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
}

h2 {
    color: #555;
    margin-bottom: 20px;
    font-size: 1.5em;
}

h3 {
    color: #666;
    margin-bottom: 15px;
    font-size: 1.2em;
}

.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 5px;
    color: #555;
    font-weight: 500;
}

input[type="text"],
input[type="tel"],
input[type="file"],
select {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
    transition: border-color 0.3s;
}

input:focus,
select:focus {
    outline: none;
    border-color: #667eea;
}

.btn-primary,
.btn-secondary {
    padding: 12px 24px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    transition: background-color 0.3s;
    width: 100%;
    margin-top: 10px;
}

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

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

.btn-secondary {
    background: #f0f0f0;
    color: #333;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.form-group .btn-secondary {
    width: auto;
    margin-top: 5px;
    margin-right: 10px;
}

.card {
    background: #f9f9f9;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #eee;
    position: relative;
}

#logout-btn {
    position: absolute;
    left: 0;
    top: 0;
}

#user-info {
    background: #e8f4f8;
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 20px;
}

#user-info p {
    margin: 5px 0;
    color: #555;
}

#users-list,
#devices-list {
    margin-top: 20px;
}

.user-item,
.device-item {
    background: white;
    padding: 15px;
    border-radius: 5px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
}

.user-item h4,
.device-item h4 {
    margin-bottom: 10px;
    color: #333;
}

.user-item p,
.device-item p {
    color: #666;
    font-size: 14px;
    margin: 5px 0;
}

.error {
    background: #fee;
    color: #c33;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 15px;
}

.success {
    background: #efe;
    color: #3c3;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 15px;
}

.hidden {
    display: none;
}

#contacts-preview {
    margin-top: 15px;
    max-height: 200px;
    overflow-y: auto;
    background: white;
    padding: 10px;
    border-radius: 5px;
}

.contact-item {
    padding: 5px;
    border-bottom: 1px solid #eee;
}

#contacts-list {
    max-height: 300px;
    overflow-y: auto;
}

#contacts-list .contact-item {
    transition: background-color 0.2s;
}

#contacts-list .contact-item:hover {
    background-color: #f5f5f5;
}

.remove-contact-btn:hover {
    opacity: 0.8;
}

a {
    color: #667eea;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

#settlement-map {
    border: 2px solid #ddd;
}

.pac-container {
    direction: rtl;
    text-align: right;
    z-index: 10003 !important; /* Higher than modal z-index */
}

.pac-item {
    padding: 10px;
    cursor: pointer;
}

.pac-item:hover {
    background-color: #f0f0f0;
}

#selected-settlement-info {
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.7);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 10px rgba(102, 126, 234, 0);
    }
}

/* reCAPTCHA containers - hidden but present for invisible reCAPTCHA */
#recaptcha-container,
#recaptcha-container-register {
    position: absolute !important;
    left: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    visibility: hidden !important;
}

/* ============================================
   RESPONSIVE DESIGN - MOBILE & DESKTOP
   ============================================ */

/* Mobile First - Base styles for mobile */
@media screen and (max-width: 768px) {
    html, body {
        padding: 0 !important;
        margin: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
        position: relative;
    }
    
    #app {
        width: 100vw !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .container {
        max-width: 100% !important;
        width: 100% !important;
        padding: 20px 15px !important;
        border-radius: 0 !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }
    
    h1 {
        font-size: 1.5em;
        margin-bottom: 20px;
    }
    
    h2 {
        font-size: 1.3em;
        margin-bottom: 15px;
    }
    
    h3 {
        font-size: 1.1em;
        margin-bottom: 10px;
    }
    
    .form-group {
        margin-bottom: 15px;
    }
    
    input[type="text"],
    input[type="tel"],
    input[type="file"],
    select,
    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 10px;
    }
    
    .btn-primary,
    .btn-secondary {
        padding: 12px 20px;
        font-size: 16px;
    }
    
    .card {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        padding-bottom: 15px;
    }
    
    header h1 {
        width: 100%;
        margin-bottom: 0;
    }
    
    #user-info {
        padding: 12px;
    }
    
    /* Modal adjustments for mobile */
    #load-contacts-modal > div,
    #role-selection-modal > div {
        max-width: 95%;
        padding: 20px 15px;
        max-height: 95vh;
    }
    
    /* QR code smaller on mobile */
    #qr-code-container img {
        width: 150px !important;
        height: 150px !important;
    }
    
    /* Map adjustments */
    #settlement-map {
        height: 300px !important;
    }
    
    /* Contacts list */
    #contacts-list {
        max-height: 200px;
    }
    
    /* Settlement autocomplete */
    #settlement-autocomplete {
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    /* Country code selector */
    #login-country-code,
    #register-country-code {
        font-size: 14px;
        padding: 8px;
    }
    
    /* Dashboard sections */
    #admin-sections {
        margin-top: 15px;
    }
    
    /* Device form */
    #add-device-form .form-group {
        margin-bottom: 15px;
    }
}

/* Tablet - Medium screens */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        max-width: 700px;
        padding: 25px;
    }
    
    #load-contacts-modal > div,
    #role-selection-modal > div {
        max-width: 600px;
    }
    
    #settlement-map {
        height: 400px !important;
    }
}

/* Desktop - Large screens */
@media (min-width: 1025px) {
    body {
        padding: 30px;
    }
    
    .container {
        max-width: 900px;
        padding: 40px;
    }
    
    /* Dashboard layout - two columns on desktop */
    #dashboard-screen {
        display: grid;
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    #admin-sections {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }
    
    #admin-sections > section {
        margin-bottom: 0;
    }
    
    /* Modal larger on desktop */
    #load-contacts-modal > div,
    #role-selection-modal > div {
        max-width: 600px;
        padding: 40px;
    }
    
    /* Map larger on desktop */
    #settlement-map {
        height: 500px !important;
    }
    
    /* Contacts list taller on desktop */
    #contacts-list {
        max-height: 400px;
    }
    
    /* Form groups side by side where appropriate */
    .form-group-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 15px;
    }
    
    /* Header with more space */
    header {
        padding-bottom: 25px;
    }
}

/* Very large screens */
@media (min-width: 1400px) {
    .container {
        max-width: 1200px;
    }
    
    #admin-sections {
        grid-template-columns: 1fr 1fr 1fr;
    }
}

/* Landscape mobile */
@media (max-width: 768px) and (orientation: landscape) {
    body {
        padding: 5px;
    }
    
    .container {
        padding: 15px 10px;
    }
    
    #settlement-map {
        height: 250px !important;
    }
    
    #contacts-list {
        max-height: 150px;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    .btn-primary,
    .btn-secondary {
        min-height: 44px; /* iOS recommended touch target */
    }
    
    input[type="text"],
    input[type="tel"],
    select {
        min-height: 44px;
    }
    
    /* Remove hover effects on touch devices */
    .btn-primary:hover,
    .btn-secondary:hover {
        opacity: 1;
    }
}

/* Country code selector responsive */
@media (max-width: 768px) {
    #login-country-code,
    #register-country-code {
        width: 100px !important;
        font-size: 12px;
        padding: 8px 4px;
    }
    
    #login-phone,
    #register-phone {
        flex: 1;
        min-width: 0;
    }
}

/* Modal buttons responsive */
@media (max-width: 768px) {
    #role-selection-modal .btn-primary,
    #role-selection-modal .btn-secondary {
        width: 100%;
        margin-top: 10px;
    }
    
    #load-contacts-modal button {
        font-size: 14px;
        padding: 12px;
    }
}

/* Dashboard header responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.3em;
    }
    
    #logout-btn {
        width: 100%;
        margin-top: 10px;
    }
}

/* Form inputs responsive */
@media (max-width: 768px) {
    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 100px;
    }
    
    #manual-contacts-modal {
        font-size: 16px;
    }
}

/* Print styles */
@media print {
    body {
        background: white;
        padding: 0;
    }
    
    .screen:not(.active) {
        display: none !important;
    }
    
    .btn-primary,
    .btn-secondary,
    button {
        display: none;
    }
}

/* Toast Notification Styles */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    max-width: 400px;
}

.toast {
    background: white;
    border-radius: 8px;
    padding: 16px 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    max-width: 400px;
    pointer-events: auto;
    animation: slideInRight 0.3s ease-out;
    border-right: 4px solid #667eea;
}

.toast.success {
    border-right-color: #4caf50;
}

.toast.error {
    border-right-color: #f44336;
}

.toast.warning {
    border-right-color: #ff9800;
}

.toast.info {
    border-right-color: #2196f3;
}

.toast-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.toast-content {
    flex: 1;
    color: #333;
    font-size: 14px;
    line-height: 1.5;
}

.toast-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.toast-close:hover {
    color: #333;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.fade-out {
    animation: slideOutRight 0.3s ease-out forwards;
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Confirm Dialog Styles */
.confirm-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

.confirm-dialog {
    background: white;
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    animation: slideUp 0.3s ease-out;
}

.confirm-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 12px;
    color: #333;
}

.confirm-message {
    font-size: 14px;
    color: #666;
    margin-bottom: 20px;
    line-height: 1.5;
}

.confirm-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.confirm-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

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

.confirm-btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.confirm-btn-secondary {
    background: #f5f5f5;
    color: #333;
}

.confirm-btn-secondary:hover {
    background: #e0e0e0;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

@media (max-width: 768px) {
    #toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .toast {
        min-width: auto;
        max-width: none;
    }
    
    .confirm-dialog {
        margin: 20px;
        width: calc(100% - 40px);
    }
}

