/* IP Forward Management System - Pure Monochrome Dark Theme */

:root {
    /* Pure monochrome palette */
    --black: #000000;
    --gray-950: #0a0a0a;
    --gray-900: #111111;
    --gray-850: #1a1a1a;
    --gray-800: #1f1f1f;
    --gray-750: #262626;
    --gray-700: #2d2d2d;
    --gray-600: #404040;
    --gray-500: #666666;
    --gray-400: #999999;
    --gray-300: #b3b3b3;
    --gray-200: #cccccc;
    --gray-100: #e6e6e6;
    --white: #ffffff;
    
    /* Semantic colors - all monochrome */
    --bg-primary: var(--black);
    --bg-secondary: var(--gray-900);
    --bg-tertiary: var(--gray-850);
    --surface: var(--gray-800);
    --surface-elevated: var(--gray-750);
    --border: var(--gray-700);
    --border-light: var(--gray-600);
    
    --text-primary: var(--white);
    --text-secondary: var(--gray-300);
    --text-muted: var(--gray-500);
    --text-inverse: var(--black);
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.8);
    --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.9);
    
    /* Glow effects - white only */
    --glow-subtle: 0 0 10px rgba(255, 255, 255, 0.1);
    --glow: 0 0 20px rgba(255, 255, 255, 0.15);
    --glow-strong: 0 0 30px rgba(255, 255, 255, 0.2);
}

* {
    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;
    background-color: #0a0a0a;
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
}

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

/* Header */
header {
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-bottom: 30px;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

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

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-right: 12px;
    border-right: 1px solid var(--border);
}

.username {
    font-weight: 600;
    font-size: 18px;
    color: var(--text-primary);
}

.user-role {
    font-size: 10px;
    padding: 3px 10px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background-color: rgba(144, 238, 144, 0.15);
    color: #90ee90;
    border: 1px solid rgba(144, 238, 144, 0.3);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
    background-color: var(--surface);
    color: var(--text-primary);
}

.btn:hover {
    background-color: var(--surface-elevated);
    border-color: var(--border-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

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

.btn-primary:hover {
    background-color: var(--gray-200);
    border-color: var(--gray-200);
    box-shadow: var(--glow);
}

.btn-secondary {
    background-color: var(--surface);
    color: var(--text-primary);
    border-color: var(--border);
}

.btn-secondary:hover {
    background-color: var(--surface-elevated);
    border-color: var(--border-light);
}

.btn-success {
    background-color: var(--gray-700);
    color: var(--text-primary);
    border-color: var(--gray-600);
}

.btn-success:hover {
    background-color: var(--gray-600);
    border-color: var(--gray-500);
}

.btn-danger {
    background-color: var(--gray-850);
    color: var(--text-primary);
    border-color: var(--gray-700);
}

.btn-danger:hover {
    background-color: var(--gray-900);
    border-color: var(--gray-600);
    box-shadow: var(--shadow);
}

.btn-warning {
    background-color: var(--gray-600);
    color: var(--white);
    border-color: var(--gray-500);
    font-weight: 500;
}

.btn-warning:hover {
    background-color: var(--gray-500);
    border-color: var(--gray-400);
}

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

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* Cards */
.card {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
    transition: all 0.2s ease;
}

#create-rule-card {
    padding: 20px 24px;
}

.card:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow-lg);
}

.card-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text-primary);
}

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

#create-rule-card .form-group {
    margin-bottom: 12px;
}

#create-rule-card .card-title {
    margin-bottom: 12px;
}

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

.form-label-help {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 12px;
    margin-left: 8px;
}

.form-input,
.form-select {
    width: 100%;
    padding: 12px 14px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--white);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
    background-color: var(--surface);
}

.form-input.error,
.form-select.error {
    border-color: var(--gray-400);
    background-color: rgba(255, 255, 255, 0.05);
}

.form-input.success {
    border-color: var(--gray-200);
    background-color: rgba(255, 255, 255, 0.05);
}

.form-help {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 6px;
}

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

.form-value {
    padding: 12px 14px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 600;
}

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

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

input[type="number"] {
    -moz-appearance: textfield;
}

/* Port validation indicator */
.port-input-wrapper {
    position: relative;
}

.port-status-indicator {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 10px;
    height: 10px;
    border-radius: 50%;
    transition: all 0.3s ease;
    border: 2px solid var(--surface);
}

.port-status-indicator.checking {
    background-color: var(--gray-500);
    animation: pulse 1.5s ease-in-out infinite;
    box-shadow: 0 0 8px var(--gray-500);
}

.port-status-indicator.available {
    background-color: #00ff00;
    box-shadow: 0 0 12px rgba(0, 255, 0, 0.6);
}

