/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
}

header h1 {
    color: #667eea;
    font-size: 24px;
}

nav {
    display: flex;
    gap: 20px;
}

nav a {
    color: #333;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: 4px;
    transition: background 0.3s;
}

nav a:hover {
    background: #f0f0f0;
}

.user-info {
    font-size: 14px;
    color: #666;
}

/* Pages */
.page {
    display: none;
    animation: fadeIn 0.3s;
}

.page.active {
    display: block;
}

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

/* Auth Container */
.auth-container {
    max-width: 400px;
    margin: 100px auto;
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.auth-container h2 {
    margin-bottom: 10px;
    color: #667eea;
}

.auth-container p {
    margin-bottom: 20px;
    color: #666;
    font-size: 14px;
}

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

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #333;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    transition: border 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: #667eea;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-block;
    text-decoration: none;
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
    margin-left: 10px;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 10px;
}

.btn-small:hover {
    background: #5568d3;
}

/* Cards */
.card {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.card h3 {
    margin-bottom: 15px;
    color: #667eea;
}

/* Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

#user-details {
    line-height: 2;
}

#user-details strong {
    color: #667eea;
}

/* Commands Grid */
.commands-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.command-card {
    background: white;
    padding: 25px;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.command-card h3 {
    color: #667eea;
    margin-bottom: 10px;
}

.command-card p {
    color: #666;
    font-size: 14px;
    margin-bottom: 20px;
}

/* Command Output */
.command-output {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    margin-top: 30px;
}

.output-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
}

.output-header span {
    font-weight: bold;
    font-size: 16px;
}

.exit-code {
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 14px;
}

.exit-code.success {
    background: #d4edda;
    color: #155724;
}

.exit-code.error {
    background: #f8d7da;
    color: #721c24;
}

.output-section {
    margin-bottom: 20px;
}

.output-section h4 {
    margin-bottom: 10px;
    color: #667eea;
    font-size: 14px;
    text-transform: uppercase;
}

.output-section pre {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 5px;
    border-left: 4px solid #667eea;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
    max-height: 300px;
    overflow-y: auto;
}

/* Token Display */
.token-display {
    margin-bottom: 20px;
}

.token-display h4 {
    margin-bottom: 10px;
    color: #667eea;
}

.token-value {
    display: flex;
    align-items: center;
    background: #f8f9fa;
    padding: 15px;
    border-radius: 5px;
    border-left: 4px solid #667eea;
}

.token-value code {
    flex: 1;
    font-family: 'Courier New', monospace;
    word-break: break-all;
    font-size: 13px;
}

/* Messages */
.error-message {
    color: #dc3545;
    font-size: 14px;
    margin-top: 10px;
    display: none;
}

.error-message.show {
    display: block;
}

.warning {
    background: #fff3cd;
    border-left: 4px solid #ffc107;
    padding: 10px 15px;
    margin-top: 20px;
    border-radius: 4px;
    color: #856404;
    font-size: 14px;
}

.info-message {
    padding: 10px 15px;
    border-radius: 4px;
    font-size: 14px;
    display: none;
}

.info-message.success {
    background: #d4edda;
    border-left: 4px solid #28a745;
    color: #155724;
}

.info-message.error {
    background: #f8d7da;
    border-left: 4px solid #dc3545;
    color: #721c24;
}

.auth-link {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
}

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

.auth-link a:hover {
    text-decoration: underline;
}

/* Loading State */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: "...";
    animation: dots 1.5s infinite;
}

@keyframes dots {
    0%, 20% { content: "."; }
    40% { content: ".."; }
    60%, 100% { content: "..."; }
}

/* Card Header */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #f0f0f0;
}

/* Systems and Agents Lists */
.systems-list,
.agents-list {
    display: grid;
    gap: 15px;
}

.system-item,
.agent-item {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 5px;
    border-left: 4px solid #667eea;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s;
}

.system-item:hover,
.agent-item:hover {
    background: #e9ecef;
    transform: translateX(5px);
}

.system-item.selected {
    background: #e7f3ff;
    border-left-color: #0066cc;
}

.system-info,
.agent-info {
    flex: 1;
}

.system-info h4,
.agent-info h4 {
    margin: 0 0 5px 0;
    color: #333;
}

