/* ═══════════════════════════════════════════════════════
   style.css — Graphical Traceroute Tool
   Modern responsive UI with dark/light theme support
   ═══════════════════════════════════════════════════════ */

/* ─── CSS Variables ─────────────────────────────────── */
:root {
    --bg:          #f4f6f9;
    --bg-card:     #ffffff;
    --bg-input:    #f0f2f5;
    --bg-hover:    #e8eaed;
    --text:        #1a1a2e;
    --text-muted:  #6b7280;
    --border:      #e2e5ea;
    --primary:     #2563eb;
    --primary-hover:#1d4ed8;
    --green:       #16a34a;
    --yellow:      #eab308;
    --red:         #dc2626;
    --gray:        #9ca3af;
    --purple:      #7c3aed;
    --orange:      #ea580c;
    --blue:        #2563eb;
    --shadow:      0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg:   0 4px 12px rgba(0,0,0,0.1);
    --radius:      10px;
    --radius-sm:   6px;
    --font:        'Segoe UI', system-ui, -apple-system, sans-serif;
    --transition:  0.2s ease;
}

[data-theme="dark"] {
    --bg:          #0f172a;
    --bg-card:     #1e293b;
    --bg-input:    #334155;
    --bg-hover:    #334155;
    --text:        #e2e8f0;
    --text-muted:  #94a3b8;
    --border:      #334155;
    --primary:     #3b82f6;
    --primary-hover:#2563eb;
    --shadow:      0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg:   0 4px 12px rgba(0,0,0,0.4);
}

/* ─── Reset & Base ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background var(--transition), color var(--transition);
}

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

/* ─── Header ────────────────────────────────────────── */
.header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

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

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

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ─── Container ─────────────────────────────────────── */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
    width: 100%;
    flex: 1;
}

/* ─── Card ──────────────────────────────────────────── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    transition: background var(--transition), border-color var(--transition);
}

.card h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ─── Search Form ───────────────────────────────────── */
.search-card { border-left: 4px solid var(--primary); }

.search-form { display: flex; flex-direction: column; gap: 12px; }

.input-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.input-group input,
.input-group select {
    flex: 1;
    min-width: 200px;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color var(--transition);
}

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

.quick-links {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.quick-links .label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.btn-tag {
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-input);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-tag:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ─── Buttons ───────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    cursor: pointer;
    color: var(--text);
    transition: all var(--transition);
}
.btn-icon:hover { background: var(--bg-hover); }

/* ─── Loading State ─────────────────────────────────── */
.loading-card {
    text-align: center;
    padding: 48px 24px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

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

.loading-sub {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 4px;
}

/* ─── Error State ───────────────────────────────────── */
.error-card {
    text-align: center;
    padding: 40px 24px;
    border-left: 4px solid var(--red);
}

.error-card p {
    font-size: 1rem;
    margin: 12px 0 16px;
    color: var(--red);
}

/* ─── Summary Row ───────────────────────────────────── */
.summary-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow);
    transition: transform var(--transition);
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.stat-value {
    display: block;
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ─── Actions Row ───────────────────────────────────── */
.actions-row {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

/* ─── Tabs ──────────────────────────────────────────── */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 4px;
    flex-wrap: wrap;
}

.tab {
    flex: 1;
    min-width: 120px;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.tab:hover { color: var(--text); }
.tab.active {
    background: var(--bg-card);
    color: var(--primary);
    box-shadow: var(--shadow);
}

.tab-content { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ─── Hop Table ─────────────────────────────────────── */
.hop-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.hop-table th {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 2px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.hop-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.hop-table tr:hover td { background: var(--bg-hover); }

.hop-table .hop-number {
    font-weight: 700;
    color: var(--text);
}

.hop-table .hop-host {
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hop-table .latency-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.latency-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}

.latency-dot.green  { background: var(--green); }
.latency-dot.yellow { background: var(--yellow); }
.latency-dot.red    { background: var(--red); }
.latency-dot.gray   { background: var(--gray); }

.timeout-text {
    color: var(--text-muted);
    font-style: italic;
}

/* ─── Graph & Chart Containers ──────────────────────── */
.graph-container,
.chart-container,
.map-container { padding: 0; overflow: hidden; }

#networkGraph,
#worldMap {
    width: 100%;
    height: 400px;
    min-height: 300px;
}

#latencyChart {
    width: 100%;
    height: 350px;
    padding: 20px;
}

/* ─── History Section ───────────────────────────────── */
.history-section { border-top: 3px solid var(--primary); }

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    cursor: pointer;
    transition: all var(--transition);
}

.history-item:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
}

.history-item .target-name {
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

.history-item .meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.empty-state {
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
}

/* ─── Footer ────────────────────────────────────────── */
.footer {
    text-align: center;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    font-size: 0.82rem;
    color: var(--text-muted);
    background: var(--bg-card);
}

/* ─── Icons ─────────────────────────────────────────── */
.icon    { width: 18px; height: 18px; }
.icon-lg { width: 24px; height: 24px; }
.icon-xl { width: 48px; height: 48px; }

.text-blue   { color: var(--blue); }
.text-green  { color: var(--green); }
.text-yellow { color: var(--yellow); }
.text-red    { color: var(--red); }
.text-gray   { color: var(--gray); }
.text-purple { color: var(--purple); }
.text-orange { color: var(--orange); }

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

/* ─── Responsive ────────────────────────────────────── */
@media (max-width: 768px) {
    .container { padding: 12px; }
    .input-group { flex-direction: column; }
    .input-group input,
    .input-group select { min-width: 100%; }
    .summary-row { grid-template-columns: 1fr 1fr; }
    .tabs { flex-wrap: nowrap; overflow-x: auto; }
    .tab { min-width: 100px; font-size: 0.78rem; padding: 8px 10px; }
    .hop-table { font-size: 0.78rem; }
    .hop-table th,
    .hop-table td { padding: 8px 6px; }
    #networkGraph,
    #worldMap { height: 300px; }
}

@media (max-width: 480px) {
    .summary-row { grid-template-columns: 1fr; }
    .actions-row { flex-direction: column; }
    .btn { width: 100%; justify-content: center; }
}