.port-status-indicator.taken {
    background-color: #ff0000;
    box-shadow: 0 0 8px rgba(255, 0, 0, 0.6);
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.4;
    }
}

/* Tables */
.table-container {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid var(--border);
}

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

thead {
    background-color: rgba(0, 0, 0, 0.3);
    border-bottom: 2px solid var(--border);
}

th {
    padding: 12px 8px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    white-space: nowrap;
}

td {
    padding: 12px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-primary);
}

tbody tr {
    transition: background-color 0.15s ease;
    background-color: transparent;
}

tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.03);
}

.table-actions {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
}

/* Status badges */
.status-badge {
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: inline-block;
    border: 1px solid;
}

.status-active {
    background-color: rgba(144, 238, 144, 0.15);
    color: #90ee90;
    border: 1px solid rgba(144, 238, 144, 0.3);
}

.status-inactive {
    background-color: rgba(255, 165, 0, 0.15);
    color: #ffa500;
    border: 1px solid rgba(255, 165, 0, 0.3);
}

.status-error {
    background-color: var(--gray-850);
    color: var(--text-secondary);
    border-color: var(--gray-700);
}

.status-pending {
    background-color: var(--gray-750);
    color: var(--text-secondary);
    border-color: var(--gray-600);
}

.status-unreachable {
    background-color: var(--gray-900);
    color: var(--text-muted);
    border-color: var(--gray-700);
}

.status-enabled {
    background-color: rgba(144, 238, 144, 0.2);
    color: #90ee90;
    border-color: rgba(144, 238, 144, 0.4);
}

.status-disabled {
    background-color: rgba(255, 0, 0, 0.15);
    color: #ff0000;
    border-color: rgba(255, 0, 0, 0.3);
}

.status-healthy {
    background-color: rgba(144, 238, 144, 0.2);
    color: #90ee90;
    border-color: rgba(144, 238, 144, 0.4);
}

.status-unknown {
    background-color: var(--gray-750);
    color: var(--text-muted);
    border-color: var(--gray-600);
}

.status-machine-offline {
    background-color: rgba(255, 255, 0, 0.15);
    color: #ffff00;
    border-color: rgba(255, 255, 0, 0.4);
    animation: pulse-badge 2s ease-in-out infinite;
}

@keyframes pulse-badge {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* Rule status indicators (colored circles) */
.rule-status-indicator {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--surface);
    transition: all 0.3s ease;
}

.rule-status-indicator.status-active {
    background-color: #00ff00;
    box-shadow: 0 0 8px rgba(0, 255, 0, 0.5);
}

.rule-status-indicator.status-inactive {
    background-color: #ffa500;
    box-shadow: 0 0 8px rgba(255, 165, 0, 0.5);
}

.rule-status-indicator.status-error {
    background-color: #ff0000;
    box-shadow: 0 0 8px rgba(255, 0, 0, 0.5);
}

.rule-status-indicator.status-machine-offline {
    background-color: #ffff00;
    box-shadow: 0 0 8px rgba(255, 255, 0, 0.5);
    animation: pulse-warning 2s ease-in-out infinite;
}

@keyframes pulse-warning {
    0%, 100% {
        opacity: 1;
        box-shadow: 0 0 8px rgba(255, 255, 0, 0.5);
    }
    50% {
        opacity: 0.6;
        box-shadow: 0 0 12px rgba(255, 255, 0, 0.7);
    }
}

/* Text truncation with tooltip */
.truncate-text {
    display: inline-block;
    max-width: 25ch;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
    cursor: help;
}

/* Traffic flow arrow */
.traffic-arrow {
    display: inline-block;
    color: var(--text-muted);
    font-size: 16px;
    opacity: 0.6;
    font-weight: normal;
}

/* Alerts */
.alert {
    padding: 14px 18px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 14px;
    border: 1px solid;
}

.alert-success {
    background-color: var(--surface);
    color: var(--text-primary);
    border-color: var(--gray-200);
}

.alert-error {
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    border-color: var(--border);
}

.alert-warning {
    background-color: #3a3a1a;
    color: #ffff99;
    border-color: #666633;
}

.alert-info {
    background-color: var(--surface);
    color: var(--text-primary);
    border-color: var(--border);
}

/* Login page */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #0a0a0a;
    position: relative;
    overflow: hidden;
}

.login-container::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 2px, rgba(255, 255, 255, 0.03) 2px, rgba(255, 255, 255, 0.03) 4px),
        repeating-linear-gradient(90deg, transparent, transparent 2px, rgba(255, 255, 255, 0.03) 2px, rgba(255, 255, 255, 0.03) 4px);
    animation: slide 60s linear infinite;
}

