/* 固越成型機 MQTT 轉拋與看板 - CSS 樣式表 */
:root {
    --bg-dark: #0f172a;
    --card-bg: #1e293b;
    --card-border: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #0284c7;
    --accent-green: #10b981;
    --accent-yellow: #f59e0b;
    --accent-red: #ef4444;
    --accent-purple: #a855f7;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    padding: 1.5rem;
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--card-border);
}

.header-title h1 {
    font-size: 1.6rem;
    font-weight: 700;
    color: #f1f5f9;
}

.header-title p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.2rem;
}

.stats-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.stat-card .label { color: var(--text-muted); font-size: 0.85rem; font-weight: 500; margin-bottom: 0.4rem; }
.stat-card .value { font-size: 2rem; font-weight: 800; color: var(--text-main); line-height: 1.1; }
.stat-card .subtext { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.3rem; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.section-title { font-size: 1.15rem; font-weight: 700; display: flex; align-items: center; gap: 0.5rem; }

.filter-bar {
    display: flex;
    align-items: center;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 0.35rem 0.5rem;
    gap: 0.4rem;
}

.filter-pill {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 0.45rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.2s ease;
}

.filter-pill.active {
    background: linear-gradient(135deg, #1d4ed8, #2563eb);
    color: white;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.pill-count {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.1rem 0.45rem;
    border-radius: 9999px;
    font-size: 0.75rem;
}

.machines-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2.25rem;
}

.machine-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    padding: 1.25rem;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    position: relative;
}

.machine-card:hover {
    transform: translateY(-3px);
    border-color: rgba(56, 189, 248, 0.5);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
}

.machine-card.running { border-color: rgba(16, 185, 129, 0.4); }
.machine-card.has-alarm { border-color: rgba(239, 68, 68, 0.7); background: rgba(35, 18, 25, 0.9); }
.machine-card.disabled { opacity: 0.6; filter: grayscale(40%); }

.machine-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.machine-title { font-size: 1.3rem; font-weight: 800; color: #38bdf8; display: flex; align-items: center; gap: 0.5rem; }
.machine-ip { font-size: 0.8rem; color: var(--text-muted); font-weight: 400; }

.status-badge { display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.25rem 0.65rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 700; }
.badge-running { background: rgba(16, 185, 129, 0.2); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.4); }
.badge-idle { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.3); }
.badge-offline { background: rgba(239, 68, 68, 0.15); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.3); }
.badge-alarm { background: rgba(239, 68, 68, 0.3); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.6); animation: pulse 2s infinite; }
.badge-disabled { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }

@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); } 70% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); } 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); } }
.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot-running { background-color: #34d399; box-shadow: 0 0 6px #34d399; }
.dot-idle { background-color: #fbbf24; }
.dot-offline { background-color: #f87171; }

.card-row-container {
    background: rgba(15, 23, 42, 0.5);
    border-radius: 10px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    margin-bottom: 0.75rem;
}

.card-row { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; }
.card-label { color: var(--text-muted); display: flex; align-items: center; gap: 0.35rem; }
.card-value { font-weight: 600; color: #f1f5f9; }

.val-highlight { color: #60a5fa; }
.val-purple { color: var(--accent-purple); font-weight: 700; }
.val-muted { color: var(--text-muted); }
.val-alarm { color: #f87171; font-weight: 700; }

.alarm-alert-banner {
    background: rgba(239, 68, 68, 0.2);
    border: 1px solid rgba(239, 68, 68, 0.5);
    border-radius: 8px;
    padding: 0.4rem 0.65rem;
    font-size: 0.8rem;
    color: #fca5a5;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 600;
}

.card-footer { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--text-muted); border-top: 1px solid rgba(255, 255, 255, 0.05); padding-top: 0.6rem; }

.system-monitor-section { margin-top: 1.5rem; }
.log-section { background: var(--card-bg); border: 1px solid var(--card-border); border-radius: 14px; padding: 1.25rem; }
.log-list { max-height: 280px; overflow-y: auto; font-family: monospace; font-size: 0.82rem; display: flex; flex-direction: column; gap: 0.5rem; }
.log-item { padding: 0.5rem 0.75rem; background: rgba(15, 23, 42, 0.6); border-radius: 6px; border-left: 3px solid var(--primary); display: flex; justify-content: space-between; gap: 1rem; }

.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.75); backdrop-filter: blur(6px);
    display: flex; justify-content: center; align-items: center; z-index: 1000;
    opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }

.modal {
    background: #151e32; border: 1px solid var(--card-border); border-radius: 16px;
    width: 94%; max-width: 880px; max-height: 90vh; overflow-y: auto; padding: 1.75rem;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.6); transform: scale(0.95); transition: transform 0.2s ease;
}
.modal-overlay.active .modal { transform: scale(1); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; }
.modal-title { font-size: 1.3rem; font-weight: 700; color: #38bdf8; }
.close-btn { background: none; border: none; color: var(--text-muted); font-size: 1.5rem; cursor: pointer; }
.close-btn:hover { color: white; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.25rem; }
.detail-box { background: rgba(15, 23, 42, 0.6); border-radius: 10px; padding: 1rem; border: 1px solid rgba(255, 255, 255, 0.05); }
.detail-box h4 { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.5rem; border-bottom: 1px solid rgba(255, 255, 255, 0.08); padding-bottom: 0.25rem; }

.words-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 0.5rem;
    max-height: 280px;
    overflow-y: auto;
    font-size: 0.82rem;
}

.word-item {
    background: #0b1120;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    padding: 0.5rem 0.7rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.word-label { color: #38bdf8; font-weight: 600; }
.word-val { color: #f1f5f9; font-weight: 700; font-family: monospace; }

.telemetry-tag { background: #0b1120; border-radius: 6px; padding: 0.6rem; margin-bottom: 0.4rem; font-family: monospace; font-size: 0.8rem; }
.json-viewer { background: #070a12; border-radius: 8px; padding: 0.75rem; font-family: monospace; font-size: 0.8rem; color: #a5f3fc; max-height: 180px; overflow-y: auto; white-space: pre-wrap; }

.btn {
    background: linear-gradient(135deg, #0284c7, #2563eb); color: white; border: none; padding: 0.55rem 1.2rem;
    border-radius: 8px; font-size: 0.85rem; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 0.4rem; transition: all 0.2s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(2, 132, 199, 0.4); }
.btn-secondary { background: rgba(255, 255, 255, 0.1); color: var(--text-main); }
.btn-secondary:hover { background: rgba(255, 255, 255, 0.2); }
.btn-danger { background: linear-gradient(135deg, #dc2626, #991b1b); }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.75rem; border-radius: 6px; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.4rem; }
.form-control { width: 100%; background: #0b1120; border: 1px solid var(--card-border); color: white; padding: 0.65rem 0.85rem; border-radius: 8px; font-size: 0.9rem; outline: none; }

#toast-container { position: fixed; bottom: 2rem; right: 2rem; z-index: 2000; }
.toast { background: #1e293b; color: white; padding: 0.75rem 1.25rem; border-radius: 8px; border-left: 4px solid var(--primary); box-shadow: 0 10px 25px rgba(0,0,0,0.5); margin-top: 0.5rem; font-size: 0.9rem; }
