/* =================================================================
   stdin.sh - Modern UI Styles
   ================================================================= */

/* CSS Variables for Theming */
:root {
    --primary-color: #2196F3;
    --primary-dark: #1976D2;
    --primary-light: #64B5F6;
    --secondary-color: #4CAF50;
    --accent-color: #FF9800;
    --danger-color: #f44336;
    --warning-color: #FFC107;
    --text-primary: #212121;
    --text-secondary: #757575;
    --bg-light: #f5f7fa;
    --bg-white: #ffffff;
    --border-color: #e0e0e0;
    --border-radius: 8px;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --max-width: 1400px;
    --transition: all 0.3s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-attachment: fixed;
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    background: var(--bg-white);
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 50;
    border-bottom: 3px solid var(--primary-color);
}

.header-container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo svg {
    flex-shrink: 0;
}

.logo h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -0.5px;
}

.logo h1 span {
    color: var(--primary-color);
    font-weight: 800;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 24px;
}

.version {
    background: var(--bg-light);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
    position: relative;
}

.nav-link:hover {
    color: var(--primary-color);
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--primary-color);
    transition: width 0.3s ease;
}

.nav-link:hover::after {
    width: 100%;
}

/* Main Container */
.container {
    max-width: var(--max-width);
    margin: 0 auto;
    padding: 32px 24px;
    width: 100%;
}

main.container {
    flex: 1;
    display: grid;
    gap: 32px;
}

/* Sections */
section {
    background: var(--bg-white);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
}

section:hover {
    box-shadow: var(--shadow-lg);
}

section h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--bg-light);
    display: flex;
    align-items: center;
    gap: 8px;
}

section h2::before {
    content: '';
    width: 4px;
    height: 24px;
    background: var(--primary-color);
    border-radius: 2px;
}

section h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 20px 0 12px 0;
}

/* Forms & Inputs */
label {
    display: inline-flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 500;
    color: var(--text-secondary);
    font-size: 14px;
}

input[type="text"],
input[type="number"],
textarea {
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    transition: var(--transition);
    font-family: inherit;
    background: var(--bg-white);
    height: 40px;
    box-sizing: border-box;
}

/* Fix for number input spinner appearance */
input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    appearance: none;
    -webkit-appearance: none;
    margin: 0;
}

textarea {
    height: auto;
    min-height: 80px;
}

input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

input[type="text"]::placeholder,
input[type="number"]::placeholder,
textarea::placeholder {
    color: #bbb;
}

/* Buttons */
button {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

button:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

button:active {
    transform: translateY(0);
}

#create-tunnel,
#save-flow {
    background: var(--primary-color);
    color: white;
}

#create-tunnel:hover,
#save-flow:hover {
    background: var(--primary-dark);
}

#load-template,
#load-preset {
    background: var(--secondary-color);
    color: white;
}

#load-template:hover,
#load-preset:hover {
    background: #45a049;
}

/* Tables */
#tunnels table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
    background: var(--bg-white);
    border-radius: var(--border-radius);
    overflow: hidden;
}

/* Tunnel Form */
.tunnel-form {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--bg-light);
    border-radius: var(--border-radius);
}

.tunnel-form label {
    flex: 1;
    min-width: 180px;
}

.tunnel-form input {
    width: 100%;
}

.tunnel-form button {
    margin-bottom: 0;
    height: 40px;
}

#tunnels th,
#tunnels td {
    padding: 12px 16px;
    text-align: left;
    font-size: 14px;
}

#tunnels th {
    background: var(--bg-light);
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.5px;
}

#tunnels td {
    border-bottom: 1px solid var(--border-color);
}

#tunnels tbody tr {
    transition: var(--transition);
}

#tunnels tbody tr:hover {
    background: var(--bg-light);
}

#tunnels tbody tr:last-child td {
    border-bottom: none;
}

#tunnels code {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    background: var(--bg-light);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    white-space: nowrap;
}

/* Flow Builder */
.builder {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 20px;
    margin-top: 16px;
}

.palette {
    background: var(--bg-light);
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px;
}

.palette h3 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.block {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary-color) 100%);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 12px 16px;
    margin-bottom: 10px;
    cursor: grab;
    font-weight: 600;
    font-size: 13px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.block:hover {
    transform: translateX(4px);
    box-shadow: var(--shadow-md);
}

