:root {
    color-scheme: light;
    --page: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #172033;
    --muted: #64748b;
    --blue: #2563eb;
    --shadow: 0 2px 10px rgba(15, 23, 42, .05);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--page); color: var(--text); font-size: 12px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.mobile-only { display: none; }

.app-shell { min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; }
.app-header {
    min-height: 62px; display: flex; align-items: center; justify-content: space-between;
    gap: 18px; padding: 12px 22px; background: #fff; border-bottom: 1px solid var(--border);
}
.brand-row, .header-actions { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    width: 36px; height: 36px; display: grid; place-items: center; border-radius: 9px;
    color: #fff; background: var(--blue); font-size: 19px; font-weight: 700;
}
.app-header h1 { margin: 0; font-size: 16px; letter-spacing: .02em; }
.app-header h1 span { color: #94a3b8; font-weight: 400; }
.readonly-badge { padding: 4px 7px; border-radius: 5px; color: #475569; background: #f1f5f9; font-size: 9px; font-weight: 700; letter-spacing: .06em; }
.primary-button, .secondary-button {
    min-height: 31px; padding: 5px 11px; border-radius: 6px; border: 1px solid transparent;
}
.primary-button { color: #fff; background: var(--blue); }
.primary-button:hover { background: #1d4ed8; }
.primary-button:disabled { opacity: .55; cursor: wait; }
.primary-button.refreshing { display: inline-flex; align-items: center; gap: 7px; opacity: .8; }
.primary-button.refreshing::before { content: ""; width: 11px; height: 11px; border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.secondary-button { color: #334155; background: #fff; border-color: #cbd5e1; }
.secondary-button:hover { background: #f8fafc; }

.content-shell { min-width: 0; padding: 16px 22px; }
.desktop-filters {
    display: grid; grid-template-columns: auto auto auto minmax(250px, 1fr) auto auto;
    align-items: end; gap: 10px; padding: 11px; background: #fff; border: 1px solid var(--border);
    border-radius: 8px 8px 0 0;
}
.desktop-filters label { display: grid; gap: 4px; color: #64748b; font-size: 10px; font-weight: 600; }
.desktop-filters input, .desktop-filters select {
    height: 31px; min-width: 125px; padding: 5px 8px; color: #273449; background: #fff;
    border: 1px solid #cbd5e1; border-radius: 6px; outline: none;
}
.desktop-filters input:focus, .desktop-filters select:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(37, 99, 235, .1); }
.desktop-filters .search-input { min-width: 0; width: 100%; }
.showing-count { align-self: center; color: var(--muted); white-space: nowrap; }
.status-strip { display: flex; justify-content: space-between; gap: 16px; padding: 8px 3px; color: var(--muted); font-size: 11px; }
#last-updated.stale { color: #b91c1c; font-weight: 600; }

.schedule-table { min-width: 1040px; overflow: auto; background: #fff; border: 1px solid var(--border); border-radius: 0 0 8px 8px; box-shadow: var(--shadow); }
.schedule-grid {
    display: grid; grid-template-columns: minmax(300px, 2.3fr) 105px minmax(130px, 1fr) 88px 150px 150px 72px 72px 72px;
    align-items: stretch; min-width: 1160px;
}
.schedule-grid > div { min-width: 0; padding: 8px 9px; border-right: 1px solid #eef2f7; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.schedule-grid > div:last-child { border-right: 0; }
.schedule-head > div:nth-child(4),
.schedule-head > div:nth-child(7),
.schedule-head > div:nth-child(8),
.schedule-head > div:nth-child(9),
.schedule-row > div:nth-child(4),
.schedule-row > div:nth-child(7),
.schedule-row > div:nth-child(8),
.schedule-row > div:nth-child(9) { text-align: right; }
.schedule-head { position: sticky; top: 0; z-index: 3; color: #64748b; background: #f8fafc; border-bottom: 1px solid var(--border); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.schedule-row { min-height: 38px; border-bottom: 1px solid #edf1f5; }
.row-root { min-height: 52px; }
.row-template { min-height: 44px; }
.row-group, .row-task { min-height: 32px; }
.schedule-row:hover { filter: brightness(.988); }
.row-root { background: #f8fafc; font-weight: 600; }
.row-template { background: #eff6ff; }
.row-group { background: #fffbeb; }
.row-task { background: #fff; }
.row-control { background: #ffe4e6; box-shadow: inset 12px 0 #f43f5e; }
.row-control.control-sensor { background: #cffafe; box-shadow: inset 12px 0 #06b6d4; }
.date-divider { padding: 7px 11px; color: #475569; background: #eef2f7; border-bottom: 1px solid #dbe3ec; font-size: 10px; font-weight: 700; }
.name-cell { display: flex; align-items: center; gap: 5px; padding-left: calc(9px + var(--depth) * 19px) !important; }
.tree-toggle { width: 18px; height: 18px; flex: 0 0 18px; display: grid; place-items: center; padding: 0; color: #475569; background: #fff; border: 1px solid #cbd5e1; border-radius: 4px; line-height: 1; }
.tree-spacer { width: 18px; flex: 0 0 18px; }
.entity-name { min-width: 0; display: grid; align-content: center; gap: 1px; }
.entity-title { min-width: 0; display: flex; align-items: baseline; gap: 5px; }
.entity-name strong { overflow: hidden; text-overflow: ellipsis; }
.entity-name small { color: #94a3b8; font-family: Consolas, monospace; font-size: 9px; font-weight: 600; }
.entity-name .entity-count { display: block; overflow: hidden; text-overflow: ellipsis; font-family: inherit; font-size: 9px; }
.ppid-cell { display: grid; align-content: center; gap: 1px; }
.ppid-cell small { color: #64748b; font-size: 9px; font-weight: 400; }
.ppid-cell .executor-name { color: #64748b; font-family: inherit; font-size: 10px; font-weight: 600; text-align: center; }
.ppid-cell .server-badge { display: inline-flex; justify-self: center; padding: 2px 5px; border-radius: 4px; color: #475569; background: #e2e8f0; font-size: 8px; font-weight: 700; }
.row-task .ppid-cell, .row-control .ppid-cell { display: flex; align-items: center; justify-content: center; gap: 6px; }
.state-badge { display: inline-flex; align-items: center; min-height: 20px; padding: 3px 7px; border-radius: 999px; color: #475569; background: #f1f5f9; font-size: 9px; font-weight: 700; }
.state-running, .state-restarting { color: #1d4ed8; background: #dbeafe; }
.state-success { color: #047857; background: #d1fae5; }
.state-failed, .state-upstream-failed { color: #b91c1c; background: #fee2e2; }
.state-waiting, .state-queued, .state-scheduled, .state-pending { color: #92400e; background: #fef3c7; }
.state-warning { color: #a16207; background: #fef9c3; }
.state-skipped { color: #6b7280; background: #e5e7eb; }
.state-incomplete { color: #7e22ce; background: #f3e8ff; }
.empty-state { padding: 55px 18px; color: #8793a5; background: #fff; text-align: center; }

.app-footer { display: flex; justify-content: space-between; gap: 12px; padding: 0 22px 12px; color: #94a3b8; font-size: 10px; }

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: radial-gradient(circle at top, #eef4ff 0, #f8fafc 50%); }
.login-shell { width: 100%; max-width: 390px; }
.login-card { padding: 30px; border: 1px solid var(--border); border-radius: 16px; background: #fff; box-shadow: 0 16px 45px rgba(15, 23, 42, .10); }
.login-card > .brand-mark { margin-bottom: 18px; }
.login-heading h1 { margin: 0; font-size: 20px; }
.login-heading p { margin: 7px 0 22px; color: var(--muted); }
.login-form { display: grid; gap: 8px; }
.login-form label { margin-top: 6px; color: #334155; font-weight: 600; }
.login-form input { width: 100%; height: 38px; padding: 8px 10px; color: var(--text); background: #fff; border: 1px solid #cbd5e1; border-radius: 7px; outline: none; }
.login-form input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.login-button { width: 100%; height: 38px; margin-top: 12px; font-weight: 600; }
.login-error { margin-bottom: 14px; padding: 9px 10px; border-radius: 7px; color: #991b1b; background: #fef2f2; }

@media (max-width: 700px) {
    body { font-size: 13px; }
    .desktop-only { display: none !important; }
    .mobile-only { display: block; }
    .app-header { min-height: 57px; padding: 9px 12px; }
    .brand-row { gap: 8px; }
    .brand-mark { width: 33px; height: 33px; font-size: 17px; }
    .app-header h1 { font-size: 13px; }
    .readonly-badge { display: none; }
    .header-actions { gap: 6px; }
    .primary-button, .secondary-button { min-height: 32px; padding: 5px 8px; }
    .content-shell { padding: 11px 10px 17px; }
    .status-strip { padding: 2px 2px 10px; font-size: 10px; }
    #status-text { display: none; }
    .mobile-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-bottom: 9px; }
    .mobile-summary article { padding: 10px; border: 1px solid var(--border); border-radius: 9px; background: #fff; box-shadow: var(--shadow); }
    .mobile-summary span { display: block; color: var(--muted); font-size: 10px; }
    .mobile-summary strong { display: block; margin-top: 3px; font-size: 19px; }
    .mobile-runs { display: grid; gap: 8px; }
    .mobile-run { padding: 12px; border: 1px solid var(--border); border-left: 4px solid var(--blue); border-radius: 10px; background: #fff; box-shadow: var(--shadow); }
    .mobile-run-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
    .mobile-run-head strong { min-width: 0; overflow-wrap: anywhere; font-size: 13px; }
    .mobile-run dl { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 5px 7px; margin: 0; font-size: 11px; }
    .mobile-run dt { color: #94a3b8; }
    .mobile-run dd { min-width: 0; margin: 0; color: #334155; overflow-wrap: anywhere; }
    .app-footer { padding: 0 10px 10px; justify-content: flex-end; font-size: 9px; }
    .app-footer span:first-child { display: none; }
}
