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

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface2: #242836;
    --border: #2e3345;
    --text: #e1e4ed;
    --text-dim: #8b8fa3;
    --accent: #cc0000;
    --accent-hover: #e60000;
    --green: #22c55e;
    --yellow: #eab308;
    --red: #ef4444;
}

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

/* Login */
#login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    width: 360px;
}

.login-box h1 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    text-align: center;
}

.login-box input {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.login-box input:focus {
    outline: none;
    border-color: var(--accent);
}

.login-error {
    color: var(--red);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    display: none;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    width: 100%;
    justify-content: center;
    padding: 0.6rem;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { opacity: 0.9; }

.btn-warning { background: var(--yellow); color: #000; }
.btn-warning:hover { opacity: 0.9; }

.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

.btn-secondary { background: #555; color: #fff; }
.btn-secondary:hover { opacity: 0.9; }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
}

.btn-outline:hover { border-color: var(--text-dim); color: var(--text); }

.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

/* Dashboard layout */
#dashboard-view { display: none; }

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

/* Nav */
.nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.nav-link {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}

.nav-link:hover {
    color: var(--text);
    background: var(--surface2);
}

.nav-link.active {
    color: var(--text);
    background: var(--surface2);
}

.signalr-status {
    font-size: 0.8rem;
    color: var(--text-dim);
}

.signalr-status .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
    background: var(--red);
}

.signalr-status.connected .dot { background: var(--green); }

.main { padding: 1.5rem; max-width: 1400px; margin: 0 auto; }

/* Status cards */
.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.status-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
}

.status-card .label {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.3rem;
}

.status-card .value {
    font-size: 1.4rem;
    font-weight: 600;
}

.status-card .value.running { color: var(--green); }
.status-card .value.paused { color: var(--yellow); }

.status-card .value.clickable { cursor: pointer; text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 4px; }
.status-card .value.clickable:hover { color: var(--accent); }

.purchasers-card { position: relative; }

.purchasers-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    min-width: 220px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-top: 0.5rem;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.purchasers-dropdown.open { display: block; }

.purchasers-dropdown .purchaser-item {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
}

.purchasers-dropdown .purchaser-item:last-child { border-bottom: none; }

.purchasers-dropdown .purchaser-name { font-weight: 500; }

.purchasers-dropdown .purchaser-time {
    color: var(--text-dim);
    font-size: 0.75rem;
    margin-top: 0.15rem;
}

.purchasers-dropdown .purchaser-empty {
    padding: 0.75rem;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.8rem;
}

/* Controls bar */
.controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

/* Sections */
.section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 0.9rem;
}

.section-body { padding: 1rem; }

/* TCIN list */
.tcin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 0.75rem;
}

.tcin-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--surface2);
    border-radius: 6px;
    padding: 0.6rem 0.8rem;
}

.tcin-card img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: 4px;
    background: #fff;
    flex-shrink: 0;
}

.tcin-card .tcin-info {
    flex: 1;
    min-width: 0;
}

.tcin-card .tcin-title {
    font-size: 0.85rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tcin-card .tcin-title a {
    color: var(--text);
    text-decoration: none;
}

.tcin-card .tcin-title a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.tcin-card .tcin-id {
    font-size: 0.75rem;
    color: var(--text-dim);
    font-family: monospace;
}

.tcin-card .btn { flex-shrink: 0; }

.tcin-card.pending {
    opacity: 0.6;
    border-style: dashed;
}

.badge-pending {
    display: inline-block;
    background: #b8860b;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    margin-left: 0.4rem;
    vertical-align: middle;
}

.add-tcin-form {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.add-tcin-form input {
    flex: 1;
    padding: 0.4rem 0.7rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85rem;
}

.add-tcin-form input:focus {
    outline: none;
    border-color: var(--accent);
}

/* Stock history */
.history-list { max-height: 300px; overflow-y: auto; }

.history-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.history-item:last-child { border-bottom: none; }

.history-item img {
    width: 36px;
    height: 36px;
    object-fit: contain;
    border-radius: 4px;
    background: #fff;
}

.history-item .history-info { flex: 1; }

.history-item .history-title {
    font-size: 0.85rem;
}

.history-item .history-meta {
    font-size: 0.75rem;
    color: var(--text-dim);
    font-family: monospace;
}

.history-item .history-time {
    font-size: 0.75rem;
    color: var(--text-dim);
}

/* Log stream */
.log-container {
    height: 400px;
    overflow-y: auto;
    background: var(--bg);
    border-radius: 6px;
    padding: 0.75rem;
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.78rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
}

.log-line { color: var(--text-dim); }
.log-line.stock { color: var(--green); font-weight: 600; }
.log-line.error { color: var(--red); }
.log-line.warning { color: var(--yellow); }

/* Empty state */
.empty {
    text-align: center;
    padding: 2rem;
    color: var(--text-dim);
    font-size: 0.9rem;
}

/* Two-column layout for bottom sections */
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* Log file list */
.log-file-list {
    display: flex;
    flex-direction: column;
}

.log-file-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

.log-file-row:last-child { border-bottom: none; }

.log-file-row:hover { background: var(--surface2); }

.log-file-name {
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.85rem;
}

.log-file-meta {
    font-size: 0.78rem;
    color: var(--text-dim);
    flex-shrink: 0;
    margin-left: 1rem;
}

/* Log file viewer */
.log-viewer {
    height: calc(100vh - 180px);
    overflow-y: auto;
    background: var(--bg);
    border-radius: 6px;
    padding: 0.75rem;
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.78rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
}

.file-viewer-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Logs view */
#logs-view { display: none; }

@media (max-width: 900px) {
    .two-col { grid-template-columns: 1fr; }
}