.block:active {
    cursor: grabbing;
}

.canvas {
    min-height: 200px;
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 16px;
    background: var(--bg-light);
    transition: var(--transition);
}

.canvas:empty::after {
    content: '\1F4E5  Drag blocks here to build your flow...';
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 200px;
    color: var(--text-secondary);
    font-size: 16px;
    font-weight: 500;
}

.canvas.drag-over {
    background: rgba(33, 150, 243, 0.05);
    border-color: var(--primary-color);
}

.step {
    background: linear-gradient(to right, #fffbea, #fff8dc);
    border: 2px solid #e5d36e;
    border-radius: var(--border-radius);
    padding: 16px;
    margin-bottom: 12px;
    position: relative;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.step:hover {
    box-shadow: var(--shadow-md);
    border-color: #d4c25e;
}

.step strong {
    display: block;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    text-transform: capitalize;
}

.step textarea {
    width: calc(100% - 40px);
    display: block;
    margin-top: 8px;
    min-height: 80px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    resize: vertical;
}

.delete-block {
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    width: 28px;
    height: 28px;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.delete-block:hover {
    background: #d32f2f;
    transform: rotate(90deg) scale(1.1);
    box-shadow: var(--shadow-md);
}

.delete-flow {
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 12px;
    margin-left: 8px;
    transition: var(--transition);
}

.delete-flow:hover {
    background: #d32f2f;
}

.flow-actions {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-top: 20px;
    padding: 16px;
    background: var(--bg-light);
    border-radius: var(--border-radius);
}

.flow-actions label {
    flex: 1;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.flow-actions input {
    width: 100%;
    height: 40px;
}

.flow-actions button {
    height: 40px;
    margin-bottom: 0;
}

/* Flows List */
#flows-list {
    list-style: none;
    margin-top: 12px;
}

#flows-list li {
    padding: 12px 16px;
    background: var(--bg-light);
    border-radius: 6px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: var(--transition);
}

#flows-list li:hover {
    background: #e8f4f8;
    transform: translateX(4px);
}

.flow-name {
    cursor: pointer;
    text-decoration: none;
    color: var(--primary-color);
    font-weight: 600;
    transition: var(--transition);
}

.flow-name:hover {
    text-decoration: underline;
    color: var(--primary-dark);
}

/* Modal styles */
.modal {
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
}

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

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: #000;
}

/* Preset cards */
.preset-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.preset-card {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 16px;
    background: #f9f9f9;
    transition: transform 0.2s, box-shadow 0.2s;
}

.preset-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.preset-card h3 {
    margin: 0 0 8px 0;
    font-size: 16px;
    color: #333;
}

.preset-card p {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: #666;
    line-height: 1.4;
}

.load-preset-btn {
    background: #2196F3;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    width: 100%;
}

.load-preset-btn:hover {
    background: #1976D2;
}

/* Footer */
footer {
    background: var(--bg-white);
    border-top: 1px solid var(--border-color);
    padding: 24px 0;
    margin-top: 32px;
}

footer .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

footer p {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 0;
}

.footer-links {
    display: flex;
    gap: 20px;
}

.footer-links a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
}

.footer-links a:hover {
    color: var(--primary-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    .header-container {
        flex-direction: column;
        gap: 16px;
        text-align: center;
    }
    
    .header-nav {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .builder {
        grid-template-columns: 1fr;
    }
    
    .flow-actions {
        flex-direction: column;
        align-items: stretch;
    }
    
    .flow-actions label {
        width: 100%;
    }
    
    #tunnels table {
        font-size: 12px;
    }
    
    #tunnels th,
    #tunnels td {
        padding: 8px 4px;
    }
    
    .preset-list {
        grid-template-columns: 1fr;
    }
    
    footer .container {
        flex-direction: column;
        text-align: center;
    }
}

/* Utility Classes */
.status-online {
    color: var(--secondary-color);
    font-weight: 600;
}

.status-offline {
    color: var(--text-secondary);
}

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

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid var(--primary-color);
    border-radius: 50%;
    border-top-color: transparent;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Smooth Scrolling */
html {
    scroll-behavior: smooth;
}