.system-info p,
.agent-info p {
    margin: 0;
    color: #666;
    font-size: 14px;
}

.system-actions,
.agent-actions {
    display: flex;
    gap: 10px;
}

.status-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    margin-left: 10px;
}

.status-badge.active {
    background: #d4edda;
    color: #155724;
}

.status-badge.inactive {
    background: #f8d7da;
    color: #721c24;
}

.status-badge.error {
    background: #fff3cd;
    color: #856404;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

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

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

.close {
    float: right;
    font-size: 28px;
    font-weight: bold;
    color: #999;
    cursor: pointer;
    line-height: 20px;
}

.close:hover {
    color: #333;
}

.modal-content h3 {
    color: #667eea;
    margin-bottom: 20px;
}

.modal-content textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
}

.modal-content select {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    background: white;
}

.modal-error {
    color: #dc3545;
    font-size: 14px;
    margin: 10px 0;
    display: none;
}

.modal-error.show {
    display: block;
}

/* Properties Management */
.form-row {
    display: grid;
    grid-template-columns: 2fr 3fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.properties-list {
    display: grid;
    gap: 15px;
}

.property-item {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 5px;
    border-left: 4px solid #667eea;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    transition: all 0.3s;
}

.property-item:hover {
    background: #e9ecef;
    transform: translateX(5px);
}

.property-info {
    flex: 1;
}

.property-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.property-header h4 {
    margin: 0;
    color: #333;
    font-size: 16px;
}

.property-type-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    background: #e7f3ff;
    color: #0066cc;
}

.property-value {
    margin-bottom: 10px;
    background: white;
    padding: 10px;
    border-radius: 4px;
    border: 1px solid #dee2e6;
}

.property-value code {
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #333;
    word-break: break-all;
}

.property-meta {
    margin: 0;
    color: #999;
    font-size: 12px;
}

.property-meta small {
    margin-right: 10px;
}

.property-actions {
    display: flex;
    gap: 10px;
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
}

/* Responsive */
@media (max-width: 768px) {
    header .container {
        flex-direction: column;
        gap: 15px;
    }

    nav {
        flex-wrap: wrap;
        justify-content: center;
    }

    .auth-container {
        margin: 50px 20px;
        padding: 30px 20px;
    }

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

    .system-item,
    .agent-item,
    .property-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .modal-content {
        padding: 20px;
    }
}

/* Decision Logs Modal */
.modal-large {
    max-width: 900px;
    width: 95%;
}

.decision-logs-container {
    max-height: 70vh;
    overflow-y: auto;
}

.decision-log-item {
    background: #f8f9fa;
    border-left: 4px solid #667eea;
    border-radius: 5px;
    margin-bottom: 15px;
    overflow: hidden;
}

.log-header {
    background: #e9ecef;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #dee2e6;
}

.log-header strong {
    color: #667eea;
}

.log-header small {
    color: #666;
}

.log-content {
    padding: 15px;
}

.log-content pre {
    margin: 0;
    background: white;
    padding: 15px;
    border-radius: 4px;
    overflow-x: auto;
    font-size: 12px;
    line-height: 1.4;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #dee2e6;
}

/* Inbox Styles */
.badge {
    display: inline-block;
    background: #dc3545;
    color: white;
    font-size: 11px;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 5px;
    vertical-align: middle;
}

