/* ===== CSS Variables ===== */
:root {
    --primary-color: #ff6b35;
    --primary-hover: #e85a2a;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f8fafc;
    --sidebar-bg: #2d2d2d;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 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);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
}

/* ===== Global Links ===== */
a {
    color: var(--primary-color);
    text-decoration: none;
}

a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* ===== Auth Page ===== */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #ff6b35 0%, #ff8c42 100%);
}

.auth-container {
    width: 100%;
    max-width: 450px;
    padding: 20px;
}

.auth-box {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.auth-header {
    padding: 32px;
    text-align: center;
    background: white;
    color: var(--text-primary);
}

.auth-header h1 {
    font-size: 28px;
    margin-bottom: 8px;
}

.auth-header p {
    opacity: 0.7;
    font-size: 14px;
    color: var(--text-secondary);
}

.auth-header a {
    display: inline-block;
    text-decoration: none;
}

.auth-logo {
    max-width: 200px;
    height: auto;
    margin-bottom: 16px;
    transition: opacity 0.2s;
}

.auth-logo:hover {
    opacity: 0.8;
}

.auth-tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
}

.tab-btn {
    flex: 1;
    padding: 16px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.auth-form {
    display: none;
    padding: 32px;
}

.auth-form.active {
    display: block;
}

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

.auth-footer a {
    color: white;
    text-decoration: none;
    transition: opacity 0.2s;
}

.auth-footer a:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.auth-footer .separator {
    color: white;
    margin: 0 12px;
    opacity: 0.6;
}

/* ===== App Layout ===== */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    color: white;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 24px 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px;
}

.sidebar-header a {
    display: block;
    text-decoration: none;
}

.sidebar-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.sidebar-logo {
    width: 230px;
    height: auto;
    display: block;
    filter: brightness(0) invert(1);
    transition: opacity 0.2s;
}

.sidebar-logo:hover {
    opacity: 0.8;
}

.sidebar-nav {
    padding: 16px 0;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 24px;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    transition: all 0.2s;
    font-size: 15px;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: white;
}

.nav-item.active {
    background: rgba(37, 99, 235, 0.2);
    color: white;
    border-left: 3px solid var(--primary-color);
}

.nav-item .icon {
    margin-right: 12px;
    font-size: 18px;
}

.sidebar-nav hr {
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin: 16px 0;
}

.sidebar-footer {
    padding: 20px 24px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    font-size: 12px;
    margin-top: auto;
}

.sidebar-footer a {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    transition: color 0.2s;
}

.sidebar-footer a:hover {
    color: white;
    text-decoration: underline;
}

.sidebar-footer .separator {
    color: rgba(255, 255, 255, 0.5);
    margin: 0 8px;
}

.main-content {
    flex: 1;
    margin-left: 250px;
    padding: 32px;
    max-width: 1400px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.page-header h1 {
    font-size: 32px;
    font-weight: 700;
}

.user-info {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ===== Cards ===== */
.card {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}

.card h3 {
    margin-bottom: 16px;
    font-size: 18px;
    font-weight: 600;
}

/* ===== Buttons ===== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

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

.btn-danger {
    background: var(--danger-color);
    color: white;
}

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

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

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

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

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group small {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.form-group small a {
    color: var(--primary-color);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    font-weight: normal;
}

/* Checkbox Styling */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    max-width: 20px;
    max-height: 20px;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    position: relative;
    transition: all 0.2s;
    background: white;
    margin: 0;
    vertical-align: middle;
    flex-shrink: 0;
    aspect-ratio: 1 / 1;
    display: inline-block;
}

input[type="checkbox"]:hover {
    border-color: var(--primary-color);
}

input[type="checkbox"]:checked {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    color: white;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.checkbox-label input[type="checkbox"] {
    margin-top: 3px;
}

.error-message {
    color: var(--danger-color);
    font-size: 14px;
    margin-top: 10px;
    padding: 12px;
    background: rgba(239, 68, 68, 0.1);
    border-radius: 8px;
    display: none;
}

.error-message:not(:empty) {
    display: block;
}

.success-message {
    color: var(--success-color);
    font-size: 14px;
    margin-top: 10px;
    padding: 12px;
    background: rgba(16, 185, 129, 0.1);
    border-radius: 8px;
}

/* ===== Tables ===== */
.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead {
    background: var(--bg-color);
}

.data-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table td {
    padding: 16px;
    border-top: 1px solid var(--border-color);
    font-size: 14px;
}

.data-table tbody tr:hover {
    background: var(--bg-color);
}

.data-table td.loading {
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
}

.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.badge-success {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success-color);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger-color);
}

.badge-secondary {
    background: rgba(100, 116, 139, 0.1);
    color: var(--secondary-color);
}

/* ===== Modals ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-content.modal-large {
    max-width: 800px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.close-btn:hover {
    background: var(--bg-color);
}

.modal form {
    padding: 24px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.modal-actions .btn {
    flex-shrink: 0;
    min-width: 120px;
    font-size: 14px;
}

/* ===== Dashboard ===== */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
}

