* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #25D366;
    --primary-dark: #1da851;
    --secondary: #128C7E;
    --danger: #dc3545;
    --warning: #ffc107;
    --success: #28a745;
    --dark: #1e1e1e;
    --gray: #6c757d;
    --light-gray: #f8f9fa;
    --border: #dee2e6;
    --white: #ffffff;
    --shadow: 0 2px 10px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--light-gray);
    color: var(--dark);
    line-height: 1.6;
}

/* Screens */
.screen {
    display: none;
}

.screen.active {
    display: block;
}

/* Login Screen */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
}

.login-box {
    background: var(--white);
    padding: 40px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    text-align: center;
    margin-bottom: 10px;
    color: var(--dark);
}

.subtitle {
    text-align: center;
    color: var(--gray);
    margin-bottom: 30px;
    font-size: 0.9em;
}

/* Dashboard Layout */
#dashboard-screen {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 250px;
    background: var(--dark);
    color: var(--white);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
    font-size: 1.2em;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    transition: all 0.3s;
}

.nav-item:hover {
    background: rgba(255,255,255,0.1);
    color: var(--white);
}

.nav-item.active {
    background: var(--primary);
    color: var(--white);
}

.nav-item .icon {
    margin-right: 10px;
    font-size: 1.2em;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.user-info {
    display: flex;
    flex-direction: column;
    margin-bottom: 10px;
}

.user-info .small {
    font-size: 0.8em;
    color: rgba(255,255,255,0.6);
}

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
}

.page {
    display: none;
}

.page.active {
    display: block;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
}

.page-header h1 {
    font-size: 2em;
}

.page-header p {
    color: var(--gray);
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--dark);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 1em;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group small {
    display: block;
    margin-top: 5px;
    color: var(--gray);
    font-size: 0.85em;
}

.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.checkbox-label input {
    width: auto;
    margin-right: 8px;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s;
    background: var(--gray);
    color: var(--white);
}

.btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.btn-small {
    padding: 8px 15px;
    font-size: 0.9em;
}

.btn-block {
    width: 100%;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--white);
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
}

.stat-icon {
    font-size: 2.5em;
    margin-right: 15px;
}

.stat-info h3 {
    font-size: 2em;
    margin-bottom: 5px;
}

.stat-info p {
    color: var(--gray);
    font-size: 0.9em;
}

/* Cards Grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.card {
    background: var(--white);
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.card-header h3 {
    font-size: 1.2em;
}

.card-body {
    margin-bottom: 15px;
}

.card-body p {
    margin: 5px 0;
    color: var(--gray);
}

.card-footer {
    display: flex;
    gap: 10px;
    padding-top: 15px;
    border-top: 1px solid var(--border);
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 500;
}

.status-connected {
    background: #d4edda;
    color: #155724;
}

.status-disconnected {
    background: #f8d7da;
    color: #721c24;
}

.status-qr_ready {
    background: #fff3cd;
    color: #856404;
}

.status-active {
    background: #d4edda;
    color: #155724;
}

.status-inactive {
    background: #e2e3e5;
    color: #383d41;
}

/* Quick Actions */
.quick-actions {
    margin-top: 30px;
}

.quick-actions h2 {
    margin-bottom: 20px;
}

.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.action-card {
    background: var(--white);
    padding: 30px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    border: none;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.action-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
}