.inbox-filters {
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.inbox-filters label {
    font-weight: 500;
    margin-right: 5px;
    color: #333;
}

.inbox-filters select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.inbox-list {
    display: grid;
    gap: 15px;
}

.inbox-item {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 5px;
    border-left: 4px solid #667eea;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.inbox-item:hover {
    background: #e9ecef;
    transform: translateX(5px);
}

.inbox-item.unread {
    background: #e7f3ff;
    border-left-color: #0066cc;
    font-weight: 500;
}

.inbox-item.read {
    background: #f8f9fa;
    border-left-color: #6c757d;
}

.inbox-item.archived {
    background: #f5f5f5;
    border-left-color: #999;
    opacity: 0.7;
}

.inbox-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.inbox-item-title {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.inbox-item-title h4 {
    margin: 0;
    color: #333;
    font-size: 16px;
}

.message-type-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
}

.message-type-badge.action-required {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
}

.message-type-badge.notification {
    background: #d4edda;
    color: #155724;
    border: 1px solid #28a745;
}

.inbox-status-badge {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
}

.inbox-status-badge.unread {
    background: #e7f3ff;
    color: #0066cc;
}

.inbox-status-badge.read {
    background: #e9ecef;
    color: #6c757d;
}

.inbox-status-badge.archived {
    background: #f5f5f5;
    color: #999;
}

.inbox-item-meta {
    color: #666;
    font-size: 13px;
}

.inbox-item-message {
    color: #555;
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Message Modal */
.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.modal-actions button {
    flex: 1;
    min-width: 100px;
}

.message-modal-content {
    background: white;
    padding: 30px;
    border-radius: 10px;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.message-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    gap: 10px;
}

.message-modal-header h3 {
    color: #667eea;
    margin: 0;
    flex: 1;
}

.message-modal-badges {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
}

.message-modal-body {
    margin-bottom: 20px;
}

.message-modal-body p {
    line-height: 1.6;
    color: #333;
    margin-bottom: 15px;
}

.message-event-data {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 5px;
    border-left: 4px solid #667eea;
    margin-top: 15px;
}

.message-event-data h4 {
    color: #667eea;
    font-size: 14px;
    margin: 0 0 10px 0;
    text-transform: uppercase;
}

.message-event-data pre {
    margin: 0;
    background: white;
    padding: 10px;
    border-radius: 4px;
    overflow-x: auto;
    font-size: 12px;
    line-height: 1.4;
}

.message-meta {
    color: #999;
    font-size: 12px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
}

.btn-approve {
    background: #28a745;
    color: white;
}

.btn-approve:hover {
    background: #218838;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(40, 167, 69, 0.4);
}

.btn-reject {
    background: #dc3545;
    color: white;
}

.btn-reject:hover {
    background: #c82333;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(220, 53, 69, 0.4);
}

.btn-close {
    background: #6c757d;
    color: white;
}

.btn-close:hover {
    background: #5a6268;
}

/* Empty state for inbox */
.inbox-empty {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.inbox-empty svg,
.inbox-empty i {
    font-size: 48px;
    margin-bottom: 15px;
    opacity: 0.3;
}

.inbox-empty h3 {
    color: #999;
    font-size: 18px;
    margin-bottom: 10px;
}

.inbox-empty p {
    color: #bbb;
    font-size: 14px;
}

/* Responsive adjustments for inbox */
@media (max-width: 768px) {
    .inbox-item-header {
        flex-direction: column;
    }

    .inbox-filters {
        flex-direction: column;
    }

    .inbox-filters select {
        width: 100%;
    }

    .modal-actions {
        flex-direction: column;
    }

    .modal-actions button {
        width: 100%;
    }
}

/* Billing Styles */
.billing-section {
    margin-bottom: 30px;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    overflow: hidden;
}

.billing-responsibility {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white !important;
    padding: 15px 20px;
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.billing-items {
    padding: 20px;
    background: white;
}

.billing-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: #f8f9fa;
    border-radius: 5px;
    margin-bottom: 10px;
    border-left: 4px solid #667eea;
    gap: 15px;
}

.billing-item:last-child {
    margin-bottom: 0;
}

.billing-code {
    flex: 2;
    color: #333;
    font-size: 14px;
}

.billing-item-count {
    flex: 0 0 120px;
    color: #666;
    font-size: 14px;
    text-align: center;
}

.billing-fee {
    flex: 0 0 150px;
    color: #667eea;
    font-size: 16px;
    font-weight: 600;
    text-align: right;
}

.billing-subtotal {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 2px solid #dee2e6;
    text-align: right;
    font-size: 16px;
    color: #333;
}

.billing-grand-total {
    margin-top: 30px;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 8px;
    text-align: center;
}

.billing-grand-total h3 {
    color: white;
    margin: 0;
    font-size: 24px;
    font-weight: 700;
}

/* Responsive billing styles */
@media (max-width: 768px) {
    .billing-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .billing-fee {
        align-self: flex-end;
    }

    .billing-grand-total h3 {
        font-size: 20px;
    }
}