.quick-action-card {
    grid-column: span 1;
    text-align: center;
    padding: 32px;
    background: linear-gradient(135deg, #ff6b35 0%, #ff8c42 100%);
    color: white;
}

.quick-action-card h3 {
    color: white;
    margin-bottom: 12px;
}

.quick-action-card .btn-primary {
    background: white;
    color: var(--primary-color);
    margin-top: 16px;
}

.stats-card {
    display: flex;
    align-items: center;
    gap: 20px;
}

.stat-icon {
    font-size: 40px;
    opacity: 0.9;
}

.stat-content h4 {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stat-number {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary-color);
}

.recent-flows-card {
    grid-column: 1 / -1;
}

.recent-flows-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.flow-item {
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
}

.flow-item:hover {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.02);
}

.flow-info h4 {
    font-size: 16px;
    margin-bottom: 4px;
}

.flow-info p {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ===== Test Section ===== */
.test-section {
    margin-top: 24px;
    padding: 20px;
    background: var(--bg-color);
    border-radius: 8px;
}

.test-section h3 {
    font-size: 16px;
    margin-bottom: 16px;
}

.test-result {
    margin-top: 16px;
    padding: 16px;
    border-radius: 8px;
    display: none;
}

.test-result.show {
    display: block;
}

.test-result.success {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid var(--success-color);
    color: var(--success-color);
}

.test-result.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger-color);
    color: var(--danger-color);
}

/* ===== Flow Preview ===== */
.flow-preview {
    margin-top: 24px;
    padding: 20px;
    background: var(--bg-color);
    border-radius: 8px;
}

.flow-preview h4 {
    font-size: 16px;
    margin-bottom: 16px;
}

.flow-diagram {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}

.flow-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.flow-icon {
    font-size: 32px;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.flow-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    max-width: 120px;
}

.flow-arrow {
    font-size: 24px;
    color: var(--text-secondary);
}

/* ===== Settings ===== */
.settings-group {
    margin-bottom: 24px;
}

.settings-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 14px;
}

.settings-value {
    font-size: 14px;
    color: var(--text-secondary);
}

.help-text {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: normal;
}

/* ===== Loading ===== */
.loading {
    color: var(--text-secondary);
    font-style: italic;
}

/* ===== Mobile Navigation ===== */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--sidebar-bg);
    color: white;
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
    z-index: 101;
    box-shadow: var(--shadow);
}

.mobile-header a {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.mobile-header-logo {
    max-height: 32px;
    width: auto;
    filter: brightness(0) invert(1);
    object-fit: contain;
    transition: opacity 0.2s;
}

.mobile-header-logo:hover {
    opacity: 0.8;
}

.hamburger-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    transition: background 0.2s;
}

.hamburger-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}

/* ===== Mobile Cards (Alternative to Tables) ===== */
.mobile-cards {
    display: none;
}

.mobile-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
}

.mobile-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.mobile-card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}

.mobile-card-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.mobile-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.mobile-card-label {
    color: var(--text-secondary);
    font-weight: 500;
    min-width: 100px;
}

.mobile-card-value {
    color: var(--text-primary);
    text-align: right;
    flex: 1;
}

.mobile-card-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.mobile-card-actions .btn {
    flex: 1;
    min-width: 0;
    justify-content: center;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }

    .sidebar {
        width: 250px;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        z-index: 100;
        padding-top: 60px;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar-header {
        padding-top: 10px;
    }

    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-top: 76px;
    }

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

    .page-header h1 {
        font-size: 24px;
    }

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

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

    .flow-diagram {
        flex-direction: column;
    }

    .flow-arrow {
        transform: rotate(90deg);
    }

    .modal {
        padding: 0;
        align-items: flex-start;
    }

    .modal-content {
        margin: 0;
        max-height: 100vh;
        max-height: 100dvh; /* Dynamic viewport height for mobile browsers */
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .modal-header {
        padding: 16px;
        flex-shrink: 0;
    }

    .modal-header h2 {
        font-size: 18px;
    }

    .modal form {
        padding: 16px;
        overflow-y: auto;
        flex: 1;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    }

    .modal-actions {
        margin-top: 16px;
        padding-top: 16px;
        position: sticky;
        bottom: 0;
        background: var(--card-bg);
        flex-shrink: 0;
    }

    .modal-actions .btn {
        flex: 1;
        padding: 12px 16px;
        justify-content: center;
    }

    .flow-preview {
        margin-top: 16px;
        padding: 16px;
    }

    .card {
        padding: 16px;
    }

    /* Hide table on mobile, show cards instead */
    .table-container {
        display: none;
    }

    .mobile-cards {
        display: block;
    }
}

/* ===== Utility Classes ===== */
.text-center {
    text-align: center;
}

.mt-2 {
    margin-top: 16px;
}

.mb-2 {
    margin-bottom: 16px;
}

.hidden {
    display: none !important;
}
