body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: #f4f7f6;
    color: #333;
    margin: 0;
    line-height: 1.6;
    direction: rtl;
}

/* Header Styles */
header {
    background-color: #fff;
    padding: 1rem 2rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    margin: 0;
    font-size: 1.5rem;
    color: #005a8d;
}

/* New Brand Logo Styles */
.brand-logo {
    text-align: right;
}

.brand-logo .main-brand {
    display: block;
    font-size: 1.8em;
    font-weight: 700;
    color: #2c3e50;
    letter-spacing: 3px;
    line-height: 1.1;
}

.brand-logo .tagline {
    display: block;
    font-size: 0.8em;
    color: #7f8c8d;
    letter-spacing: 1px;
}


/* Main Content Styles */
main {
    padding: 2rem;
}

.container {
    background-color: #fff;
    border: 1px solid #ddd;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

h2 {
    border-bottom: 2px solid #eee;
    padding-bottom: 10px;
    margin-top: 0;
    color: #005a8d;
}

/* Device Card Styles */
.device-card {
    border: 1px solid #e0e0e0;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 8px;
    background-color: #fafafa;
}

.device-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.device-card-header h3 {
    margin: 0;
}

/* Relay Control Styles */
.relay-control-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 10px;
}

.relay-button {
    padding: 8px 12px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    color: white;
    transition: background-color 0.2s;
}

.relay-on { background-color: #28a745; }
.relay-off { background-color: #dc3545; }
.relay-on:hover { background-color: #218838; }
.relay-off:hover { background-color: #c82333; }

/* Form Styles */
.form-inline {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.form-inline input, .form-inline select, .form-inline button {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.form-inline input, .form-inline select {
    flex-grow: 1;
}

/* Settings Button and Modal Styles */
.settings-button {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 5px;
}

.modal {
    display: none; 
    position: fixed; 
    z-index: 1; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    overflow: auto; 
    background-color: rgba(0,0,0,0.4);
}

.modal-content {
    background-color: #fefefe;
    margin: 15% auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 500px;
    border-radius: 8px;
}

.close-button {
    color: #aaa;
    float: left; /* For RTL layout */
    font-size: 28px;
    font-weight: bold;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

#settings-form label {
    display: block;
    margin-top: 10px;
    text-align: right;
}

#settings-form input {
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
}

#settings-form button {
    width: 100%;
    padding: 10px;
    margin-top: 20px;
    background-color: #28a745;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

/* Login Page Specific Styles */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 4rem 1rem;
    gap: 2rem;
    flex-wrap: wrap;
}

.form-card {
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    width: 300px;
    text-align: center;
}

.form-card input {
    width: 100%;
    padding: 10px;
    margin-bottom: 1rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}

.form-card button {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 4px;
    background-color: #007bff;
    color: white;
    font-size: 1rem;
    cursor: pointer;
}
.form-card button:hover { background-color: #0056b3; }

.error-msg {
    color: #dc3545;
    margin-top: 10px;
    min-height: 1.2em;
}

.device-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.settings-device-button {
    padding: 7px 12px;
    border: none;
    border-radius: 5px;
    background-color: #0d6efd;
    color: #fff;
    cursor: pointer;
    font-weight: bold;
}

.settings-device-button:hover {
    background-color: #0b5ed7;
}

.delete-button {
    padding: 7px 12px;
    border: none;
    border-radius: 5px;
    background-color: #dc3545;
    color: #fff;
    cursor: pointer;
    font-weight: bold;
}

.delete-button:hover {
    background-color: #bb2d3b;
}

.device-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.settings-device-button {
    padding: 7px 12px;
    border: none;
    border-radius: 5px;
    background-color: #0d6efd;
    color: #fff;
    cursor: pointer;
    font-weight: bold;
}

.settings-device-button:hover {
    background-color: #0b5ed7;
}

.settings-modal-content {
    max-width: 850px;
    width: 90%;
    margin: 5% auto;
    direction: rtl;
}

.settings-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #eee;
    margin-bottom: 12px;
}

.settings-modal-header h2 {
    border-bottom: none;
    margin: 0;
}

.settings-tabs {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid #ddd;
    margin-bottom: 16px;
}

.settings-tab {
    background: transparent;
    border: none;
    padding: 10px 16px;
    cursor: pointer;
    color: #555;
    font-weight: bold;
    border-bottom: 3px solid transparent;
}

.settings-tab.active {
    color: #0d6efd;
    border-bottom-color: #0d6efd;
}

.settings-tab-content {
    display: none;
}

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

.info-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 12px;
    border-bottom: 1px solid #eee;
}

.settings-help {
    background: #eef6ff;
    color: #0d4f8b;
    border: 1px solid #b8dcff;
    padding: 10px;
    border-radius: 6px;
}

.relay-settings-row {
    display: grid;
    grid-template-columns: 100px 1fr 2fr;
    gap: 12px;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;
}

.relay-settings-row select {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 5px;
}

.relay-mode-description {
    color: #666;
    font-size: 0.9rem;
}

.settings-modal-footer {
    display: flex;
    justify-content: flex-start;
    gap: 10px;
    margin-top: 20px;
    border-top: 1px solid #eee;
    padding-top: 16px;
}

.save-settings-button {
    padding: 10px 18px;
    border: none;
    border-radius: 5px;
    background-color: #0d6efd;
    color: #fff;
    cursor: pointer;
    font-weight: bold;
}

.cancel-settings-button {
    padding: 10px 18px;
    border: 1px solid #ccc;
    border-radius: 5px;
    background-color: #f8f9fa;
    color: #333;
    cursor: pointer;
}

@media (max-width: 700px) {
    .relay-settings-row {
        grid-template-columns: 1fr;
    }

    .settings-tabs {
        flex-direction: column;
    }

    .settings-modal-footer {
        flex-direction: column;
    }
}
