:root {
    --bg: #f5f2ec;
    --panel: #ececec;
    --ink: #1a1a1a;
    --muted: #666;
    --border: #b9b3a6;
    --accent: #ff4a1c;
    --accent-ink: #ffffff;
}

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

body {
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    padding-bottom: 72px; /* room for bottom tab bar on mobile */
}

.app { max-width: 900px; margin: 0 auto; }

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 16px;
    border-bottom: 2px solid var(--ink);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 42px; width: auto; }
.brand-name { font-size: 22px; font-weight: 800; letter-spacing: 0.5px; }
.brand-sub { font-size: 11px; font-weight: 700; letter-spacing: 1.5px; color: var(--muted); }

.demo-badge {
    border: 1px solid var(--accent);
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 6px 10px;
    border-radius: 4px;
}

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

.mode-toggle {
    display: flex;
    border: 1px solid var(--ink);
    border-radius: 4px;
    overflow: hidden;
    margin-right: 8px;
}

.mode-btn {
    border: none;
    background: var(--panel);
    color: var(--ink);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 8px 14px;
    cursor: pointer;
}

.mode-btn.active { background: var(--accent); color: var(--accent-ink); }

/* Demo vs Advanced sections */
.app-root.mode-demo .advanced-only { display: none; }
.app-root.mode-advanced .demo-only { display: none; }
.field.hidden-in-demo { display: none; }
.app-root.mode-demo .mt-ids { display: none; }
.app-root.mode-demo .device-card[data-advanced-only="true"] { display: none; }

.reset-button {
    border: 1px solid var(--border);
    background: none;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
}

.reset-button:hover { border-color: var(--ink); color: var(--ink); }

.signed-in-as { font-size: 12px; color: var(--muted); }
.logout-form { display: inline; }

.tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.tab {
    flex: 1;
    background: none;
    border: none;
    padding: 14px 8px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--muted);
    border-bottom: 3px solid transparent;
    cursor: pointer;
}

.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.count {
    display: inline-block;
    background: #d9d4c9;
    color: var(--ink);
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 4px;
    margin-left: 4px;
}

.tab-panel { padding: 16px; }
.tab-panel.hidden { display: none; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 12px;
}

.section-header h2, .tab-panel h2 {
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.section-actions { font-size: 13px; color: var(--muted); }

.link-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    margin-left: 8px;
}

.filter-input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    background: #e6e2da;
    font-size: 14px;
    margin-bottom: 12px;
}

.device-grid, .message-type-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}

.message-type-grid.cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.device-card, .message-type-card {
    text-align: left;
    padding: 14px;
    border: 1px solid var(--border);
    background: var(--panel);
    cursor: pointer;
    min-height: 56px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.device-card.selected, .message-type-card.selected {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

.device-asset, .mt-name { font-weight: 700; font-size: 15px; }
.device-serial, .mt-ids { font-size: 12px; color: var(--muted); }
.device-card.selected .device-serial, .message-type-card.selected .mt-ids { color: #ffe0d6; }

.group-heading {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--muted);
    margin: 16px 0 10px;
}

.field-form-anchor {
    grid-column: 1 / -1;
    background: var(--panel);
    border: 1px solid var(--border);
    padding: 16px;
}

.field-form-anchor.hidden { display: none; }

#field-form-container { margin-top: 8px; }
#field-form-container:empty { margin-top: 0; }

.field-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    margin-bottom: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field label {
    font-size: 12px;
    color: var(--muted);
}

.field input, .field select {
    padding: 10px;
    border: 1px solid var(--border);
    background: var(--panel);
    font-size: 14px;
}

.end-mode-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border: 1px solid var(--border);
    margin-bottom: 16px;
}

.end-mode-toggle button {
    padding: 14px;
    text-align: left;
    border: none;
    background: var(--panel);
    cursor: pointer;
}

.end-mode-toggle button.active { background: var(--accent); color: var(--accent-ink); }
.end-mode-toggle .mode-title { font-weight: 700; display: block; }
.end-mode-toggle .mode-sub { font-size: 12px; opacity: 0.85; }

.send-button {
    width: 100%;
    padding: 18px;
    background: var(--accent);
    color: var(--accent-ink);
    border: none;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
}

.send-button:disabled { background: #d9d4c9; color: var(--muted); cursor: not-allowed; }
.send-button.sent { background: #2e7d32; color: #fff; }
.send-button.failed { background: #c62828; color: #fff; }

.alert-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border-left: 4px solid var(--accent);
    background: var(--panel);
    padding: 16px;
    margin-bottom: 10px;
}

.alert-title { font-weight: 700; }
.alert-device, .alert-meta { font-size: 13px; color: var(--muted); }

.close-alert-btn {
    padding: 10px 14px;
    border: 1px solid var(--border);
    background: #fff;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.history-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.history-table th { text-align: left; text-transform: uppercase; font-size: 11px; color: var(--muted); padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.history-table td { padding: 10px 4px; border-bottom: 1px solid #e0dcd2; }

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.login-card {
    width: 100%;
    max-width: 360px;
}

.login-logo { display: block; height: 72px; width: auto; margin: 0 auto 12px; }
.login-card .brand-name { text-align: center; margin-bottom: 2px; }
.login-card .brand-sub { text-align: center; margin-bottom: 28px; }

.login-card .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.login-card label { font-size: 12px; color: var(--muted); }
.login-card input {
    padding: 12px;
    border: 1px solid var(--border);
    background: var(--panel);
    font-size: 15px;
}

.login-error {
    background: #fdeae4;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 16px;
}

/* Mobile: bottom tab bar, single-column grids */
@media (max-width: 600px) {
    .device-grid, .message-type-grid, .message-type-grid.cols-3, .field-grid { grid-template-columns: 1fr; }

    .app-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .header-actions { flex-wrap: wrap; }

    .tabs {
        position: fixed;
        bottom: 0; left: 0; right: 0;
        background: var(--bg);
        border-top: 1px solid var(--border);
        border-bottom: none;
        z-index: 10;
    }

    .history-table { display: block; overflow-x: auto; white-space: nowrap; }
}
