/* ===== CSS Reset & Base Styles ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary-hue: 220;
    --primary-color: hsl(var(--primary-hue), 90%, 56%);
    --primary-light: hsl(var(--primary-hue), 90%, 96%);
    --primary-dark: hsl(var(--primary-hue), 90%, 46%);
    --success-color: hsl(142, 76%, 45%);
    --success-bg: hsl(142, 76%, 95%);
    --danger-color: hsl(0, 84%, 60%);
    --danger-bg: hsl(0, 84%, 96%);
    --warning-color: hsl(38, 92%, 50%);
    --warning-bg: hsl(38, 92%, 95%);
    --bg-primary: hsl(220, 20%, 97%);
    --bg-secondary: hsl(0, 0%, 100%);
    --bg-card: hsl(0, 0%, 100%);
    --text-primary: hsl(220, 20%, 15%);
    --text-secondary: hsl(220, 10%, 45%);
    --text-muted: hsl(220, 10%, 60%);
    --border-color: hsl(220, 15%, 90%);
    --border-light: hsl(220, 15%, 94%);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.06);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.08);
    --space-xs: 0.25rem; --space-sm: 0.5rem; --space-md: 1rem;
    --space-lg: 1.5rem; --space-xl: 2rem; --space-2xl: 3rem;
    --radius-sm: 6px; --radius-md: 10px; --radius-lg: 16px;
    --transition-fast: 0.15s ease; --transition-normal: 0.2s ease;
}

html { font-size: 16px; scroll-behavior: smooth; }
body { font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif; background: var(--bg-primary); color: var(--text-primary); line-height: 1.6; min-height: 100vh; }
.app-container { min-height: 100vh; display: flex; flex-direction: column; }

/* Header */
.header { background: linear-gradient(135deg, var(--primary-color), hsl(var(--primary-hue), 80%, 45%)); padding: var(--space-xl) var(--space-lg); color: white; box-shadow: var(--shadow-lg); position: relative; overflow: hidden; }
.header::before { content: ''; position: absolute; top: -50%; right: -10%; width: 300px; height: 300px; background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%); border-radius: 50%; }
.header-content { max-width: 1200px; margin: 0 auto; position: relative; z-index: 1; }
.logo { display: flex; align-items: center; gap: var(--space-sm); font-size: 1.75rem; font-weight: 700; }
.logo-icon { font-size: 2rem; animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
.header-subtitle { font-size: 0.9rem; opacity: 0.85; margin-top: var(--space-xs); }

/* Main Content */
.main-content { flex: 1; max-width: 1200px; margin: 0 auto; padding: var(--space-xl) var(--space-lg); width: 100%; }

/* Description Card */
.description-card { display: flex; align-items: center; gap: var(--space-md); background: linear-gradient(135deg, var(--primary-light), hsl(var(--primary-hue), 80%, 98%)); border: 1px solid hsl(var(--primary-hue), 60%, 90%); border-radius: var(--radius-lg); padding: var(--space-lg); margin-bottom: var(--space-xl); animation: slideDown 0.5s ease; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.description-icon { width: 44px; height: 44px; background: var(--primary-color); border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; color: white; flex-shrink: 0; }
.description-card p { color: var(--text-secondary); font-size: 0.95rem; }

/* Form Section */
.scan-form-section { background: var(--bg-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: var(--space-xl); margin-bottom: var(--space-xl); border: 1px solid var(--border-light); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-lg); margin-bottom: var(--space-lg); }
@media (max-width: 768px) { .form-row { grid-template-columns: 1fr; } }
.form-group { display: flex; flex-direction: column; gap: var(--space-sm); }
.form-group label { font-size: 0.875rem; font-weight: 500; color: var(--text-secondary); display: flex; align-items: center; gap: var(--space-sm); }
.form-group input { padding: var(--space-md) var(--space-lg); border: 2px solid var(--border-color); border-radius: var(--radius-md); font-size: 0.95rem; font-family: inherit; transition: all var(--transition-normal); background: var(--bg-secondary); }
.form-group input:hover { border-color: hsl(var(--primary-hue), 50%, 80%); }
.form-group input:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 4px hsla(var(--primary-hue), 90%, 56%, 0.15); }
.form-group input::placeholder { color: var(--text-muted); }
.form-options { display: flex; gap: var(--space-lg); margin-bottom: var(--space-xl); flex-wrap: wrap; }
.option-group { display: flex; align-items: center; gap: var(--space-sm); }
.option-group label { font-size: 0.875rem; color: var(--text-secondary); }
.option-group select { padding: var(--space-sm) var(--space-md); border: 2px solid var(--border-color); border-radius: var(--radius-sm); font-size: 0.875rem; background: var(--bg-secondary); cursor: pointer; }
.form-actions { display: flex; gap: var(--space-md); justify-content: flex-end; flex-wrap: wrap; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: var(--space-sm); padding: var(--space-md) var(--space-lg); border: none; border-radius: var(--radius-md); font-size: 0.9rem; font-weight: 500; cursor: pointer; transition: all var(--transition-normal); }
.btn-primary { background: linear-gradient(135deg, var(--primary-color), var(--primary-dark)); color: white; box-shadow: 0 4px 14px hsla(var(--primary-hue), 90%, 50%, 0.3); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px hsla(var(--primary-hue), 90%, 50%, 0.4); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-secondary { background: var(--bg-secondary); color: var(--text-secondary); border: 2px solid var(--border-color); }
.btn-secondary:hover { border-color: var(--primary-color); color: var(--primary-color); background: var(--primary-light); }
.btn-danger { background: var(--danger-color); color: white; }
.btn-toggle { background: transparent; border: none; color: var(--primary-color); font-size: 0.875rem; font-weight: 500; cursor: pointer; padding: var(--space-sm) var(--space-md); border-radius: var(--radius-sm); }

/* Progress */
.progress-section { background: var(--bg-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: var(--space-lg); margin-bottom: var(--space-xl); border: 1px solid var(--border-light); }
.progress-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-md); }
.progress-title { font-weight: 500; color: var(--text-secondary); }
.progress-percent { font-weight: 600; color: var(--primary-color); }
.progress-bar { height: 8px; background: var(--border-light); border-radius: 4px; overflow: hidden; margin-bottom: var(--space-md); }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary-color), hsl(var(--primary-hue), 90%, 65%)); width: 0%; border-radius: 4px; transition: width 0.3s ease; }
.progress-stats { text-align: center; font-size: 0.875rem; color: var(--text-muted); }