.action-icon {
    font-size: 3em;
    margin-bottom: 10px;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    overflow-y: auto;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: var(--white);
    padding: 30px;
    border-radius: 10px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large {
    max-width: 700px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2em;
    cursor: pointer;
    color: var(--gray);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* QR Code */
.qrcode-container {
    text-align: center;
}

.qrcode-instructions {
    text-align: left;
    background: #e7f9ef;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    border-left: 4px solid var(--primary);
}

.qrcode-instructions h3 {
    color: var(--primary);
    margin-bottom: 10px;
}

.qrcode-instructions ol {
    margin-left: 20px;
    line-height: 1.8;
}

.qrcode-instructions li {
    margin-bottom: 5px;
}

.qrcode-display {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
    background: var(--light-gray);
    border-radius: 10px;
    padding: 20px;
}

.qrcode-display img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

.qrcode-tip {
    margin-top: 15px;
    font-size: 0.9em;
    color: var(--gray);
    font-style: italic;
}

.spinner {
    border: 4px solid var(--light-gray);
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Messages */
.messages-container {
    background: var(--white);
    padding: 20px;
    border-radius: 10px;
    box-shadow: var(--shadow);
}

.stats-row {
    display: flex;
    gap: 20px;
    margin: 20px 0;
}

.stat-item {
    flex: 1;
    text-align: center;
    padding: 15px;
    background: var(--light-gray);
    border-radius: 5px;
}

.stat-item h4 {
    font-size: 1.5em;
    margin-bottom: 5px;
}

.stat-item p {
    color: var(--gray);
    font-size: 0.9em;
}

.messages-list {
    margin-top: 20px;
}

.message-item {
    padding: 15px;
    border-bottom: 1px solid var(--border);
}

.message-item:last-child {
    border-bottom: none;
}

.message-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.message-sender {
    font-weight: 500;
}

.message-time {
    color: var(--gray);
    font-size: 0.85em;
}

.message-text {
    color: var(--gray);
}

.message-direction-incoming {
    border-left: 3px solid var(--primary);
    padding-left: 12px;
}

.message-direction-outgoing {
    border-left: 3px solid var(--secondary);
    padding-left: 12px;
}

/* Flows */
.flows-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.flow-tree {
    background: var(--white);
    border-radius: 10px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.flow-main {
    padding: 20px;
    border-left: 4px solid var(--primary);
}

.flow-main.has-menu {
    border-left-color: var(--secondary);
}

.flow-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
}

.flow-title {
    flex: 1;
}

.flow-title h3 {
    font-size: 1.2em;
    margin-bottom: 5px;
}

.flow-badges {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 5px;
}

.flow-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8em;
    font-weight: 500;
}

.flow-badge.menu {
    background: #e3f2fd;
    color: #1976d2;
}

.flow-badge.simple {
    background: #f3e5f5;
    color: #7b1fa2;
}

.flow-actions {
    display: flex;
    gap: 8px;
}

.flow-details {
    margin: 15px 0;
}

.flow-details p {
    margin: 8px 0;
    color: var(--gray);
}

.flow-details strong {
    color: var(--dark);
}

.flow-triggers {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 5px;
}

.trigger-tag {
    background: var(--light-gray);
    padding: 4px 10px;
    border-radius: 15px;
    font-size: 0.85em;
    color: var(--dark);
}

.flow-response {
    background: var(--light-gray);
    padding: 12px;
    border-radius: 5px;
    margin-top: 10px;
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.95em;
    color: var(--dark);
}

.sub-flows {
    background: #f8f9fa;
    border-top: 1px solid var(--border);
}

.sub-flows-header {
    padding: 12px 20px;
    background: #e9ecef;
    font-weight: 500;
    color: var(--dark);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sub-flow-item {
    padding: 15px 20px 15px 40px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.sub-flow-item:last-child {
    border-bottom: none;
}

.sub-flow-item::before {
    content: '└─';
    position: absolute;
    left: 20px;
    color: var(--gray);
}

.sub-flow-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

.info-box {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.info-box h3 {
    margin-bottom: 10px;
    font-size: 1.1em;
}

.info-box p {
    margin: 8px 0;
    opacity: 0.95;
}

.info-box code {
    background: rgba(255,255,255,0.2);
    padding: 2px 8px;
    border-radius: 3px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

/* Settings */
.settings-container {
    background: var(--white);
    padding: 30px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    max-width: 600px;
}

.settings-section {
    margin-bottom: 30px;
}

.settings-section h2 {
    margin-bottom: 20px;
}

/* Error Messages */
.error-message {
    color: var(--danger);
    margin-top: 10px;
    padding: 10px;
    border-radius: 5px;
    background: #f8d7da;
    display: none;
}

.error-message.active {
    display: block;
}

.success-message {
    color: var(--success);
    margin-top: 10px;
    padding: 10px;
    border-radius: 5px;
    background: #d4edda;
    display: none;
}

.success-message.active {
    display: block;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--gray);
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray);
}

.empty-state .icon {
    font-size: 4em;
    margin-bottom: 20px;
}

/* Responsive */
@media (max-width: 768px) {
    #dashboard-screen {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
    }

    .sidebar-nav {
        display: flex;
        flex-wrap: wrap;
    }

    .nav-item {
        flex: 1;
        min-width: 120px;
        justify-content: center;
    }

    .main-content {
        padding: 15px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-header button {
        margin-top: 15px;
    }

    .stats-grid,
    .cards-grid,
    .actions-grid {
        grid-template-columns: 1fr;
    }
}