@keyframes slide {
    0% {
        transform: translate(0, 0);
    }
    100% {
        transform: translate(50px, 50px);
    }
}

.login-card {
    background-color: var(--surface);
    padding: 48px;
    border-radius: 12px;
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 420px;
    border: 1px solid var(--border);
    position: relative;
    z-index: 1;
}

.login-title {
    font-size: 32px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
    color: var(--text-primary);
    letter-spacing: -1px;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 32px;
    font-size: 14px;
}

.tab-buttons {
    display: flex;
    gap: 12px;
    margin-bottom: 32px;
}

.tab-button {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border);
    background-color: transparent;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-secondary);
}

.tab-button:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.tab-button.active {
    background-color: var(--white);
    color: var(--text-inverse);
    border-color: var(--white);
    box-shadow: var(--glow);
}

.tab-content {
    display: none;
}

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

/* Loading spinner */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(0, 0, 0, 0.2);
    border-radius: 50%;
    border-top-color: var(--black);
    animation: spin 1s linear infinite;
}

/* Loading spinner on dark buttons (secondary, danger) */
.btn-secondary .loading,
.btn-danger .loading {
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--white);
}

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

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.empty-state-text {
    font-size: 14px;
    color: var(--text-muted);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    backdrop-filter: blur(8px);
}

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

.modal-content {
    background-color: var(--surface);
    padding: 32px;
    border-radius: 12px;
    box-shadow: var(--shadow-xl);
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--border);
}

.modal-content::-webkit-scrollbar-track {
    background: var(--surface);
}

.modal-content::-webkit-scrollbar-thumb {
    border-color: var(--surface);
}

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

.modal-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

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

.modal-close:hover {
    color: var(--text-primary);
    background-color: var(--bg-secondary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

/* Utility classes */
.hidden {
    display: none !important;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mt-1 {
    margin-top: 8px;
}

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

.mb-1 {
    margin-bottom: 8px;
}

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

.flex {
    display: flex;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.gap-1 {
    gap: 8px;
}

.gap-2 {
    gap: 16px;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: #0a0a0a;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 6px;
    border: 3px solid #0a0a0a;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* Selection */
::selection {
    background-color: var(--white);
    color: var(--text-inverse);
}

::-moz-selection {
    background-color: var(--white);
    color: var(--text-inverse);
}

/* Rule Preview */
.rule-preview {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px 16px;
    margin-bottom: 16px;
    display: flex;
    gap: 12px;
    align-items: center;
}

.rule-preview-icon {
    font-size: 18px;
    flex-shrink: 0;
    opacity: 0.7;
}

.rule-preview-text {
    flex: 1;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.6;
}

.rule-preview-text strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-width: 400px;
}

.toast {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px 20px;
    box-shadow: var(--shadow-xl);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    animation: slideIn 0.3s ease-out;
    transition: opacity 0.3s ease-out, transform 0.3s ease-out;
}

.toast.hiding {
    opacity: 0;
    transform: translateX(400px);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(400px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast-icon {
    font-size: 20px;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast-content {
    flex: 1;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
}

.toast-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    border-radius: 4px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.toast-close:hover {
    color: var(--text-primary);
    background-color: var(--bg-secondary);
}

/* Toast type variations */
.toast.toast-success {
    background-color: rgba(0, 255, 0, 0.1);
    border-color: rgba(0, 255, 0, 0.3);
}

.toast.toast-success .toast-icon {
    color: #00ff00;
}

.toast.toast-error {
    background-color: rgba(255, 0, 0, 0.1);
    border-color: rgba(255, 0, 0, 0.3);
}

.toast.toast-error .toast-icon {
    color: #ff0000;
}

.toast.toast-warning {
    background-color: rgba(255, 165, 0, 0.1);
    border-color: rgba(255, 165, 0, 0.3);
}

.toast.toast-warning .toast-icon {
    color: #ffa500;
}

.toast.toast-info {
    background-color: var(--surface);
    border-color: var(--border-light);
}

.toast.toast-info .toast-icon {
    color: var(--gray-300);
}

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

    .user-info {
        border-right: none;
        padding-right: 0;
        border-bottom: 1px solid var(--border);
        padding-bottom: 12px;
    }

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

    .table-container {
        font-size: 12px;
    }

    th, td {
        padding: 8px;
    }
    
    .login-card {
        padding: 32px 24px;
        margin: 20px;
    }
    
    #toast-container {
        bottom: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .toast {
        min-width: auto;
    }
}

/* Focus visible for accessibility */
*:focus-visible {
    outline: 2px solid var(--white);
    outline-offset: 2px;
}