/* Results */
.results-section { background: var(--bg-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: var(--space-xl); margin-bottom: var(--space-xl); border: 1px solid var(--border-light); }
.results-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-lg); flex-wrap: wrap; gap: var(--space-md); }
.results-header h2 { font-size: 1.1rem; font-weight: 600; display: flex; align-items: center; gap: var(--space-sm); }
.results-stats { display: flex; gap: var(--space-md); }
.stat { font-size: 0.8rem; font-weight: 500; padding: var(--space-xs) var(--space-md); border-radius: var(--radius-sm); }
.stat-open { background: var(--success-bg); color: var(--success-color); }
.stat-closed { background: var(--danger-bg); color: var(--danger-color); }
.stat-filtered { background: var(--warning-bg); color: var(--warning-color); }
.results-table-container { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border-light); }
.results-table { width: 100%; border-collapse: collapse; }
.results-table th, .results-table td { padding: var(--space-md) var(--space-lg); text-align: left; }
.results-table th { background: var(--bg-primary); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; color: var(--text-secondary); border-bottom: 2px solid var(--border-color); }
.results-table tbody tr { border-bottom: 1px solid var(--border-light); transition: background var(--transition-fast); }
.results-table tbody tr:hover:not(.empty-row) { background: var(--primary-light); }
.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 20px; font-size: 0.8rem; font-weight: 500; }
.status-open { background: var(--success-bg); color: var(--success-color); }
.status-open::before { content: ''; width: 8px; height: 8px; background: var(--success-color); border-radius: 50%; animation: blink 1.5s infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.status-closed { background: var(--danger-bg); color: var(--danger-color); }
.status-closed::before { content: ''; width: 8px; height: 8px; background: var(--danger-color); border-radius: 50%; }
.status-timeout { background: var(--warning-bg); color: var(--warning-color); }
.status-timeout::before { content: ''; width: 8px; height: 8px; background: var(--warning-color); border-radius: 50%; }
.empty-row td { padding: var(--space-2xl); }
.empty-state { text-align: center; color: var(--text-muted); }
.empty-icon { font-size: 3rem; display: block; margin-bottom: var(--space-md); opacity: 0.5; }
.port-badge { display: inline-block; font-family: monospace; font-weight: 600; padding: 2px 8px; background: var(--bg-primary); border-radius: var(--radius-sm); font-size: 0.85rem; }
.service-name { color: var(--text-secondary); font-size: 0.85rem; }
.response-time { font-family: monospace; font-size: 0.85rem; color: var(--text-muted); }

/* Ports Reference */
.ports-reference { background: var(--bg-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: var(--space-lg); margin-bottom: var(--space-xl); border: 1px solid var(--border-light); }
.reference-header { display: flex; justify-content: space-between; align-items: center; }
.reference-header h3 { font-size: 1rem; font-weight: 600; display: flex; align-items: center; gap: var(--space-sm); }
.reference-content { margin-top: var(--space-lg); }
.ports-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: var(--space-md); }
.port-item { display: flex; flex-direction: column; align-items: center; padding: var(--space-md); background: var(--bg-primary); border-radius: var(--radius-md); cursor: pointer; transition: all var(--transition-normal); }
.port-item:hover { background: var(--primary-light); transform: translateY(-2px); }
.port-number { font-family: monospace; font-size: 1rem; font-weight: 600; color: var(--primary-color); }
.port-service { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

/* Footer */
.footer { background: var(--bg-secondary); border-top: 1px solid var(--border-light); padding: var(--space-lg); text-align: center; }
.footer p { font-size: 0.85rem; color: var(--text-muted); }

/* Modal */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(4px); }
.modal-content { position: relative; background: var(--bg-card); border-radius: var(--radius-lg); box-shadow: var(--shadow-xl); width: 90%; max-width: 500px; max-height: 80vh; display: flex; flex-direction: column; animation: slideUp 0.3s ease; }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: var(--space-lg); border-bottom: 1px solid var(--border-light); }
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-close { width: 32px; height: 32px; border: none; background: transparent; font-size: 1.5rem; color: var(--text-muted); cursor: pointer; border-radius: var(--radius-sm); }
.modal-close:hover { background: var(--danger-bg); color: var(--danger-color); }
.modal-body { flex: 1; overflow-y: auto; padding: var(--space-lg); }
.modal-footer { padding: var(--space-lg); border-top: 1px solid var(--border-light); display: flex; justify-content: flex-end; }
.history-list { list-style: none; }
.history-list li { padding: var(--space-md); border-bottom: 1px solid var(--border-light); cursor: pointer; }
.history-list li:hover:not(.empty-history) { background: var(--primary-light); }
.empty-history { text-align: center; color: var(--text-muted); cursor: default !important; }
.history-item-host { font-weight: 500; color: var(--text-primary); }
.history-item-ports { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; }
.history-item-time { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* Responsive */
@media (max-width: 640px) {
    .header { padding: var(--space-lg) var(--space-md); }
    .main-content { padding: var(--space-lg) var(--space-md); }
    .description-card { flex-direction: column; text-align: center; }
    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; justify-content: center; }
}
